| 109 | // bluetooth_add_event_callback() to receive events directly. |
| 110 | |
| 111 | static void bt_event_bridge(Device*, void* /*context*/, BtEvent event) { |
| 112 | switch (event.type) { |
| 113 | case BT_EVENT_RADIO_STATE_CHANGED: |
| 114 | switch (event.radio_state) { |
| 115 | case BT_RADIO_STATE_ON: |
| 116 | getMainDispatcher().dispatch([] { |
| 117 | auto peers = settings::loadAll(); |
| 118 | bool has_hid_host_auto = false; |
| 119 | bool has_hid_device_auto = false; |
| 120 | for (const auto& p : peers) { |
| 121 | if (!p.autoConnect) continue; |
| 122 | if (p.profileId == BT_PROFILE_HID_HOST) has_hid_host_auto = true; |
| 123 | if (p.profileId == BT_PROFILE_HID_DEVICE) has_hid_device_auto = true; |
| 124 | } |
| 125 | if (has_hid_host_auto) { |
| 126 | LOGGER.info("HID host auto-connect peer found — starting scan"); |
| 127 | if (Device* dev = device_find_first_active_by_type(&BLUETOOTH_TYPE)) { |
| 128 | bluetooth_scan_start(dev); |
| 129 | } |
| 130 | } else if (has_hid_device_auto) { |
| 131 | LOGGER.info("HID device auto-start (bonded peer found)"); |
| 132 | if (Device* dev = bluetooth_hid_device_get_device()) { |
| 133 | bluetooth_hid_device_start(dev, BT_HID_DEVICE_MODE_KEYBOARD); |
| 134 | } |
| 135 | } else { |
| 136 | if (settings::shouldSppAutoStart()) { |
| 137 | LOGGER.info("Auto-starting SPP server"); |
| 138 | if (Device* dev = bluetooth_serial_get_device()) { |
| 139 | bluetooth_serial_start(dev); |
| 140 | } |
| 141 | } |
| 142 | if (settings::shouldMidiAutoStart()) { |
| 143 | LOGGER.info("Auto-starting MIDI server"); |
| 144 | if (Device* dev = bluetooth_midi_get_device()) { |
| 145 | bluetooth_midi_start(dev); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | }); |
| 150 | break; |
| 151 | default: |
| 152 | break; |
| 153 | } |
| 154 | break; |
| 155 | |
| 156 | case BT_EVENT_SCAN_STARTED: |
| 157 | { |
| 158 | auto lock = scan_cache_mutex.asScopedLock(); |
| 159 | lock.lock(); |
| 160 | scan_results_cache.clear(); |
| 161 | scan_addr_cache.clear(); |
| 162 | } |
| 163 | break; |
| 164 | |
| 165 | case BT_EVENT_SCAN_FINISHED: |
| 166 | getMainDispatcher().dispatch([] { autoConnectHidHost(); }); |
| 167 | break; |
| 168 |
nothing calls this directly
no test coverage detected