You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.8 KiB

3 months ago
3 months ago
  1. export const cmdNameMap = {
  2. door_open: '开门',
  3. door_close: '关门',
  4. door_stop: '停止开关门',
  5. liquid_arm_rotation: '加液机械臂启动',
  6. liquid_arm_reset: '加液机械臂复位',
  7. liquid_arm_stop: '加液机械臂停止',
  8. liquid_pump_start: '启动加液泵',
  9. liquid_pump_stop: '停止加液泵',
  10. liquid_pump_pre_filling: '预充加液头',
  11. liquid_pump_pre_evacuation: '排空加液头',
  12. shaker_start: '摇匀',
  13. shaker_stop: '停止摇匀',
  14. pallet_elevator_lift_up: '托盘上升',
  15. pallet_elevator_lift_down: '托盘下降',
  16. pallet_elevator_stop: '托盘停止',
  17. heater_start: '开始加热',
  18. heater_stop: '停止加热',
  19. heater_start_heat_maintaining: '启动恒温',
  20. heater_stop_heat_maintaining: '停止恒温',
  21. cold_trap_start_refrigeration: '启动制冷',
  22. cold_trap_stop_refrigeration: '停止制冷',
  23. fan_start: '打开风扇',
  24. fan_stop: '关闭风扇',
  25. transportation_arm_move: '龙门架机械臂移动',
  26. transportation_arm_stop: '龙门架机械臂停止移动',
  27. transportation_arm_reset: '龙门架机械臂复位',
  28. holding_jaw_open: '打开夹爪',
  29. holding_jaw_pause: '暂停夹爪',
  30. holding_jaw_close: '闭合夹爪',
  31. cover_elevator_lift_up: '拍子抬升',
  32. cover_elevator_stop: '拍子停止',
  33. cover_elevator_reset: '拍子复位',
  34. cover_elevator_lift_down: '拍子下降',
  35. cold_trap_start_recycle: '开启循环',
  36. cold_trap_stop_recycle: '停止循环',
  37. solution_add: '加液',
  38. move_to_heat_area: '移至加热',
  39. move_to_solution_area: '移至加液',
  40. heat_start: '开始加热',
  41. heat_stop: '停止加热',
  42. take_photo: '拍照',
  43. tray_up: '抬起托盘',
  44. tray_down: '降下托盘',
  45. shake_start: '开始摇匀',
  46. shake_stop: '停止摇匀',
  47. dual_robot_joint_origin: '加液机械臂回原点',
  48. gantry_x_origin: '机械臂x轴回原点',
  49. gantry_y_origin: '机械臂y轴回原点',
  50. gantry_z_origin: '机械臂z轴回原点',
  51. cap_lifting_origin: '拍子电机回原点',
  52. tray_lifting_origin: '加热区托盘电机回原点',
  53. }
  54. export const generateColors = (count: number): string[] => {
  55. const colors: string[] = []
  56. for (let i = 0; i < count; i++) {
  57. // Increase hue step to make colors more distinct
  58. const hue = (i * 360) / count
  59. // Introduce variation in saturation and lightness with larger steps
  60. const saturation = 30 + (i % 5) * 20 // Alternate between 30, 50, 70, 90, 110
  61. const lightness = 30 + (i % 4) * 20 // Alternate between 30, 50, 70, 90
  62. // Convert HSL to RGB
  63. const rgb = hslToRgb(hue, saturation, lightness)
  64. // Convert RGB to hex
  65. const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
  66. colors.push(hex)
  67. }
  68. return colors
  69. }
  70. const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
  71. s /= 100
  72. l /= 100
  73. const k = (n: number) => (n + h / 30) % 12
  74. const a = s * Math.min(l, 1 - l)
  75. const f = (n: number) =>
  76. l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))
  77. return {
  78. r: Math.round(f(0) * 255),
  79. g: Math.round(f(8) * 255),
  80. b: Math.round(f(4) * 255),
  81. }
  82. }
  83. const rgbToHex = (r: number, g: number, b: number): string => {
  84. const toHex = (c: number) => `0${c.toString(16)}`.slice(-2)
  85. return `#${toHex(r)}${toHex(g)}${toHex(b)}`
  86. }
  87. export const colors = generateColors(100)
  88. export function isNumber(value: any) {
  89. return typeof value === 'number' && !Number.isNaN(value)
  90. }
  91. export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss'): string {
  92. const now = new Date()
  93. const tokens: Record<string, string> = {
  94. YYYY: String(now.getFullYear()),
  95. MM: String(now.getMonth() + 1).padStart(2, '0'),
  96. DD: String(now.getDate()).padStart(2, '0'),
  97. HH: String(now.getHours()).padStart(2, '0'),
  98. mm: String(now.getMinutes()).padStart(2, '0'),
  99. ss: String(now.getSeconds()).padStart(2, '0'),
  100. }
  101. return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
  102. }