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 65 66 67 68 69 70 71 72 73 74 75 76
use lotus_shared::message::message_type;
use serde::{Deserialize, Serialize};
/// Represents an event triggered by a sensor in the system.
///
/// A trigger event occurs when an object enters or leaves a sensor's detection area.
/// Each sensor has a unique index and can detect both entry and exit events.
#[derive(Debug, Serialize, Deserialize)]
pub struct TriggerEvent {
/// Unique identifier for the trigger event
pub id: String,
/// Index of the sensor that generated this event
pub sensor_index: i32,
/// The type of trigger (Enter or Leave)
pub kind: TriggerKind,
}
impl TriggerEvent {
/// Returns true if this is an entry event
pub fn is_enter(&self) -> bool {
self.kind.is_enter()
}
/// Returns true if this is a leave event
pub fn is_leave(&self) -> bool {
self.kind.is_leave()
}
}
message_type!(TriggerEvent, "builtin", "trigger_event");
/// Represents the type of trigger event that occurred.
#[derive(Debug, Serialize, Deserialize)]
pub enum TriggerKind {
/// Indicates an object entered the sensor's detection area
Enter,
/// Indicates an object left the sensor's detection area
Leave,
}
impl TriggerKind {
/// Returns true if this trigger represents an entry event
pub fn is_enter(&self) -> bool {
matches!(self, Self::Enter)
}
/// Returns true if this trigger represents a leave event
pub fn is_leave(&self) -> bool {
matches!(self, Self::Leave)
}
}
/// Represents a button press or release event in the cockpit.
///
/// Button events capture the state changes of buttons in different
/// cockpit positions, tracking whether they are pressed or released.
#[derive(Debug, Serialize, Deserialize)]
pub struct ButtonEvent {
/// Unique identifier for the button event
pub id: String,
/// Current state of the button (true = pressed, false = released)
pub value: bool,
/// Index identifying the cockpit position of this button
pub cockpit_index: u8,
}
message_type!(ButtonEvent, "builtin", "button_event");
/// Represents the state of the battery switch.
///
/// A simple wrapper around a boolean value indicating whether
/// the battery is switched on (true) or off (false).
#[derive(Debug, Serialize, Deserialize)]
pub struct BatterySwitch(pub bool);
message_type!(BatterySwitch, "builtin", "battery_switch");