Merge pull request #8425 from rotorman/patch-1
Bluetooth: making better use of constants
This commit is contained in:
@@ -217,11 +217,11 @@ void Bluetooth::processTrainerByte(uint8_t data)
|
|||||||
|
|
||||||
if (bufferIndex >= BLUETOOTH_PACKET_SIZE) {
|
if (bufferIndex >= BLUETOOTH_PACKET_SIZE) {
|
||||||
uint8_t crc = 0x00;
|
uint8_t crc = 0x00;
|
||||||
for (int i=0; i<13; i++) {
|
for (int i=0; i<(BLUETOOTH_PACKET_SIZE-1); i++) {
|
||||||
crc ^= buffer[i];
|
crc ^= buffer[i];
|
||||||
}
|
}
|
||||||
if (crc == buffer[13]) {
|
if (crc == buffer[BLUETOOTH_PACKET_SIZE-1]) {
|
||||||
if (buffer[0] == 0x80) {
|
if (buffer[0] == TRAINER_FRAME) {
|
||||||
processTrainerFrame(buffer);
|
processTrainerFrame(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ void Bluetooth::sendTrainer()
|
|||||||
crc = 0x00;
|
crc = 0x00;
|
||||||
|
|
||||||
buffer[bufferIndex++] = START_STOP; // start byte
|
buffer[bufferIndex++] = START_STOP; // start byte
|
||||||
pushByte(0x80); // trainer frame type?
|
pushByte(TRAINER_FRAME);
|
||||||
for (int channel=0; channel<lastCh; channel+=2, cur+=3) {
|
for (int channel=0; channel<lastCh; channel+=2, cur+=3) {
|
||||||
uint16_t channelValue1 = PPM_CH_CENTER(channel) + limit((int16_t)-PPM_range, channelOutputs[channel], (int16_t)PPM_range) / 2;
|
uint16_t channelValue1 = PPM_CH_CENTER(channel) + limit((int16_t)-PPM_range, channelOutputs[channel], (int16_t)PPM_range) / 2;
|
||||||
uint16_t channelValue2 = PPM_CH_CENTER(channel+1) + limit((int16_t)-PPM_range, channelOutputs[channel+1], (int16_t)PPM_range) / 2;
|
uint16_t channelValue2 = PPM_CH_CENTER(channel+1) + limit((int16_t)-PPM_range, channelOutputs[channel+1], (int16_t)PPM_range) / 2;
|
||||||
|
|||||||
@@ -259,9 +259,10 @@ inline uint8_t TELEMETRY_RSSI()
|
|||||||
return telemetryData.rssi.value();
|
return telemetryData.rssi.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint8_t START_STOP = 0x7E;
|
constexpr uint8_t START_STOP = 0x7E;
|
||||||
constexpr uint8_t BYTE_STUFF = 0x7D;
|
constexpr uint8_t BYTE_STUFF = 0x7D;
|
||||||
constexpr uint8_t STUFF_MASK = 0x20;
|
constexpr uint8_t STUFF_MASK = 0x20;
|
||||||
|
constexpr uint8_t TRAINER_FRAME = 0x80;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TS_IDLE = 0, // waiting for 0x5e frame marker
|
TS_IDLE = 0, // waiting for 0x5e frame marker
|
||||||
|
|||||||
Reference in New Issue
Block a user