CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
BluetoothMenuUi.cpp File Reference

Bluetooth UI flow for toggling BLE, status display, and device scanning. More...

#include "AppUiInternal.h"
#include "cdc_os_ui/views/BlePairingView.h"
#include "cdc_hal/IBluetoothController.h"
#include "cdc_msg/MessageTransfer.h"
#include "cdc_views/RenderHelpers.h"
#include "cdc_log.h"
#include <cstdio>
#include <cstring>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_timer.h"

Go to the source code of this file.

Classes

class  cdc::ui::BleScanView
 ListView for the BLE scan results that drives async name resolution while visible and cancels it when the view closes. More...

Namespaces

namespace  cdc
namespace  cdc::ui
 Centralized key-code constants for cdc_views.

Typedefs

using cdc::ui::BleListenerToken = hal::IBluetoothController::ListenerToken

Enumerations

enum  cdc::ui::BluetoothMenuIdx {
  cdc::ui::BT_IDX_ENABLE = 0 , cdc::ui::BT_IDX_PAIR , cdc::ui::BT_IDX_PAIRED , cdc::ui::BT_IDX_STATUS ,
  cdc::ui::BT_IDX_SCAN , cdc::ui::BT_IDX_BEACON , cdc::ui::BT_IDX_FORGET_BONDS , cdc::ui::BT_IDX_FIXED_COUNT
}
 Bluetooth fixed menu indices and capacity limits. More...
enum class  cdc::ui::BleResolvePhase : uint8_t {
  cdc::ui::Idle , cdc::ui::Begin , cdc::ui::Connecting , cdc::ui::Discovering ,
  cdc::ui::Reading , cdc::ui::Settle
}

Functions

static void cdc::ui::onBluetoothMenuSelect (uint16_t index, void *userData)
 Handles Bluetooth menu selection.
static void cdc::ui::toggleBluetoothEnable ()
 Toggles BLE controller enabled state.
static void cdc::ui::showBluetoothStatus ()
 Shows BLE status and adapter information.
static void cdc::ui::startBluetoothScan ()
 Starts BLE scan and opens result list.
static void cdc::ui::showPairedDevices ()
 Shows the list of paired (bonded) devices.
static bool cdc::ui::renderBleRow (Gdey029T94 *gfx, const ListItem &item, uint16_t index, int x, int y, int w, int h, bool selected, void *userCtx)
 Renders one BLE scan row with signal bars and RSSI text.
static void cdc::ui::sortBleScanResults ()
 Sorts BLE scan results by RSSI descending.
void cdc::ui::rebuildBluetoothMenu ()
 Rebuilds Bluetooth menu entries and dynamic module items.
void cdc::ui::showBluetoothMenu ()
 Shows top-level Bluetooth menu.
static void cdc::ui::bleResolveStop ()
static void cdc::ui::bleResolveBeginNext (uint32_t nowMs)
 Starts resolving the next device that still shows its MAC.
static void cdc::ui::bleResolveMac (const hal::BleScanResult &d, char *out, size_t n)
 Formats a scan result's MAC the same way as the no-name fallback.
static bool cdc::ui::bleDeviceNeedsName (uint8_t i)
 True when the row still shows the MAC fallback (no name yet).
static void cdc::ui::bleResolveClearEvents ()
static void cdc::ui::rOnConnect (uint16_t connHandle)
static void cdc::ui::rOnDisconnect (uint16_t connHandle, int)
static void cdc::ui::rOnServiceDiscovered (uint16_t connHandle, const hal::IBluetoothController::DiscoveredService *svc, bool complete)
static void cdc::ui::rOnCharRead (uint16_t connHandle, uint16_t, const uint8_t *data, uint16_t len)
static void cdc::ui::bleResolveCleanupToSettle (uint32_t nowMs)
 Tears down the current attempt and waits briefly for a clean stack.
static void cdc::ui::bleResolveStart ()
static void cdc::ui::bleResolveTick (uint32_t nowMs)
static void cdc::ui::rebuildPairedList ()
 Rebuilds the paired-device list from the current bond store.
static void cdc::ui::onForgetConfirm (void *)
 Confirmed-forget handler: unpairs the selected device and refreshes.
