Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: USBJoysteck.cpp
- Revision:
- 8:59dd4860477f
- Parent:
- 4:00ac3d093b24
- Child:
- 10:db099ac191e8
--- a/USBJoysteck.cpp Tue Sep 27 12:50:45 2016 +0000 +++ b/USBJoysteck.cpp Tue Sep 27 13:42:03 2016 +0000 @@ -20,149 +20,158 @@ #include "stdint.h" #include "USBJoystick.h" -bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint8_t button, uint8_t hat) { - HID_REPORT report; - _t = t; - _r = r; - _x = x; - _y = y; - _button = button; - _hat = hat; +bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint8_t button, uint8_t hat) +{ + HID_REPORT report; + _t = t; + _r = r; + _x = x; + _y = y; + _button = button; + _hat = hat; - // Fill the report according to the Joystick Descriptor - report.data[0] = _t & 0xff; - report.data[1] = _r & 0xff; - report.data[2] = _x & 0xff; - report.data[3] = _y & 0xff; - report.data[4] = ((_button & 0x0f) << 4) | (_hat & 0x0f) ; - report.length = 5; - - return send(&report); -} - -bool USBJoystick::update() { - HID_REPORT report; + // Fill the report according to the Joystick Descriptor + report.data[0] = _t & 0xff; + report.data[1] = _r & 0xff; + report.data[2] = _x & 0xff; + report.data[3] = _y & 0xff; + report.data[4] = ((_button & 0x0f) << 4) | (_hat & 0x0f) ; + report.length = 5; - // Fill the report according to the Joystick Descriptor - report.data[0] = _t & 0xff; - report.data[1] = _r & 0xff; - report.data[2] = _x & 0xff; - report.data[3] = _y & 0xff; - report.data[4] = ((_button & 0x0f) << 4) | (_hat & 0x0f) ; - report.length = 5; - - return send(&report); + return send(&report); } -bool USBJoystick::throttle(int16_t t) { - _t = t; - return update(); +bool USBJoystick::update() +{ + HID_REPORT report; + + // Fill the report according to the Joystick Descriptor + report.data[0] = _t & 0xff; + report.data[1] = _r & 0xff; + report.data[2] = _x & 0xff; + report.data[3] = _y & 0xff; + report.data[4] = ((_button & 0x0f) << 4) | (_hat & 0x0f) ; + report.length = 5; + + return send(&report); } -bool USBJoystick::rudder(int16_t r) { - _r = r; - return update(); +bool USBJoystick::throttle(int16_t t) +{ + _t = t; + return update(); } -bool USBJoystick::move(int16_t x, int16_t y) { - _x = x; - _y = y; - return update(); +bool USBJoystick::rudder(int16_t r) +{ + _r = r; + return update(); } -bool USBJoystick::button(uint8_t button) { - _button = button; - return update(); +bool USBJoystick::move(int16_t x, int16_t y) +{ + _x = x; + _y = y; + return update(); } -bool USBJoystick::hat(uint8_t hat) { - _hat = hat; - return update(); +bool USBJoystick::button(uint8_t button) +{ + _button = button; + return update(); +} + +bool USBJoystick::hat(uint8_t hat) +{ + _hat = hat; + return update(); } -void USBJoystick::_init() { +void USBJoystick::_init() +{ - _t = -127; - _r = -127; - _x = 0; - _y = 0; - _button = 0x00; - _hat = 0x00; + _t = -127; + _r = -127; + _x = 0; + _y = 0; + _button = 0x00; + _hat = 0x00; } -uint8_t * USBJoystick::reportDesc() { - static uint8_t reportDescriptor[] = { +uint8_t * USBJoystick::reportDesc() +{ + static uint8_t reportDescriptor[] = { - USAGE_PAGE(1), 0x01, // Generic Desktop - LOGICAL_MINIMUM(1), 0x00, // Logical_Minimum (0) - USAGE(1), 0x04, // Usage (Joystick) - COLLECTION(1), 0x01, // Application - USAGE_PAGE(1), 0x02, // Simulation Controls - USAGE(1), 0xBB, // Throttle - USAGE(1), 0xBA, // Rudder - LOGICAL_MINIMUM(1), 0x81, // -127 - LOGICAL_MAXIMUM(1), 0x7f, // 127 - REPORT_SIZE(1), 0x08, - REPORT_COUNT(1), 0x02, - INPUT(1), 0x02, // Data, Variable, Absolute - USAGE_PAGE(1), 0x01, // Generic Desktop - USAGE(1), 0x01, // Usage (Pointer) - COLLECTION(1), 0x00, // Physical - USAGE(1), 0x30, // X - USAGE(1), 0x31, // Y + USAGE_PAGE(1), 0x01, // Generic Desktop + LOGICAL_MINIMUM(1), 0x00, // Logical_Minimum (0) + USAGE(1), 0x04, // Usage (Joystick) + COLLECTION(1), 0x01, // Application + USAGE_PAGE(1), 0x02, // Simulation Controls + USAGE(1), 0xBB, // Throttle + USAGE(1), 0xBA, // Rudder + LOGICAL_MINIMUM(1), 0x81, // -127 + LOGICAL_MAXIMUM(1), 0x7f, // 127 + REPORT_SIZE(1), 0x08, + REPORT_COUNT(1), 0x02, + INPUT(1), 0x02, // Data, Variable, Absolute + USAGE_PAGE(1), 0x01, // Generic Desktop + USAGE(1), 0x01, // Usage (Pointer) + COLLECTION(1), 0x00, // Physical + USAGE(1), 0x30, // X + USAGE(1), 0x31, // Y // 8 bit values - LOGICAL_MINIMUM(1), 0x81, // -127 - LOGICAL_MAXIMUM(1), 0x7f, // 127 - REPORT_SIZE(1), 0x08, - REPORT_COUNT(1), 0x02, - INPUT(1), 0x02, // Data, Variable, Absolute + LOGICAL_MINIMUM(1), 0x81, // -127 + LOGICAL_MAXIMUM(1), 0x7f, // 127 + REPORT_SIZE(1), 0x08, + REPORT_COUNT(1), 0x02, + INPUT(1), 0x02, // Data, Variable, Absolute // 16 bit values // LOGICAL_MINIMUM(1), 0x00, // 0 // LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767 // REPORT_SIZE(1), 0x10, // REPORT_COUNT(1), 0x02, -// INPUT(1), 0x02, // Data, Variable, Absolute +// INPUT(1), 0x02, // Data, Variable, Absolute - END_COLLECTION(0), + END_COLLECTION(0), // 4 Position Hat Switch // USAGE(1), 0x39, // Usage (Hat switch) // LOGICAL_MINIMUM(1), 0x00, // 0 // LOGICAL_MAXIMUM(1), 0x03, // 3 // PHYSICAL_MINIMUM(1), 0x00, // Physical_Minimum (0) // PHYSICAL_MAXIMUM(2), 0x0E, 0x01, // Physical_Maximum (270) -// UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos) +// UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos) // REPORT_SIZE(1), 0x04, // REPORT_COUNT(1), 0x01, -// INPUT(1), 0x02, // Data, Variable, Absolute +// INPUT(1), 0x02, // Data, Variable, Absolute // 8 Position Hat Switch - USAGE(1), 0x39, // Usage (Hat switch) - LOGICAL_MINIMUM(1), 0x00, // 0 - LOGICAL_MAXIMUM(1), 0x07, // 7 - PHYSICAL_MINIMUM(1), 0x00, // Physical_Minimum (0) - PHYSICAL_MAXIMUM(2), 0x3B, 0x01, // Physical_Maximum (315) - UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos) - REPORT_SIZE(1), 0x04, - REPORT_COUNT(1), 0x01, - INPUT(1), 0x02, // Data, Variable, Absolute + USAGE(1), 0x39, // Usage (Hat switch) + LOGICAL_MINIMUM(1), 0x00, // 0 + LOGICAL_MAXIMUM(1), 0x07, // 7 + PHYSICAL_MINIMUM(1), 0x00, // Physical_Minimum (0) + PHYSICAL_MAXIMUM(2), 0x3B, 0x01, // Physical_Maximum (315) + UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos) + REPORT_SIZE(1), 0x04, + REPORT_COUNT(1), 0x01, + INPUT(1), 0x02, // Data, Variable, Absolute // - USAGE_PAGE(1), 0x09, // Buttons - USAGE_MINIMUM(1), 0x01, // 1 - USAGE_MAXIMUM(1), 0x04, // 4 - LOGICAL_MINIMUM(1), 0x00, // 0 - LOGICAL_MAXIMUM(1), 0x01, // 1 - REPORT_SIZE(1), 0x01, - REPORT_COUNT(1), 0x04, - UNIT_EXPONENT(1), 0x00, // Unit_Exponent (0) - UNIT(1), 0x00, // Unit (None) - INPUT(1), 0x02, // Data, Variable, Absolute - END_COLLECTION(0) + USAGE_PAGE(1), 0x09, // Buttons + USAGE_MINIMUM(1), 0x01, // 1 + USAGE_MAXIMUM(1), 0x04, // 4 + LOGICAL_MINIMUM(1), 0x00, // 0 + LOGICAL_MAXIMUM(1), 0x01, // 1 + REPORT_SIZE(1), 0x01, + REPORT_COUNT(1), 0x04, + UNIT_EXPONENT(1), 0x00, // Unit_Exponent (0) + UNIT(1), 0x00, // Unit (None) + INPUT(1), 0x02, // Data, Variable, Absolute + END_COLLECTION(0) - }; + }; - reportLength = sizeof(reportDescriptor); - return reportDescriptor; + reportLength = sizeof(reportDescriptor); + return reportDescriptor; }