|
| 1 | +#define REMOTEXY_MODE__SOFTSERIAL |
| 2 | + |
| 3 | +#include "Arduino.h" |
| 4 | +#include "config.h" |
| 5 | +#include "def.h" |
| 6 | +#include "types.h" |
| 7 | +#include "MultiWii.h" |
| 8 | + |
| 9 | +#include <SoftwareSerial.h> |
| 10 | +#include <RemoteXY.h> |
| 11 | + |
| 12 | +// RemoteXY connection settings |
| 13 | +#define REMOTEXY_SERIAL_RX 8 |
| 14 | +#define REMOTEXY_SERIAL_TX 7 |
| 15 | +#define REMOTEXY_SERIAL_SPEED 9600 |
| 16 | + |
| 17 | +#if defined(Bluetooth) |
| 18 | + |
| 19 | +#pragma pack(push, 1) |
| 20 | +uint8_t RemoteXY_CONF[] = |
| 21 | + { 255,7,0,1,0,80,0,8,162,0, |
| 22 | + 5,37,68,12,42,42,38,26,31,5, |
| 23 | + 2,-11,13,41,41,64,26,16,2,1, |
| 24 | + 52,4,22,11,38,26,31,31,79,78, |
| 25 | + 0,79,70,70,0,66,0,42,18,13, |
| 26 | + 28,246,26,2,1,22,4,22,11,2, |
| 27 | + 26,31,31,79,78,0,79,70,70,0, |
| 28 | + 2,0,38,51,21,7,121,26,31,31, |
| 29 | + 79,78,0,79,70,70,0 }; |
| 30 | + |
| 31 | +struct { |
| 32 | + |
| 33 | + // input variable |
| 34 | + int8_t right_x; // =-100..100 x-coordinate joystick position |
| 35 | + int8_t right_y; // =-100..100 y-coordinate joystick position |
| 36 | + int8_t left_x; // =-100..100 x-coordinate joystick position |
| 37 | + int8_t left_y; // =-100..100 y-coordinate joystick position |
| 38 | + uint8_t aux2; // =1 if switch ON and =0 if OFF |
| 39 | + uint8_t aux1; // =1 if switch ON and =0 if OFF |
| 40 | + uint8_t aux3; // =1 if switch ON and =0 if OFF |
| 41 | + |
| 42 | + // output variable |
| 43 | + int8_t height; // =0..100 level position |
| 44 | + |
| 45 | + // other variable |
| 46 | + uint8_t connect_flag; // =1 if wire connected, else =0 |
| 47 | + |
| 48 | +} RemoteXY; |
| 49 | +#pragma pack(pop) |
| 50 | + |
| 51 | + |
| 52 | +int16_t bluetooth_rcData[RC_CHANS];// defined in RX.cpp |
| 53 | + |
| 54 | + |
| 55 | +void resetbluetoothData() |
| 56 | +{ |
| 57 | + RemoteXY.left_y = -100; |
| 58 | + RemoteXY.left_x = 0; |
| 59 | + RemoteXY.right_y = 0; |
| 60 | + RemoteXY.right_x = 0; |
| 61 | + |
| 62 | + RemoteXY.aux1 = 0; |
| 63 | + RemoteXY.aux2 = 0; |
| 64 | + RemoteXY.aux3 = 0; |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +void bluetooth_Init() { //setup |
| 69 | + |
| 70 | + RemoteXY_Init (); |
| 71 | + resetbluetoothData(); |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +void bluetooth_Read_RC() { //loop |
| 76 | + static unsigned long lastRecvTime = 0; |
| 77 | + RemoteXY_Handler (); |
| 78 | + //unsigned long now = millis(); |
| 79 | + // if ( now - lastRecvTime > 1000 ) { |
| 80 | + // signal lost? |
| 81 | + // resetbluetoothData(); |
| 82 | +// } |
| 83 | + |
| 84 | + bluetooth_rcData[THROTTLE] = map(RemoteXY.left_y,-100,100, 1000, 2000); //If your channels are inverted, reverse the map value. Example. From 1000 to 2000 ---> 2000 to 1000 |
| 85 | + bluetooth_rcData[ROLL] = map(RemoteXY.right_x,-100,100, 1000, 2000); |
| 86 | + bluetooth_rcData[PITCH] = map(RemoteXY.right_y,-100,100, 1000, 2000); |
| 87 | + bluetooth_rcData[YAW] = map(RemoteXY.left_x,-100,100, 1000, 2000); |
| 88 | + |
| 89 | + bluetooth_rcData[AUX1] = map(RemoteXY.aux1, 0, 1, 1000, 2000); |
| 90 | + bluetooth_rcData[AUX2] = map(RemoteXY.aux2, 0, 1, 1000, 2000); |
| 91 | + bluetooth_rcData[AUX3] = map(RemoteXY.aux3, 0, 1, 1000, 2000); |
| 92 | +} |
| 93 | + |
| 94 | +#endif |
0 commit comments