static void cdc::ui::onPairedSelect (uint16_t index, void *userData)
 Asks for confirmation to forget the selected paired device.

Variables

static const char * cdc::ui::TAG = "BleMenu"
static constexpr uint8_t cdc::ui::BT_MENU_MAX_ITEMS = 16
static constexpr uint8_t cdc::ui::BLE_MAX_SCAN_RESULTS = hal::IBluetoothController::MAX_SCAN_RESULTS
static constexpr uint8_t cdc::ui::BLE_MAX_BONDS = hal::IBluetoothController::MAX_BONDED_DEVICES
static constexpr uint32_t cdc::ui::BLE_SCAN_TIMEOUT_MS = 8000
static ListViewcdc::ui::s_bluetoothMenu = nullptr
 Bluetooth menu and scan state.
static ListItem cdc::ui::s_bluetoothItems [BT_MENU_MAX_ITEMS]
static core::ModuleMenuItem cdc::ui::s_bluetoothModuleItems [12]
static uint8_t cdc::ui::s_bluetoothModuleCount = 0
static ListViewcdc::ui::s_bleScanView = nullptr
 BLE scan result list state.
static ListItem cdc::ui::s_bleScanItems [BLE_MAX_SCAN_RESULTS]
static hal::BleScanResult cdc::ui::s_bleScanResults [BLE_MAX_SCAN_RESULTS]
static uint8_t cdc::ui::s_bleScanCount = 0
static ListViewcdc::ui::s_pairedView = nullptr
 Paired (bonded) device list state.
static ListItem cdc::ui::s_pairedItems [BLE_MAX_BONDS]
static hal::BleBondInfo cdc::ui::s_pairedBonds [BLE_MAX_BONDS]
static char cdc::ui::s_pairedLabels [BLE_MAX_BONDS][24]
static uint8_t cdc::ui::s_pairedCount = 0
static hal::BleBondInfo cdc::ui::s_forgetTarget = {}
static constexpr size_t cdc::ui::BLE_STATUS_BUF_SIZE = 256
 PSRAM-backed text buffer used for BLE status details.
static char cdc::ui::s_bleStatusBuf [BLE_STATUS_BUF_SIZE]
static constexpr uint16_t cdc::ui::BLE_GAP_SVC_UUID = 0x1800
static constexpr uint16_t cdc::ui::BLE_DEV_NAME_UUID = 0x2A00
static constexpr uint32_t cdc::ui::BLE_RESOLVE_DEVICE_TIMEOUT_MS = 5000
static constexpr uint32_t cdc::ui::BLE_RESOLVE_SETTLE_TIMEOUT_MS = 800
static BleResolvePhase cdc::ui::s_resolvePhase = BleResolvePhase::Idle
static bool cdc::ui::s_resolveActive = false
static uint8_t cdc::ui::s_resolveIndex = 0
static uint16_t cdc::ui::s_resolveConn = 0xFFFF
static uint16_t cdc::ui::s_resolveNameHandle = 0
static uint32_t cdc::ui::s_resolveDeviceStartMs = 0
static uint32_t cdc::ui::s_resolveSettleStartMs = 0
static volatile bool cdc::ui::s_evtConnected = false
static volatile bool cdc::ui::s_evtDiscovered = false
static volatile bool cdc::ui::s_evtGotName = false
static volatile bool cdc::ui::s_evtDisconnected = false
static volatile uint16_t cdc::ui::s_evtConnHandle = 0xFFFF
static volatile uint16_t cdc::ui::s_evtNameHandle = 0
static char cdc::ui::s_resolveNameBuf [32]
static constexpr BleListenerToken cdc::ui::kInvalidListener = hal::IBluetoothController::INVALID_LISTENER
static BleListenerToken cdc::ui::s_tokResConn = kInvalidListener
static BleListenerToken cdc::ui::s_tokResDisc = kInvalidListener
static BleListenerToken cdc::ui::s_tokResSvc = kInvalidListener
static BleListenerToken cdc::ui::s_tokResRead = kInvalidListener

Detailed Description

Bluetooth UI flow for toggling BLE, status display, and device scanning.

Definition in file BluetoothMenuUi.cpp.