CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
IModule.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_core/IService.h"
4#include <cstdint>
5
6struct cJSON;
7
8namespace cdc::ui {
9 class IView;
10}
11
12namespace cdc::core {
13
17enum class MenuLocation : uint8_t {
18 MAIN_MENU, // Top-level main menu
19 TOOLS_MENU, // Under Tools submenu
20 SETTINGS_MENU, // Under Settings submenu
21 BLUETOOTH_MENU, // Under Bluetooth submenu (for BLE services)
22 WIFI_MENU, // Under WiFi submenu (for WiFi-related features)
23 EXPERT_MENU // Under Expert submenu (for advanced tools)
24};
25
30 const char* label; // Display label (use I18n for translation)
31 uint8_t priority; // Sort order (lower = higher in list)
32 ui::IView* (*getView)(); // Factory function to get the view (push view on select)
33 bool (*isVisible)(); // Optional visibility check (nullptr = always visible)
34 const char* moduleName; // Owner module name (set automatically)
35 MenuLocation location; // Where to show this item
36 void (*onSelect)(); // Toggle/action callback (used when getView is nullptr)
37};
38
43 const char* (*getLabel)(); // Dynamic label getter (for state-dependent text)
44 void (*callback)(); // Action when selected
45 uint8_t priority; // Sort order (lower = higher in list)
46 const char* moduleName; // Owner module name (set automatically)
47};
48
55class IModule : public IService {
56public:
57 struct SlotRequest {
58 const char* mapName = nullptr;
59 uint8_t minEccSlots = 0;
60 uint16_t minRmemSlots = 0;
61 };
62
63 struct SlotRange {
64 bool hasEcc = false;
65 bool hasRmem = false;
66 uint8_t eccStart = 0;
67 uint8_t eccEnd = 0;
68 uint16_t rmemStart = 0;
69 uint16_t rmemEnd = 0;
70 uint8_t moduleId = 0;
71 };
72
77 virtual const char* getVersion() const = 0;
78
85 struct BackupResult {
86 uint16_t imported = 0;
87 uint16_t failed = 0;
88 };
89
100 virtual bool exportBackup(cJSON* out) { (void)out; return false; }
101
112 virtual BackupResult importBackup(const cJSON* in) { (void)in; return {}; }
113
120 virtual uint8_t getMenuItems(ModuleMenuItem* items, uint8_t maxItems) {
121 (void)items; (void)maxItems;
122 return 0;
123 }
124
129 virtual ui::IView* getEntryView() { return nullptr; }
130
137 virtual uint8_t getLockScreenContextItems(LockScreenContextItem* items, uint8_t maxItems) {
138 (void)items; (void)maxItems;
139 return 0;
140 }
141
145 virtual void onUnlock() {}
146
150 virtual void onLock() {}
151
155 virtual void onUsbConnect() {}
156
160 virtual void onUsbDisconnect() {}
161
166 virtual void onTick(uint32_t nowMs) { (void)nowMs; }
167
172 virtual void setSlotRange(const SlotRange& range) { (void)range; }
173
178 virtual SlotRequest getSlotRequest() const { return {}; }
179};
180
181} // namespace cdc::core
Module interface that extends IService with module-specific features.
Definition IModule.h:55
virtual void onTick(uint32_t nowMs)
Called periodically (optional tick for background work).
Definition IModule.h:166
virtual ui::IView * getEntryView()
Returns the module's entry view (main view when selected from menu).
Definition IModule.h:129
virtual uint8_t getLockScreenContextItems(LockScreenContextItem *items, uint8_t maxItems)
Returns the module's lock screen context menu items.
Definition IModule.h:137
virtual bool exportBackup(cJSON *out)
Exports this module's data as a JSON section for the backup file.
Definition IModule.h:100
virtual uint8_t getMenuItems(ModuleMenuItem *items, uint8_t maxItems)
Returns module menu items.
Definition IModule.h:120
virtual const char * getVersion() const =0
Returns the module version string.
virtual SlotRequest getSlotRequest() const
Returns slot requirements for this module (from compile-time memory map).
Definition IModule.h:178
virtual void onUsbDisconnect()
Called when USB is disconnected.
Definition IModule.h:160
virtual BackupResult importBackup(const cJSON *in)
Restores this module's data from its JSON backup section.
Definition IModule.h:112
virtual void onLock()
Called when device is locked.
Definition IModule.h:150
virtual void onUsbConnect()
Called when USB is connected.
Definition IModule.h:155
virtual void setSlotRange(const SlotRange &range)
Sets the slot range assigned by the module registry (from compile-time memory map).
Definition IModule.h:172
virtual void onUnlock()
Called when device is unlocked.
Definition IModule.h:145
MenuLocation
Menu location for module registration.
Definition IModule.h:17
Centralized key-code constants for cdc_views.
Definition IModule.h:8
Per-module restore outcome reported by importBackup().
Definition IModule.h:85
uint16_t failed
Records skipped due to errors.
Definition IModule.h:87
uint16_t imported
Records restored successfully.
Definition IModule.h:86
Lock screen context menu item registered by a module.
Definition IModule.h:42
Menu item registered by a module.
Definition IModule.h:29
MenuLocation location
Definition IModule.h:35
const char * moduleName
Definition IModule.h:34