WIP state
This commit is contained in:
parent
bdeb2b85e7
commit
a91462d6db
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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 <stdio.h>
|
||||
|
@ -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;
|
||||
|
|
10
src/state.c
Normal file
10
src/state.c
Normal file
|
@ -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!
|
||||
}
|
12
src/state.h
Normal file
12
src/state.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef HARDWARE_H
|
||||
#define HARDWARE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Initializes wand state.
|
||||
void state_init();
|
||||
|
||||
// Sets the wand's power, 0-100.
|
||||
void state_set_power(uint8_t power);
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include "vibe_bt.h"
|
||||
#include "state.h"
|
||||
#include "vibe.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue