
An I/O controller for virtual pinball machines: accelerometer nudge sensing, analog plunger input, button input encoding, LedWiz compatible output controls, and more.
Dependencies: mbed FastIO FastPWM USBDevice
Fork of Pinscape_Controller by
USBJoystick Class Reference
USBJoystick example. More...
#include <USBJoystick.h>
Inherited by MyUSBJoystick.
Public Member Functions | |
USBJoystick (uint16_t vendor_id, uint16_t product_id, uint16_t product_release, int waitForConnect, bool enableJoystick, int axisFormat, bool useKB) | |
Constructor. | |
bool | kbUpdate (uint8_t data[8]) |
Send a keyboard report. | |
bool | mediaUpdate (uint8_t data) |
Send a media key update. | |
bool | update (int16_t x, int16_t y, int16_t z, uint32_t buttons, uint16_t status) |
Update the joystick status. | |
bool | updateStatus (uint32_t stat) |
Update just the status. | |
bool | sendPlungerStatus (int npix, int flags, int dir, uint32_t avgScanTime, uint32_t processingTime) |
Write the plunger status report header. | |
bool | sendPlungerStatus2 (int nativeScale, int jitterLo, int jitterHi, int rawPos, int axcTime) |
Send a secondary plunger status report header. | |
bool | sendPlungerStatusBarcode (int nbits, int codetype, int startOfs, int pixPerBit, int raw, int mask) |
Send a barcode plunger status report header. | |
bool | sendPlungerStatusQuadrature (int chA, int chB) |
Send a quadrature sensor status report header. | |
bool | sendPlungerPix (int &idx, int npix, const uint8_t *pix) |
Write an exposure report. | |
bool | reportConfig (int numOutputs, int unitNo, int plungerZero, int plungerMax, int plunterRlsTime, bool configured, bool sbxpbx, bool newAccelFeatures, bool flashStatusFeature, bool reportTimingFeatures, bool chimeLogicFeature, size_t freeHeapBytes) |
Write a configuration report. | |
bool | reportConfigVar (const uint8_t *data) |
Write a configuration variable query report. | |
bool | reportID (int index) |
Write a device ID report. | |
bool | reportBuildInfo (const char *date) |
Write a build data report. | |
bool | reportButtonStatus (int numButtons, const uint8_t *state) |
Write a physical button status report. | |
bool | reportRawIR (int n, const uint16_t *data) |
Write an IR raw sensor input report. | |
bool | reportIRCode (uint8_t pro, uint8_t flags, uint64_t code) |
Write an IR input report. | |
bool | update () |
Send a joystick report to the host. | |
bool | move (int16_t x, int16_t y) |
Move the cursor to (x, y) | |
bool | setZ (int16_t z) |
Set the z position. | |
bool | buttons (uint32_t buttons) |
Press one or several buttons. | |
Static Public Attributes | |
static const int | maxRawIR = (reportLen - 3)/2 |
Maximum number of raw IR readings that can be sent in one report via reportRawIR(). |
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" #include <math.h> USBJoystick joystick; int main(void) { while (1) { // Basic Joystick joystick.update(tx, y, z, buttonBits); wait(0.001); } }
Definition at line 86 of file USBJoystick.h.
Constructor & Destructor Documentation
USBJoystick | ( | uint16_t | vendor_id, |
uint16_t | product_id, | ||
uint16_t | product_release, | ||
int | waitForConnect, | ||
bool | enableJoystick, | ||
int | axisFormat, | ||
bool | useKB | ||
) |
Constructor.
- Parameters:
-
vendor_id Your vendor_id (default: 0x1234) product_id Your product_id (default: 0x0002) product_release Your product_release (default: 0x0001) waitforConnect don't return until the connection is established enableJoystick enable the joystick interface (if false, uses the OUT-only LedWiz-style interface) axisFormat an AXIS_FORMAT_xxx value specifying the joystick axis report format useKB enable the USB keyboard reporting interface
Definition at line 108 of file USBJoystick.h.
Member Function Documentation
bool buttons | ( | uint32_t | buttons ) |
Press one or several buttons.
- Parameters:
-
buttons button state, as a bitwise combination of JOY_Bn values
- Returns:
- true if there is no error, false otherwise
Definition at line 518 of file USBJoystick.cpp.
bool kbUpdate | ( | uint8_t | data[8] ) |
Send a keyboard report.
The argument gives the key state, in the standard 6KRO USB keyboard report format: byte 0 is the modifier key bit mask, byte 1 is reserved (must be 0), and bytes 2-6 are the currently pressed keys, as USB key codes.
Definition at line 72 of file USBJoystick.cpp.
bool mediaUpdate | ( | uint8_t | data ) |
Send a media key update.
The argument gives the bit mask of media keys currently pressed. See the HID report descriptor for the order of bits.
Definition at line 84 of file USBJoystick.cpp.
bool move | ( | int16_t | x, |
int16_t | y | ||
) |
Move the cursor to (x, y)
- Parameters:
-
x x-axis position y y-axis position
- Returns:
- true if there is no error, false otherwise
Definition at line 505 of file USBJoystick.cpp.
bool reportBuildInfo | ( | const char * | date ) |
Write a build data report.
- Parameters:
-
date build date plus time, in __DATE__ " " __TIME__ macro format ("Mon dd, yyyy hh:mm:ss")
Definition at line 316 of file USBJoystick.cpp.
bool reportButtonStatus | ( | int | numButtons, |
const uint8_t * | state | ||
) |
Write a physical button status report.
- Parameters:
-
numButtons the number of buttons state the button states, 1 bit per button, 8 buttons per byte, starting with button 0 in the low-order bit (0x01) of the first byte
Definition at line 431 of file USBJoystick.cpp.
bool reportConfig | ( | int | numOutputs, |
int | unitNo, | ||
int | plungerZero, | ||
int | plungerMax, | ||
int | plunterRlsTime, | ||
bool | configured, | ||
bool | sbxpbx, | ||
bool | newAccelFeatures, | ||
bool | flashStatusFeature, | ||
bool | reportTimingFeatures, | ||
bool | chimeLogicFeature, | ||
size_t | freeHeapBytes | ||
) |
Write a configuration report.
- Parameters:
-
numOutputs the number of configured output channels unitNo the device unit number plungerZero plunger zero calibration point plungerMax plunger max calibration point plungerRlsTime measured plunger release time, in milliseconds configured true if a configuration has been saved to flash from the host sbxpbx true if this firmware version supports SBX/PBX protocol extensions newAccelFeatures true if this firmware version supports the new accelerometer features (adjustable dynamic range, adjustable auto-centering mode time, auto-centering mode on/off) flashStatusFeature true if this firmware version supports the flash write success flags in the status bits reportTimingFeatures true if this firmware version supports configurable joystick report timing chimeLogicFeature true if this firmware version supports Chime Logic freeHeapBytes number of free bytes in the malloc heap
Definition at line 380 of file USBJoystick.cpp.
bool reportConfigVar | ( | const uint8_t * | data ) |
Write a configuration variable query report.
- Parameters:
-
data the 7-byte data variable buffer, starting with the variable ID byte
Definition at line 360 of file USBJoystick.cpp.
bool reportID | ( | int | index ) |
Write a device ID report.
Definition at line 277 of file USBJoystick.cpp.
bool reportIRCode | ( | uint8_t | pro, |
uint8_t | flags, | ||
uint64_t | code | ||
) |
Write an IR input report.
This reports a decoded command read in learning mode to the host.
- Parameters:
-
pro protocol ID (see IRProtocolID.h) flags bit flags: 0x02 = protocol uses dittos code decoded command code
Definition at line 482 of file USBJoystick.cpp.
bool reportRawIR | ( | int | n, |
const uint16_t * | data | ||
) |
Write an IR raw sensor input report.
This reports a set of raw timing reports for input read from the IR sensor, for learning remote purposes.
- Parameters:
-
n number of items to report, up to maxRawIR data items to report; each is a timing reading, in 2us increments, with the low bit in each report set to 0 for a "space" (IR off) or 1 for a "mark" (IR on)
Definition at line 455 of file USBJoystick.cpp.
bool sendPlungerPix | ( | int & | idx, |
int | npix, | ||
const uint8_t * | pix | ||
) |
Write an exposure report.
We'll fill out a report with as many pixels as will fit in the packet, send the report, and update the index to the next pixel to send. The caller should call this repeatedly to send reports for all pixels.
- Parameters:
-
idx current index in pixel array, updated to point to next pixel to send npix number of pixels in the overall array pix pixel array
Definition at line 255 of file USBJoystick.cpp.
bool sendPlungerStatus | ( | int | npix, |
int | flags, | ||
int | dir, | ||
uint32_t | avgScanTime, | ||
uint32_t | processingTime | ||
) |
Write the plunger status report header.
Note that we automatically add the "calibration mode" bit to the flags, so the caller doesn't have to include this. The caller only has to include the sensor-specific flags.
- Parameters:
-
npix number of pixels in the sensor (0 for non-imaging sensors) pos the decoded plunger position, or -1 if none detected flags (see USBProtocol.h, message type 2A, "byte 7" bit flags) avgScanTime average sensor scan time in microseconds processingTime time in microseconds to process the current frame
Definition at line 96 of file USBJoystick.cpp.
bool sendPlungerStatus2 | ( | int | nativeScale, |
int | jitterLo, | ||
int | jitterHi, | ||
int | rawPos, | ||
int | axcTime | ||
) |
Send a secondary plunger status report header.
- Parameters:
-
nativeScale upper bound of the sensor's native reading scale jitterLo low end of jitter filter window (in sensor native scale units) jitterHi high end of jitter filter window rawPos raw position reading, before applying jitter filter axcTime auto-exposure time in microseconds
Definition at line 143 of file USBJoystick.cpp.
bool sendPlungerStatusBarcode | ( | int | nbits, |
int | codetype, | ||
int | startOfs, | ||
int | pixPerBit, | ||
int | raw, | ||
int | mask | ||
) |
Send a barcode plunger status report header.
- Parameters:
-
nbits number of bits in bar code codetype bar code type (1=Gray code/Manchester bit coding) pixofs pixel offset of first bit raw raw bar code bits mask mask of successfully read bar code bits
Definition at line 194 of file USBJoystick.cpp.
bool sendPlungerStatusQuadrature | ( | int | chA, |
int | chB | ||
) |
Send a quadrature sensor status report header.
- Parameters:
-
chA channel "A" reading chB channel "B" reading
Definition at line 232 of file USBJoystick.cpp.
bool setZ | ( | int16_t | z ) |
bool update | ( | ) |
Send a joystick report to the host.
- Returns:
- true if there is no error, false otherwise
Definition at line 46 of file USBJoystick.cpp.
bool update | ( | int16_t | x, |
int16_t | y, | ||
int16_t | z, | ||
uint32_t | buttons, | ||
uint16_t | status | ||
) |
Update the joystick status.
- Parameters:
-
x x-axis position y y-axis position z z-axis position buttons buttons state, as a bit mask (combination with '|' of JOY_Bn values)
- Returns:
- true if there is no error, false otherwise
Definition at line 33 of file USBJoystick.cpp.
bool updateStatus | ( | uint32_t | stat ) |
Update just the status.
Definition at line 525 of file USBJoystick.cpp.
Field Documentation
const int maxRawIR = (reportLen - 3)/2 [static] |
Maximum number of raw IR readings that can be sent in one report via reportRawIR().
Definition at line 291 of file USBJoystick.h.
Generated on Sat Apr 18 2020 19:09:14 by
