Skip to content

Add readable capabilities and headset volume read-back - #605

Merged
Sapd merged 6 commits into
Sapd:masterfrom
Mihuy1:feature/readable-capabilities
Oct 22, 2026
Merged

Sapd merged 6 commits into
Sapd:masterfrom
Mihuy1:feature/readable-capabilities

Conversation

@Mihuy1

@Mihuy1 Mihuy1 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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 *_STATUS capability. 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 returns 0 by default and adds no enum entries.
  • FeatureHandlerRegistry keeps one handler per capability and direction. registerHandler() and execute() take a capabilitytype, and the table is now std::array<std::array<FeatureHandler, 2>, NUM_CAPABILITIES>. Every existing registerHandler() call names its direction, and the one execute() call in main.cpp passes req.type.
  • A device with CAP_SIDETONE in its readable mask still reports CAP_SIDETONE_STATUS. Existing devices don't change, so their --capabilities output and README rows stay the same.

Headset volume

  • HIDDevice has a new getHeadsetVolume() virtual next to setHeadsetVolume(). It returns HeadsetVolumeResult, and the default implementation returns notSupported. An INFO handler calls it.
  • --volume LEVEL sets the volume and --volume without a value reads it, the same as -s. Both request-table rows use CAP_HEADSET_VOLUME. If a device can set the volume but not read it, --volume prints "This headset can't read back volume".
  • The test device lists sidetone in its readable mask instead of listing CAP_SIDETONE_STATUS, and it implements the volume read.

Output and APIs

  • The README marks a readable capability with r, or with r* 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.
  • Structured output has two new lists, readable_capabilities and readable_capabilities_str, and a headset_volume object with level and device_level. ENV output has matching keys. API_VERSION is now 1.8.
  • The JSON and YAML serializers now write an empty array as []. YAML used to write a bare key:, which parses as null. No existing array was ever empty, but readable_capabilities is empty for most devices.
  • The C++ API has Headset::canRead(), readableCapabilitiesMask() and getHeadsetVolume().
  • The C API has hsc_get_readable_capabilities() and hsc_get_headset_volume(). The capability enum doesn't change.
  • ADDING_A_CAPABILITY.md, ADDING_A_DEVICE.md and LIBRARY_USAGE.md explain the readable mask.

Differences from your sketch in #599

  1. I registered the read-only capabilities as CAPABILITYTYPE_INFO, not ACTION. These are battery, chatmix, sidetone status, mic attachment and mic mute. Their request-table rows use INFO, so execute(cap, req.type, …) would never reach an ACTION handler for them.
  2. A non-virtual HIDDevice::getAdvertisedCapabilities() adds CAP_SIDETONE_STATUS, so devices don't have to add it in their own getCapabilities(). Devices override getCapabilities() as before, and the CLI, the output code, the library and the C struct read capabilities from getAdvertisedCapabilities().
  3. CAP_SIDETONE also has an INFO handler, so every capability a device can mark readable has a read handler. A test checks this. -s without a value still reads through CAP_SIDETONE_STATUS.
  4. I added hsc_get_headset_volume() next to hsc_get_readable_capabilities(). Without it, C code could see that the volume is readable but couldn't read it.

Not changed

Testing

  • make check passes. New tests cover the readable mask, the derived CAP_SIDETONE_STATUS, both handler directions, the C and C++ read functions, --volume in every output format, and empty arrays.
  • I ran --volume, -s, --capabilities, --readme-helper and -o with json, yaml and env against the test device. That included test profile 1, which returns errors, and test profile 10, which has fewer capabilities.

Checklist

  • I adjusted the README (if needed)
  • For new features in HeadsetControl: I discussed it beforehand in Issues or Discussions and adhered to the wiki

…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
@github-actions github-actions Bot added the awaiting-maintainer The author replied or pushed - our move label Oct 22, 2026

@Sapd Sapd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Mihuy1

Mihuy1 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

ecked 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.

Hey, added test profile 6 that keeps CAP_HEADSET_VOLUME but leaves it out of the readable mask, so --volume hits This headset can't read back volume.

@Sapd
Sapd requested a balanced review from Copilot October 22, 2026 21:14

@Sapd Sapd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Sapd
Sapd merged commit 2adcfc7 into Sapd:master Oct 22, 2026
7 of 8 checks passed
@github-actions github-actions Bot removed the awaiting-maintainer The author replied or pushed - our move label Oct 22, 2026
Sapd added a commit that referenced this pull request Oct 22, 2026
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread cli/main.cpp
Comment on lines +446 to +448
const char* mark = (readable_any & B(j)) ? "r" : "x";
if (caps_all & B(j)) {
std::cout << " x |";
std::cout << " " << mark << " |";
Comment on lines +125 to +128
if (type == CAPABILITYTYPE_INFO && getCapabilityDescriptor(cap).isActionFeature()) {
return canRead(cap);
}
return (getAdvertisedCapabilities() & B(cap)) != 0;
@Sapd Sapd mentioned this pull request Oct 23, 2026
1 of 2 tasks
Mihuy1 pushed a commit to Mihuy1/HeadsetControl that referenced this pull request Oct 24, 2026
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
Dasio added a commit to Dasio/HeadsetControl that referenced this pull request Oct 26, 2026
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>
@Mihuy1 Mihuy1 mentioned this pull request Oct 28, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants