Skip to content

Commit 1dba02e

Browse files
committed
Update docs
1 parent 4505f13 commit 1dba02e

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

docs/ADDING_A_CAPABILITY.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This guide explains how to add a new capability (feature) to HeadsetControl.
66

77
A 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)
1010
2. Add metadata (CLI flags, description, value range)
1111
3. Create a result type
1212
4. 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
5347
Find the `CAPABILITY_DESCRIPTORS` array and add your capability:
@@ -186,9 +180,9 @@ public:
186180

187181
Here'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:**

docs/DEVELOPMENT.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,21 @@ public:
157157
158158
### Capability System
159159
160-
Capabilities are defined in `lib/device.hpp`:
160+
Capabilities are defined in `lib/device.hpp` using an X-macro pattern:
161161
162162
```cpp
163-
enum capabilities {
164-
CAP_SIDETONE,
165-
CAP_BATTERY_STATUS,
166-
CAP_LIGHTS,
167-
CAP_INACTIVE_TIME,
163+
// Single source of truth - add one line to add a capability
164+
#define CAPABILITIES_XLIST \
165+
X(CAP_SIDETONE, "sidetone", 's') \
166+
X(CAP_BATTERY_STATUS, "battery", 'b') \
167+
X(CAP_LIGHTS, "lights", 'l') \
168168
// ... more capabilities
169+
170+
// Enum is auto-generated from CAPABILITIES_XLIST
171+
enum capabilities {
172+
#define X(id, name, short_char) id,
173+
CAPABILITIES_XLIST
174+
#undef X
169175
NUM_CAPABILITIES
170176
};
171177
@@ -189,7 +195,7 @@ Quick overview:
189195
See **[ADDING_A_CAPABILITY.md](ADDING_A_CAPABILITY.md)** for a complete step-by-step guide.
190196

191197
Quick overview:
192-
1. Add capability enum in `lib/device.hpp`
198+
1. Add to `CAPABILITIES_XLIST` in `lib/device.hpp` (enum + strings auto-generated)
193199
2. Add descriptor in `lib/capability_descriptors.hpp`
194200
3. Add result type in `lib/result_types.hpp`
195201
4. Add virtual method in `lib/devices/hid_device.hpp`

0 commit comments

Comments
 (0)