| 268 | } |
| 269 | |
| 270 | bool start(Device* dev) { |
| 271 | LOGGER.info("Auto-enabling BLE on boot"); |
| 272 | if (!device_is_ready(dev)) { |
| 273 | LOGGER.info("Starting BLE device"); |
| 274 | if (device_start(dev) != ERROR_NONE) { |
| 275 | LOGGER.error("Failed to start BLE device"); |
| 276 | return false; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // TODO: Fix bug where repeatedly calling start would add this callback multiple times |
| 281 | if (bluetooth_add_event_callback(dev, nullptr, bt_event_bridge) != ERROR_NONE) { |
| 282 | LOGGER.error("Failed to set BLE callback"); |
| 283 | } |
| 284 | |
| 285 | LOGGER.info("Enabling BT radio"); |
| 286 | if (bluetooth_set_radio_enabled(dev, true) != ERROR_NONE) { |
| 287 | LOGGER.error("Failed to enable BLE radio"); |
| 288 | // Add bridge again |
| 289 | bluetooth_remove_event_callback(dev, bt_event_bridge); |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | LOGGER.info("BT enabled"); |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | bool stop(Device* dev) { |
| 298 | BtRadioState state; |
no test coverage detected