app: display bluetooth status/search

This commit is contained in:
King Kévin 2021-06-24 20:26:34 +02:00
parent dc822fd341
commit bc06b38260
1 changed files with 13 additions and 0 deletions

View File

@ -805,17 +805,30 @@ void main(void)
led_toggle(); // toggle LED (good to indicate if main function is stuck)
}
if (0 == (rtc_get_counter_val() % (RTC_TICKS_SECOND * 11))) { // 11 seconds have passed, time to check BT audio state
static bool bt_search = false; // set when searching audio device
if (0 == btaudio_status) {
puts("BT audio off, switching on\n");
gpio_set(GPIO_PORT(BTAUDIO_BUTTON_PIN), GPIO_PIN(BTAUDIO_BUTTON_PIN)); // press button to switch on
sleep_ms(BTAUDIO_ON); // keep pressed
gpio_clear(GPIO_PORT(BTAUDIO_BUTTON_PIN), GPIO_PIN(BTAUDIO_BUTTON_PIN)); // release button
led_tm1637_text("bton"); // show on display we are switching Bluetooth on
led_tm1637_on(); // switch on display
} else if (btaudio_status <= 2) {
puts("BT audio connected\n");
if (bt_search) { // we just searched before
led_tm1637_off(); // stop displaying we are searching
bt_search = false; // clear flag
}
} else if (btaudio_status <= 6) {
puts("BT audio disconnected\n");
led_tm1637_text("btof"); // show on display we are disconnected
led_tm1637_on(); // switch on display
bt_search = true; // remember we are searching (no actively re-pairing)
} else {
puts("BT audio searching\n");
led_tm1637_text("btsc"); // show on display we are searching
led_tm1637_on(); // switch on display
bt_search = true; // remember we are searching (with re-pairing)
}
btaudio_status = 0; // reset counter
}