diff --git a/src/drivers/lego/driver.rs b/src/drivers/lego/driver.rs index 90795bc6..665917b6 100644 --- a/src/drivers/lego/driver.rs +++ b/src/drivers/lego/driver.rs @@ -6,7 +6,7 @@ use packed_struct::{types::SizedInteger, PackedStruct}; use super::{ event::{ AccelerometerEvent, AccelerometerInput, AxisEvent, BinaryInput, ButtonEvent, Event, - JoyAxisInput, TouchAxisInput, TriggerEvent, TriggerInput, WheelEvent, + JoyAxisInput, StatusEvent, StatusInput, TouchAxisInput, TriggerEvent, TriggerInput, }, hid_report::{ DInputDataLeftReport, DInputDataRightReport, KeyboardDataReport, MouseDataReport, @@ -605,8 +605,49 @@ impl Driver { }), )); - // State events - // TODO: Add state events. + // Status events + if state.l_controller_battery != old_state.l_controller_battery { + events.push(Event::Status(StatusEvent::LeftControllerBattery( + StatusInput { + value: state.l_controller_battery, + }, + ))); + } + if state.l_controller_mode0 != old_state.l_controller_mode0 { + events.push(Event::Status(StatusEvent::LeftControllerMode0( + StatusInput { + value: state.l_controller_mode0, + }, + ))); + } + if state.l_controller_mode1 != old_state.l_controller_mode1 { + events.push(Event::Status(StatusEvent::LeftControllerMode1( + StatusInput { + value: state.l_controller_mode1, + }, + ))); + } + if state.r_controller_battery != old_state.r_controller_battery { + events.push(Event::Status(StatusEvent::RightControllerBattery( + StatusInput { + value: state.r_controller_battery, + }, + ))); + } + if state.r_controller_mode0 != old_state.r_controller_mode0 { + events.push(Event::Status(StatusEvent::RightControllerMode0( + StatusInput { + value: state.r_controller_mode0, + }, + ))); + } + if state.r_controller_mode1 != old_state.r_controller_mode1 { + events.push(Event::Status(StatusEvent::RightControllerMode1( + StatusInput { + value: state.r_controller_mode1, + }, + ))); + } }; events diff --git a/src/drivers/lego/event.rs b/src/drivers/lego/event.rs index 5a406f28..03ad5dd4 100644 --- a/src/drivers/lego/event.rs +++ b/src/drivers/lego/event.rs @@ -5,6 +5,7 @@ pub enum Event { Accelerometer(AccelerometerEvent), Axis(AxisEvent), Trigger(TriggerEvent), + Status(StatusEvent), } /// Binary input contain either pressed or unpressed @@ -13,6 +14,33 @@ pub struct BinaryInput { pub pressed: bool, } +/// Axis input contain (x, y) coordinates +#[derive(Clone, Debug)] +pub struct TouchAxisInput { + pub x: u16, + pub y: u16, +} + +/// Axis input contain (x, y) coordinates +#[derive(Clone, Debug)] +pub struct JoyAxisInput { + pub x: u8, + pub y: u8, +} + +/// AccelerometerInput represents the state of the accelerometer (x, y, z) values +#[derive(Clone, Debug)] +pub struct AccelerometerInput { + pub x: u8, + pub y: u8, +} + +// Status inputs contain some value that corresponds to the current status of a device. +#[derive(Clone, Debug)] +pub struct StatusInput { + pub value: u8, +} + /// Button events represend binary inputs #[derive(Clone, Debug)] pub enum ButtonEvent { @@ -65,20 +93,6 @@ pub enum ButtonEvent { /// Mouse wheel click on the back of the right controller MouseClick(BinaryInput), } - -/// Axis input contain (x, y) coordinates -#[derive(Clone, Debug)] -pub struct TouchAxisInput { - pub x: u16, - pub y: u16, -} - -/// Axis input contain (x, y) coordinates -#[derive(Clone, Debug)] -pub struct JoyAxisInput { - pub x: u8, - pub y: u8, -} /// Axis events are events that have (x, y) values #[derive(Clone, Debug)] pub enum AxisEvent { @@ -100,16 +114,6 @@ pub enum TriggerEvent { MouseWheel(TriggerInput), } -/// Wheel events contain positive values indicating up and negative numbers indicating down -#[derive(Clone, Debug)] -pub enum WheelEvent {} -/// AccelerometerInput represents the state of the accelerometer (x, y, z) values -#[derive(Clone, Debug)] -pub struct AccelerometerInput { - pub x: u8, - pub y: u8, -} - /// AccelerometerEvent has data from the accelerometer #[derive(Clone, Debug)] pub enum AccelerometerEvent { @@ -118,3 +122,13 @@ pub enum AccelerometerEvent { //CenterAccelerometer(AccelerometerInput), // TODO: Gyro from sysfs } + +#[derive(Clone, Debug)] +pub enum StatusEvent { + LeftControllerBattery(StatusInput), + LeftControllerMode0(StatusInput), + LeftControllerMode1(StatusInput), + RightControllerBattery(StatusInput), + RightControllerMode0(StatusInput), + RightControllerMode1(StatusInput), +} diff --git a/src/drivers/lego/hid_report.rs b/src/drivers/lego/hid_report.rs index 29ce6731..8914d735 100644 --- a/src/drivers/lego/hid_report.rs +++ b/src/drivers/lego/hid_report.rs @@ -144,11 +144,14 @@ impl ReportType { // Somehow this has pitch, roll, and yaw in two 8 bit numbers. Perhaps it is incomplete (only two), or each // number is 5 bits? Reslution of 31 is really low. bytes 29 and 30 are left controller, 31 and 32 // are right controller. -// Also note bytes 5, 6, 7, 8, 11, and 12. These change when the controller is synced either docked -// or wireless and indicate the mode for each side. 5 and 7 are 100 (or 99) when the device is fully -// synced, or 0 when diconnected (left/right respectively). 6 and 11 correspond to if the left +// Also note bytes 6, 8, 11, and 12. These change when the controller is synced either docked +// or wireless and indicate the mode for each side. 6 and 11 correspond to if the left // controller is docked 6:4, 11:2 or wireless 6:1, 11:3. 7 and 12 are for the right controller, // same numbers. +// +// Battery Indicators +// 5 and 7 are left/right controller battery level, 0-100 +// // Left Accel // Not sure what the different numbers mean yet // # ReportID: 4 / 0xffa00003: 60 , 116 , 1 , 0 , 99 , 1 , 99 , 1 , 1 , 1 , 1 , 3 , 3 , -128 , -128 , -128 , -128 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , -128 , 0 , 0 , 0 , 0 , -16 , -67 , -128 , -128 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 @@ -272,11 +275,11 @@ pub struct XInputDataReport { pub unk_4: u8, #[packed_field(bytes = "5")] - pub l_controller_synced: u8, + pub l_controller_battery: u8, #[packed_field(bytes = "6")] pub l_controller_mode0: u8, #[packed_field(bytes = "7")] - pub r_controller_synced: u8, + pub r_controller_battery: u8, #[packed_field(bytes = "8")] pub r_controller_mode0: u8,