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.
|
|
//
// Created by iflyt on 2025/3/13.
//
#ifndef LASER_CONTROL_H
#define LASER_CONTROL_H
// 宏定义激光设备相关管脚
#define LASER_PWM_PIN GPIO_PIN_13 // PWM 控制
#define LASER_PWM_PORT GPIOD
#define LASER_EN_PIN GPIO_PIN_12 // 使能
#define LASER_EN_PORT GPIOE
// 宏定义定时器和通道
#define LASER_TIMER_HANDLE TIM4 // 这里需要根据实际情况替换为正确的定时器
#define LASER_TIMER_CHANNEL 2 // 这里需要根据实际情况替换为正确的通道
// 定义最大最小功率和最大最小频率的宏
#define MIN_POWER 0.0
#define MAX_POWER 100.0
#define MIN_POWER_DUTY 0.0
#define MAX_POWER_DUTY 10000.0
#include <cstdint>
class LaserControl { public: LaserControl(); ~LaserControl();
// 初始化激光设备
void init(const bool isFlip);
// 使能激光设备
void powerOn(); // 关闭激光设备
void powerOff();
// 设置激光设备功率
void setPower(double power);
private: void initGPIO();
// 设置 PWM 频率,从而控制功率
void setDutyCycle(uint32_t dutyCycle) const;
int calculateDutyCycle(int voltage) const;
private: // 存储电压和占空比起止对应关系的数组
const int minVDutyCycle = MIN_POWER_DUTY; const int maxVDutyCycle = MAX_POWER_DUTY; bool isFlip_ { true }; // 占空比和电压反转
const uint32_t standardFrequency_ = 10000; // 默认占空比
const uint32_t standardDutyCycle_ = 0; // 50
int32_t power_ { (int32_t)MIN_POWER }; bool isPowerOn_{false}; // 当前是否上电
int32_t dutyCycle_ { 0 }; // 占空比
};
#endif //LASER_CONTROL_H
|