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