Open saidsay-so opened 1 year ago
@CasualX What do you think of this possible API?
Hey sorry I haven't been responsive, I've not found the motivation to do any programming (outside of work) lately.
Some quick notes: In general I'm not a fan of builders in general but due to the pain of packed structs I'm willing to tolerate them.
A quick note: you have some indented by spaces in some of the files, I would appreciate if you could change that back to tabs. I like tabs for indentation (and spaces for alignment).
In case you're interested: the way I have dealt with misaligned fields in structs before is: if there's only few fields (like a single one) then I may just break the field up in a smaller integer size and suffix them _hi and _lo. Another strategy I've used is to create 2 structs: a public one (not packed) and a private packed one and convert to packed privately when needed.
But since I'm unlikely to ever use the ds4 code I can live with it :)
What's blocking a merge? It works quite well.
Actually there is a bug, touch pad is keep touching 0,0 even inside report is None.
Edit: Fixed https://github.com/musikid/vigem-client/commit/bd8f2ebe109cace02913f3dd32e4415c6b6fae8d
Introduces a new API for DualShock4 reports, which includes builders for the raw reports' structs and some of their special fields. Both versions of the reports have a builder, which is the only way to construct the underlying reports, since their fields are now private to avoid exposing superfluous fields and avoid breaking change if we decide to change their layout.
Example
Special fields
Some fields also have a dedicated builder to allow more ergonomic construction, like the buttons and status.
Buttons
With
DS4Buttons
, a set of buttons to be pressed (or not) can be built using either the builder pattern or the bitwise operators. This also includes the D-Pad direction, which is set within the same integer as the other buttons internally.Example
Special buttons
Similarly to
DS4Buttons
, a set of special buttons can be created withDS4SpecialButtons
.Example
Touch reports and touchpoints
Touch reports, which contains two touchpoints, can be created with a single constructor.
Example
Status
The status can be built only (maybe others?) with
with_battery_status
function, which takes aBatteryStatus
as argument to reflect the possible battery statuses available.Example