ignore buttons if bluetooth is connected
This commit is contained in:
parent
34d94d3ee5
commit
5dc32c9136
|
@ -3,6 +3,7 @@
|
|||
#include "hardware/gpio.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "state.h"
|
||||
#include "vibe_bt.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define POLL_PERIOD_MS 100
|
||||
|
@ -21,7 +22,9 @@ static uint8_t resume_power = 50;
|
|||
static void button_timer_callback(struct btstack_timer_source* ts) {
|
||||
// TODO: Debounce this.
|
||||
if (gpio_get(BUTTON_PIN_POWER)) {
|
||||
if (current_power == 0) {
|
||||
if (bt_connected) {
|
||||
printf("=> Ignoring input, bluetooth connected.\n");
|
||||
} else if (current_power == 0) {
|
||||
printf("= Resuming: %i%% -> %i%%\n", current_power, resume_power);
|
||||
state_set_power(resume_power);
|
||||
} else {
|
||||
|
@ -32,13 +35,25 @@ static void button_timer_callback(struct btstack_timer_source* ts) {
|
|||
}
|
||||
|
||||
if (gpio_get(BUTTON_PIN_PLUS)) {
|
||||
state_set_power(current_power + BUTTON_STEP);
|
||||
if (bt_connected) {
|
||||
printf("+> Ignoring input, bluetooth connected.\n");
|
||||
} else if (current_power <= (100 - BUTTON_STEP)) {
|
||||
printf("+ Increasing power: %i%% -> %i%%\n", current_power, current_power + BUTTON_STEP);
|
||||
state_set_power(current_power + BUTTON_STEP);
|
||||
} else {
|
||||
printf("+ Increasing power: %i%% -> %i%%\n", current_power, 100);
|
||||
state_set_power(100);
|
||||
}
|
||||
}
|
||||
if (gpio_get(BUTTON_PIN_MINUS)) {
|
||||
if (current_power < BUTTON_STEP) {
|
||||
state_set_power(0);
|
||||
} else {
|
||||
if (bt_connected) {
|
||||
printf("-> Ignoring input, bluetooth connected.\n");
|
||||
} else if (current_power >= BUTTON_STEP) {
|
||||
printf("- Reducing power: %i%% -> %i%%\n", current_power, current_power - BUTTON_STEP);
|
||||
state_set_power(current_power - BUTTON_STEP);
|
||||
} else {
|
||||
printf("- Reducing power: %i%% -> %i%%\n", current_power, 0);
|
||||
state_set_power(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue