use crate::service::{ResourceIdentifier, ResourceType};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
#[derive(Debug)]
pub struct Button {
data: ButtonData,
}
impl Button {
pub fn new(data: ButtonData) -> Self {
Button { data }
}
pub fn data(&self) -> &ButtonData {
&self.data
}
pub fn id(&self) -> &str {
&self.data.id
}
pub fn rid(&self) -> ResourceIdentifier {
self.data.rid()
}
pub fn control_id(&self) -> u8 {
self.data.metadata.control_id
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ButtonData {
pub id: String,
pub id_v1: Option<String>,
pub owner: ResourceIdentifier,
pub metadata: ButtonMetadata,
pub button: ButtonState,
}
impl ButtonData {
pub fn rid(&self) -> ResourceIdentifier {
ResourceIdentifier {
rid: self.id.to_owned(),
rtype: ResourceType::Button,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ButtonMetadata {
pub control_id: u8,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ButtonState {
#[deprecated]
pub last_event: Option<ButtonEvent>,
pub button_report: Option<ButtonReport>,
pub repeat_interval: Option<usize>,
pub event_values: HashSet<ButtonEvent>,
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ButtonEvent {
InitialPress,
Repeat,
ShortRelease,
LongRelease,
DoubleShortRelease,
LongPress,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ButtonReport {
pub updated: String,
pub event: ButtonEvent,
}
#[derive(Debug)]
pub struct RelativeRotary {
data: RelativeRotaryData,
}
impl RelativeRotary {
pub fn new(data: RelativeRotaryData) -> Self {
RelativeRotary { data }
}
pub fn data(&self) -> &RelativeRotaryData {
&self.data
}
pub fn id(&self) -> &str {
&self.data.id
}
pub fn rid(&self) -> ResourceIdentifier {
self.data.rid()
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct RelativeRotaryData {
pub id: String,
pub id_v1: Option<String>,
pub owner: ResourceIdentifier,
pub relative_rotary: RelativeRotaryState,
}
impl RelativeRotaryData {
pub fn rid(&self) -> ResourceIdentifier {
ResourceIdentifier {
rid: self.id.to_owned(),
rtype: ResourceType::RelativeRotary,
}
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct RelativeRotaryState {
#[deprecated = "moved to `rotary_report`"]
pub last_event: Option<RelativeRotaryLastEvent>,
pub rotary_report: Option<RotationReport>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct RelativeRotaryLastEvent {
pub action: RelativeRotaryAction,
pub rotation: RelativeRotaryRotationState,
}
#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RelativeRotaryAction {
Start,
Repeat,
}
#[derive(Clone, Debug, Deserialize)]
pub struct RelativeRotaryRotationState {
pub direction: RelativeRotaryDirection,
pub steps: u16,
pub duration: u16,
}
#[derive(Clone, Copy, Debug, Deserialize)]
pub enum RelativeRotaryDirection {
#[serde(rename = "clock_wise")]
Clockwise,
#[serde(rename = "counter_clock_wise")]
CounterClockwise,
}
#[derive(Clone, Debug, Deserialize)]
pub struct RotationReport {
pub updated: String,
pub action: RelativeRotaryAction,
pub rotation: RelativeRotaryRotationState,
}