Skip to content

Return std::expected from the ps5 controller feature reads#28

Merged
jwinarske merged 2 commits into
mainfrom
jw/expected-hid-domain
Jul 13, 2026
Merged

Return std::expected from the ps5 controller feature reads#28
jwinarske merged 2 commits into
mainfrom
jw/expected-hid-domain

Conversation

@jwinarske

@jwinarske jwinarske commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Return std::expected from the ps5 controller feature reads

Convert InputReader::GetControllerMacAll/Version/CalibrationData from an int 0/1 status (whose result the caller discarded) to std::expected<void, std::error_code>, marked [[nodiscard]].

Their two failure modes map to two error domains: an ioctl failure carries the errno via sys::ioctl, while a well-formed response that fails a protocol check (wrong ReportID / signature bytes) carries a new hid:: error category
(src/bluez/hid_error.h) — the textbook way to represent a domain error in a std::error_code. Both compose through the same expected channel.

open_and_init() now consumes the results: the feature reads are best-effort (a controller still streams input without calibration), so a failure is logged as a warning with the specific message and initialisation continues.

Verified: full build green; a standalone check confirms the hid category (name "hid", message "invalid device response", enum comparison); a ps5 client start/SIGTERM cycle exits cleanly. Decoding a real controller needs hardware.

Convert InputReader::GetControllerMacAll/Version/CalibrationData from an int
0/1 status (whose result the caller discarded) to
std::expected<void, std::error_code>, marked [[nodiscard]].

Their two failure modes map to two error domains: an ioctl failure carries the
errno via sys::ioctl, while a well-formed response that fails a protocol check
(wrong ReportID / signature bytes) carries a new hid:: error category
(src/bluez/hid_error.h) — the textbook way to represent a domain error in a
std::error_code. Both compose through the same expected channel.

open_and_init() now consumes the results: the feature reads are best-effort (a
controller still streams input without calibration), so a failure is logged as
a warning with the specific message and initialisation continues.

Verified: full build green; a standalone check confirms the hid category
(name "hid", message "invalid device response", enum comparison); a ps5 client
start/SIGTERM cycle exits cleanly. Decoding a real controller needs hardware.

Signed-off-by: Joel Winarske <joel.winarske@linux.com>
Comment thread src/bluez/hid_error.h Fixed
Addresses the CodeQL "no trivial switch statements" review comment on #28: a
single-case switch reads more naturally as an if.

Signed-off-by: Joel Winarske <joel.winarske@linux.com>
@jwinarske
jwinarske merged commit 3e0e146 into main Jul 13, 2026
6 checks passed
@jwinarske
jwinarske deleted the jw/expected-hid-domain branch July 13, 2026 16:45
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.

2 participants