diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/arduino.json b/.vscode/arduino.json index b4fef73..bec8b68 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,6 +1,7 @@ { - "board": "arduino:avr:pro", - "configuration": "cpu=16MHzatmega328", + "board": "sparkfun:avr:promicro", + "configuration": "cpu=16MHzatmega32U4", "sketch": "crossbow.ino", - "port": "COM5" + "port": "COM23", + "output": "./build" } \ No newline at end of file diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/common.h b/common.h index 44642e2..9c3a17d 100644 --- a/common.h +++ b/common.h @@ -4,8 +4,7 @@ #define PPM_CHANNEL_COUNT 10 -#define TX_RC_FRAME_RATE 100 //ms - +#define TX_RC_FRAME_RATE 5000 //ms #define CHANNEL_ID 0x01 #define QSP_PREAMBLE 0x51 @@ -16,8 +15,6 @@ #define PIN_LED 13 - - enum dataStates { IDLE, PREAMBLE_RECEIVED, diff --git a/crossbow.ino b/crossbow.ino index 5efef59..416e44f 100644 --- a/crossbow.ino +++ b/crossbow.ino @@ -166,7 +166,7 @@ void setup(void) { #ifdef DEVICE_MODE_TX uint8_t get10bitHighShift(uint8_t channel) { - return (2 + (channel * 2)) % 8; + return ((channel % 4) * 2) + 2; } uint8_t get10bitLowShift(uint8_t channel) { @@ -197,12 +197,21 @@ void loop(void) { uint8_t channelValue4 = map(ppmReader.get(i), 1000, 2000, 0, 15) & 0x0f; if (i < 4) { + /* + * First 4 channels encoded with 10 bits + */ uint8_t bitIndex = i + (i / 4); - qspPayload[bitIndex] |= (channelValue10 >> get10bitHighShift(i)) & (0x03ff >> get10bitHighShift(i)); //255 | shift right 2 bits - qspPayload[bitIndex + 1] |= (channelValue10 << get10bitLowShift(i)) & 0xff << (8 - get10bitHighShift(i)); //192 | shift left 6 bits + qspPayload[bitIndex] |= (channelValue10 >> get10bitHighShift(i)) & (0x3ff >> get10bitHighShift(i)); + qspPayload[bitIndex + 1] |= (channelValue10 << get10bitLowShift(i)) & 0xff << (8 - get10bitHighShift(i)); } else if (i == 4 || i == 5) { + /* + * Next 2 with 8 bits + */ qspPayload[i + 1] |= channelValue8; } else if (i == 6) { + /* + * And last 4 with 4 bits per channel + */ qspPayload[7] |= (channelValue4 << 4) & B11110000; } else if (i == 7) { qspPayload[7] |= channelValue4 & B00001111; diff --git a/scratch.txt b/scratch.txt new file mode 100644 index 0000000..7c0950f --- /dev/null +++ b/scratch.txt @@ -0,0 +1,30 @@ +/* +FIXME this should work, but does not... + +channel get10bitHighShift get10bitLowShift +0 2 6 +1 4 4 +2 6 2 +3 8 0 + +if (i < 4) { + uint8_t bitIndex = i + (i / 4); + qspPayload[bitIndex] |= (channelValue10 >> get10bitHighShift(i)) & (0xff >> get10bitHighShift(i)); + qspPayload[bitIndex + 1] |= (channelValue10 << get10bitLowShift(i)) & (0xff << (8 - get10bitHighShift(i))); +} + +if (i == 0) { + qspPayload[0] |= (channelValue10 >> 2) & B11111111; //255 + qspPayload[1] |= (channelValue10 << 6) & B11000000; //192 +} else if (i == 1) { + qspPayload[1] |= (channelValue10 >> 4) & B00111111; //63 + qspPayload[2] |= (channelValue10 << 4) & B11110000; //240 +} else if (i == 2) { + qspPayload[2] |= (channelValue10 >> 6) & B00001111; //15 + qspPayload[3] |= (channelValue10 << 2) & B11111100; //252 +} else if (i == 3) { + qspPayload[3] |= (channelValue10 >> 8) & B00000011; //3 + qspPayload[4] |= channelValue10 & B11111111; //255 +} + +*/ \ No newline at end of file