lotus_script/message/types.rs
1use lotus_shared::message::message_type;
2use serde::{Deserialize, Serialize};
3
4/// Represents an event triggered by a sensor in the system.
5///
6/// A trigger event occurs when an object enters or leaves a sensor's detection area.
7/// Each sensor has a unique index and can detect both entry and exit events.
8#[derive(Debug, Serialize, Deserialize)]
9pub struct TriggerEvent {
10 /// Unique identifier for the trigger event
11 pub id: String,
12 /// Index of the sensor that generated this event
13 pub sensor_index: i32,
14 /// The type of trigger (Enter or Leave)
15 pub kind: TriggerKind,
16}
17
18impl TriggerEvent {
19 /// Returns true if this is an entry event
20 pub fn is_enter(&self) -> bool {
21 self.kind.is_enter()
22 }
23
24 /// Returns true if this is a leave event
25 pub fn is_leave(&self) -> bool {
26 self.kind.is_leave()
27 }
28}
29
30message_type!(TriggerEvent, "builtin", "trigger_event");
31
32/// Represents the type of trigger event that occurred.
33#[derive(Debug, Serialize, Deserialize)]
34pub enum TriggerKind {
35 /// Indicates an object entered the sensor's detection area
36 Enter,
37 /// Indicates an object left the sensor's detection area
38 Leave,
39}
40
41impl TriggerKind {
42 /// Returns true if this trigger represents an entry event
43 pub fn is_enter(&self) -> bool {
44 matches!(self, Self::Enter)
45 }
46
47 /// Returns true if this trigger represents a leave event
48 pub fn is_leave(&self) -> bool {
49 matches!(self, Self::Leave)
50 }
51}
52
53/// Represents a button press or release event in the cockpit.
54///
55/// Button events capture the state changes of buttons in different
56/// cockpit positions, tracking whether they are pressed or released.
57#[derive(Debug, Serialize, Deserialize)]
58pub struct ButtonEvent {
59 /// Unique identifier for the button event
60 pub id: String,
61 /// Current state of the button (true = pressed, false = released)
62 pub value: bool,
63 /// Index identifying the cockpit position of this button
64 pub cockpit_index: u8,
65}
66
67message_type!(ButtonEvent, "builtin", "button_event");
68
69/// Represents the state of the battery switch.
70///
71/// A simple wrapper around a boolean value indicating whether
72/// the battery is switched on (true) or off (false).
73#[derive(Debug, Serialize, Deserialize)]
74pub struct BatterySwitch(pub bool);
75
76message_type!(BatterySwitch, "builtin", "battery_switch");