From cd5feefde9071427bc42246a6d205971696cbcb1 Mon Sep 17 00:00:00 2001 From: Cliff Date: Mon, 13 Sep 2021 19:37:20 -0700 Subject: [PATCH] Remove magic numbers --- radio/src/bluetooth.cpp | 4 ++-- radio/src/bluetooth.h | 1 + radio/src/gui/colorlcd/model_setup.cpp | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/radio/src/bluetooth.cpp b/radio/src/bluetooth.cpp index 147158ca4..1237898b3 100644 --- a/radio/src/bluetooth.cpp +++ b/radio/src/bluetooth.cpp @@ -151,7 +151,7 @@ void Bluetooth::processTrainerFrame(const uint8_t * buffer) { BLUETOOTH_TRACE(CRLF); - for (uint8_t channel=0, i=1; channel<8; channel+=2, i+=3) { + for (uint8_t channel=0, i=1; channel> 4) + ((buffer[i+2] & 0x0f) << 8) - 1500; @@ -251,7 +251,7 @@ void Bluetooth::sendTrainer() int16_t PPM_range = g_model.extendedLimits ? 640*2 : 512*2; int firstCh = g_model.trainerData.channelsStart; - int lastCh = firstCh + 8; + int lastCh = firstCh + BLUETOOTH_TRAINER_CHANNELS; uint8_t * cur = buffer; bufferIndex = 0; diff --git a/radio/src/bluetooth.h b/radio/src/bluetooth.h index 2267a758b..b6a7ec96c 100644 --- a/radio/src/bluetooth.h +++ b/radio/src/bluetooth.h @@ -48,6 +48,7 @@ enum BluetoothStates { #define MAX_BLUETOOTH_DISTANT_ADDR 6 #define BLUETOOTH_PACKET_SIZE 14 #define BLUETOOTH_LINE_LENGTH 32 +#define BLUETOOTH_TRAINER_CHANNELS 8 #if defined(LOG_BLUETOOTH) #define BLUETOOTH_TRACE(...) \ diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index d9b96b47d..ef723093d 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -584,11 +584,11 @@ class TrainerModuleWindow : public FormGroup COLOR_THEME_PRIMARY1); channelStart = new NumberEdit( this, grid.getFieldSlot(2, 0), 1, - MAX_OUTPUT_CHANNELS - 8 + g_model.trainerData.channelsCount + 1, + MAX_OUTPUT_CHANNELS - BLUETOOTH_TRAINER_CHANNELS + 1, GET_DEFAULT(1 + g_model.trainerData.channelsStart)); char chend[6]; snprintf(chend, sizeof(chend), "%s%d", STR_CH, - g_model.trainerData.channelsStart + 8); + g_model.trainerData.channelsStart + BLUETOOTH_TRAINER_CHANNELS); btChannelEnd = new StaticText(this, grid.getFieldSlot(2, 1), chend, 0, COLOR_THEME_PRIMARY1); @@ -597,7 +597,7 @@ class TrainerModuleWindow : public FormGroup g_model.trainerData.channelsStart = newValue - 1; char chend[6]; snprintf(chend, sizeof(chend), "%s%d", STR_CH, - g_model.trainerData.channelsStart + 8); + g_model.trainerData.channelsStart + BLUETOOTH_TRAINER_CHANNELS); SET_DIRTY(); btChannelEnd->setText(chend); });