state: what if up/down had different ramp speeds
This commit is contained in:
parent
e7129abc6a
commit
589ca48d64
11
src/state.c
11
src/state.c
|
@ -13,17 +13,18 @@ uint16_t current_power = 0;
|
|||
uint16_t target_power = 0;
|
||||
|
||||
#define RAMP_PERIOD_MS 1
|
||||
#define RAMP_STEP 200
|
||||
#define RAMP_STEP_UP 200
|
||||
#define RAMP_STEP_DOWN 50
|
||||
|
||||
// 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.
|
||||
static btstack_timer_source_t ramp_timer;
|
||||
static void ramp_timer_callback(struct btstack_timer_source* ts) {
|
||||
if (current_power != target_power) {
|
||||
if (current_power < target_power - RAMP_STEP) {
|
||||
current_power += RAMP_STEP;
|
||||
} else if (current_power > target_power + RAMP_STEP) {
|
||||
current_power -= RAMP_STEP;
|
||||
if (current_power < target_power - RAMP_STEP_UP) {
|
||||
current_power += RAMP_STEP_UP;
|
||||
} else if (current_power > target_power + RAMP_STEP_DOWN) {
|
||||
current_power -= RAMP_STEP_DOWN;
|
||||
} else {
|
||||
current_power = target_power;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue