diff --git a/radio/src/gui/212x64/lcd.cpp b/radio/src/gui/212x64/lcd.cpp index 074f5b95ce8..561a2dd0b4c 100644 --- a/radio/src/gui/212x64/lcd.cpp +++ b/radio/src/gui/212x64/lcd.cpp @@ -620,16 +620,13 @@ void putsVBat(coord_t x, coord_t y, LcdFlags att) void drawStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att) { - // Skip "---": idx + 1 - // Skip source symbol: + 2 - const char* stickName = STR_VSRCRAW[idx + 1] + 2; - lcdDrawSizedText(x, y, stickName, UINT8_MAX, att); + lcdDrawSizedText(x, y, getStickName(idx), UINT8_MAX, att); } void drawSource(coord_t x, coord_t y, uint32_t idx, LcdFlags att) { if (idx == MIXSRC_NONE) { - lcdDrawTextAtIndex(x, y, STR_VSRCRAW, 0, att); // TODO macro + lcdDrawText(x, y, STR_EMPTY, att); } else if (idx <= MIXSRC_LAST_INPUT) { lcdDrawChar(x+2, y+1, CHR_INPUT, TINSIZE); diff --git a/radio/src/gui/colorlcd/special_functions.cpp b/radio/src/gui/colorlcd/special_functions.cpp index 92a1d6fbc9b..5c2fa1103d7 100644 --- a/radio/src/gui/colorlcd/special_functions.cpp +++ b/radio/src/gui/colorlcd/special_functions.cpp @@ -518,7 +518,7 @@ class SpecialFunctionButton : public Button else if (value == NUM_STICKS + 1) text = std::string(STR_CHANS); else - text = TEXT_AT_INDEX(STR_VSRCRAW, value); + text = getStickName(value - 1); dc->drawText(col1, line2, text.c_str(), COLOR_THEME_SECONDARY1); break; } diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.cpp b/radio/src/gui/colorlcd/switch_warn_dialog.cpp index aa22cbc7ce3..796894d73c2 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.cpp +++ b/radio/src/gui/colorlcd/switch_warn_dialog.cpp @@ -92,7 +92,7 @@ void SwitchWarnDialog::checkEvents() if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) { continue; } if ( (g_model.potsWarnEnabled & (1 << i))) { if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) { - warn_txt += STR_VSRCRAW[POT1 + i + 1]; + warn_txt += getPotName(i); } } } diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 993c47c3c74..9c106305ecf 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -26,21 +26,11 @@ #include "extmodule_serial_driver.h" #endif -#if defined(PCBFRSKY) || defined(PCBFLYSKY) uint8_t switchToMix(uint8_t source) { div_t qr = div(source-1, 3); - return qr.quot+MIXSRC_FIRST_SWITCH; + return qr.quot + MIXSRC_FIRST_SWITCH; } -#else -uint8_t switchToMix(uint8_t source) -{ - if (source <= 3) - return MIXSRC_3POS; - else - return MIXSRC_FIRST_SWITCH - 3 + source; -} -#endif int circularIncDec(int current, int inc, int min, int max, IsValueAvailable isValueAvailable) { @@ -192,10 +182,10 @@ bool isSourceAvailable(int source) #endif if (source >= MIXSRC_FIRST_POT && source <= MIXSRC_LAST_POT) { - return IS_POT_SLIDER_AVAILABLE(POT1+source - MIXSRC_FIRST_POT); + return IS_POT_SLIDER_AVAILABLE(source - MIXSRC_FIRST_POT); } -#if defined(PCBX10) +#if defined(PCBHORUS) && !defined(PCBX12S) if (source >= MIXSRC_MOUSE1 && source <= MIXSRC_MOUSE2) return false; #endif diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 9a0621c5ccc..3a3cb0fe626 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -1413,7 +1413,7 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, break; default: if (value > 0 && value < NUM_STICKS + 1) { - str = yaml_output_enum(value - 1 + MIXSRC_FIRST_STICK, enum_MixSources); + str = analogGetCanonicalStickName(value - 1); if (str && !wf(opaque, str, strlen(str))) return false; } } diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index 984a141c00c..075fe2c0812 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -621,10 +621,33 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx) } strncpy(pos, name, dest_len - 1); pos[dest_len - 1] = '\0'; + + } +#if defined(PCBHORUS) + else if (idx <= MIXSRC_MOUSE2) { + // TODO + } +#endif +#if defined(IMU) + else if (idx <= MIXSRC_TILT_Y) { + idx -= MIXSRC_TILT_X; + getStringAtIndex(dest, STR_IMU_VSRCRAW, idx); + } +#endif +#if defined(PCBHORUS) + else if (idx <= MIXSRC_LAST_SPACEMOUSE) { + idx -= MIXSRC_FIRST_SPACEMOUSE; + getStringAtIndex(dest, STR_SM_VSRCRAW, idx); + } +#endif + else if (idx == MIXSRC_MAX) { + copyToTerminated(dest, "MAX"); + } else if (idx <= MIXSRC_LAST_HELI) { + idx -= MIXSRC_FIRST_HELI; + getStringAtIndex(dest, STR_CYC_VSRCRAW, idx); } else if (idx <= MIXSRC_LAST_TRIM) { - // TODO: trim strings - // idx -= MIXSRC_Rud; - // getStringAtIndex(dest, STR_VSRCRAW, idx + 1); + idx -= MIXSRC_FIRST_TRIM; + getStringAtIndex(dest, STR_TRIMS_VSRCRAW, idx); } else if (idx <= MIXSRC_LAST_SWITCH) { idx -= MIXSRC_FIRST_SWITCH; char* pos = strAppend(dest, STR_CHAR_SWITCH, sizeof(STR_CHAR_SWITCH) - 1); diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index 7bf34c55d18..ad6e9c92084 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -537,7 +537,7 @@ bool getSwitch(swsrc_t swtch, uint8_t flags) if (swtch == SWSRC_NONE) return true; - uint8_t cs_idx = abs(swtch); + uint16_t cs_idx = abs(swtch); if (cs_idx == SWSRC_ONE) { result = !s_mixer_first_run_done; diff --git a/radio/src/tests/CMakeLists.txt b/radio/src/tests/CMakeLists.txt index 6c7eacf6a1b..87c11cb8534 100644 --- a/radio/src/tests/CMakeLists.txt +++ b/radio/src/tests/CMakeLists.txt @@ -40,7 +40,9 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND) endif() - file(GLOB TEST_SRC_FILES ${RADIO_SRC_DIR}/tests/*.cpp) + file(GLOB TEST_SRC_FILES ${RADIO_SRC_DIR}/tests/*.cpp + CONFIGURE_DEPENDS "${RADIO_SRC_DIR}/tests/*.cpp") + set(TEST_SRC_FILES ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h ${SIMU_SRC} diff --git a/radio/src/tests/functions.cpp b/radio/src/tests/functions.cpp index d1743c60b9b..860e77f12fb 100644 --- a/radio/src/tests/functions.cpp +++ b/radio/src/tests/functions.cpp @@ -27,9 +27,13 @@ TEST_F(SpecialFunctionsTest, SwitchFiledSize) { // test the size of swtch member g_model.customFn[0].swtch = SWSRC_LAST; - EXPECT_EQ(g_model.customFn[0].swtch, SWSRC_LAST) << "CustomFunctionData.swtch member is too small to hold all possible values"; + EXPECT_EQ(g_model.customFn[0].swtch, SWSRC_LAST) + << "CustomFunctionData.swtch member is too small to hold all possible " + "values"; g_model.customFn[0].swtch = -SWSRC_LAST; - EXPECT_EQ(g_model.customFn[0].swtch, -SWSRC_LAST) << "CustomFunctionData.swtch member is too small to hold all possible values"; + EXPECT_EQ(g_model.customFn[0].swtch, -SWSRC_LAST) + << "CustomFunctionData.swtch member is too small to hold all possible " + "values"; } #if defined(PCBFRSKY) diff --git a/radio/src/tests/sources.cpp b/radio/src/tests/sources.cpp new file mode 100644 index 00000000000..6a655bb5811 --- /dev/null +++ b/radio/src/tests/sources.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "gtests.h" + +#include "storage/yaml/yaml_tree_walker.h" +#include "storage/yaml/yaml_parser.h" +#include "storage/yaml/yaml_datastructs.h" +#include "storage/yaml/yaml_bits.h" + +static const char _radio_config[] = + "potsConfig: \n" + " P1:\n" + " type: without_detent\n" + " name: \"\"\n" + " P2:\n" + " type: multipos_switch\n" + " name: \"\"\n" + " P3:\n" + " type: with_detent\n" + " name: \"\"\n" + " SL1:\n" + " type: slider\n" + " name: \"\"\n" + " SL2:\n" + " type: slider\n" + " name: \"\"\n" + "switchConfig: \n" + " SA:\n" + " type: 3pos\n" + " name: \"\"\n" + " SB:\n" + " type: 3pos\n" + " name: \"\"\n" + " SC:\n" + " type: 3pos\n" + " name: \"\"\n" + " SD:\n" + " type: 3pos\n" + " name: \"\"\n" + " SE:\n" + " type: 3pos\n" + " name: \"\"\n" + " SF:\n" + " type: 2pos\n" + " name: \"\"\n" + " SG:\n" + " type: 3pos\n" + " name: \"\"\n" + " SH:\n" + " type: toggle\n" + " name: \"\"\n"; + +static void loadRadioYamlStr(const char* str) +{ + YamlTreeWalker tree; + tree.reset(get_radiodata_nodes(), (uint8_t*)&g_eeGeneral); + + YamlParser yp; + yp.init(YamlTreeWalker::get_parser_calls(), &tree); + + size_t len = strlen(str); + yp.parse(str, len); +} + +TEST(Sources, getSourceString) +{ + loadRadioYamlStr(_radio_config); + +#if defined(IMU) + EXPECT_STREQ(getSourceString(MIXSRC_TILT_X), "TltX"); + EXPECT_STREQ(getSourceString(MIXSRC_TILT_Y), "TltY"); +#endif + +#if defined(PCBHORUS) + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_A), "smA"); + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_B), "smB"); + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_C), "smC"); + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_D), "smD"); + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_E), "smE"); + EXPECT_STREQ(getSourceString(MIXSRC_SPACEMOUSE_F), "smF"); +#endif + + EXPECT_STREQ(getSourceString(MIXSRC_MAX), "MAX"); + +#if defined(HELI) + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI), "CYC1"); + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI + 1), "CYC2"); + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI + 2), "CYC3"); +#else + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI), "[C1]"); + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI + 1), "[C2]"); + EXPECT_STREQ(getSourceString(MIXSRC_FIRST_HELI + 2), "[C3]"); +#endif + + EXPECT_STREQ(getSourceString(MIXSRC_TrimRud), STR_CHAR_TRIM "Rud"); + EXPECT_STREQ(getSourceString(MIXSRC_TrimEle), STR_CHAR_TRIM "Ele"); + EXPECT_STREQ(getSourceString(MIXSRC_TrimThr), STR_CHAR_TRIM "Thr"); +} diff --git a/radio/src/translations.cpp b/radio/src/translations.cpp index cb21b7d0726..b464f160e21 100644 --- a/radio/src/translations.cpp +++ b/radio/src/translations.cpp @@ -53,6 +53,14 @@ ISTR(VTELEMSCREENTYPE); ISTR(VKEYS); ISTR(VSWITCHES); ISTR(VSRCRAW); +#if defined(IMU) +ISTR(IMU_VSRCRAW); +#endif +#if defined(PCBHORUS) +ISTR(SM_VSRCRAW); +#endif +ISTR(CYC_VSRCRAW); +ISTR(TRIMS_VSRCRAW); ISTR(ROTARY_ENC_OPT); ISTR(VTMRMODES); ISTR(VPERSISTENT); diff --git a/radio/src/translations.h b/radio/src/translations.h index 3a168823f00..660011f0fd8 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -143,7 +143,14 @@ extern const char* STR_VSWASHTYPE[]; extern const char* STR_VKEYS[]; extern const char* STR_VSWITCHES[]; -extern const char* STR_VSRCRAW[]; +#if defined(IMU) +extern const char* STR_IMU_VSRCRAW[]; +#endif +#if defined(PCBHORUS) +extern const char* STR_SM_VSRCRAW[]; +#endif +extern const char* STR_CYC_VSRCRAW[]; +extern const char* STR_TRIMS_VSRCRAW[]; extern const char* STR_ROTARY_ENC_OPT[];