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.
Dependents: USBJoystick_HelloWorld2_wip
Fork of USBJoystick by
USBJoystick Class Reference
USBJoystick example. More...
#include <USBJoystick.h>
Public Member Functions | |
| USBJoystick (uint16_t vendor_id=0x1209, uint16_t product_id=0x0601, uint16_t product_release=0x0101, int waitForConnect=true) | |
| Constructor. | |
| bool | update (int16_t t, int16_t r, int16_t f, int16_t b, int16_t x, int16_t y, uint32_t buttons, uint8_t hat) |
| Write state of the joystick. | |
| bool | update () |
| Write state of the joystick. | |
| bool | throttle (int16_t t) |
| Move the throttle position. | |
| bool | rudder (int16_t r) |
| Move the rudder position. | |
| bool | flaps (int16_t r) |
| Move the flaps position. | |
| bool | breaks (int16_t b) |
| Move the breaks position. | |
| bool | move (int16_t x, int16_t y) |
| Move the cursor to (x, y) | |
| bool | buttons (uint32_t buttons) |
| Press one or several buttons. | |
| bool | hat (uint8_t hat) |
| Press hat. | |
| virtual uint8_t * | reportDesc () |
| To define the interface descriptor string. | |
Detailed Description
USBJoystick example.
#include "mbed.h" #include "USBJoystick.h" USBJoystick joystick; int main(void) { while (1) { joystick.move(20, 0); wait(0.5); } }
#include "mbed.h" #include "USBJoystick.h" USBJoystick joystick; int main(void) { uint16_t i = 0; int16_t throttle = 0; int16_t rudder = 0; int16_t x = 0; int16_t y = 0; int32_t radius = 120; int32_t angle = 0; uint32_t buttons = 0; uint8_t hat = 0; while (1) { // Basic Joystick throttle = (i >> 8) & 0xFF; // value -127 .. 128 rudder = (i >> 8) & 0xFF; // value -127 .. 128 buttons = (i >> 8) & 0x0F; // value 0 .. 15, one bit per button hat = (i >> 8) & 0x07; // value 0 .. 7 or 8 for neutral i++; x = cos((double)angle*3.14/180.0)*radius; // value -127 .. 128 y = sin((double)angle*3.14/180.0)*radius; // value -127 .. 128 angle += 3; joystick.update(throttle, rudder, x, y, buttons, hat); wait(0.001); } }
Definition at line 156 of file USBJoystick.h.
Constructor & Destructor Documentation
| USBJoystick | ( | uint16_t | vendor_id = 0x1209, |
| uint16_t | product_id = 0x0601, |
||
| uint16_t | product_release = 0x0101, |
||
| int | waitForConnect = true |
||
| ) |
Constructor.
- Parameters:
-
vendor_id Your vendor_id (default: 0x1234) product_id Your product_id (default: 0x0002) product_release Your product_release (default: 0x0001)
Definition at line 170 of file USBJoystick.h.
Member Function Documentation
| bool breaks | ( | int16_t | b ) |
Move the breaks position.
- Parameters:
-
b breaks position
- Returns:
- true if there is no error, false otherwise
Definition at line 121 of file USBJoystick.cpp.
| bool buttons | ( | uint32_t | buttons ) |
Press one or several buttons.
- Parameters:
-
buttons buttons state
- Returns:
- true if there is no error, false otherwise
Definition at line 134 of file USBJoystick.cpp.
| bool flaps | ( | int16_t | r ) |
Move the flaps position.
- Parameters:
-
f flaps position
- Returns:
- true if there is no error, false otherwise
Definition at line 115 of file USBJoystick.cpp.
| bool hat | ( | uint8_t | hat ) |
Press hat.
- Parameters:
-
hat hat state
- Returns:
- true if there is no error, false otherwise
Definition at line 140 of file USBJoystick.cpp.
| bool move | ( | int16_t | x, |
| int16_t | y | ||
| ) |
Move the cursor to (x, y)
- Parameters:
-
x-axis position y-axis position
- Returns:
- true if there is no error, false otherwise
Definition at line 127 of file USBJoystick.cpp.
| uint8_t * reportDesc | ( | ) | [virtual] |
To define the interface descriptor string.
- Returns:
- pointer to the interface descriptor string To define the product descriptor string.
- pointer to the product descriptor string To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
- pointer to the report descriptor
Definition at line 197 of file USBJoystick.cpp.
| bool rudder | ( | int16_t | r ) |
Move the rudder position.
- Parameters:
-
r rudder position
- Returns:
- true if there is no error, false otherwise
Definition at line 109 of file USBJoystick.cpp.
| bool throttle | ( | int16_t | t ) |
Move the throttle position.
- Parameters:
-
t throttle position
- Returns:
- true if there is no error, false otherwise
Definition at line 103 of file USBJoystick.cpp.
| bool update | ( | int16_t | t, |
| int16_t | r, | ||
| int16_t | f, | ||
| int16_t | b, | ||
| int16_t | x, | ||
| int16_t | y, | ||
| uint32_t | buttons, | ||
| uint8_t | hat | ||
| ) |
Write state of the joystick.
- Parameters:
-
t throttle position r rudder position f flaps position b breaks position x x-axis position y y-axis position buttons buttons state hat hat state 0 (up), 1 (right, 2 (down), 3 (left) or 4 (neutral) @returns true if there is no error, false otherwise
Definition at line 30 of file USBJoystick.cpp.
| bool update | ( | ) |
Write state of the joystick.
- Returns:
- true if there is no error, false otherwise
Definition at line 45 of file USBJoystick.cpp.
Generated on Tue Jul 19 2022 20:53:24 by
1.7.2
