use postcard::experimental::max_size::MaxSize;
use rmk_macro::event;
use rmk_types::modifier::ModifierCombination;
use serde::{Deserialize, Serialize};
use crate::input_device::pointing::PointingMode;
use crate::input_device::rotary_encoder::Direction;
#[event(
channel_size = crate::KEYBOARD_EVENT_CHANNEL_SIZE,
pubs = crate::KEYBOARD_EVENT_PUB_SIZE,
subs = crate::KEYBOARD_EVENT_SUB_SIZE
)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct KeyboardEvent {
pub pressed: bool,
pub pos: KeyboardEventPos,
}
impl KeyboardEvent {
pub fn key(row: u8, col: u8, pressed: bool) -> Self {
Self {
pressed,
pos: KeyboardEventPos::Key(KeyPos { row, col }),
}
}
pub fn rotary_encoder(id: u8, direction: Direction, pressed: bool) -> Self {
Self {
pressed,
pos: KeyboardEventPos::RotaryEncoder(RotaryEncoderPos { id, direction }),
}
}
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum KeyboardEventPos {
Key(KeyPos),
RotaryEncoder(RotaryEncoderPos),
}
impl KeyboardEventPos {
pub(crate) fn key_pos(col: u8, row: u8) -> Self {
Self::Key(KeyPos { row, col })
}
pub(crate) fn rotary_encoder_pos(id: u8, direction: Direction) -> Self {
Self::RotaryEncoder(RotaryEncoderPos { id, direction })
}
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct KeyPos {
pub row: u8,
pub col: u8,
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RotaryEncoderPos {
pub id: u8,
pub direction: Direction,
}
#[event(channel_size = crate::MODIFIER_EVENT_CHANNEL_SIZE, pubs = crate::MODIFIER_EVENT_PUB_SIZE, subs = crate::MODIFIER_EVENT_SUB_SIZE)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ModifierEvent {
pub modifier: ModifierCombination,
}
#[event(
channel_size = crate::POINTING_EVENT_CHANNEL_SIZE,
pubs = crate::POINTING_EVENT_PUB_SIZE,
subs = crate::POINTING_EVENT_SUB_SIZE
)]
#[derive(Serialize, Deserialize, Clone, Debug, Copy, MaxSize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PointingEvent {
pub device_id: u8,
pub axes: [AxisEvent; 3],
}
#[derive(Serialize, Deserialize, Clone, Debug, Copy, MaxSize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AxisEvent {
pub typ: AxisValType,
pub axis: Axis,
pub value: i16,
}
#[derive(Serialize, Deserialize, Clone, Debug, Copy, MaxSize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AxisValType {
Rel,
Abs,
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, MaxSize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Axis {
X,
Y,
Z,
H,
V,
}
#[event(channel_size = 8, pubs = 2, subs = 2)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PointingSetCpiEvent {
pub device_id: u8,
pub cpi: u16,
}
#[event(channel_size = 8, pubs = 2, subs = 2)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PointingProcessorEvent {
pub device_id: u8,
pub mode: PointingMode,
}