Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The refactor clarifies some function details, uses docstrings instead of comment blocks, and simplifies functions with documented intention-value converstion equations (such as
set_position
). The appropriate version bump was already pushed to master.It has not been tested because I cannot test it because I do not own the required hardware. I would buy it, but I don't have any use for it besides about 20 minutes of testing this single commit.
Several other subtle changes were made: functions and parameters have been type hinted, the high byte mask-and-shift in
send_data
has been replaced with a simple shift, thevalue
range check insend_data
was streamlined via comparison operator chaining, and thestroke
and USB ID values have been checked for negatives.The most important change is a proper implementation of the
stroke
value. Previously, it was just specified as part of a handful of equations the user had to calculate. Instead, it is now a required constructor parameter, and is used in these equations automatically. This prevents accidental inconsistency errors on the users' behalf and enables the aforementioned simplification of equation-based functions likeset_position
.Additionally, the packet echo from sending data over USB has been implemented as function returns, in case any users want that echo. It proves especially useful in the case of
set_position
andget_feedback
because those functions do not simply echo the sent packet.Several comments as well as the readme have also been de-cringed.