HID Joystick - For use with X-Plane or other programs that can read HID JoySticks

Dependencies:   USBDevice mbed-rtos mbed

Fork of JoyStick by Ries Twisk

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.

Committer:
rvt
Date:
Wed Jun 22 12:50:16 2016 +0000
Revision:
5:a0bb17c379ce
Parent:
2:ae7a31a3c618
Latest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rvt 2:ae7a31a3c618 1 #include "SimpleButtonDecoder.h"
rvt 2:ae7a31a3c618 2
rvt 2:ae7a31a3c618 3
rvt 2:ae7a31a3c618 4 SimpleButtonDecoder::SimpleButtonDecoder(AnalogInFiltered *analogIn, int value, short deBounceRuns)
rvt 2:ae7a31a3c618 5 {
rvt 2:ae7a31a3c618 6 _analogIn = analogIn;
rvt 2:ae7a31a3c618 7 _value = value;
rvt 2:ae7a31a3c618 8 _isChanged = false;
rvt 2:ae7a31a3c618 9 _deBounceRuns = deBounceRuns;
rvt 2:ae7a31a3c618 10 _debounceCount = 1;
rvt 2:ae7a31a3c618 11
rvt 2:ae7a31a3c618 12 _pulseUp=false;
rvt 2:ae7a31a3c618 13 _status=false;
rvt 2:ae7a31a3c618 14 }
rvt 2:ae7a31a3c618 15
rvt 2:ae7a31a3c618 16 SimpleButtonDecoder::~SimpleButtonDecoder()
rvt 2:ae7a31a3c618 17 {
rvt 2:ae7a31a3c618 18 }
rvt 2:ae7a31a3c618 19
rvt 2:ae7a31a3c618 20 void SimpleButtonDecoder::process()
rvt 2:ae7a31a3c618 21 {
rvt 2:ae7a31a3c618 22 _pulseUp=false;
rvt 2:ae7a31a3c618 23 _pulseDown=false;
rvt 2:ae7a31a3c618 24
rvt 2:ae7a31a3c618 25 // Detect if the analog in is within the value range + fuzzy factor
rvt 2:ae7a31a3c618 26 if (abs((_analogIn->getData() + 32768) - _value) < _analogIn->getFuzzyFactor()) {
rvt 2:ae7a31a3c618 27 // When the analog values iw within the fuzzy factor for XX debounce runs, consider this now a up flank to true state
rvt 2:ae7a31a3c618 28 if (_debounceCount == _deBounceRuns) {
rvt 2:ae7a31a3c618 29 _pulseUp=!_status;
rvt 2:ae7a31a3c618 30 _status=true;
rvt 2:ae7a31a3c618 31 _debounceCount++;
rvt 2:ae7a31a3c618 32 return;
rvt 2:ae7a31a3c618 33 }
rvt 2:ae7a31a3c618 34 // If the _debounceCount is bigger then deboucneruns, consider this a on state (passed the up flanc)
rvt 2:ae7a31a3c618 35 if (_debounceCount > _deBounceRuns) {
rvt 2:ae7a31a3c618 36 return;
rvt 2:ae7a31a3c618 37 }
rvt 2:ae7a31a3c618 38 _debounceCount++;
rvt 2:ae7a31a3c618 39 } else {
rvt 2:ae7a31a3c618 40 // If debounce count is at 1, then consider this a down flanc back to false
rvt 2:ae7a31a3c618 41 if (_debounceCount == 1) {
rvt 2:ae7a31a3c618 42 _debounceCount--;
rvt 2:ae7a31a3c618 43 _pulseDown=_status;
rvt 2:ae7a31a3c618 44 _status=false;
rvt 2:ae7a31a3c618 45 return;
rvt 2:ae7a31a3c618 46 }
rvt 2:ae7a31a3c618 47 // if the debounce is below <1 then we have a stable state again.
rvt 2:ae7a31a3c618 48 if (_debounceCount < 1) {
rvt 2:ae7a31a3c618 49 return;
rvt 2:ae7a31a3c618 50 }
rvt 2:ae7a31a3c618 51 _debounceCount--;
rvt 2:ae7a31a3c618 52 }
rvt 2:ae7a31a3c618 53 }
rvt 2:ae7a31a3c618 54
rvt 2:ae7a31a3c618 55 bool SimpleButtonDecoder::getStatus()
rvt 2:ae7a31a3c618 56 {
rvt 2:ae7a31a3c618 57 return _status;
rvt 2:ae7a31a3c618 58 }
rvt 2:ae7a31a3c618 59
rvt 2:ae7a31a3c618 60 bool SimpleButtonDecoder::getIsChanged()
rvt 2:ae7a31a3c618 61 {
rvt 2:ae7a31a3c618 62 return _pulseUp || _pulseDown;
rvt 2:ae7a31a3c618 63 }
rvt 2:ae7a31a3c618 64
rvt 2:ae7a31a3c618 65 bool SimpleButtonDecoder::getIsPressed()
rvt 2:ae7a31a3c618 66 {
rvt 2:ae7a31a3c618 67 return _pulseUp;
rvt 2:ae7a31a3c618 68 }
rvt 2:ae7a31a3c618 69
rvt 2:ae7a31a3c618 70 bool SimpleButtonDecoder::getIsReleased()
rvt 2:ae7a31a3c618 71 {
rvt 2:ae7a31a3c618 72 return _pulseUp;
rvt 2:ae7a31a3c618 73 }