diff --git a/geeksville-private/TODO.md b/geeksville-private/TODO.md index e4916490f..4916d94d2 100644 --- a/geeksville-private/TODO.md +++ b/geeksville-private/TODO.md @@ -2,11 +2,7 @@ You probably don't care about this section - skip to the next one. -* disable bluetooth while wifi is active -* failed adding https service -* fix wifi connections for mqtt * send debug info 'in-band' - * usb lora dongle from pine64 * turn on watchdog reset if app hangs on nrf52 or esp32 * list portduino on platformio diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index d36541e57..cd95c91ed 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -21,6 +21,8 @@ static bool pinShowing; static uint32_t doublepressed; +static bool bluetoothActive; + static void startCb(uint32_t pin) { pinShowing = true; @@ -52,23 +54,27 @@ void updateBatteryLevel(uint8_t level) void deinitBLE() { - // DEBUG_MSG("Shutting down bluetooth\n"); - // ble_gatts_show_local(); + if (bluetoothActive) { + bluetoothActive = false; - // FIXME - do we need to dealloc things? - what needs to stay alive across light sleep? - auto ret = nimble_port_stop(); - assert(ret == ESP_OK); + // DEBUG_MSG("Shutting down bluetooth\n"); + // ble_gatts_show_local(); - nimble_port_deinit(); // teardown nimble datastructures + // FIXME - do we need to dealloc things? - what needs to stay alive across light sleep? + auto ret = nimble_port_stop(); + assert(ret == ESP_OK); - // DEBUG_MSG("BLE port_deinit done\n"); + nimble_port_deinit(); // teardown nimble datastructures - ret = esp_nimble_hci_and_controller_deinit(); - assert(ret == ESP_OK); + // DEBUG_MSG("BLE port_deinit done\n"); - // DEBUG_MSG("BLE task exiting\n"); + ret = esp_nimble_hci_and_controller_deinit(); + assert(ret == ESP_OK); - DEBUG_MSG("Done shutting down bluetooth\n"); + // DEBUG_MSG("BLE task exiting\n"); + + DEBUG_MSG("Done shutting down bluetooth\n"); + } } void loopBLE() @@ -479,6 +485,8 @@ void disablePin() doublepressed = millis(); } + + // This routine is called multiple times, once each time we come back from sleep void reinitBluetooth() { @@ -536,6 +544,7 @@ void reinitBluetooth() ble_store_config_init(); nimble_port_freertos_init(ble_host_task); + bluetoothActive = true; } bool bluetoothOn;