Skip to content

Commit

Permalink
feat(input_device): add event definition
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Dec 27, 2024
1 parent 4a3597c commit ff8aa3a
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions rmk/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,63 @@ use defmt::Format;
use postcard::experimental::max_size::MaxSize;
use serde::{Deserialize, Serialize};

/// Raw events from input devices and keyboards
///
/// This should be as close to the raw output of the devices as possible.
/// The input processors receives it, processes it,
/// and then converts it to the final keyboard/mouse report.
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Event {
/// Keyboard event
Key(KeyEvent),
/// Multi-touch touchpad
Touchpad(TouchpadEvent),
/// Joystick, suppose we have x,y,z axes for this joystick
Joystick([AxisEvent; 3]),
}

/// Event for multi-touch touchpad
#[derive(Serialize, Deserialize, Clone, Debug, Format, MaxSize)]
pub struct TouchpadEvent {
/// Finger slot
pub finger: u8,
/// X, Y, Z axes for touchpad
pub axis: [AxisEvent; 3],
}

#[derive(Serialize, Deserialize, Clone, Debug, Copy, Format, MaxSize)]
pub struct AxisEvent {
/// The axis event value type, relative or absolute
pub typ: AxisValType,
/// The axis name
pub axis: Axis,
/// Value of the axis event
pub value: i8,
}

#[derive(Serialize, Deserialize, Clone, Debug, Copy, Format, MaxSize)]
pub enum AxisValType {
/// The axis value is relative
Rel,
/// The axis value is absolute
Abs,
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
#[non_exhaustive]
pub enum Axis {
X,
Y,
Z,
H,
V,
// .. More is allowed
}

#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
pub struct KeyEvent {
pub row: u8,
pub col: u8,
pub pressed: bool,
}


#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
pub struct MouseEvent {
pub buttons: u8,
pub x: i8,
pub y: i8,
pub wheel: i8, // Scroll down (negative) or up (positive) this many units
pub pan: i8, // Scroll left (negative) or right (positive) this many units
}

0 comments on commit ff8aa3a

Please sign in to comment.