Improve lovense solace pro support #799
Open
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.
Important disclaimer: I'm tinkering with this to learn rust, and also have only tested this via my wasm frankenbuild. Review with skepticism.
First commit switches the manual command to
SetPoint, which fixes bothFSetSitemoving at low speed (SetPointappears to move at an appropriate speed for the distance, up to maximum), as well asFSetSitehaving some bad momentum calculation going on where issuing repeated large movements causes the device to somehow buffer movement that then plays (at high speed!) upon the next command. Fun.Second commit rewrites the control loop to behave much better. At least in my high-latency-wasm-via-js setup, the delay on BT commands meant that sleeping 100ms per step actually stretched steps out much longer, and any variation in BT latency lead to uneven pacing.
Instead, do the math based on the current time of where in the motion we should be at each wakeup, and then sleep for
100ms-command_duration.Combined, this means if a BT command takes 200ms, we'd just immediately start the next one, and to the right spot for 200ms of time. Fast movements correctly move at near full speed, and longer movements hit their target duration much more closely. In my simple test app, this makes a interactive slider to control the device at least as responsive as the phone app's manual UI, if not better.
Other notes:
RwLockseemed like the right pattern for passingInstantaround, which meant the other values needn't be atomic, I think. There's some crate withAtomicInstant, but, at 100ms, thread contention isn't really a concern. The tuple should probably be a struct? I avoided touching things that weren't relevant, but the resulting patterns might be dumb.