1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use serde::{Deserialize, Serialize};

use super::MessageType;

#[derive(Debug, Serialize, Deserialize)]
pub struct TriggerEvent {
    pub id: String,
    pub sensor_index: i32,
    pub kind: TriggerKind,
}

impl TriggerEvent {
    pub fn is_enter(&self) -> bool {
        self.kind.is_enter()
    }

    pub fn is_leave(&self) -> bool {
        self.kind.is_leave()
    }
}

impl MessageType for TriggerEvent {
    fn id() -> &'static str {
        "builtin:trigger_event"
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub enum TriggerKind {
    Enter,
    Leave,
}

impl TriggerKind {
    pub fn is_enter(&self) -> bool {
        matches!(self, Self::Enter)
    }

    pub fn is_leave(&self) -> bool {
        matches!(self, Self::Leave)
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ButtonEvent {
    pub id: String,
    pub value: bool,
    pub cockpit_index: u8,
}

impl MessageType for ButtonEvent {
    fn id() -> &'static str {
        "builtin:button_event"
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BatterySwitch(pub bool);

impl MessageType for BatterySwitch {
    fn id() -> &'static str {
        "builtin:battery_switch"
    }
}