Repository navigation
Add readable capabilities and headset volume read-back - #605
Conversation
…bility Reading a setting back is a property of a capability, not a capability of its own. Devices advertise it with getReadableCapabilities(), a second bitmask over the same enum, instead of adding *_STATUS twins. - FeatureHandlerRegistry keys handlers on (capability, capabilitytype), so a capability can have a set (ACTION) and a read (INFO) handler - CAP_HEADSET_VOLUME gains getHeadsetVolume(); --volume without a value reads it, --volume LEVEL sets it - CAP_SIDETONE_STATUS stays for compatibility: a device with CAP_SIDETONE in its readable mask reports it automatically - The test device moves sidetone to the readable mask and implements the headset volume read - Structured output gains readable_capabilities and headset_volume (API_VERSION 1.8) - C++ API: canRead(), readableCapabilitiesMask(), getHeadsetVolume() - C API: hsc_get_readable_capabilities(), hsc_get_headset_volume()
YAML left a bare "key:" for an empty array, which parses as null rather than an empty list, and JSON wrapped a blank line in brackets. No existing array is empty in practice, but readable_capabilities is for most devices.
- ADDING_A_CAPABILITY: keep the original API_VERSION example, and add the output step to "Reading a setting back" (without it the read is dropped) - ADDING_A_DEVICE: the example marks sidetone readable, so show getSidetone() - LIBRARY_USAGE: the sample Corsair VOID Pro can't read anything back, and the C snippet no longer relies on a variable from another snippet - Test --volume in every output format, pinned to the test device - readableCapabilitiesMask() and the README helper AND the two masks instead of looping over every capability
Sapd
left a comment
There was a problem hiding this comment.
Checked the parsing locally, since an optional-argument long option is where this usually breaks: --volume, --volume 20 and --volume=20 all behave, --volume -b does not swallow -b, and the range and non-numeric errors are right. JSON against master is purely additive, and the test device still advertises CAP_SIDETONE_STATUS through the derived mask, so nothing breaks for existing consumers. Empty arrays are [] in JSON and YAML while ENV, text and short output stay byte-identical. README matches --readme-helper, clang-format is clean, API_VERSION bumped.
One gap: "This headset can't read back ..." can't be reached from any test. Profile 10 drops CAP_HEADSET_VOLUME from getCapabilities() entirely, so --volume there hits "doesn't support volume" — the assertion in testCliHeadsetVolumeOutputs is correct, but it isn't covering the new branch. The only thing that triggers it today is the A50 Gen 5, i.e. hardware. A profile that keeps the capability without setting the readable bit would cover it.
getHeadsetVolume()'s supports() && !canRead() reads oddly, but it keeps the macro's "doesn't support" message distinct from "can't read back", so leave it.
The design is what I wanted out of #599 — direction on the handler, no new *_STATUS enum entries, and old devices keeping theirs.
Profile 6 keeps CAP_HEADSET_VOLUME settable but drops it from the readable mask, so the CLI's "can't read back" error and the library's NotSupported path in getHeadsetVolume() are reachable from tests.
Hey, added test profile 6 that keeps |
Sapd
left a comment
There was a problem hiding this comment.
Profile 6 covers it. Checked the test has teeth rather than just passing: deleting the branch from handleFeature() fails it with
✗ FAILED: ASSERT_CONTAINS failed: a write-only capability should say it can't be read
Looking for: can't read back volume
and restoring it goes green again. The four assertions around it are the useful part — set still works, the pure query skips the unreadable capability, and the readable count drops to 1.
One thing on the slot you picked: profile 6 was already the full-battery profile in getBattery(), and profile 7 is low battery, so the docblock line above yours — Profile 7-9: Reserved — was already wrong before this. Your entry now describes 6 as only the volume case. Not worth another push; 8 and 9 are the genuinely free slots if this ever needs moving, and I'll straighten the docblock out on master.
Merging. Thanks for turning both of these around quickly — the readable mask is a better shape than the sketch I put in #599.
Profile 6 is the full-battery profile and 7 is low battery; neither was reserved. #605 documented 6 as only the new volume case and left 7 listed as reserved.
There was a problem hiding this comment.
🟡 Changes recommended
Directional support checks and partial-readability markers remain inconsistent with their intended behavior.
2 open issues
What changed in this PR
Adds capability read-back to HeadsetControl without introducing new status enum entries. Headset volume reading is exposed through the CLI and library APIs, with implementation limited to the test device.
Changes:
- Adds readable capability masks and separate read/set handler dispatch.
- Exposes volume read-back and readable capabilities through C++, C, and structured output.
- Updates documentation and tests, including explicit empty-array serialization.
| File | Description |
|---|---|
| tests/test_output_formats.cpp | Tests empty JSON and YAML arrays. |
| tests/test_library_api.cpp | Tests C and C++ read-back APIs. |
| tests/test_device_registry.cpp | Tests readable masks and directional handlers. |
| tests/test_cli_output.cpp | Tests volume queries and output formats. |
| README.md | Documents readable capability markers. |
| lib/headsetcontrol.hpp | Declares C++ read-back APIs. |
| lib/headsetcontrol.cpp | Implements C++ read-back and capability reporting. |
| lib/headsetcontrol_c.h | Declares C read-back APIs. |
| lib/headsetcontrol_c.cpp | Implements C wrappers and volume conversion. |
| lib/feature_handlers.hpp | Separates read/set handlers and adds volume reading. |
| lib/devices/hid_device.hpp | Adds readability and directional support interfaces. |
| lib/devices/hid_device.cpp | Uses advertised capabilities in C conversion. |
| lib/devices/headsetcontrol_test.hpp | Implements test-device volume reading and profiles. |
| lib/device.hpp | Carries native volume in feature results. |
| lib/capability_descriptors.hpp | Updates volume help for optional read-back. |
| docs/LIBRARY_USAGE.md | Documents read-back APIs and output additions. |
| docs/ADDING_A_DEVICE.md | Explains device readable masks and getters. |
| docs/ADDING_A_CAPABILITY.md | Documents read handler integration. |
| cli/output/serializers.hpp | Serializes empty arrays explicitly. |
| cli/output/output.cpp | Reports readable capabilities and volume results. |
| cli/output/output_data.hpp | Adds readable lists and volume output data. |
| cli/main.cpp | Integrates volume queries, directional dispatch, and README markers. |
Review effort: Balanced
| const char* mark = (readable_any & B(j)) ? "r" : "x"; | ||
| if (caps_all & B(j)) { | ||
| std::cout << " x |"; | ||
| std::cout << " " << mark << " |"; |
| if (type == CAPABILITYTYPE_INFO && getCapabilityDescriptor(cap).isActionFeature()) { | ||
| return canRead(cap); | ||
| } | ||
| return (getAdvertisedCapabilities() & B(cap)) != 0; |
The A50 Gen 5 now lists CAP_HEADSET_VOLUME in getReadableCapabilities(), so bare --volume reads the headset volume wheel level. The GET is 02 0c 03 00 08 0c; byte 8 of the reply holds the 0..21 step the setter writes, normalised back with mapDiscreteToSidetone<22> so a read value round-trips through --volume. A level above 21 is a protocol error. Follows Sapd#605; discussed in Sapd#599. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ev2YcPPCCCNDpuScBqpNCP
Follows Sapd#605: CAP_SIDETONE_STATUS is derived from CAP_SIDETONE in getReadableCapabilities() instead of being listed. README regenerated; the sidetone column is now "r". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Changes made
This adds read-back as discussed in #599. A capability can now have a read handler next to its set handler, and devices list the capabilities they can read in a second bitmask over the same enum. There is no new
*_STATUScapability. As you suggested, only the test device implements it. The ASTRO A50 Gen 5 read-back will come in a separate PR.Mechanism
HIDDevice::getReadableCapabilities()returns the readable bitmask. It returns0by default and adds no enum entries.FeatureHandlerRegistrykeeps one handler per capability and direction.registerHandler()andexecute()take acapabilitytype, and the table is nowstd::array<std::array<FeatureHandler, 2>, NUM_CAPABILITIES>. Every existingregisterHandler()call names its direction, and the oneexecute()call inmain.cpppassesreq.type.CAP_SIDETONEin its readable mask still reportsCAP_SIDETONE_STATUS. Existing devices don't change, so their--capabilitiesoutput and README rows stay the same.Headset volume
HIDDevicehas a newgetHeadsetVolume()virtual next tosetHeadsetVolume(). It returnsHeadsetVolumeResult, and the default implementation returnsnotSupported. An INFO handler calls it.--volume LEVELsets the volume and--volumewithout a value reads it, the same as-s. Both request-table rows useCAP_HEADSET_VOLUME. If a device can set the volume but not read it,--volumeprints "This headset can't read back volume".CAP_SIDETONE_STATUS, and it implements the volume read.Output and APIs
r, or withr*when only some product variants have it, and a footnote explains the marker. I regenerated the table with--readme-helper. Only the test device row changes.readable_capabilitiesandreadable_capabilities_str, and aheadset_volumeobject withlevelanddevice_level. ENV output has matching keys.API_VERSIONis now 1.8.[]. YAML used to write a barekey:, which parses as null. No existing array was ever empty, butreadable_capabilitiesis empty for most devices.Headset::canRead(),readableCapabilitiesMask()andgetHeadsetVolume().hsc_get_readable_capabilities()andhsc_get_headset_volume(). The capability enum doesn't change.ADDING_A_CAPABILITY.md,ADDING_A_DEVICE.mdandLIBRARY_USAGE.mdexplain the readable mask.Differences from your sketch in #599
CAPABILITYTYPE_INFO, notACTION. These are battery, chatmix, sidetone status, mic attachment and mic mute. Their request-table rows useINFO, soexecute(cap, req.type, …)would never reach an ACTION handler for them.HIDDevice::getAdvertisedCapabilities()addsCAP_SIDETONE_STATUS, so devices don't have to add it in their owngetCapabilities(). Devices overridegetCapabilities()as before, and the CLI, the output code, the library and the C struct read capabilities fromgetAdvertisedCapabilities().CAP_SIDETONEalso has an INFO handler, so every capability a device can mark readable has a read handler. A test checks this.-swithout a value still reads throughCAP_SIDETONE_STATUS.hsc_get_headset_volume()next tohsc_get_readable_capabilities(). Without it, C code could see that the volume is readable but couldn't read it.Not changed
CAP_SIDETONE_STATUSkeep it. Besides the five you mentioned in A capability to read and set the headset's hardware volume #599, the Jabra GN protocol devices list it, and so does the Arctis Nova 7 Gen 2.Testing
make checkpasses. New tests cover the readable mask, the derivedCAP_SIDETONE_STATUS, both handler directions, the C and C++ read functions,--volumein every output format, and empty arrays.--volume,-s,--capabilities,--readme-helperand-owithjson,yamlandenvagainst the test device. That included test profile 1, which returns errors, and test profile 10, which has fewer capabilities.Checklist