Repository navigation
Don't keep headset settings the headset rejected #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,9 +169,10 @@ pub enum MouseCmd { | |
| Activate(zbus::OwnedObjectPath, &'static str), | ||
| } | ||
|
|
||
| /// (new, previous): the previous value goes back into settings if the headset rejects the new one. | ||
| pub enum HeadsetCmd { | ||
| Sidetone(u32), | ||
| Idle(u32), | ||
| Sidetone(u32, u32), | ||
| Idle(u32, u32), | ||
| } | ||
|
|
||
| pub struct MicCmd { | ||
|
|
@@ -404,14 +405,28 @@ fn headset(st: Shared, ctx: Context, rx: Receiver<HeadsetCmd>) { | |
| update(&st, &ctx, |s| s.headset = dev); | ||
|
|
||
| match rx.recv_timeout(Duration::from_secs(30)) { | ||
| Ok(HeadsetCmd::Sidetone(v)) => report(&st, &ctx, audio::headset_set("-s", v), "Sidetone set"), | ||
| Ok(HeadsetCmd::Idle(v)) => report(&st, &ctx, audio::headset_set("-i", v), "Auto-off set"), | ||
| Ok(HeadsetCmd::Sidetone(v, prev)) => set_or_revert(&st, &ctx, "-s", v, prev, |s| &mut s.sidetone, "Sidetone set"), | ||
| Ok(HeadsetCmd::Idle(v, prev)) => set_or_revert(&st, &ctx, "-i", v, prev, |s| &mut s.idle_minutes, "Auto-off set"), | ||
| Err(RecvTimeoutError::Timeout) => {} | ||
| Err(RecvTimeoutError::Disconnected) => return, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The slider already saved `v`; put `prev` back if the headset didn't take it (unless it moved on since). | ||
| fn set_or_revert(st: &Shared, ctx: &Context, flag: &str, v: u32, prev: u32, field: fn(&mut Settings) -> &mut u32, ok: &str) { | ||
| let r = audio::headset_set(flag, v); | ||
| if r.is_err() { | ||
| update(st, ctx, |s| { | ||
| let f = field(&mut s.settings); | ||
| if *f == v { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identify requests independently of their values. If the user requests 10, then 20, then 10 while the first command is pending, a failure of the first command matches the latest value and restores its previous value. If the later commands succeed, the headset ends at 10 but the slider remains at the restored value. Use a request generation or identifier to check whether a failed request is still current.
|
||
| *f = prev; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
Comment on lines
+422
to
+424
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the user releases the slider again before an earlier Useful? React with 👍 / 👎. |
||
| }); | ||
| } | ||
| report(st, ctx, r, ok); | ||
| } | ||
|
|
||
| // -------------------------------------------------------------------- mic | ||
|
|
||
| fn mic(st: Shared, ctx: Context, rx: Receiver<MicCmd>) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the last confirmed value, not the previous request.
If the user queues values 10 and 20 from an initial value of 0, and both commands fail, the second command restores 10. That value was also rejected. The auto-off slider has the same issue.
Track the last successfully applied value for each setting and use it for rollback.