1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "UsbJoystick.h"
- #include "PPM.h"
-
- #define CHANNELS 8
-
-
-
-
- unsigned short a2dValue;
- unsigned char high;
- unsigned char low;
- unsigned char temp;
- unsigned char report[8];
-
- void setup(void) {
-
-
-
- ppm.begin(CHANNELS);
- usbDeviceConnect();
- }
-
- void loop(void) {
- UsbJoystick.refresh();
- calculateReport();
- UsbJoystick.sendJoystick(report[0],report[1],report[2],report[3],report[4],report[5],report[6],report[7]);
- }
-
- void calculateReport() {
- if(!ppm.available()) {
-
- return;
- }
-
-
-
-
- a2dValue = ppm.get(1) - MIN_PULSE;
- high = a2dValue >> 8;
- low = a2dValue & 255;
- report[0] = low;
- temp = high;
-
- a2dValue = ppm.get(0) - MIN_PULSE;
- high = a2dValue >> 6;
- low = a2dValue & 63;
- report[1] = (low << 2) + temp;
- temp = high;
-
- a2dValue = ppm.get(2) - MIN_PULSE;
- high = a2dValue >> 4;
- low = a2dValue & 15;
- report[2] = (low << 4) + temp;
- temp = high;
-
- a2dValue = ppm.get(3) - MIN_PULSE;
- high = a2dValue >> 2;
- low = a2dValue & 3;
- report[3] = (low << 6) + temp;
- temp = high;
-
- high = 0;
- low = 0;
- report[4] = temp;
- temp = high;
-
- a2dValue = ppm.get(4) - MIN_PULSE;
- high = a2dValue >> 8;
- low = a2dValue & 255;
- report[5] = low + temp;
- temp = high;
-
- a2dValue = ppm.get(5) - MIN_PULSE;
- high = a2dValue >> 6;
- low = a2dValue & 63;
- report[6] = (low << 2) + temp;
- temp = high;
-
-
-
- report[7] = (temp & 15);
-
- }
|