@@ -6,7 +6,7 @@ This guide explains how to add a new capability (feature) to HeadsetControl.
66
77A capability is a feature like sidetone, battery status, or LED control. Adding one involves:
88
9- 1 . Define the capability enum and string
9+ 1 . Add to CAPABILITIES_XLIST ( enum + strings auto-generated)
10102 . Add metadata (CLI flags, description, value range)
11113 . Create a result type
12124 . Add the virtual method to HIDDevice base class
@@ -18,7 +18,7 @@ A capability is a feature like sidetone, battery status, or LED control. Adding
1818
1919| File | Purpose |
2020| ------| ---------|
21- | ` lib/device.hpp ` | Capability enum and string name |
21+ | ` lib/device.hpp ` | Add to CAPABILITIES_XLIST (generates enum + strings) |
2222| ` lib/capability_descriptors.hpp ` | CLI metadata (flags, description, validation) |
2323| ` lib/result_types.hpp ` | Result struct for the feature |
2424| ` lib/devices/hid_device.hpp ` | Virtual method in base class |
@@ -28,26 +28,20 @@ A capability is a feature like sidetone, battery status, or LED control. Adding
2828
2929## Step-by-Step Guide
3030
31- ### 1. Add Capability Enum (` lib/device.hpp ` )
31+ ### 1. Add Capability to X-Macro (` lib/device.hpp ` )
32+
33+ Add a single line to ` CAPABILITIES_XLIST ` . The enum, string name, and short char are all generated automatically:
3234
3335``` cpp
34- enum capabilities {
35- CAP_SIDETONE,
36- CAP_BATTERY_STATUS,
36+ # define CAPABILITIES_XLIST \
37+ X( CAP_SIDETONE, "sidetone", 's') \
38+ X( CAP_BATTERY_STATUS, "battery", 'b') \
3739 // ... existing capabilities ...
38- CAP_YOUR_FEATURE, // <- Add here
39- NUM_CAPABILITIES // Keep this last
40- };
41-
42- // Add string name (must match enum order)
43- constexpr const char * capabilities_str[] = {
44- "sidetone",
45- "battery",
46- // ... existing names ...
47- "your_feature", // <- Add here
48- };
40+ X(CAP_YOUR_FEATURE, "your feature", '\0') // <- Add here (use '\0' for no short char)
4941```
5042
43+ That's it! The enum value `CAP_YOUR_FEATURE` and all string conversion functions are generated from this single line.
44+
5145### 2. Add Descriptor (`lib/capability_descriptors.hpp`)
5246
5347Find the `CAPABILITY_DESCRIPTORS` array and add your capability:
@@ -186,9 +180,9 @@ public:
186180
187181Here's a real example from the codebase:
188182
189- ** device.hpp: **
183+ ** device.hpp** (add to CAPABILITIES_XLIST):
190184``` cpp
191- CAP_VOLUME_LIMITER,
185+ X ( CAP_VOLUME_LIMITER, "volume limiter", '\0')
192186```
193187
194188**capability_descriptors.hpp:**
0 commit comments