Merge pull request #8425 from rotorman/patch-1

Bluetooth: making better use of constants
This commit is contained in:
Bertrand Songis
2021-04-16 18:00:54 +02:00
committed by GitHub
2 changed files with 8 additions and 7 deletions
+4 -4
View File
@@ -217,11 +217,11 @@ void Bluetooth::processTrainerByte(uint8_t data)
if (bufferIndex >= BLUETOOTH_PACKET_SIZE) {
uint8_t crc = 0x00;
for (int i=0; i<13; i++) {
for (int i=0; i<(BLUETOOTH_PACKET_SIZE-1); i++) {
crc ^= buffer[i];
}
if (crc == buffer[13]) {
if (buffer[0] == 0x80) {
if (crc == buffer[BLUETOOTH_PACKET_SIZE-1]) {
if (buffer[0] == TRAINER_FRAME) {
processTrainerFrame(buffer);
}
}
@@ -251,7 +251,7 @@ void Bluetooth::sendTrainer()
crc = 0x00;
buffer[bufferIndex++] = START_STOP; // start byte
pushByte(0x80); // trainer frame type?
pushByte(TRAINER_FRAME);
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 channelValue2 = PPM_CH_CENTER(channel+1) + limit((int16_t)-PPM_range, channelOutputs[channel+1], (int16_t)PPM_range) / 2;
+4 -3
View File
@@ -259,9 +259,10 @@ inline uint8_t TELEMETRY_RSSI()
return telemetryData.rssi.value();
}
constexpr uint8_t START_STOP = 0x7E;
constexpr uint8_t BYTE_STUFF = 0x7D;
constexpr uint8_t STUFF_MASK = 0x20;
constexpr uint8_t START_STOP = 0x7E;
constexpr uint8_t BYTE_STUFF = 0x7D;
constexpr uint8_t STUFF_MASK = 0x20;
constexpr uint8_t TRAINER_FRAME = 0x80;
typedef enum {
TS_IDLE = 0, // waiting for 0x5e frame marker