Skip to content

Commit

Permalink
fix: Throttle idle trim handling for surface, enable MT12 tests (#4520)
Browse files Browse the repository at this point in the history
Co-authored-by: 3djc <[email protected]>
Co-authored-by: raphaelcoeffic <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2024
1 parent 4c2ea7a commit dfaad73
Show file tree
Hide file tree
Showing 36 changed files with 598 additions and 1,330 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
- x9lites
- xlite
- xlites
- mt12
container:
image: ghcr.io/edgetx/edgetx-dev:latest
volumes:
Expand Down Expand Up @@ -109,6 +110,7 @@ jobs:
- x9e;x9e-hall
- x9lite;x9lites
- xlite;xlites
- mt12
container:
image: ghcr.io/edgetx/edgetx-dev:latest
volumes:
Expand Down
2 changes: 2 additions & 0 deletions companion/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ elseif(PCB STREQUAL X7 AND PCBREV STREQUAL COMMANDO8)
set(FLAVOUR commando8)
elseif(PCB STREQUAL X7 AND PCBREV STREQUAL T8)
set(FLAVOUR t8)
elseif(PCB STREQUAL X7 AND PCBREV STREQUAL MT12)
set(FLAVOUR mt12)
elseif(PCB STREQUAL X9D+ AND PCBREV STREQUAL 2019)
set(FLAVOUR x9d+2019)
elseif(PCB STREQUAL X10 AND PCBREV STREQUAL EXPRESS)
Expand Down
27 changes: 3 additions & 24 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,6 @@ enum SwitchSources {
SWSRC_FIRST_TRIM SKIP,
SWSRC_LAST_TRIM SKIP = SWSRC_FIRST_TRIM + 2 * MAX_TRIMS - 1,

#if NUM_TRIMS > 6
SWSRC_TrimT7Down,
SWSRC_TrimT7Up,
SWSRC_TrimT8Down,
SWSRC_TrimT8Up,
#endif

SWSRC_FIRST_LOGICAL_SWITCH SKIP,
SWSRC_LAST_LOGICAL_SWITCH SKIP = SWSRC_FIRST_LOGICAL_SWITCH + MAX_LOGICAL_SWITCHES - 1,

Expand Down Expand Up @@ -482,7 +475,8 @@ enum MixSources {

#if defined(LUA_INPUTS)
MIXSRC_FIRST_LUA SKIP,
MIXSRC_LAST_LUA SKIP = MIXSRC_FIRST_LUA + (MAX_SCRIPTS * MAX_SCRIPT_OUTPUTS) - 1,
MIXSRC_LAST_LUA SKIP =
MIXSRC_FIRST_LUA + (MAX_SCRIPTS * MAX_SCRIPT_OUTPUTS) - 1,
#endif

// Semantic sticks
Expand Down Expand Up @@ -515,19 +509,7 @@ enum MixSources {
MIXSRC_LAST_HELI SKIP = MIXSRC_FIRST_HELI + 2,

MIXSRC_FIRST_TRIM SKIP,
MIXSRC_TrimRud = MIXSRC_FIRST_TRIM,
MIXSRC_TrimEle,
MIXSRC_TrimThr,
MIXSRC_TrimAil,
//#if defined(PCBHORUS)
MIXSRC_TrimT5,
MIXSRC_TrimT6,
MIXSRC_TrimT7,
MIXSRC_TrimT8,
MIXSRC_LAST_TRIM SKIP = MIXSRC_TrimT8,
//#else
//MIXSRC_LAST_TRIM SKIP = MIXSRC_TrimAil,
//#endif
MIXSRC_LAST_TRIM SKIP = MIXSRC_FIRST_TRIM + MAX_TRIMS - 1,

MIXSRC_FIRST_SWITCH SKIP,
MIXSRC_LAST_SWITCH SKIP = MIXSRC_FIRST_SWITCH + MAX_SWITCHES - 1,
Expand Down Expand Up @@ -560,9 +542,6 @@ enum MixSources {
#define INPUTSRC_FIRST MIXSRC_FIRST_STICK
#define INPUTSRC_LAST MIXSRC_LAST_TELEM

// TODO: this won't work forever (what about ground radios?)
#define MIXSRC_Thr (MIXSRC_FIRST_STICK + 2)

#if defined(FUNCTION_SWITCHES)
#define MIXSRC_LAST_REGULAR_SWITCH (MIXSRC_FIRST_SWITCH + switchGetMaxSwitches() - 1)
#define MIXSRC_FIRST_FS_SWITCH (MIXSRC_LAST_REGULAR_SWITCH + 1)
Expand Down
24 changes: 12 additions & 12 deletions radio/src/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,39 @@ static inline void check_struct()
CHKSIZE(TrainerData, 16);

#if defined(PCBXLITES)
CHKSIZE(RadioData, 872);
CHKSIZE(RadioData, 871);
CHKSIZE(ModelData, 6265);
#elif defined(PCBXLITE)
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6265);
#elif defined(RADIO_TPRO)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6290);
#elif defined(RADIO_POCKET)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
#elif defined(RADIO_TPROV2)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6290);
#elif defined(RADIO_T14)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6265);
#elif defined(RADIO_T20)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6326);
#elif defined(RADIO_BOXER)
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6265);
#elif defined(RADIO_MT12)
CHKSIZE(RadioData, 859);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6265);
#elif defined(PCBX7)
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6265);
#elif defined(PCBX9E)
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6707);
#elif defined(PCBX9D) || defined(PCBX9DP)
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 869);
CHKSIZE(ModelData, 6706);
#elif defined(PCBHORUS)
#if defined(PCBX10)
Expand Down
9 changes: 1 addition & 8 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,16 +824,9 @@ PACK(struct TrainerData {
NOBACKUP(uint8_t blOffBright:7); \
NOBACKUP(char bluetoothName[LEN_BLUETOOTH_NAME]);
#else
#if defined(STORAGE_BLUETOOTH)
#define BLUETOOTH_FIELDS \
uint8_t spare6 SKIP; \
char bluetoothName[LEN_BLUETOOTH_NAME];
#else
#define BLUETOOTH_FIELDS
#endif
#define EXTRA_GENERAL_FIELDS \
uint8_t backlightColor; \
BLUETOOTH_FIELDS
char bluetoothName[LEN_BLUETOOTH_NAME];
#endif

#if defined(BUZZER)
Expand Down
8 changes: 6 additions & 2 deletions radio/src/gui/128x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ void doMainScreenGraphics()
drawThrottle(LBOX_CENTERX, calibratedAnalogs[ADC_MAIN_TH]);
#else
int16_t calibStickVert = calibratedAnalogs[ADC_MAIN_LV];
if (g_model.throttleReversed && inputMappingConvertMode(ADC_MAIN_LV) == THR_STICK)
if (g_model.throttleReversed &&
inputMappingConvertMode(ADC_MAIN_LV) == inputMappingGetThrottle()) {
calibStickVert = -calibStickVert;
}
drawStick(LBOX_CENTERX, calibratedAnalogs[ADC_MAIN_LH], calibStickVert);

calibStickVert = calibratedAnalogs[ADC_MAIN_RV];
if (g_model.throttleReversed && inputMappingConvertMode(ADC_MAIN_RV) == THR_STICK)
if (g_model.throttleReversed &&
inputMappingConvertMode(ADC_MAIN_RV) == inputMappingGetThrottle()) {
calibStickVert = -calibStickVert;
}
drawStick(RBOX_CENTERX, calibratedAnalogs[ADC_MAIN_RH], calibStickVert);
#endif

Expand Down
8 changes: 6 additions & 2 deletions radio/src/gui/212x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ static bool isAsteriskDisplayed() {
void doMainScreenGraphics()
{
int16_t calibStickVert = calibratedAnalogs[ADC_MAIN_LV];
if (g_model.throttleReversed && inputMappingConvertMode(ADC_MAIN_LV) == THR_STICK)
if (g_model.throttleReversed &&
inputMappingConvertMode(ADC_MAIN_LV) == inputMappingGetThrottle()) {
calibStickVert = -calibStickVert;
}
drawStick(LBOX_CENTERX, calibratedAnalogs[ADC_MAIN_LH], calibStickVert);

calibStickVert = calibratedAnalogs[ADC_MAIN_RV];
if (g_model.throttleReversed && inputMappingConvertMode(ADC_MAIN_RV) == THR_STICK)
if (g_model.throttleReversed &&
inputMappingConvertMode(ADC_MAIN_RV) == inputMappingGetThrottle()) {
calibStickVert = -calibStickVert;
}
drawStick(RBOX_CENTERX, calibratedAnalogs[ADC_MAIN_RH], calibStickVert);
}

Expand Down
3 changes: 2 additions & 1 deletion radio/src/gui/colorlcd/input_edit_adv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ InputEditAdvanced::InputEditAdvanced(uint8_t input_n, uint8_t index) :
// Trim
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1);
auto c = new Choice(line, rect_t{}, -TRIM_OFF, -TRIM_LAST,
const auto trimLast = TRIM_OFF + keysGetMaxTrims() - 1;
auto c = new Choice(line, rect_t{}, -TRIM_OFF, -trimLast,
GET_VALUE(-input->trimSource),
SET_VALUE(input->trimSource, -newValue));

Expand Down
5 changes: 0 additions & 5 deletions radio/src/input_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

#include <stdint.h>

// Air radios / input order in mode 1
#define RUD_STICK 0
#define ELE_STICK 1
#define THR_STICK 2
#define AIL_STICK 3

#define MAX_INPUT_MODES 4

Expand Down
15 changes: 0 additions & 15 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,6 @@ struct LuaSingleField {
};

const LuaSingleField luaSingleFields[] = {
{MIXSRC_FIRST_STICK, "rud", "Rudder"},
{MIXSRC_FIRST_STICK + 1, "ele", "Elevator"},
{MIXSRC_FIRST_STICK + 2, "thr", "Throttle"},
{MIXSRC_FIRST_STICK + 3, "ail", "Aileron"},

#if defined(IMU)
{MIXSRC_TILT_X, "tiltx", "Tilt X"},
{MIXSRC_TILT_Y, "tilty", "Tilt Y"},
Expand All @@ -390,16 +385,6 @@ const LuaSingleField luaSingleFields[] = {
{MIXSRC_MAX, "min", "MIN"},
{MIXSRC_MAX, "max", "MAX"},

{MIXSRC_TrimRud, "trim-rud", "Rudder trim"},
{MIXSRC_TrimEle, "trim-ele", "Elevator trim"},
{MIXSRC_TrimThr, "trim-thr", "Throttle trim"},
{MIXSRC_TrimAil, "trim-ail", "Aileron trim"},

#if MAX_TRIMS > 4
{MIXSRC_TrimT5, "trim-t5", "Aux trim T5"},
{MIXSRC_TrimT6, "trim-t6", "Aux trim T6"},
#endif

{MIXSRC_TX_VOLTAGE, "tx-voltage", "Transmitter battery voltage [volts]"},
{MIXSRC_TX_TIME, "clock", "RTC clock [minutes from midnight]"},
};
Expand Down
25 changes: 22 additions & 3 deletions radio/src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,20 +591,39 @@ void evalInputs(uint8_t mode)
}
}

#if defined(SURFACE_RADIO)
constexpr int IDLE_TRIM_SCALE = 1;
#else
constexpr int IDLE_TRIM_SCALE = 2;
#endif

int getStickTrimValue(int stick, int stickValue)
{
if (stick < 0)
return 0;

int trim = trims[stick];
uint8_t thrTrimSw = g_model.getThrottleStickTrimSource() - MIXSRC_FIRST_TRIM;
if (stick == thrTrimSw) {
if (stick == thrTrimSw) { // trim for throttle
if (g_model.throttleReversed) trim = -trim;
if (g_model.thrTrim) {
if (g_model.thrTrim) { // throttle idle ON
// evalTrims() store 2 * trim value in trims[]
// so here, trim values range from -256 to 256
// and extended trim values range from -1024 to 1024
trim = (g_model.extendedTrims) ? 2 * TRIM_EXTENDED_MAX + trim
: 2 * TRIM_MAX + trim;
trim = trim * (1024 - stickValue) / (2 * RESX);
trim = trim * (1024 - stickValue) / (IDLE_TRIM_SCALE * RESX);
#if defined(SURFACE_RADIO)
// Throttle Idle trim (g_model.thrTrim) should affect only forward stick (0 to 1024)
// Return no trim for reverse side when throttle idle trim is enabled
if (stickValue < 0) return 0;
#endif
}
#if defined(SURFACE_RADIO)
// divide throtle trim by two since since the full extend
// of forward/reverse chan is only 1024 instead of 2048
trim >>= 1;
#endif
}
return trim;
}
Expand Down
17 changes: 0 additions & 17 deletions radio/src/myeeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,6 @@ enum CurveRefType {

#define TRIM_OFF (1)
#define TRIM_ON (0)
#define TRIM_RUD (-1)
#define TRIM_ELE (-2)
#define TRIM_THR (-3)
#define TRIM_AIL (-4)
#if defined(PCBPL18)
#define TRIM_T5 (-5)
#define TRIM_T6 (-6)
#define TRIM_T7 (-7)
#define TRIM_T8 (-8)
#define TRIM_LAST TRIM_T8
#elif defined(PCBHORUS)
#define TRIM_T5 (-5)
#define TRIM_T6 (-6)
#define TRIM_LAST TRIM_T6
#else
#define TRIM_LAST TRIM_AIL
#endif

enum MixerMultiplex {
MLTPX_ADD = 0,
Expand Down
2 changes: 1 addition & 1 deletion radio/src/storage/yaml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ elseif(PCB STREQUAL X7)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_128x64.cpp)
endif()
elseif(PCB STREQUAL X9LITE)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_x9lite.cpp)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_128x64.cpp)
elseif(PCB STREQUAL X9LITES)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_128x64.cpp)
elseif(PCB STREQUAL XLITE)
Expand Down
4 changes: 1 addition & 3 deletions radio/src/storage/yaml/yaml_datastructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
#else
#include "yaml_datastructs_128x64.cpp"
#endif
#elif defined(PCBX9LITE) && !defined(PCBX9LITES)
#include "yaml_datastructs_x9lite.cpp"
#elif defined(PCBX9LITES)
#elif defined(PCBX9LITE)
#include "yaml_datastructs_128x64.cpp"
#elif defined(PCBXLITE) && !defined(PCBXLITES)
#include "yaml_datastructs_128x64.cpp"
Expand Down
9 changes: 0 additions & 9 deletions radio/src/storage/yaml/yaml_datastructs_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ const struct YamlIdStr enum_MixSources[] = {
{ MIXSRC_NONE, "NONE" },
{ MIXSRC_MIN, "MIN" },
{ MIXSRC_MAX, "MAX" },
{ MIXSRC_TrimRud, "TrimRud" },
{ MIXSRC_TrimEle, "TrimEle" },
{ MIXSRC_TrimThr, "TrimThr" },
{ MIXSRC_TrimAil, "TrimAil" },
{ MIXSRC_TrimT5, "TrimT5" },
{ MIXSRC_TrimT6, "TrimT6" },
{ MIXSRC_TrimT7, "TrimT7" },
{ MIXSRC_TrimT8, "TrimT8" },
{ MIXSRC_TX_VOLTAGE, "TX_VOLTAGE" },
{ MIXSRC_TX_TIME, "TX_TIME" },
{ MIXSRC_TX_GPS, "TX_GPS" },
Expand Down Expand Up @@ -349,7 +341,6 @@ static const struct YamlNode struct_RadioData[] = {
YAML_ARRAY("switchConfig", 2, 32, struct_switchConfig, nullptr),
YAML_ARRAY("flexSwitches", 0, MAX_FLEX_SWITCHES, struct_flexSwitch, flex_sw_valid),
YAML_UNSIGNED( "backlightColor", 8 ),
YAML_PADDING( 8 ),
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_CUSTOM("rotEncDirection",r_rotEncDirection,nullptr),
Expand Down
14 changes: 10 additions & 4 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static uint32_t r_mixSrcRaw(const YamlNode* node, const char* val, uint8_t val_l
val[1] == 'm' &&
val[2] == 'r' &&
val[3] >= '1' &&
val[3] <= ('1' + MAX_TIMERS)) {
val[3] <= ('0' + MAX_TIMERS)) {

return MIXSRC_FIRST_TIMER + (val[3] - '1');

Expand All @@ -263,15 +263,16 @@ static uint32_t r_mixSrcRaw(const YamlNode* node, const char* val, uint8_t val_l
val[3] == 'E' &&
val[4] == 'R' &&
val[5] >= '1' &&
val[5] <= ('1' + MAX_TIMERS)) {
val[5] <= ('0' + MAX_TIMERS)) {

return MIXSRC_FIRST_TIMER + (val[5] - '1');

} else if (val_len > 1 &&
val[0] == 'T' &&
val[1] >= '1' &&
val[1] <= '9') {
return yaml_str2uint(val + 1, val_len - 1) + MIXSRC_FIRST_TRIM - 1;
val[1] <= ('0' + MAX_TRIMS)) {

return MIXSRC_FIRST_TRIM + (val[1] - '1');
}

auto idx = analogLookupCanonicalIdx(ADC_INPUT_MAIN, val, val_len);
Expand Down Expand Up @@ -343,6 +344,11 @@ static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf,
if (!wf(opaque, "CYC", 3)) return false;
str = yaml_unsigned2str(val - MIXSRC_FIRST_HELI + 1);
}
else if (val >= MIXSRC_FIRST_TRIM
&& val <= MIXSRC_LAST_TRIM) {
if (!wf(opaque, "T", 1)) return false;
str = yaml_unsigned2str(val - MIXSRC_FIRST_TRIM + 1);
}
else if (val >= MIXSRC_FIRST_SWITCH
&& val <= MIXSRC_LAST_SWITCH) {
str = switchGetCanonicalName(val - MIXSRC_FIRST_SWITCH);
Expand Down
Loading

0 comments on commit dfaad73

Please sign in to comment.