基质喷涂
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.

65 lines
1.6 KiB

  1. //
  2. // Created by iflyt on 2025/3/13.
  3. //
  4. #ifndef LASER_CONTROL_H
  5. #define LASER_CONTROL_H
  6. // 宏定义激光设备相关管脚
  7. #define LASER_PWM_PIN GPIO_PIN_13 // PWM 控制
  8. #define LASER_PWM_PORT GPIOD
  9. #define LASER_EN_PIN GPIO_PIN_12 // 使能
  10. #define LASER_EN_PORT GPIOE
  11. // 宏定义定时器和通道
  12. #define LASER_TIMER_HANDLE TIM4 // 这里需要根据实际情况替换为正确的定时器
  13. #define LASER_TIMER_CHANNEL 2 // 这里需要根据实际情况替换为正确的通道
  14. // 定义最大最小功率和最大最小频率的宏
  15. #define MIN_POWER 0.0
  16. #define MAX_POWER 100.0
  17. #define MIN_POWER_DUTY 0.0
  18. #define MAX_POWER_DUTY 10000.0
  19. #include <cstdint>
  20. class LaserControl {
  21. public:
  22. LaserControl();
  23. ~LaserControl();
  24. // 初始化激光设备
  25. void init(const bool isFlip);
  26. // 使能激光设备
  27. void powerOn();
  28. // 关闭激光设备
  29. void powerOff();
  30. // 设置激光设备功率
  31. void setPower(double power);
  32. private:
  33. void initGPIO();
  34. // 设置 PWM 频率,从而控制功率
  35. void setDutyCycle(uint32_t dutyCycle) const;
  36. int calculateDutyCycle(int voltage) const;
  37. private:
  38. // 存储电压和占空比起止对应关系的数组
  39. const int minVDutyCycle = MIN_POWER_DUTY;
  40. const int maxVDutyCycle = MAX_POWER_DUTY;
  41. bool isFlip_ { true }; // 占空比和电压反转
  42. const uint32_t standardFrequency_ = 10000; // 默认占空比
  43. const uint32_t standardDutyCycle_ = 0; // 50
  44. int32_t power_ { (int32_t)MIN_POWER };
  45. bool isPowerOn_{false}; // 当前是否上电
  46. int32_t dutyCycle_ { 0 }; // 占空比
  47. };
  48. #endif //LASER_CONTROL_H