use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use std::fmt::{self, Display};
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum HubType {
Unknown = 0,
Wedo2SmartHub = 1,
MoveHub = 2,
Hub = 3,
RemoteControl = 4,
DuploTrainBase = 5,
TechnicMediumHub = 6,
Mario = 7,
}
impl Display for HubType {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use HubType::*;
match self {
Unknown | MoveHub | Hub | Mario => write!(fmt, "{:?}", self),
Wedo2SmartHub => write!(fmt, "Wedo 2 Smart Hub"),
RemoteControl => write!(fmt, "Remote Control"),
DuploTrainBase => write!(fmt, "Duplo Train Base"),
TechnicMediumHub => write!(fmt, "Technic Medium Hub"),
}
}
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DeviceType {
Unknown = 0,
SimpleMediumLinearMotor = 1,
TrainMotor = 2,
Light = 8,
VoltageSensor = 20,
CurrentSensor = 21,
PiezoBuzzer = 22,
HubLed = 23,
TiltSensor = 34,
MotionSensor = 35,
ColorDistanceSensor = 37,
MediumLinearMotor = 38,
MoveHubMediumLinearMotor = 39,
MoveHubTiltSensor = 40,
DuploTrainBaseMotor = 41,
DuploTrainBaseSpeaker = 42,
DuploTrainBaseColorSensor = 43,
DuploTrainBaseSpeedometer = 44,
TechnicLargeLinearMotor = 46, TechnicXlargeLinearMotor = 47, TechnicMediumAngularMotor = 48, TechnicLargeAngularMotor = 49, TechnicMediumHubGestSensor = 54,
RemoteControlButton = 55,
RemoteControlRssi = 56,
TechnicMediumHubAccelerometer = 57,
TechnicMediumHubGyroSensor = 58,
TechnicMediumHubTiltSensor = 59,
TechnicMediumHubTemperatureSensor = 60,
TechnicColorSensor = 61, TechnicDistanceSensor = 62, TechnicForceSensor = 63, MarioAccelerometer = 71,
MarioBarcodeSensor = 73,
MarioPantsSensor = 74,
TechnicMediumAngularMotorGrey = 75, TechnicLargeAngularMotorGrey = 76, }
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Color {
Black = 0,
Pink = 1,
Purple = 2,
Blue = 3,
LightBlue = 4,
Cyan = 5,
Green = 6,
Yellow = 7,
Orange = 8,
Red = 9,
White = 10,
None = 255,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BrakingStyle {
Float = 0,
Hold = 126,
Brake = 127,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DuploTrainBaseSound {
Brake = 3,
StationDeparture = 5,
WaterRefill = 7,
Horn = 9,
Steam = 10,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum BLEManufacturerData {
DuploTrainBaseId = 32,
MoveHubId = 64,
HubId = 65,
RemoteControlId = 66,
MarioId = 67,
TechnicMediumHubId = 128,
}
pub mod bleservice {
use lazy_static::lazy_static;
use uuid::Uuid;
pub const WEDO2_SMART_HUB_2: &str = "00004f0e-1212-efde-1523-785feabcd123";
pub const WEDO2_SMART_HUB_3: &str = "2a19";
pub const WEDO2_SMART_HUB_4: &str = "180f";
pub const WEDO2_SMART_HUB_5: &str = "180a";
lazy_static! {
pub static ref WEDO2_SMART_HUB: Uuid =
Uuid::parse_str("00001523-1212-efde-1523-785feabcd123").unwrap();
pub static ref LPF2_HUB: Uuid =
Uuid::parse_str("00001623-1212-efde-1623-785feabcd123").unwrap();
}
}
pub mod blecharacteristic {
use lazy_static::lazy_static;
use uuid::Uuid;
pub const WEDO2_BATTERY: &str = "2a19";
pub const WEDO2_FIRMWARE_REVISION: &str = "2a26";
pub const WEDO2_BUTTON: &str = "00001526-1212-efde-1523-785feabcd123"; pub const WEDO2_PORT_TYPE: &str = "00001527-1212-efde-1523-785feabcd123"; pub const WEDO2_LOW_VOLTAGE_ALERT: &str =
"00001528-1212-efde-1523-785feabcd123"; pub const WEDO2_HIGH_CURRENT_ALERT: &str =
"00001529-1212-efde-1523-785feabcd123"; pub const WEDO2_LOW_SIGNAL_ALERT: &str =
"0000152a-1212-efde-1523-785feabcd123"; pub const WEDO2_DISCONNECT: &str = "0000152b-1212-efde-1523-785feabcd123"; pub const WEDO2_SENSOR_VALUE: &str = "00001560-1212-efde-1523-785feabcd123"; pub const WEDO2_VALUE_FORMAT: &str = "00001561-1212-efde-1523-785feabcd123"; pub const WEDO2_PORT_TYPE_WRITE: &str =
"00001563-1212-efde-1523-785feabcd123"; pub const WEDO2_MOTOR_VALUE_WRITE: &str =
"00001565-1212-efde-1523-785feabcd123"; pub const WEDO2_NAME_ID: &str = "00001524-1212-efde-1523-785feabcd123"; lazy_static! {
pub static ref LPF2_ALL: Uuid =
Uuid::parse_str("00001624-1212-efde-1623-785feabcd123").unwrap();
}
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum MessageType {
HubProperties = 0x01,
HubActions = 0x02,
HubAlerts = 0x03,
HubAttachedIo = 0x04,
GenericErrorMessages = 0x05,
HwNetworkCommands = 0x08,
FwUpdateGoIntoBootMode = 0x10,
FwUpdateLockMemory = 0x11,
FwUpdateLockStatusRequest = 0x12,
FwLockStatus = 0x13,
PortInformationRequest = 0x21,
PortModeInformationRequest = 0x22,
PortInputFormatSetupSingle = 0x41,
PortInputFormatSetupCombinedmode = 0x42,
PortInformation = 0x43,
PortModeInformation = 0x44,
PortValueSingle = 0x45,
PortValueCombinedmode = 0x46,
PortInputFormatSingle = 0x47,
PortInputFormatCombinedmode = 0x48,
VirtualPortSetup = 0x61,
PortOutputCommand = 0x81,
PortOutputCommandFeedback = 0x82,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum HubPropertyReference {
AdvertisingName = 0x01,
Button = 0x02,
FwVersion = 0x03,
HwVersion = 0x04,
Rssi = 0x05,
BatteryVoltage = 0x06,
BatteryType = 0x07,
ManufacturerName = 0x08,
RadioFirmwareVersion = 0x09,
LegoWirelessProtocolVersion = 0x0A,
SystemTypeId = 0x0B,
HwNetworkId = 0x0C,
PrimaryMacAddress = 0x0D,
SecondaryMacAddress = 0x0E,
HardwareNetworkFamily = 0x0F,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum HubPropertyOperation {
SetDownstream = 0x01,
EnableUpdatesDownstream = 0x02,
DisableUpdatesDownstream = 0x03,
ResetDownstream = 0x04,
RequestUpdateDownstream = 0x05,
UpdateUpstream = 0x06,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum HubPropertyPayload {
AdvertisingName = 0x01,
ButtonState = 0x02,
FwVersion = 0x03,
HwVersion = 0x04,
Rssi = 0x05,
BatteryVoltage = 0x06,
BatteryType = 0x07,
ManufacturerName = 0x08,
RadioFirmwareVersion = 0x09,
LwpProtocolVersion = 0x0A,
SystemTypeId = 0x0B,
HwNetworkId = 0x0C,
PrimaryMacAddress = 0x0D,
SecondaryMacAddress = 0x0E,
HwNetworkFamily = 0x0F,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ActionType {
SwitchOffHub = 0x01,
Disconnect = 0x02,
VccPortControlOn = 0x03,
VccPortControlOff = 0x04,
ActivateBusyIndication = 0x05,
ResetBusyIndication = 0x06,
Shutdown = 0x2F,
HubWillSwitchOff = 0x30,
HubWillDisconnect = 0x31,
HubWillGoIntoBootMode = 0x32,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AlertPayload {
StatusOk = 0x00,
Alert = 0xFF,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum Event {
DetachedIo = 0x00,
AttachedIo = 0x01,
AttachedVirtualIo = 0x02,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum HwNetworkCommandType {
ConnectionRequest = 0x02,
FamilyRequest = 0x03,
FamilySet = 0x04,
JoinDenied = 0x05,
GetFamily = 0x06,
Family = 0x07,
GetSubfamily = 0x08,
Subfamily = 0x09,
SubfamilySet = 0x0A,
GetExtendedFamily = 0x0B,
ExtendedFamily = 0x0C,
ExtendedFamilySet = 0x0D,
ResetLongPressTiming = 0x0E,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum PortInputFormatSetupSubCommand {
SetModeanddatasetCombinations = 0x01,
LockLpf2DeviceForSetup = 0x02,
UnlockAndStartMultiEnabled = 0x03,
UnlockAndStartMultiDisabled = 0x04,
NotUsed = 0x05,
ResetSensor = 0x06,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum MarioPantsType {
None = 0x00,
Propeller = 0x06,
Cat = 0x11,
Fire = 0x12,
Normal = 0x21,
Builder = 0x22,
}
#[repr(u16)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum MarioColor {
White = 0x1300,
Red = 0x1500,
Blue = 0x1700,
Yellow = 0x1800,
Black = 0x1a00,
Green = 0x2500,
Brown = 0x6a00,
Cyan = 0x4201,
}