diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bef5fd..3a89bbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ add_executable(vibe-check src/main.c src/state.c src/vibe_bt.c - src/buttons.c ) target_link_libraries(vibe-check diff --git a/src/buttons.c b/src/buttons.c deleted file mode 100644 index d8de504..0000000 --- a/src/buttons.c +++ /dev/null @@ -1,78 +0,0 @@ -#include "buttons.h" -#include "btstack.h" -#include "hardware/gpio.h" -#include "pico/stdlib.h" -#include "state.h" -#include "vibe_bt.h" -#include - -#define POLL_PERIOD_MS 100 - -#define BUTTON_PIN_POWER 20 -#define BUTTON_PIN_PLUS 19 -#define BUTTON_PIN_MINUS 18 - -#define BUTTON_STEP 25 - -static btstack_timer_source_t button_timer; - -// What power do we return to when the power button is pressed while off? -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 (bt_connected) { - printf("=> Ignoring input, bluetooth connected.\n"); - } else if (target_power == 0) { - printf("= Resuming: %i%% -> %i%%\n", target_power, resume_power); - state_set_power(resume_power); - } else { - printf("= Suspending: %i%% -> %i%%\n", target_power, resume_power); - resume_power = target_power; - state_set_power(0); - } - } - - if (gpio_get(BUTTON_PIN_PLUS)) { - if (bt_connected) { - printf("+> Ignoring input, bluetooth connected.\n"); - } else if (target_power <= (100 - BUTTON_STEP)) { - printf("+ Increasing power: %i%% -> %i%%\n", target_power, target_power + BUTTON_STEP); - state_set_power(target_power + BUTTON_STEP); - } else { - printf("+ Increasing power: %i%% -> %i%%\n", target_power, 100); - state_set_power(100); - } - } - if (gpio_get(BUTTON_PIN_MINUS)) { - if (bt_connected) { - printf("-> Ignoring input, bluetooth connected.\n"); - } else if (target_power >= BUTTON_STEP) { - printf("- Reducing power: %i%% -> %i%%\n", target_power, target_power - BUTTON_STEP); - state_set_power(target_power - BUTTON_STEP); - } else { - printf("- Reducing power: %i%% -> %i%%\n", target_power, 0); - state_set_power(0); - } - } - - btstack_run_loop_set_timer(ts, POLL_PERIOD_MS); - btstack_run_loop_add_timer(ts); -} - -void buttons_init() { - gpio_set_dir(BUTTON_PIN_POWER, GPIO_IN); - gpio_set_dir(BUTTON_PIN_PLUS, GPIO_IN); - gpio_set_dir(BUTTON_PIN_MINUS, GPIO_IN); - - button_timer.process = button_timer_callback; - button_timer.process(&button_timer); - - // Why do these not trigger?? - // printf("Setting interrupts for buttons...\n"); - // gpio_set_irq_callback(button_callback); - // gpio_set_irq_enabled(BUTTON_PIN_POWER, BUTTON_EVENTS, true); - // gpio_set_irq_enabled(BUTTON_PIN_PLUS, BUTTON_EVENTS, true); - // gpio_set_irq_enabled(BUTTON_PIN_MINUS, BUTTON_EVENTS, true); -} diff --git a/src/buttons.h b/src/buttons.h deleted file mode 100644 index 0321902..0000000 --- a/src/buttons.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef BUTTONS_H -#define BUTTONS_H - -void buttons_init(); - -#endif diff --git a/src/main.c b/src/main.c index 90f927d..7207dc2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,4 @@ #include "btstack.h" -#include "buttons.h" #include "hci_dump.h" #include "hci_dump_segger_rtt_stdout.h" #include "pico/btstack_cyw43.h" @@ -47,9 +46,6 @@ int main() { // set initial state state_init(); - // hook up buttons - buttons_init(); - att_server_init(profile_data, bt_att_read_callback, bt_att_write_callback); hci_event_callback_registration.callback = &bt_packet_handler;