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 Mike R

Embed: (wiki syntax)

« Back to documentation index

USBJoystick Class Reference

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_idYour vendor_id (default: 0x1234)
product_idYour product_id (default: 0x0002)
product_releaseYour product_release (default: 0x0001)
waitforConnectdon't return until the connection is established
enableJoystickenable the joystick interface (if false, uses the OUT-only LedWiz-style interface)
axisFormatan AXIS_FORMAT_xxx value specifying the joystick axis report format
useKBenable 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:
buttonsbutton 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:
xx-axis position
yy-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:
datebuild 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:
numButtonsthe number of buttons
statethe 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:
numOutputsthe number of configured output channels
unitNothe device unit number
plungerZeroplunger zero calibration point
plungerMaxplunger max calibration point
plungerRlsTimemeasured plunger release time, in milliseconds
configuredtrue if a configuration has been saved to flash from the host
sbxpbxtrue if this firmware version supports SBX/PBX protocol extensions
newAccelFeaturestrue if this firmware version supports the new accelerometer features (adjustable dynamic range, adjustable auto-centering mode time, auto-centering mode on/off)
flashStatusFeaturetrue if this firmware version supports the flash write success flags in the status bits
reportTimingFeaturestrue if this firmware version supports configurable joystick report timing
chimeLogicFeaturetrue if this firmware version supports Chime Logic
freeHeapBytesnumber 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:
datathe 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:
proprotocol ID (see IRProtocolID.h)
flagsbit flags: 0x02 = protocol uses dittos
codedecoded 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:
nnumber of items to report, up to maxRawIR
dataitems 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:
idxcurrent index in pixel array, updated to point to next pixel to send
npixnumber of pixels in the overall array
pixpixel 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:
npixnumber of pixels in the sensor (0 for non-imaging sensors)
posthe decoded plunger position, or -1 if none detected
flags(see USBProtocol.h, message type 2A, "byte 7" bit flags)
avgScanTimeaverage sensor scan time in microseconds
processingTimetime 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:
nativeScaleupper bound of the sensor's native reading scale
jitterLolow end of jitter filter window (in sensor native scale units)
jitterHihigh end of jitter filter window
rawPosraw position reading, before applying jitter filter
axcTimeauto-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:
nbitsnumber of bits in bar code
codetypebar code type (1=Gray code/Manchester bit coding)
pixofspixel offset of first bit
rawraw bar code bits
maskmask 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:
chAchannel "A" reading
chBchannel "B" reading

Definition at line 232 of file USBJoystick.cpp.

bool setZ ( int16_t  z )

Set the z position.

Parameters:
zz-axis osition

Definition at line 512 of file USBJoystick.cpp.

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:
xx-axis position
yy-axis position
zz-axis position
buttonsbuttons 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.