state: what if up/down had different ramp speeds

This commit is contained in:
embr 2023-05-02 01:31:47 +02:00
parent e7129abc6a
commit 589ca48d64

View file

@ -13,17 +13,18 @@ uint16_t current_power = 0;
uint16_t target_power = 0; uint16_t target_power = 0;
#define RAMP_PERIOD_MS 1 #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 // 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. // chip with electrical ripples, so be a bit gentle about it.
static btstack_timer_source_t ramp_timer; static btstack_timer_source_t ramp_timer;
static void ramp_timer_callback(struct btstack_timer_source* ts) { static void ramp_timer_callback(struct btstack_timer_source* ts) {
if (current_power != target_power) { if (current_power != target_power) {
if (current_power < target_power - RAMP_STEP) { if (current_power < target_power - RAMP_STEP_UP) {
current_power += RAMP_STEP; current_power += RAMP_STEP_UP;
} else if (current_power > target_power + RAMP_STEP) { } else if (current_power > target_power + RAMP_STEP_DOWN) {
current_power -= RAMP_STEP; current_power -= RAMP_STEP_DOWN;
} else { } else {
current_power = target_power; current_power = target_power;
} }