An input/output controller for virtual pinball machines, with plunger position tracking, accelerometer-based nudge sensing, button input encoding, and feedback device control.

Dependencies:   USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA

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=0x1234, uint16_t product_id=0x0100, uint16_t product_release=0x0001, int waitForConnect=true)
 Constructor.
bool update (int16_t x, int16_t y, int16_t z, uint32_t buttons, uint16_t status)
 Write a state of the mouse.
bool updateStatus (uint32_t stat)
 Update just the status.
bool updateExposure (int &idx, int npix, const uint16_t *pix)
 Write an exposure report.
bool reportConfig (int numOutputs, int unitNo)
 Write a configuration report.
bool update ()
 Write a state of the mouse.
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.

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 83 of file USBJoystick.h.


Constructor & Destructor Documentation

USBJoystick ( uint16_t  vendor_id = 0x1234,
uint16_t  product_id = 0x0100,
uint16_t  product_release = 0x0001,
int  waitForConnect = true 
)

Constructor.

Parameters:
vendor_idYour vendor_id (default: 0x1234)
product_idYour product_id (default: 0x0002)
product_releaseYour product_release (default: 0x0001)

Definition at line 93 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 132 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 119 of file USBJoystick.cpp.

bool reportConfig ( int  numOutputs,
int  unitNo 
)

Write a configuration report.

Parameters:
numOutputsthe number of configured output channels
unitNothe device unit number

Definition at line 97 of file USBJoystick.cpp.

bool setZ ( int16_t  z )

Set the z position.

Parameters:
zz-axis osition

Definition at line 126 of file USBJoystick.cpp.

bool update (  )

Write a state of the mouse.

Returns:
true if there is no error, false otherwise

Definition at line 43 of file USBJoystick.cpp.

bool update ( int16_t  x,
int16_t  y,
int16_t  z,
uint32_t  buttons,
uint16_t  status 
)

Write a state of the mouse.

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 30 of file USBJoystick.cpp.

bool updateExposure ( int &  idx,
int  npix,
const uint16_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 65 of file USBJoystick.cpp.

bool updateStatus ( uint32_t  stat )

Update just the status.

Definition at line 141 of file USBJoystick.cpp.