Skip to content

Commit

Permalink
Fix some source names
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Dec 21, 2022
1 parent 40e9297 commit 6e6be76
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 29 deletions.
7 changes: 2 additions & 5 deletions radio/src/gui/212x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/special_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/switch_warn_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
29 changes: 26 additions & 3 deletions radio/src/strhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion radio/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 6 additions & 2 deletions radio/src/tests/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
117 changes: 117 additions & 0 deletions radio/src/tests/sources.cpp
Original file line number Diff line number Diff line change
@@ -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");
}
8 changes: 8 additions & 0 deletions radio/src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion radio/src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand Down

0 comments on commit 6e6be76

Please sign in to comment.