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.

110 lines
3.9 KiB

3 months ago
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. door_origin: '门电机回原点',
  54. }
  55. export const generateColors = (count: number): string[] => {
  56. const colors: string[] = []
  57. for (let i = 0; i < count; i++) {
  58. // Increase hue step to make colors more distinct
  59. const hue = (i * 360) / count
  60. // Introduce variation in saturation and lightness with larger steps
  61. const saturation = 30 + (i % 5) * 20 // Alternate between 30, 50, 70, 90, 110
  62. const lightness = 30 + (i % 4) * 20 // Alternate between 30, 50, 70, 90
  63. // Convert HSL to RGB
  64. const rgb = hslToRgb(hue, saturation, lightness)
  65. // Convert RGB to hex
  66. const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
  67. colors.push(hex)
  68. }
  69. return colors
  70. }
  71. const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
  72. s /= 100
  73. l /= 100
  74. const k = (n: number) => (n + h / 30) % 12
  75. const a = s * Math.min(l, 1 - l)
  76. const f = (n: number) =>
  77. l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))
  78. return {
  79. r: Math.round(f(0) * 255),
  80. g: Math.round(f(8) * 255),
  81. b: Math.round(f(4) * 255),
  82. }
  83. }
  84. const rgbToHex = (r: number, g: number, b: number): string => {
  85. const toHex = (c: number) => `0${c.toString(16)}`.slice(-2)
  86. return `#${toHex(r)}${toHex(g)}${toHex(b)}`
  87. }
  88. export const colors = generateColors(100)
  89. export function isNumber(value: any) {
  90. return typeof value === 'number' && !Number.isNaN(value)
  91. }
  92. export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss'): string {
  93. const now = new Date()
  94. const tokens: Record<string, string> = {
  95. YYYY: String(now.getFullYear()),
  96. MM: String(now.getMonth() + 1).padStart(2, '0'),
  97. DD: String(now.getDate()).padStart(2, '0'),
  98. HH: String(now.getHours()).padStart(2, '0'),
  99. mm: String(now.getMinutes()).padStart(2, '0'),
  100. ss: String(now.getSeconds()).padStart(2, '0'),
  101. }
  102. return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
  103. }