Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBDevice mbed-rtos mbed
Fork of JoyStick by
Diff: main.cpp
- Revision:
- 1:5b2ab44eb31f
- Parent:
- 0:33bc88c4ab31
- Child:
- 2:ae7a31a3c618
--- a/main.cpp Wed Aug 28 02:33:03 2013 +0000
+++ b/main.cpp Wed Aug 28 13:12:39 2013 +0000
@@ -1,29 +1,19 @@
#include "mbed.h"
#include "USBHID.h"
#include "USBJoystick.h"
-#include "MovingAverage.h"
#include "LowPassFilter.h"
-#include "AntiLog.h"
#include "AnalogInFiltered.h"
#include "rtos.h"
-
+// When set, it will send debug data over USB serial
#define TTY_DEBUG
// Value that defines when to start sending data this prevents the noise sending loads's of data over HID
#define DATA_CHANGE_TRIGGER 64
-Serial pc(USBTX, USBRX); // tx, rx
-
-// Activity led for HID data transmissions
-DigitalOut HIDActivity(LED3);
+// Activity LED for HID data
+#define HIDACTIVITYLED LED3
-//This report will contain data to be sent
-HID_REPORT send_report;
-HID_REPORT recv_report;
-
-//USBJoyStick;
-USBJoystick joystick;
// Structure that hold's the dataset of the input's
Mutex analogValueMutex;
@@ -35,12 +25,28 @@
long value5;
} analogData;
+#ifdef TTY_DEBUG
+
+// Serial port for debug data
+Serial pc(USBTX, USBRX); // tx, rx
+
+/**
+Debug thread to show some values from the system over USB serial.
+Ensure that TTY_DEBUG is defined so that these routines will get activated.
+This is what I do to view the values on OSX within a terminal
+$ cd /dev
+$ ls | grep usbmodem
+cu.usbmodemfa1232
+tty.usbmodemfa1232
+$ screen tty.usbmodemfa1232
+*/
void debug_thread(void const *args)
{
+ // Make a local copy
+ AnalogData localCopy;
+ AnalogData previous;
while (true) {
- // Make a local copy
- AnalogData localCopy;
- AnalogData previous;
+ // Lock and copy input values
analogValueMutex.lock();
memcpy (&localCopy, &analogData, sizeof(AnalogData));
analogValueMutex.unlock();
@@ -53,16 +59,22 @@
pc.printf("Analog in p18: %d diff: %d \n\r",localCopy.value3,localCopy.value3-previous.value3);
pc.printf("Analog in p17: %d diff: %d \n\r",localCopy.value4,localCopy.value4-previous.value4);
pc.printf("Analog in p16: %d diff: %d \n\r",localCopy.value5,localCopy.value5-previous.value5);
-
+
+ // Make local copy so we can show diff version
memcpy (&previous, &localCopy, sizeof(AnalogData));
-
-
Thread::wait(1000);
}
}
+#endif
void hid_thread(void const *args)
{
+ //USB HID JoyStick
+ USBJoystick joystick;
+
+ // Activity led for HID data transmissions
+ DigitalOut hIDActivity(HIDACTIVITYLED);
+
while (true) {
// TODO read buttons
@@ -71,7 +83,9 @@
AnalogData localCopy;
// Wait for analog in to have some data
+ hIDActivity=false;
Thread::signal_wait(0x1);
+ hIDActivity=true;
// Make a local copy of the data
analogValueMutex.lock();
@@ -87,8 +101,6 @@
buttons,
hat);
- HIDActivity=!HIDActivity;
-
// Wait 50 ms to send a other USB update
Thread::wait(50);
}
@@ -110,11 +122,11 @@
Thread _hid_thread(hid_thread);
// Initialise moving average filters
- LowPassFilter lowPassFilter1(new AntiLog(new AnalogFilterInterface(),-5.0),0.95f); // The close the alpha value is to 1, the lower the cut-off frequency
- LowPassFilter lowPassFilter2(new AntiLog(new AnalogFilterInterface(),-5.0),0.95f);
- LowPassFilter lowPassFilter3(new AntiLog(new AnalogFilterInterface(),-5.0),0.95f);
- LowPassFilter lowPassFilter4(new AntiLog(new AnalogFilterInterface(),-5.0),0.95f);
- LowPassFilter lowPassFilter5(new AntiLog(new AnalogFilterInterface(),-5.0),0.95f);
+ LowPassFilter lowPassFilter1(new AnalogFilterInterface(),0.95f); // The close the alpha value is to 1, the lower the cut-off frequency
+ LowPassFilter lowPassFilter2(new AnalogFilterInterface(),0.95f);
+ LowPassFilter lowPassFilter3(new AnalogFilterInterface(),0.95f);
+ LowPassFilter lowPassFilter4(new AnalogFilterInterface(),0.95f);
+ LowPassFilter lowPassFilter5(new AnalogFilterInterface(),0.95f);
// Initialise analog input and tell it what fulters to use
AnalogInFiltered ai1(&lowPassFilter1, p20);
@@ -138,7 +150,7 @@
|| ai2.getIsChanged(DATA_CHANGE_TRIGGER)
|| ai3.getIsChanged(DATA_CHANGE_TRIGGER)
|| ai4.getIsChanged(DATA_CHANGE_TRIGGER)
-// || ai5.getIsChanged(8)
+// || ai5.getIsChanged(DATA_CHANGE_TRIGGER)
) {
// Copy analog data to global data
analogValueMutex.lock();
