forked from EmbeddedTeam/app_photomagnetic
feat: Parameterize heating start with configurable duty cycle
This commit is contained in:
+15
-3
@@ -32,8 +32,13 @@ public:
|
||||
s_active = true;
|
||||
}
|
||||
|
||||
static auto StartFullEnergy() -> void {
|
||||
pwm_set_pulse_dt(&s_pwm_spec, s_pwm_spec.period);
|
||||
/// Start PWM with raw duty cycle (0.0 ~ 1.0).
|
||||
static auto Start(float duty_cycle) -> void {
|
||||
duty_cycle = std::clamp(duty_cycle, 0.0f, 1.0f);
|
||||
const uint32_t pulse =
|
||||
static_cast<uint32_t>(s_pwm_spec.period * duty_cycle);
|
||||
pwm_set_pulse_dt(&s_pwm_spec, pulse);
|
||||
s_active = true;
|
||||
}
|
||||
|
||||
static auto Stop() -> void {
|
||||
@@ -42,7 +47,14 @@ public:
|
||||
pwm_set_pulse_dt(&s_pwm_spec, 0);
|
||||
}
|
||||
|
||||
static auto CurrentTemp() -> sensor_value { return s_current_temp; }
|
||||
static auto CurrentTemp() -> sensor_value {
|
||||
if (sensor_sample_fetch(s_temp_sensor) == 0) {
|
||||
sensor_value temp;
|
||||
sensor_channel_get(s_temp_sensor, SENSOR_CHAN_AMBIENT_TEMP, &temp);
|
||||
s_current_temp = temp;
|
||||
}
|
||||
return s_current_temp;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kPeriodNs = PWM_KHZ(5);
|
||||
|
||||
Reference in New Issue
Block a user