CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
BlePairingView.cpp
Go to the documentation of this file.
1
5
10#include "cdc_hal/IDisplay.h"
11#include "cdc_ui/ViewStack.h"
12#include "cdc_ui/I18n.h"
13#include "cdc_views/KeyCodes.h"
15
16#include <goodisplay/gdey029T94.h>
17
18static constexpr const char* kSleepInhibitor = "ble_pair";
19
20namespace cdc::ui {
21
22void BlePairingView::onEnter(void* context) {
23 (void)context;
25 if (ble && !ble->isEnabled()) ble->enable();
26 if (auto* kb = core::getKeyboard()) kb->setDiscoverable(true);
28 lastConnected_ = ble && ble->isConnected();
29 lastUpdate_ = 0;
30 dirty_ = true;
31}
32
34 if (auto* kb = core::getKeyboard()) kb->setDiscoverable(false);
36}
37
38void BlePairingView::onTick(uint32_t nowMs) {
39 // Keep the badge awake and unlocked while discoverable so the central
40 // numeric-comparison prompt is shown instead of being rejected on lock.
42
43 if (nowMs - lastUpdate_ >= 1000) {
44 lastUpdate_ = nowMs;
46 bool connected = ble && ble->isConnected();
47 if (connected != lastConnected_) {
48 lastConnected_ = connected;
49 markDirty();
50 }
51 }
52}
53
58
59void BlePairingView::render(bool partial) {
61 if (!display) return;
62 auto* gfx = static_cast<Gdey029T94*>(display->getNativeHandle());
63 if (!gfx) return;
64
65 const uint16_t width = display->getWidth();
66 const uint16_t height = display->getHeight();
67
68 if (!partial) gfx->fillScreen(EPD_WHITE);
69
70 gfx->setFont(nullptr);
71 gfx->setTextColor(EPD_BLACK);
72 gfx->setTextSize(1);
73
74 render::drawHeaderCentered(gfx, ui::tr("core.ble_pairing_title"), 6, width);
75
77 const char* name = (ble && ble->getDeviceName()) ? ble->getDeviceName() : "";
78 const bool connected = ble && ble->isConnected();
79
80 // Instruction
81 gfx->setCursor(8, 34);
82 render::printText(gfx, ui::tr("core.ble_pairing_instr"));
83
84 // Advertised device name, emphasized and truncated to the panel width
85 gfx->setTextSize(2);
86 gfx->setCursor(8, 50);
87 render::printTruncated(gfx, name, width - 16);
88 gfx->setTextSize(1);
89
90 // Connection status
91 gfx->setCursor(8, 82);
92 render::printText(gfx, connected ? ui::tr("core.ble_pairing_connected")
93 : ui::tr("core.ble_pairing_waiting"));
94
95 render::drawFooterBar(gfx, width, height, nullptr,
96 ui::tr("core.ble_pairing_exit"), false);
97
98 clearDirty();
99}
100
101} // namespace cdc::ui
static constexpr const char * kSleepInhibitor
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
void onEnter(void *context) override
void render(bool partial) override
void onTick(uint32_t nowMs) override
InputResult onKey(char key) override
bool addSleepInhibitor(const char *reason)
Sleep inhibitor API implementation.
static SleepManager & instance()
Returns singleton sleep manager instance.
bool removeSleepInhibitor(const char *reason)
Removes a sleep inhibitor reason.
void clearDirty() override
Definition IView.h:187
void markDirty() override
Definition IView.h:186
static ViewStack & instance()
Returns singleton view-stack instance.
Definition ViewStack.cpp:34
void resetInactivityTimer()
IKeyboardProvider * getKeyboard()
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
IBluetoothController * getBluetoothControllerInstance()
Returns singleton Bluetooth stub when NimBLE is unavailable.
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
void printTruncated(Gdey029T94 *gfx, const char *text, int maxWidthPx)
Print text at the current cursor, truncated with an ellipsis to fit maxWidthPx. Caller must have alre...
void printText(Gdey029T94 *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
Centralized key-code constants for cdc_views.
Definition IModule.h:8
const char * tr(const char *key)
Look up a translation by string key.
Definition I18n.h:208
Gdey029T94 * display
InputResult
Definition IView.h:10
static constexpr char KEY_NO
Cancel / Back / Backspace.
Definition KeyCodes.h:44