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 0:33bc88c4ab31 1 #include "AnalogInFiltered.h"
rvt 0:33bc88c4ab31 2
rvt 0:33bc88c4ab31 3
rvt 5:a0bb17c379ce 4 AnalogInFiltered::AnalogInFiltered(AnalogFilterInterface *filter, PinName pin, int fuzzyFactor) : _ain(new AnalogIn(pin)), _fuzzyFactor(fuzzyFactor), _filter(filter), _lastValue(0) {
rvt 0:33bc88c4ab31 5 }
rvt 0:33bc88c4ab31 6
rvt 0:33bc88c4ab31 7 AnalogInFiltered::~AnalogInFiltered() {
rvt 0:33bc88c4ab31 8 delete(_ain);
rvt 0:33bc88c4ab31 9 }
rvt 0:33bc88c4ab31 10
rvt 5:a0bb17c379ce 11 void AnalogInFiltered::setData (long d) {
rvt 0:33bc88c4ab31 12 _filter->setData(_ain->read_u16() - 32768);
rvt 0:33bc88c4ab31 13 }
rvt 0:33bc88c4ab31 14
rvt 5:a0bb17c379ce 15 long AnalogInFiltered::getData() const {
rvt 2:ae7a31a3c618 16 return _filter->getData();
rvt 2:ae7a31a3c618 17 }
rvt 0:33bc88c4ab31 18
rvt 2:ae7a31a3c618 19
rvt 2:ae7a31a3c618 20 bool AnalogInFiltered::getIsChanged() {
rvt 2:ae7a31a3c618 21 // _filter->setData(_ain->read_u16() - 32768);
rvt 2:ae7a31a3c618 22 if (abs(_filter->getData() - _lastValue) > _fuzzyFactor) {
rvt 0:33bc88c4ab31 23 _lastValue = _filter->getData();
rvt 0:33bc88c4ab31 24 return true;
rvt 0:33bc88c4ab31 25 }
rvt 0:33bc88c4ab31 26 return false;
rvt 0:33bc88c4ab31 27 }
rvt 0:33bc88c4ab31 28
rvt 2:ae7a31a3c618 29 int AnalogInFiltered::getFuzzyFactor() {
rvt 2:ae7a31a3c618 30 return _fuzzyFactor;
rvt 2:ae7a31a3c618 31 }