diff --git a/CMakeLists.txt b/CMakeLists.txt index 39307be..d2a7445 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_executable(vibe-check # lib/rtt/RTT/SEGGER_RTT.c src/stdio_rtt.c src/main.c + src/state.c src/vibe_bt.c ) diff --git a/src/main.c b/src/main.c index 741e019..52ab993 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,7 @@ #include "pico/btstack_cyw43.h" #include "pico/cyw43_arch.h" #include "pico/stdlib.h" +#include "state.h" #include "stdio_rtt.h" #include "vibe_bt.h" #include @@ -38,6 +39,10 @@ int main() { l2cap_init(); sm_init(); + // set initial state + state_init(); + state_set_power(0); + att_server_init(profile_data, bt_att_read_callback, bt_att_write_callback); hci_event_callback_registration.callback = &bt_packet_handler; diff --git a/src/state.c b/src/state.c new file mode 100644 index 0000000..665b807 --- /dev/null +++ b/src/state.c @@ -0,0 +1,10 @@ +#include "state.h" + +void state_init() { + // TODO: Assign GPIO pins to PWM. + state_set_power(0); +} + +void state_set_power(uint8_t power) { + // TODO: Set power! +} diff --git a/src/state.h b/src/state.h new file mode 100644 index 0000000..0a6e097 --- /dev/null +++ b/src/state.h @@ -0,0 +1,12 @@ +#ifndef HARDWARE_H +#define HARDWARE_H + +#include + +// Initializes wand state. +void state_init(); + +// Sets the wand's power, 0-100. +void state_set_power(uint8_t power); + +#endif diff --git a/src/vibe_bt.c b/src/vibe_bt.c index 84d7adc..d515546 100644 --- a/src/vibe_bt.c +++ b/src/vibe_bt.c @@ -1,4 +1,5 @@ #include "vibe_bt.h" +#include "state.h" #include "vibe.h" #include @@ -104,9 +105,10 @@ int bt_att_write_callback( return 0; if (memcmp(buffer + 8, "\x00\x64\xDF\x55", 4) != 0) return 0; + uint8_t power = buffer[7]; - // In case it somehow came unset - bt_connected = true; - printf("!! Write of %d\n", buffer[7]); + bt_connected = true; // In case it somehow came unset + state_set_power(power); + printf("!! Setting power to %d%%\n", power); return 0; }