CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
LockScreenView.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_ui/IView.h"
4#include <cstdint>
5
6namespace cdc {
7namespace hal {
9}
10}
11
12namespace cdc::ui {
13
14// Deep sleep hold threshold (5 seconds)
15static constexpr uint32_t DEEP_SLEEP_HOLD_MS = 5000;
16
20enum class StatusIcon : uint16_t {
21 NONE = 0,
22 LOCK = (1 << 0), // Padlock
23 DEEP_SLEEP = (1 << 1), // zzZ
24 LIGHT_SLEEP = (1 << 2), // z
25 BACKLIGHT = (1 << 3), // Sun
26 USB = (1 << 4), // USB connected
27 BLE = (1 << 5), // Bluetooth
28 WIFI = (1 << 6), // WiFi connected
29 SAO = (1 << 7), // SAO detected
30 CHARGING = (1 << 8), // Battery charging
31 NO_BATTERY = (1 << 9), // No battery connected
32 CAFFEINATED = (1 << 10), // Sleep inhibited (coffee cup)
33 BACKGROUND = (1 << 11), // Background plugin running
34};
35
36// Allow bitwise operations
38 return static_cast<StatusIcon>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b));
39}
41 return static_cast<StatusIcon>(static_cast<uint16_t>(a) & static_cast<uint16_t>(b));
42}
44 return a = a | b;
45}
46
58class LockScreenView : public ViewBase {
59public:
60 static constexpr uint8_t MAX_TEXT_LEN = 64;
61
65 using UnlockCallback = void(*)();
66
70 void init();
71
75 void setOnUnlock(UnlockCallback callback) { onUnlock_ = callback; }
76
80 void setDisplayName(const char* name);
81 void setInfo(const char* info);
82 void setInfo2(const char* info2);
83
84 const char* getDisplayName() const { return name_; }
85 const char* getInfo() const { return info_; }
86 const char* getInfo2() const { return info2_; }
87
91 void setClock(const char* clock);
92
96 void setDate(const char* date);
97
101 void setBatteryPercent(uint8_t percent);
102
106 void setStatusIcons(StatusIcon icons);
107 void addStatusIcon(StatusIcon icon);
108 void removeStatusIcon(StatusIcon icon);
109 StatusIcon getStatusIcons() const { return statusIcons_; }
110
111 // IView implementation
112 void render(bool partial) override;
113 InputResult onKey(char key) override;
114 void onTick(uint32_t nowMs) override;
115 void onEnter(void* context) override;
116 void onResume() override;
117 const char* getName() const override { return "LockScreenView"; }
118 const char* getFooterHint() const override;
119 // Clock/icon updates are tiny; keep them pure partials (no forced full).
120 bool prefersLightRefresh() const override { return true; }
121
125 void toggleBacklight();
126
132 using PreRenderCallback = void (*)();
133 void setPreRenderCallback(PreRenderCallback callback) { preRenderCb_ = callback; }
134
135private:
136 char name_[MAX_TEXT_LEN] = {};
137 char info_[MAX_TEXT_LEN] = {};
138 char info2_[MAX_TEXT_LEN] = {};
139 char clock_[8] = "--:--";
140 char date_[12] = {};
141 uint8_t batteryPercent_ = 0;
142 StatusIcon statusIcons_ = StatusIcon::NONE;
143 UnlockCallback onUnlock_ = nullptr;
144 PreRenderCallback preRenderCb_ = nullptr;
145
146 // Long-press N for deep sleep (flight mode)
147 uint32_t nPressStartMs_ = 0;
148 bool deepSleepMode_ = false;
149
150 void renderStatusIcons(void* gfx, int x, int y);
151 void renderBattery(void* gfx, int x, int y);
152 void renderDeepSleepScreen();
153 void checkDeepSleepTrigger(uint32_t nowMs);
154};
155
156} // namespace cdc::ui
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
void setPreRenderCallback(PreRenderCallback callback)
void removeStatusIcon(StatusIcon icon)
Removes one status icon flag.
void onResume() override
Handles returning to lock screen and reapplies backlight policy.
StatusIcon getStatusIcons() const
void onTick(uint32_t nowMs) override
Per-tick handler for long-press deep-sleep detection.
void setOnUnlock(UnlockCallback callback)
void setBatteryPercent(uint8_t percent)
Updates battery percentage indicator.
const char * getDisplayName() const
const char * getInfo() const
const char * getFooterHint() const override
Returns footer hint based on current lock-screen mode.
InputResult onKey(char key) override
Handles lock-screen key actions.
void setClock(const char *clock)
Sets clock text shown in the header.
void init()
Initializes lock-screen state fields to defaults.
static constexpr uint8_t MAX_TEXT_LEN
const char * getInfo2() const
bool prefersLightRefresh() const override
void addStatusIcon(StatusIcon icon)
Adds one status icon flag.
void setDate(const char *date)
Sets date text shown below clock.
void setStatusIcons(StatusIcon icons)
Replaces full status-icon bitmask.
void toggleBacklight()
Toggles display backlight and corresponding status icon.
void setInfo2(const char *info2)
Sets second informational line.
const char * getName() const override
void setInfo(const char *info)
Sets first informational line.
void setDisplayName(const char *name)
Sets primary display name shown on lock screen.
void onEnter(void *context) override
Handles entering lock screen and updates backlight behavior.
Centralized key-code constants for cdc_views.
Definition IModule.h:8
StatusIcon operator&(StatusIcon a, StatusIcon b)
static constexpr uint32_t DEEP_SLEEP_HOLD_MS
InputResult
Definition IView.h:10
StatusIcon operator|(StatusIcon a, StatusIcon b)
StatusIcon & operator|=(StatusIcon &a, StatusIcon b)