(
fn get_joystick_report(
matrix_keys: &mut [Button; NUMBER_OF_BUTTONS + 2],
axis: &mut [GimbalAxis; 4],
+ virtual_ry: &i16,
+ virtual_rz: &i16,
) -> JoystickReport {
let x: i16 = axis_12bit_to_i16(axis[GIMBAL_AXIS_LEFT_X].value);
let y: i16 = axis_12bit_to_i16(ADC_MAX - axis[GIMBAL_AXIS_LEFT_Y].value);
let z: i16 = axis_12bit_to_i16(axis[GIMBAL_AXIS_RIGHT_X].value);
let rx: i16 = axis_12bit_to_i16(ADC_MAX - axis[GIMBAL_AXIS_RIGHT_Y].value);
+ let ry: i16 = *virtual_ry;
+ let rz: i16 = *virtual_rz;
// Update button state for joystick buttons
let mut buttons: u32 = 0;
@@ -687,50 +721,12 @@ fn get_joystick_report(
y,
z,
rx,
+ ry,
+ rz,
buttons,
}
}
-/// Format hat value from 5 switches to USB HID coded value and button state
-///
-/// # Arguments
-/// * `input` - Hat value coded as
-/// bit 2-5: direction (U L R D)
-/// bit 1: button state
-/// 0 = not pressed
-/// 1 = pressed
-fn format_hat_value(input: u8) -> (u8, u8) {
- const HAT_CENTER: u8 = 8; //8 or 15 (OS-dependent; usually 8)
- const HAT_UP: u8 = 0;
- const HAT_UP_RIGHT: u8 = 1;
- const HAT_RIGHT: u8 = 2;
- const HAT_DOWN_RIGHT: u8 = 3;
- const HAT_DOWN: u8 = 4;
- const HAT_DOWN_LEFT: u8 = 5;
- const HAT_LEFT: u8 = 6;
- const HAT_UP_LEFT: u8 = 7;
-
- let direction: u8 = match input & 0xFE {
- 2 => HAT_UP,
- 4 => HAT_RIGHT,
- 6 => HAT_UP_RIGHT,
- 8 => HAT_DOWN,
- 12 => HAT_DOWN_RIGHT,
- 16 => HAT_LEFT,
- 24 => HAT_DOWN_LEFT,
- 18 => HAT_UP_LEFT,
- _ => HAT_CENTER,
- };
-
- // Alpine hat switch button filter
- let mut button_state: u8 = 0;
- if input & 0x01 == 0x01 && direction == HAT_CENTER {
- button_state = 1;
- }
-
- (direction, button_state)
-}
-
/// Calculate value for joystick axis
///
/// # Arguments
diff --git a/rp2040/src/usb_joystick_device.rs b/rp2040/src/usb_joystick_device.rs
index 216f5ce..aac6b94 100644
--- a/rp2040/src/usb_joystick_device.rs
+++ b/rp2040/src/usb_joystick_device.rs
@@ -67,15 +67,17 @@ pub const JOYSTICK_DESCRIPTOR: &[u8] = &[
0x09, 0x04, // Usage (Joystick)
0xA1, 0x01, // Collection (Application)
- // 4 signed 16-bit axes: X, Y, Z, Rx
+ // 6 signed 16-bit axes: X, Y, Z, Rx, Ry, Rz
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x09, 0x32, // Usage (Z)
0x09, 0x33, // Usage (Rx)
+ 0x09, 0x34, // Usage (Ry)
+ 0x09, 0x35, // Usage (Rz)
0x16, 0x00, 0x80, // Logical Minimum (-32768)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x75, 0x10, // Report Size (16)
- 0x95, 0x04, // Report Count (4)
+ 0x95, 0x06, // Report Count (6)
0x81, 0x02, // Input (Data,Var,Abs)
// 26 Buttons (1-bit each)
@@ -102,6 +104,8 @@ pub struct JoystickReport {
pub y: i16, // 16bit
pub z: i16, // 16bit
pub rx: i16, // 16bit
+ pub ry: i16, // 16bit
+ pub rz: i16, // 16bit
pub buttons: u32, // 32bit
}
@@ -111,7 +115,7 @@ pub struct Joystick<'a, B: UsbBus> {
impl