HID Joystick - For use with X-Plane or other programs that can read HID JoySticks
Dependencies: USBDevice mbed-rtos mbed
Fork of JoyStick by
This is a simple Joystick HID that I use for xplane and a home build yoke + paddels, see this forum with the look and feel of it : http://forums.x-plane.org/index.php?showtopic=70041
The analog input are filtered with a LowPass IIR filter and the digital input's will be derived from the analog input and de-bounced.
The analog values are read at a 1Khz interval and to ensure we don't push the USB stack to much at a maximum rate of 20 updates/sec HID data is send over USB only if any values where changed. The JoyStick will send 16Bit analog values as opposite of 8 bit values that are normally used to increase accuracy of the whole system. This is well noticeable within x-plane!
The JoyStick uses the JoyStick copied from Wim Huiskamp and modified to suite my needs and the MBED RTOS libraries for reading analog inputs, sending debug data over USB and sending HID data, 3 threads in total.
SimpleButtonDecoder.h@5:a0bb17c379ce, 2016-06-22 (annotated)
- Committer:
- rvt
- Date:
- Wed Jun 22 12:50:16 2016 +0000
- Revision:
- 5:a0bb17c379ce
- Parent:
- 2:ae7a31a3c618
Latest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rvt | 2:ae7a31a3c618 | 1 | #ifndef SIMPLEBUTTONDECODER_H |
rvt | 2:ae7a31a3c618 | 2 | #define SIMPLEBUTTONDECODER_H |
rvt | 2:ae7a31a3c618 | 3 | |
rvt | 2:ae7a31a3c618 | 4 | #include "mbed.h" |
rvt | 2:ae7a31a3c618 | 5 | #include "AnalogInFiltered.h" |
rvt | 2:ae7a31a3c618 | 6 | |
rvt | 2:ae7a31a3c618 | 7 | /** |
rvt | 2:ae7a31a3c618 | 8 | ButtonDecoder. |
rvt | 2:ae7a31a3c618 | 9 | I was planning to make a r2R ladder network but I couldn't find any very accurate resitors here in Ecuador (no Señor, no tengo ... sigh) |
rvt | 2:ae7a31a3c618 | 10 | so I bought some 5% resitors but they didn'0t work well enough. So this decoder sinply decoder the end value and this |
rvt | 2:ae7a31a3c618 | 11 | it means only one button at a timn can be detected reliable. |
rvt | 2:ae7a31a3c618 | 12 | */ |
rvt | 2:ae7a31a3c618 | 13 | class SimpleButtonDecoder { |
rvt | 2:ae7a31a3c618 | 14 | private: |
rvt | 2:ae7a31a3c618 | 15 | AnalogInFiltered *_analogIn; |
rvt | 2:ae7a31a3c618 | 16 | int _value; |
rvt | 2:ae7a31a3c618 | 17 | int _fuzzyFactor; |
rvt | 2:ae7a31a3c618 | 18 | bool _isChanged; |
rvt | 2:ae7a31a3c618 | 19 | short _deBounceRuns; |
rvt | 2:ae7a31a3c618 | 20 | short _debounceCount; |
rvt | 2:ae7a31a3c618 | 21 | |
rvt | 2:ae7a31a3c618 | 22 | bool _pulseUp; |
rvt | 2:ae7a31a3c618 | 23 | bool _pulseDown; |
rvt | 2:ae7a31a3c618 | 24 | bool _status; |
rvt | 2:ae7a31a3c618 | 25 | public: |
rvt | 2:ae7a31a3c618 | 26 | /** |
rvt | 2:ae7a31a3c618 | 27 | filter : Failter chain |
rvt | 2:ae7a31a3c618 | 28 | pin : Analog input to read |
rvt | 2:ae7a31a3c618 | 29 | */ |
rvt | 2:ae7a31a3c618 | 30 | SimpleButtonDecoder(AnalogInFiltered *_analogIn, int value, short deBounceRuns); |
rvt | 2:ae7a31a3c618 | 31 | ~SimpleButtonDecoder(); |
rvt | 2:ae7a31a3c618 | 32 | |
rvt | 2:ae7a31a3c618 | 33 | // Process the buttons status information |
rvt | 2:ae7a31a3c618 | 34 | // Call this function for the button to updates it's state |
rvt | 2:ae7a31a3c618 | 35 | void process(); |
rvt | 2:ae7a31a3c618 | 36 | |
rvt | 2:ae7a31a3c618 | 37 | // Returns the current button status |
rvt | 2:ae7a31a3c618 | 38 | // This state will be updated after each 'process' call |
rvt | 2:ae7a31a3c618 | 39 | bool getStatus(); |
rvt | 2:ae7a31a3c618 | 40 | |
rvt | 2:ae7a31a3c618 | 41 | // Test if the input value is changed based on a offset |
rvt | 2:ae7a31a3c618 | 42 | // This state will be updated after each 'process' call |
rvt | 2:ae7a31a3c618 | 43 | bool getIsChanged(); |
rvt | 2:ae7a31a3c618 | 44 | |
rvt | 2:ae7a31a3c618 | 45 | // Return's TRUE if the button was pressed |
rvt | 2:ae7a31a3c618 | 46 | // This state will be updated after each 'process' call |
rvt | 2:ae7a31a3c618 | 47 | bool getIsPressed(); |
rvt | 2:ae7a31a3c618 | 48 | |
rvt | 2:ae7a31a3c618 | 49 | // Returns TRUE if the button was just released, |
rvt | 2:ae7a31a3c618 | 50 | // This state will be updated after each 'process' call |
rvt | 2:ae7a31a3c618 | 51 | bool getIsReleased(); |
rvt | 2:ae7a31a3c618 | 52 | |
rvt | 2:ae7a31a3c618 | 53 | }; |
rvt | 2:ae7a31a3c618 | 54 | |
rvt | 2:ae7a31a3c618 | 55 | #endif |