Skip to main content

rmk_types/action/
encoder.rs

1//! Rotary encoder actions.
2
3use postcard::experimental::max_size::MaxSize;
4use serde::{Deserialize, Serialize};
5
6use super::KeyAction;
7
8/// Action for a rotary encoder position, stored in the encoder map.
9///
10/// Both fields default to `KeyAction::No` (no action).
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, MaxSize)]
12#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
14#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
15pub struct EncoderAction {
16    /// Action triggered when the encoder is rotated clockwise.
17    pub clockwise: KeyAction,
18    /// Action triggered when the encoder is rotated counter-clockwise.
19    pub counter_clockwise: KeyAction,
20}
21
22impl Default for EncoderAction {
23    fn default() -> Self {
24        Self {
25            clockwise: KeyAction::No,
26            counter_clockwise: KeyAction::No,
27        }
28    }
29}
30
31impl EncoderAction {
32    /// Create a new encoder action.
33    pub const fn new(clockwise: KeyAction, counter_clockwise: KeyAction) -> Self {
34        Self {
35            clockwise,
36            counter_clockwise,
37        }
38    }
39}