state: track ramp in 100ths of %s
This commit is contained in:
parent
c8f83cbc5f
commit
e7129abc6a
13
src/state.c
13
src/state.c
|
@ -8,11 +8,12 @@
|
|||
|
||||
static int pwm_slice = 0;
|
||||
|
||||
uint8_t current_power = 0;
|
||||
uint8_t target_power = 0;
|
||||
// Note: These are all in % of a %, eg. 100% = 10000.
|
||||
uint16_t current_power = 0;
|
||||
uint16_t target_power = 0;
|
||||
|
||||
#define RAMP_PERIOD_MS 1
|
||||
#define RAMP_STEP 2
|
||||
#define RAMP_STEP 200
|
||||
|
||||
// Timer and callback for ramping power. Jumping ~50% power or more in one go kills the
|
||||
// chip with electrical ripples, so be a bit gentle about it.
|
||||
|
@ -26,8 +27,8 @@ static void ramp_timer_callback(struct btstack_timer_source* ts) {
|
|||
} else {
|
||||
current_power = target_power;
|
||||
}
|
||||
pwm_set_chan_level(pwm_slice, PWM_CHAN_A, current_power);
|
||||
pwm_set_chan_level(pwm_slice, PWM_CHAN_B, current_power);
|
||||
pwm_set_chan_level(pwm_slice, PWM_CHAN_A, current_power / 100);
|
||||
pwm_set_chan_level(pwm_slice, PWM_CHAN_B, current_power / 100);
|
||||
}
|
||||
|
||||
btstack_run_loop_set_timer(ts, RAMP_PERIOD_MS);
|
||||
|
@ -52,5 +53,5 @@ void state_set_power(uint8_t power) {
|
|||
if (power > 100) {
|
||||
power = 100;
|
||||
}
|
||||
target_power = power;
|
||||
target_power = power * 100;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
// Current power level, 0-100.
|
||||
extern uint8_t current_power;
|
||||
// Target power level (that we're ramping to), 0-100.
|
||||
extern uint8_t target_power;
|
||||
|
||||
// Initialize wand state.
|
||||
void state_init();
|
||||
|
||||
|
|
Loading…
Reference in a new issue