give basic on/off BLE signaling

debouncing could be better
This commit is contained in:
Morgan 'ARR\!' Allen 2021-09-22 20:14:19 -07:00
parent e2f7b6a391
commit e3f35e4389

View file

@ -17,24 +17,26 @@ static void IRAM_ATTR gpio_isr_handler(void* arg) {
static void gpio_task(void* arg) {
uint32_t io_num;
uint8_t on = 1;
uint8_t off = 0;
uint8_t state = 0;
int8_t last_level = -1;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
uint8_t level = gpio_get_level(io_num);
if(level == last_level) continue;
last_level = level;
printf("GPIO[%d] intr, val: %d\n", io_num, level);
if(state == 0)
vTaskDelay(10 / portTICK_RATE_MS);
pumps_run();
ble_send_notification((void*)&on, 1);
state = !state;
// just a wee debounce
vTaskDelay(500 / portTICK_PERIOD_MS);
ble_send_notification((void*)&off, 1);
xQueueReset(gpio_evt_queue);
ble_send_notification((void*)&state, 1);
}
}
}
@ -42,7 +44,7 @@ static void gpio_task(void* arg) {
void user_button_init() {
gpio_config_t io_conf;
io_conf.intr_type = GPIO_PIN_INTR_NEGEDGE;
io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << GPIO_USER_BUTTON);
io_conf.pull_down_en = 0;
@ -54,5 +56,5 @@ void user_button_init() {
xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 10, NULL);
gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_USER_BUTTON, gpio_isr_handler, (void*) 0);
gpio_isr_handler_add(GPIO_USER_BUTTON, gpio_isr_handler, (void*)GPIO_USER_BUTTON);
}