From 0932636bea3bad337ed3f2cb68a804a6b01e6082 Mon Sep 17 00:00:00 2001 From: Cliff Date: Mon, 13 Sep 2021 19:36:37 -0700 Subject: [PATCH 1/5] Allow PPM Slave/jack trainer limits set in dataconstants.h --- radio/src/dataconstants.h | 6 +++++ radio/src/gui/colorlcd/model_setup.cpp | 33 +++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h index 3a0c85554..2fbae608e 100644 --- a/radio/src/dataconstants.h +++ b/radio/src/dataconstants.h @@ -46,6 +46,8 @@ #define MAX_SPECIAL_FUNCTIONS 64 // number of functions assigned to switches #define MAX_SCRIPTS 9 #define MAX_INPUTS 32 + #define MIN_TRAINER_CHANNELS 4 + #define DEF_TRAINER_CHANNELS 8 #define MAX_TRAINER_CHANNELS 16 #define MAX_TELEMETRY_SENSORS 60 #define MAX_CUSTOM_SCREENS 5 @@ -59,6 +61,8 @@ #define MAX_SPECIAL_FUNCTIONS 64 // number of functions assigned to switches #define MAX_SCRIPTS 7 #define MAX_INPUTS 32 + #define MIN_TRAINER_CHANNELS 4 + #define DEF_TRAINER_CHANNELS 8 #define MAX_TRAINER_CHANNELS 16 #define MAX_TELEMETRY_SENSORS 60 #elif defined(PCBTARANIS) @@ -71,6 +75,8 @@ #define MAX_SPECIAL_FUNCTIONS 64 // number of functions assigned to switches #define MAX_SCRIPTS 7 #define MAX_INPUTS 32 + #define MIN_TRAINER_CHANNELS 4 + #define DEF_TRAINER_CHANNELS 8 #define MAX_TRAINER_CHANNELS 16 #define MAX_TELEMETRY_SENSORS 40 #else diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index 37dfb3ee7..d9b96b47d 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -606,37 +606,36 @@ class TrainerModuleWindow : public FormGroup } else #endif if (g_model.trainerData.mode == TRAINER_MODE_SLAVE) { + #define PPMCH_START_MIN 1 + #define PPMCH_START_MAX (MAX_OUTPUT_CHANNELS - g_model.trainerData.channelsCount + 1 - DEF_TRAINER_CHANNELS) + #define PPMCH_END_MIN (g_model.trainerData.channelsStart + MIN_TRAINER_CHANNELS) + #define PPMCH_END_MAX min(g_model.trainerData.channelsStart + MAX_TRAINER_CHANNELS, MAX_OUTPUT_CHANNELS) + new StaticText(this, grid.getLabelSlot(true), STR_CHANNELRANGE, 0, COLOR_THEME_PRIMARY1); channelStart = new NumberEdit( - this, grid.getFieldSlot(2, 0), 1, - MAX_OUTPUT_CHANNELS - 8 + g_model.trainerData.channelsCount + 1, + this, grid.getFieldSlot(2, 0), PPMCH_START_MIN, PPMCH_START_MAX, GET_DEFAULT(1 + g_model.trainerData.channelsStart)); - channelEnd = - new NumberEdit(this, grid.getFieldSlot(2, 1), - g_model.trainerData.channelsStart + 1, - min(MAX_TRAINER_CHANNELS, - g_model.trainerData.channelsStart + - MAX_TRAINER_CHANNELS_M8), - GET_DEFAULT(g_model.trainerData.channelsStart + 8 + - g_model.trainerData.channelsCount)); + channelEnd = new NumberEdit( + this, grid.getFieldSlot(2, 1), PPMCH_END_MIN, PPMCH_END_MAX, + GET_DEFAULT((g_model.trainerData.channelsStart + + DEF_TRAINER_CHANNELS + + g_model.trainerData.channelsCount))); channelStart->setPrefix(STR_CH); channelEnd->setPrefix(STR_CH); channelStart->setSetValueHandler([=](int32_t newValue) { g_model.trainerData.channelsStart = newValue - 1; SET_DIRTY(); - channelEnd->setMin(g_model.trainerData.channelsStart + 1); - channelEnd->setMax(min( - MAX_TRAINER_CHANNELS, - g_model.trainerData.channelsStart + MAX_TRAINER_CHANNELS_M8)); + channelEnd->setMin(PPMCH_END_MIN); + channelEnd->setMax(PPMCH_END_MAX); channelEnd->invalidate(); }); channelEnd->setSetValueHandler([=](int32_t newValue) { g_model.trainerData.channelsCount = - newValue - g_model.trainerData.channelsStart - 8; + newValue - g_model.trainerData.channelsStart - + DEF_TRAINER_CHANNELS; SET_DIRTY(); - channelStart->setMax(MAX_TRAINER_CHANNELS - 8 + - g_model.trainerData.channelsCount + 1); + channelStart->setMax(PPMCH_START_MAX); }); grid.nextLine(); From cd5feefde9071427bc42246a6d205971696cbcb1 Mon Sep 17 00:00:00 2001 From: Cliff Date: Mon, 13 Sep 2021 19:37:20 -0700 Subject: [PATCH 2/5] 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); }); From cd4de0561b44c4125e8eea62a7cf49062f7918c9 Mon Sep 17 00:00:00 2001 From: Cliff Date: Mon, 13 Sep 2021 19:37:58 -0700 Subject: [PATCH 3/5] Fix Bug in Bluetooth trainer channel start --- radio/src/bluetooth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/bluetooth.cpp b/radio/src/bluetooth.cpp index 1237898b3..00a22bc74 100644 --- a/radio/src/bluetooth.cpp +++ b/radio/src/bluetooth.cpp @@ -259,7 +259,7 @@ void Bluetooth::sendTrainer() buffer[bufferIndex++] = START_STOP; // start byte pushByte(TRAINER_FRAME); - for (int channel=0; channel Date: Mon, 13 Sep 2021 19:38:28 -0700 Subject: [PATCH 4/5] Fix bug if switch from other mode back to BT channel count is wrong --- radio/src/gui/colorlcd/model_setup.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index ef723093d..64eb1e99b 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -595,6 +595,7 @@ class TrainerModuleWindow : public FormGroup channelStart->setPrefix(STR_CH); channelStart->setSetValueHandler([=](int32_t newValue) { g_model.trainerData.channelsStart = newValue - 1; + g_model.trainerData.channelsCount = BLUETOOTH_TRAINER_CHANNELS - DEF_TRAINER_CHANNELS; char chend[6]; snprintf(chend, sizeof(chend), "%s%d", STR_CH, g_model.trainerData.channelsStart + BLUETOOTH_TRAINER_CHANNELS); From f5b75dd9f4f3da8c767cb6383112bb61ac54e481 Mon Sep 17 00:00:00 2001 From: Cliff Date: Tue, 14 Sep 2021 20:40:48 -0700 Subject: [PATCH 5/5] Invert PPM polarity --- radio/src/translations/untranslated.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/translations/untranslated.h b/radio/src/translations/untranslated.h index 4ae88d613..429bf3f22 100644 --- a/radio/src/translations/untranslated.h +++ b/radio/src/translations/untranslated.h @@ -173,7 +173,7 @@ #define TR_AFHDS3_POWERS "25 mW\0""100 mW""500 mW""1 W\0 ""2 W\0 " #define LEN_PPM_POL "\001" -#define TR_PPM_POL "+""-" +#define TR_PPM_POL "-""+" #define LEN_SBUS_INVERSION_VALUES "\014" #define TR_SBUS_INVERSION_VALUES "normal\0 ""not inverted"