Correct way of encoding RC_DATA frame
This commit is contained in:
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
7
.vscode/arduino.json
vendored
7
.vscode/arduino.json
vendored
@@ -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"
|
||||
}
|
||||
0
build/.gitkeep
Normal file
0
build/.gitkeep
Normal file
5
common.h
5
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,
|
||||
|
||||
15
crossbow.ino
15
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;
|
||||
|
||||
30
scratch.txt
Normal file
30
scratch.txt
Normal file
@@ -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
|
||||
}
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user