put auto haptic params in mode meta
This commit is contained in:
@@ -18,14 +18,11 @@ impl ControlMode for Media {
|
||||
ControlModeMeta {
|
||||
name: "Media",
|
||||
icon: "applications-multimedia",
|
||||
haptics: true,
|
||||
steps: 36,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(true, Some(36))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_btn_press(&mut self, _: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,14 +7,11 @@ impl ControlMode for () {
|
||||
ControlModeMeta {
|
||||
name: "null",
|
||||
icon: "",
|
||||
haptics: false,
|
||||
steps: 3600,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(false, Some(0))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_btn_press(&mut self, _haptics: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -148,11 +148,12 @@ impl ControlMode for Paddle {
|
||||
ControlModeMeta {
|
||||
name: "Paddle",
|
||||
icon: "input-gaming",
|
||||
haptics: false,
|
||||
steps: 3600,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(false, Some(3600))?;
|
||||
fn on_start(&mut self, _haptics: &DialHaptics) -> Result<()> {
|
||||
let _ = self.msg.send(Msg::Enabled(true));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -16,14 +16,11 @@ impl ControlMode for Scroll {
|
||||
ControlModeMeta {
|
||||
name: "Scroll",
|
||||
icon: "input-mouse",
|
||||
haptics: false,
|
||||
steps: 90,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(false, Some(90))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_btn_press(&mut self, _: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@ impl ControlMode for ScrollMT {
|
||||
ControlModeMeta {
|
||||
name: "Scroll",
|
||||
icon: "input-mouse",
|
||||
haptics: false,
|
||||
steps: 3600,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(false, Some(3600))?;
|
||||
fn on_start(&mut self, _haptics: &DialHaptics) -> Result<()> {
|
||||
self.acc_delta = 0;
|
||||
|
||||
fake_input::scroll_mt_start().map_err(Error::Evdev)?;
|
||||
|
||||
@@ -18,14 +18,11 @@ impl ControlMode for Volume {
|
||||
ControlModeMeta {
|
||||
name: "Volume",
|
||||
icon: "audio-volume-high",
|
||||
haptics: true,
|
||||
steps: 36 * 2,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(true, Some(36 * 2))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_btn_press(&mut self, _: &DialHaptics) -> Result<()> {
|
||||
// TODO: support double-click to play/pause
|
||||
Ok(())
|
||||
|
||||
@@ -18,14 +18,11 @@ impl ControlMode for Zoom {
|
||||
ControlModeMeta {
|
||||
name: "Zoom",
|
||||
icon: "zoom-in",
|
||||
haptics: true,
|
||||
steps: 36,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()> {
|
||||
haptics.set_mode(true, Some(36))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_btn_press(&mut self, _: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,14 +6,25 @@ use crate::error::{Error, Result};
|
||||
pub mod controls;
|
||||
|
||||
pub struct ControlModeMeta {
|
||||
/// Mode Name (as displayed in the Meta selection menu)
|
||||
name: &'static str,
|
||||
/// Mode Icon (as displayed in the Meta selection menu)
|
||||
///
|
||||
/// This can be a file:// url, or a standard FreeDesktop icon name.
|
||||
icon: &'static str,
|
||||
/// Enable automatic haptic feedback when rotating the dial.
|
||||
haptics: bool,
|
||||
/// How many sections the dial should be divided into (from 0 to 3600).
|
||||
steps: u16,
|
||||
}
|
||||
|
||||
pub trait ControlMode {
|
||||
fn meta(&self) -> ControlModeMeta;
|
||||
|
||||
fn on_start(&mut self, haptics: &DialHaptics) -> Result<()>;
|
||||
fn on_start(&mut self, _haptics: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_end(&mut self, _haptics: &DialHaptics) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -66,7 +77,10 @@ impl DialController {
|
||||
|
||||
if let Some(new_mode) = self.new_mode.lock().unwrap().take() {
|
||||
self.active_mode = ActiveMode::Normal(new_mode);
|
||||
self.modes[new_mode].on_start(haptics)?;
|
||||
let mode = &mut self.modes[new_mode];
|
||||
|
||||
haptics.set_mode(mode.meta().haptics, mode.meta().steps)?;
|
||||
mode.on_start(haptics)?;
|
||||
}
|
||||
|
||||
let mode = match self.active_mode {
|
||||
@@ -79,6 +93,7 @@ impl DialController {
|
||||
|
||||
DialEventKind::Connect => {
|
||||
eprintln!("Dial Connected");
|
||||
haptics.set_mode(mode.meta().haptics, mode.meta().steps)?;
|
||||
mode.on_start(haptics)?
|
||||
}
|
||||
DialEventKind::Disconnect => {
|
||||
@@ -95,6 +110,7 @@ impl DialController {
|
||||
if !matches!(self.active_mode, ActiveMode::Meta) {
|
||||
mode.on_end(haptics)?;
|
||||
self.active_mode = ActiveMode::Meta;
|
||||
// meta_mode sets haptic feedback manually
|
||||
self.meta_mode.on_start(haptics)?;
|
||||
}
|
||||
}
|
||||
@@ -157,11 +173,11 @@ impl ControlMode for MetaMode {
|
||||
.map_err(Error::Notif)?,
|
||||
);
|
||||
|
||||
haptics.set_mode(true, 36)?;
|
||||
haptics.buzz(1)?;
|
||||
|
||||
self.first_release = true;
|
||||
|
||||
haptics.set_mode(true, Some(36))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ impl DialHaptics {
|
||||
}
|
||||
|
||||
/// `steps` should be a value between 0 and 3600, which corresponds to the
|
||||
/// number of subdivisions the dial should use. If left unspecified, this
|
||||
/// defaults to 36 (an arbitrary choice that "feels good" most of the time)
|
||||
pub fn set_mode(&self, haptics: bool, steps: Option<u16>) -> Result<()> {
|
||||
/// number of subdivisions the dial should use.
|
||||
pub fn set_mode(&self, haptics: bool, steps: u16) -> Result<()> {
|
||||
let _ = (self.msg).send(DialHapticsWorkerMsg::SetMode { haptics, steps });
|
||||
Ok(())
|
||||
}
|
||||
@@ -32,7 +31,7 @@ impl DialHaptics {
|
||||
pub(super) enum DialHapticsWorkerMsg {
|
||||
DialConnected,
|
||||
DialDisconnected,
|
||||
SetMode { haptics: bool, steps: Option<u16> },
|
||||
SetMode { haptics: bool, steps: u16 },
|
||||
Manual { repeat: u8 },
|
||||
}
|
||||
|
||||
@@ -87,8 +86,7 @@ impl DialHidWrapper {
|
||||
/// `steps` should be a value between 0 and 3600, which corresponds to the
|
||||
/// number of subdivisions the dial should use. If left unspecified, this
|
||||
/// defaults to 36 (an arbitrary choice that "feels good" most of the time)
|
||||
fn set_mode(&self, haptics: bool, steps: Option<u16>) -> Result<()> {
|
||||
let steps = steps.unwrap_or(36);
|
||||
fn set_mode(&self, haptics: bool, steps: u16) -> Result<()> {
|
||||
assert!(steps <= 3600);
|
||||
|
||||
let steps_lo = steps & 0xff;
|
||||
|
||||
Reference in New Issue
Block a user