use num_derive::FromPrimitive;
use std::fmt::{self, Display};
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, Default)]
pub enum IoTypeId {
#[default]
Unknown = 0x00,
Motor = 0x01,
SystemTrainMotor = 0x02,
Button = 0x05,
LedLight = 0x08,
Voltage = 0x14, Current = 0x15, PiezoToneSound = 0x16, HubLed = 0x17,
ExternalTiltSensor = 0x22, MotionSensor = 0x23, VisionSensor = 0x25, ExternalMotorTacho = 0x26, InternalMotorTacho = 0x27, InternalTilt = 0x28, DuploTrainBaseMotor = 41, DuploTrainBaseSpeaker = 42, DuploTrainBaseColorSensor = 43, DuploTrainBaseSpeedometer = 44, TechnicLargeLinearMotor = 46, TechnicXLargeLinearMotor = 47, TechnicMediumAngularMotor = 48, TechnicLargeAngularMotor = 49,
TechnicHubGestSensor = 0x36, RemoteButtons = 0x37, Rssi = 0x38, TechnicHubAccelerometer = 0x39, TechnicHubGyroSensor = 0x3a, TechnicHubTiltSensor = 0x3b, TechnicHubTemperatureSensor = 0x3c, TechnicColorSensor = 61, TechnicDistanceSensor = 62, TechnicForceSensor = 63, Technic3x3ColorLightMatrix = 64, TechnicSmallAngularMotor = 65, UnknownMovehubDevice = 0x42,
MarioAccelerometer = 71, MarioBarcodeSensor = 73, MarioPantsSensor = 74, TechnicMediumAngularMotorGrey = 75, TechnicLargeAngularMotorGrey = 76, }
#[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 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,
}
pub const LEGO_COLORS: [Color; 11] = [
Color::Pink,
Color::Purple,
Color::Blue,
Color::LightBlue,
Color::Cyan,
Color::Green,
Color::Yellow,
Color::Orange,
Color::Red,
Color::White,
Color::Black,
];
pub mod named_port {
pub const A: u8 = 0x00;
pub const B: u8 = 0x01;
pub const C: u8 = 0x02;
pub const D: u8 = 0x03;
pub const MOVE_AB: u8 = 0x10;
}
#[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, Hash)]
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,
PortInputFormatSetupCombined = 0x42,
PortInformation = 0x43,
PortModeInformation = 0x44,
PortValueSingle = 0x45,
PortValueCombined = 0x46,
PortInputFormatSingle = 0x47,
PortInputFormatCombined = 0x48,
VirtualPortSetup = 0x61,
PortOutputCommand = 0x81,
PortOutputCommandFeedback = 0x82,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)]
pub enum HubPropertyRef {
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,
}
pub enum PortOutputSubCommandValue {
StartPower2 = 0x02,
SetAccTime = 0x05,
SetDecTime = 0x06,
StartSpeed = 0x07,
StartSpeed2 = 0x08,
StartSpeedForTime = 0x09,
StartSpeedForTime2 = 0x0a,
StartSpeedForDegrees = 0x0b,
StartSpeedForDegrees2 = 0x0c,
GotoAbsolutePosition = 0x0d,
GotoAbsolutePosition2 = 0x0e,
PresetEncoder2 = 0x14,
}
pub enum InputSetupCombinedSubcommandValue {
SetModeanddatasetCombinations = 0x01,
LockLpf2DeviceForSetup = 0x02,
UnlockAndStartMultiEnabled = 0x03,
UnlockAndStartMultiDisabled = 0x04,
NotUsed = 0x05,
ResetSensor = 0x06,
}
pub enum MotorSensorMode {
Power = 0x0,
Speed = 0x1,
Pos = 0x2,
APos = 0x3,
Calib = 0x4,
Stats = 0x5,
}
pub enum VisionSensorMode {
Color = 0x0,
Prox = 0x1,
Count = 0x2,
Reflt = 0x3,
Ambi = 0x4,
ColO = 0x5,
RgbI = 0x6,
IrTx = 0x7,
Spec1 = 0x8,
Debug = 0x9,
Calib = 0xa,
}