diff --git a/radio/src/gui/128x64/CMakeLists.txt b/radio/src/gui/128x64/CMakeLists.txt index 0c7549fdad..841e179869 100644 --- a/radio/src/gui/128x64/CMakeLists.txt +++ b/radio/src/gui/128x64/CMakeLists.txt @@ -22,12 +22,6 @@ set(GUI_SRC view_statistics.cpp ) -set(SRC - ${SRC} - gui/common/widgets.cpp - gui/common/arm/widgets.cpp - ) - if(FLIGHT_MODES) set(GUI_SRC ${GUI_SRC} diff --git a/radio/src/gui/128x64/lcd.cpp b/radio/src/gui/128x64/lcd.cpp index c3722475cc..00d64a9c89 100644 --- a/radio/src/gui/128x64/lcd.cpp +++ b/radio/src/gui/128x64/lcd.cpp @@ -813,21 +813,6 @@ void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att) drawSwitch(x, y, mode, att); } -void drawTrimMode(coord_t x, coord_t y, uint8_t fm, uint8_t idx, LcdFlags att) -{ - trim_t v = getRawTrimValue(fm, idx); - uint8_t mode = v.mode; - uint8_t p = mode >> 1; - char s[] = "--"; - if (mode != TRIM_MODE_NONE) { - if (mode % 2 == 0) - s[0] = ':'; - else - s[0] = '+'; - s[1] = '0'+p; - } - lcdDrawText(x, y, s, att); -} void drawShortTrimMode(coord_t x, coord_t y, uint8_t fm, uint8_t idx, LcdFlags att) { trim_t v = getRawTrimValue(fm, idx); @@ -841,15 +826,6 @@ void drawShortTrimMode(coord_t x, coord_t y, uint8_t fm, uint8_t idx, LcdFlags a } } -void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att) -{ - // convertUnit(val, unit); - lcdDrawNumber(x, y, val, att & (~NO_UNIT)); - if (!(att & NO_UNIT) && unit != UNIT_RAW) { - lcdDrawTextAtIndex(lcdLastRightPos/*+1*/, y, STR_VTELEMUNIT, unit, 0); - } -} - void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags att, bool seconds=true) { att &= ~RIGHT & ~BOLD; diff --git a/radio/src/gui/128x64/lcd.h b/radio/src/gui/128x64/lcd.h index c415e10919..4f3da257a5 100644 --- a/radio/src/gui/128x64/lcd.h +++ b/radio/src/gui/128x64/lcd.h @@ -130,7 +130,6 @@ void drawSource(coord_t x, coord_t y, mixsrc_t idx, LcdFlags att=0); void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags att=0); void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att=0); -void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att); void drawShortTrimMode(coord_t x, coord_t y, uint8_t mode, uint8_t idx, LcdFlags att); #define putsChn(x, y, idx, att) drawSource(x, y, MIXSRC_CH1+idx-1, att) diff --git a/radio/src/gui/212x64/CMakeLists.txt b/radio/src/gui/212x64/CMakeLists.txt index 0c7549fdad..841e179869 100644 --- a/radio/src/gui/212x64/CMakeLists.txt +++ b/radio/src/gui/212x64/CMakeLists.txt @@ -22,12 +22,6 @@ set(GUI_SRC view_statistics.cpp ) -set(SRC - ${SRC} - gui/common/widgets.cpp - gui/common/arm/widgets.cpp - ) - if(FLIGHT_MODES) set(GUI_SRC ${GUI_SRC} diff --git a/radio/src/gui/212x64/lcd.cpp b/radio/src/gui/212x64/lcd.cpp index 56492e5c53..19bb400986 100644 --- a/radio/src/gui/212x64/lcd.cpp +++ b/radio/src/gui/212x64/lcd.cpp @@ -718,33 +718,6 @@ void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att) drawSwitch(x, y, mode, att); } -void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att) -{ - trim_t v = getRawTrimValue(phase, idx); - unsigned int mode = v.mode; - unsigned int p = mode >> 1; - - if (mode == TRIM_MODE_NONE) { - lcdDrawText(x, y, "--", att); - } - else { - if (mode % 2 == 0) - lcdDrawChar(x, y, ':', att|FIXEDWIDTH); - else - lcdDrawChar(x, y, '+', att|FIXEDWIDTH); - lcdDrawChar(lcdNextPos, y, '0'+p, att); - } -} - -void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att) -{ - // convertUnit(val, unit); - lcdDrawNumber(x, y, val, att & (~NO_UNIT)); - if (!(att & NO_UNIT) && unit != UNIT_RAW) { - lcdDrawTextAtIndex(lcdLastRightPos/*+1*/, y, STR_VTELEMUNIT, unit, 0); - } -} - void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags att, bool seconds=true) { uint32_t absvalue = abs(value); diff --git a/radio/src/gui/212x64/lcd.h b/radio/src/gui/212x64/lcd.h index b55c6aa4d4..8d5fc785c0 100644 --- a/radio/src/gui/212x64/lcd.h +++ b/radio/src/gui/212x64/lcd.h @@ -123,7 +123,6 @@ void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att=0); void drawSource(coord_t x, coord_t y, uint32_t idx, LcdFlags att=0); void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags att=0); void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att=0); -void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att); #define putsChn(x, y, idx, att) drawSource(x, y, MIXSRC_CH1+idx-1, att) void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags attr); diff --git a/radio/src/gui/480x272/CMakeLists.txt b/radio/src/gui/480x272/CMakeLists.txt index de19e4b6ad..e3e258285f 100644 --- a/radio/src/gui/480x272/CMakeLists.txt +++ b/radio/src/gui/480x272/CMakeLists.txt @@ -26,12 +26,6 @@ set(GUI_SRC view_statistics.cpp ) -set(SRC - ${SRC} - gui/common/widgets.cpp - gui/common/arm/widgets.cpp - ) - if(FLIGHT_MODES) set(GUI_SRC ${GUI_SRC} diff --git a/radio/src/gui/480x272/widgets.h b/radio/src/gui/480x272/draw_functions.h similarity index 96% rename from radio/src/gui/480x272/widgets.h rename to radio/src/gui/480x272/draw_functions.h index 411fecdeac..0d872d87ef 100644 --- a/radio/src/gui/480x272/widgets.h +++ b/radio/src/gui/480x272/draw_functions.h @@ -18,11 +18,11 @@ * GNU General Public License for more details. */ -#ifndef _WIDGETS_H_ -#define _WIDGETS_H_ +#ifndef _DRAW_FUNCTIONS_H_ +#define _DRAW_FUNCTIONS_H_ #include "opentx.h" -#include +#include "common/colorlcd/draw_functions.h" #define OPTION_MENU_NO_FOOTER 0x01 #define OPTION_MENU_TITLE_BAR 0x02 @@ -78,4 +78,4 @@ void drawTrims(uint8_t flightMode); void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags); -#endif // _WIDGETS_H_ +#endif // _DRAW_FUNCTIONS_H_ diff --git a/radio/src/gui/480x272/gui.h b/radio/src/gui/480x272/gui.h index a096fabf69..e17858f22d 100644 --- a/radio/src/gui/480x272/gui.h +++ b/radio/src/gui/480x272/gui.h @@ -24,7 +24,7 @@ #include "gui_common.h" #include "lcd.h" #include "menus.h" -#include "widgets.h" +#include "draw_functions.h" #include "bitmaps.h" #include "theme.h" diff --git a/radio/src/gui/480x272/topbar.cpp b/radio/src/gui/480x272/topbar.cpp index 3e54cab33c..a181dfc973 100644 --- a/radio/src/gui/480x272/topbar.cpp +++ b/radio/src/gui/480x272/topbar.cpp @@ -18,6 +18,7 @@ * GNU General Public License for more details. */ +#include #include "opentx.h" unsigned int Topbar::getZonesCount() const diff --git a/radio/src/gui/common/colorlcd/CMakeLists.txt b/radio/src/gui/common/colorlcd/CMakeLists.txt index 81271fe233..8ebd0ddbd0 100644 --- a/radio/src/gui/common/colorlcd/CMakeLists.txt +++ b/radio/src/gui/common/colorlcd/CMakeLists.txt @@ -1,6 +1,6 @@ set(GUI_SRC ${GUI_SRC} - ../common/colorlcd/widgets.cpp + ../common/colorlcd/draw_functions.cpp ) if(HELI) diff --git a/radio/src/gui/common/arm/widgets.cpp b/radio/src/gui/common/colorlcd/draw_functions.cpp similarity index 53% rename from radio/src/gui/common/arm/widgets.cpp rename to radio/src/gui/common/colorlcd/draw_functions.cpp index 8b1a79c79e..30455b7072 100644 --- a/radio/src/gui/common/arm/widgets.cpp +++ b/radio/src/gui/common/colorlcd/draw_functions.cpp @@ -20,6 +20,155 @@ #include "opentx.h" +void drawStringWithIndex(coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix) +{ + char s[64]; + char * tmp = (prefix ? strAppend(s, prefix) : s); + tmp = strAppend(tmp, str); + tmp = strAppendUnsigned(tmp, abs(idx)); + if (suffix) + strAppend(tmp, suffix); + lcdDrawText(x, y, s, flags); +} + +void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att) +{ + // convertUnit(val, unit); + if (!(att & NO_UNIT) && unit != UNIT_RAW) { + char unitStr[8]; + strAppend(unitStr, STR_VTELEMUNIT+1+unit*STR_VTELEMUNIT[0], STR_VTELEMUNIT[0]); + lcdDrawNumber(x, y, val, att, 0, NULL, unitStr); + } + else { + lcdDrawNumber(x, y, val, att); + } +} + +int editChoice(coord_t x, coord_t y, const char * values, int value, int min, int max, LcdFlags attr, event_t event) +{ + if (attr & INVERS) value = checkIncDec(event, value, min, max, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL); + if (values) lcdDrawTextAtIndex(x, y, values, value-min, attr); + return value; +} + +uint8_t editCheckBox(uint8_t value, coord_t x, coord_t y, LcdFlags attr, event_t event ) +{ + value = editChoice(x, y, NULL, value, 0, 1, attr, event); + drawCheckBox(x, y, value, attr); + return value; +} + +swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t event) +{ + if (attr & INVERS) CHECK_INCDEC_MODELSWITCH(event, value, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes); + drawSwitch(x, y, value, attr); + return value; +} + +void drawFatalErrorScreen(const char * message) +{ + lcdClear(); + lcdDrawText(LCD_W/2, LCD_H/2-20, message, DBLSIZE|CENTERED|TEXT_BGCOLOR); + lcdRefresh(); +} + +void runFatalErrorScreen(const char * message) +{ + while (1) { + drawFatalErrorScreen(message); + backlightEnable(100); + uint8_t refresh = false; + while (1) { + uint32_t pwr_check = pwrCheck(); + if (pwr_check == e_power_off) { + boardOff(); + return; // only happens in SIMU, required for proper shutdown + } + else if (pwr_check == e_power_press) { + refresh = true; + } + else if (pwr_check == e_power_on && refresh) { + break; + } + } + } +} + +void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att) +{ + float power_W_PREC1 = pow(10.0, (dBm - 30.0) / 10.0) * 10; + if (dBm >= 30) { + lcdDrawNumber(x, y, power_W_PREC1, PREC1 | att); + lcdDrawText(lcdNextPos, y, "W", att); + } + else if (dBm < 10) { + uint16_t power_MW_PREC1 = round(power_W_PREC1 * 1000); + lcdDrawNumber(x, y, power_MW_PREC1, PREC1 | att); + lcdDrawText(lcdNextPos, y, "mW", att); + } + else { + uint16_t power_MW = round(power_W_PREC1 * 100); + if (power_MW >= 50) { + power_MW = (power_MW / 5) * 5; + lcdDrawNumber(x, y, power_MW, att); + lcdDrawText(lcdNextPos, y, "mW", att); + } + else { + lcdDrawNumber(x, y, power_MW, att); + lcdDrawText(lcdNextPos, y, "mW", att); + } + } +} + +void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags) +{ + lcdDrawTextAtIndex(x, y, STR_MMMINV, 0, flags); +} + +#if defined(FLIGHT_MODES) +void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att) +{ + if (idx==0) { + lcdDrawMMM(x, y, att); + return; + } + // TODO this code was not included in Taranis! and used with abs(...) on Horus + if (idx < 0) { + lcdDrawChar(x-2, y, '!', att); + idx = -idx; + } +#if defined(CONDENSED) + if (att & CONDENSED) { + lcdDrawNumber(x+FW*1, y, idx-1, (att & ~CONDENSED), 1); + return; + } +#endif + drawStringWithIndex(x, y, STR_FM, idx-1, att); +} +#endif + +/* + * Copyright (C) OpenTX + * + * Based on code named + * 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 "opentx.h" + void drawCurveRef(coord_t x, coord_t y, CurveRef & curve, LcdFlags att) { if (curve.value != 0) { @@ -133,7 +282,7 @@ void drawSourceCustomValue(coord_t x, coord_t y, source_t source, int32_t value, lcdDrawNumber(x, y, value, flags|PREC1); } #if defined(INTERNAL_GPS) - else if (source == MIXSRC_TX_GPS) { + else if (source == MIXSRC_TX_GPS) { if (gpsData.fix) { drawGPSPosition(x, y, gpsData.longitude, gpsData.latitude, flags); } @@ -144,7 +293,7 @@ void drawSourceCustomValue(coord_t x, coord_t y, source_t source, int32_t value, } #endif #if defined(GVARS) - else if (source >= MIXSRC_FIRST_GVAR && source <= MIXSRC_LAST_GVAR) { + else if (source >= MIXSRC_FIRST_GVAR && source <= MIXSRC_LAST_GVAR) { drawGVarValue(x, y, source - MIXSRC_FIRST_GVAR, value, flags); } #endif diff --git a/radio/src/gui/common/colorlcd/draw_functions.h b/radio/src/gui/common/colorlcd/draw_functions.h new file mode 100644 index 0000000000..a35699de03 --- /dev/null +++ b/radio/src/gui/common/colorlcd/draw_functions.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * 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. + */ + +#ifndef __COLORLCD_DRAW_FUNCTIONS__ +#define __COLORLCD_DRAW_FUNCTIONS__ + +#include "lcd.h" + +void drawStringWithIndex(coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix); +void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att); +int editChoice(coord_t x, coord_t y, const char * values, int value, int min, int max, LcdFlags attr, event_t event); +uint8_t editCheckBox(uint8_t value, coord_t x, coord_t y, LcdFlags attr, event_t event); +swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t event); +void drawFatalErrorScreen(const char * message); +void runFatalErrorScreen(const char * message); +void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att); +void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags); + +#if defined(FLIGHT_MODES) +void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att); +#endif + +#endif // __COLORLCD_DRAW_FUNCTIONS__ diff --git a/radio/src/gui/common/colorlcd/widgets.cpp b/radio/src/gui/common/colorlcd/widgets.cpp deleted file mode 100644 index 373f0dafbc..0000000000 --- a/radio/src/gui/common/colorlcd/widgets.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * 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 "opentx.h" - -void drawStringWithIndex(coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix) -{ - char s[64]; - char * tmp = (prefix ? strAppend(s, prefix) : s); - tmp = strAppend(tmp, str); - tmp = strAppendUnsigned(tmp, abs(idx)); - if (suffix) - strAppend(tmp, suffix); - lcdDrawText(x, y, s, flags); -} - -void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att) -{ - // convertUnit(val, unit); - if (!(att & NO_UNIT) && unit != UNIT_RAW) { - char unitStr[8]; - strAppend(unitStr, STR_VTELEMUNIT+1+unit*STR_VTELEMUNIT[0], STR_VTELEMUNIT[0]); - lcdDrawNumber(x, y, val, att, 0, NULL, unitStr); - } - else { - lcdDrawNumber(x, y, val, att); - } -} - -int editChoice(coord_t x, coord_t y, const char * values, int value, int min, int max, LcdFlags attr, event_t event) -{ - if (attr & INVERS) value = checkIncDec(event, value, min, max, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL); - if (values) lcdDrawTextAtIndex(x, y, values, value-min, attr); - return value; -} - -uint8_t editCheckBox(uint8_t value, coord_t x, coord_t y, LcdFlags attr, event_t event ) -{ - value = editChoice(x, y, NULL, value, 0, 1, attr, event); - drawCheckBox(x, y, value, attr); - return value; -} - -swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t event) -{ - if (attr & INVERS) CHECK_INCDEC_MODELSWITCH(event, value, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes); - drawSwitch(x, y, value, attr); - return value; -} - -void drawFatalErrorScreen(const char * message) -{ - lcdClear(); - lcdDrawText(LCD_W/2, LCD_H/2-20, message, DBLSIZE|CENTERED|TEXT_BGCOLOR); - lcdRefresh(); -} - -void runFatalErrorScreen(const char * message) -{ - while (1) { - drawFatalErrorScreen(message); - backlightEnable(100); - uint8_t refresh = false; - while (1) { - uint32_t pwr_check = pwrCheck(); - if (pwr_check == e_power_off) { - boardOff(); - return; // only happens in SIMU, required for proper shutdown - } - else if (pwr_check == e_power_press) { - refresh = true; - } - else if (pwr_check == e_power_on && refresh) { - break; - } - } - } -} - -void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att) -{ - float power_W_PREC1 = pow(10.0, (dBm - 30.0) / 10.0) * 10; - if (dBm >= 30) { - lcdDrawNumber(x, y, power_W_PREC1, PREC1 | att); - lcdDrawText(lcdNextPos, y, "W", att); - } - else if (dBm < 10) { - uint16_t power_MW_PREC1 = round(power_W_PREC1 * 1000); - lcdDrawNumber(x, y, power_MW_PREC1, PREC1 | att); - lcdDrawText(lcdNextPos, y, "mW", att); - } - else { - uint16_t power_MW = round(power_W_PREC1 * 100); - if (power_MW >= 50) { - power_MW = (power_MW / 5) * 5; - lcdDrawNumber(x, y, power_MW, att); - lcdDrawText(lcdNextPos, y, "mW", att); - } - else { - lcdDrawNumber(x, y, power_MW, att); - lcdDrawText(lcdNextPos, y, "mW", att); - } - } -} diff --git a/radio/src/gui/common/stdlcd/CMakeLists.txt b/radio/src/gui/common/stdlcd/CMakeLists.txt index 57aad2a203..2da32d37af 100644 --- a/radio/src/gui/common/stdlcd/CMakeLists.txt +++ b/radio/src/gui/common/stdlcd/CMakeLists.txt @@ -3,7 +3,7 @@ add_definitions(-DGRAPHICS) set(GUI_SRC ${GUI_SRC} ../common/stdlcd/menus.cpp - ../common/stdlcd/widgets.cpp + ../common/stdlcd/draw_functions.cpp ../common/stdlcd/popups.cpp ../common/stdlcd/model_inputs.cpp ../common/stdlcd/model_mixes.cpp diff --git a/radio/src/gui/common/stdlcd/widgets.cpp b/radio/src/gui/common/stdlcd/draw_functions.cpp similarity index 51% rename from radio/src/gui/common/stdlcd/widgets.cpp rename to radio/src/gui/common/stdlcd/draw_functions.cpp index e91943344a..06eb7137a6 100644 --- a/radio/src/gui/common/stdlcd/widgets.cpp +++ b/radio/src/gui/common/stdlcd/draw_functions.cpp @@ -33,6 +33,33 @@ void drawStringWithIndex(coord_t x, coord_t y, const char * str, uint8_t idx, Lc } } +void drawTrimMode(coord_t x, coord_t y, uint8_t flightMode, uint8_t idx, LcdFlags att) +{ + trim_t v = getRawTrimValue(flightMode, idx); + unsigned int mode = v.mode; + unsigned int p = mode >> 1; + + if (mode == TRIM_MODE_NONE) { + lcdDrawText(x, y, "--", att); + } + else { + if (mode % 2 == 0) + lcdDrawChar(x, y, ':', att|FIXEDWIDTH); + else + lcdDrawChar(x, y, '+', att|FIXEDWIDTH); + lcdDrawChar(lcdNextPos, y, '0'+p, att); + } +} + +void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att) +{ + // convertUnit(val, unit); + lcdDrawNumber(x, y, val, att & (~NO_UNIT)); + if (!(att & NO_UNIT) && unit != UNIT_RAW) { + lcdDrawTextAtIndex(lcdLastRightPos/*+1*/, y, STR_VTELEMUNIT, unit, 0); + } +} + FlightModesType editFlightModes(coord_t x, coord_t y, event_t event, FlightModesType value, uint8_t attr) { int posHorz = menuHorizontalPosition; @@ -233,3 +260,179 @@ void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverI lcdDrawText(x, y, "External", flags); } } + +void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags) +{ + lcdDrawTextAtIndex(x, y, STR_MMMINV, 0, flags); +} + +#if defined(FLIGHT_MODES) +void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att) +{ + if (idx==0) { + lcdDrawMMM(x, y, att); + return; + } + // TODO this code was not included in Taranis! and used with abs(...) on Horus + if (idx < 0) { + lcdDrawChar(x-2, y, '!', att); + idx = -idx; + } +#if defined(CONDENSED) + if (att & CONDENSED) { + lcdDrawNumber(x+FW*1, y, idx-1, (att & ~CONDENSED), 1); + return; + } +#endif + drawStringWithIndex(x, y, STR_FM, idx-1, att); +} +#endif + +void drawCurveRef(coord_t x, coord_t y, CurveRef & curve, LcdFlags att) +{ + if (curve.value != 0) { + switch (curve.type) { + case CURVE_REF_DIFF: + lcdDrawText(x, y, "D", att); + GVAR_MENU_ITEM(lcdNextPos, y, curve.value, -100, 100, LEFT|att, 0, 0); + break; + + case CURVE_REF_EXPO: + lcdDrawText(x, y, "E", att); + GVAR_MENU_ITEM(lcdNextPos, y, curve.value, -100, 100, LEFT|att, 0, 0); + break; + + case CURVE_REF_FUNC: + lcdDrawTextAtIndex(x, y, STR_VCURVEFUNC, curve.value, att); + break; + + case CURVE_REF_CUSTOM: + drawCurveName(x, y, curve.value, att); + break; + } + } +} + +void drawSensorCustomValue(coord_t x, coord_t y, uint8_t sensor, int32_t value, LcdFlags flags) +{ + if (sensor >= MAX_TELEMETRY_SENSORS) { + // Lua luaLcdDrawChannel() can call us with a bad value + return; + } + + TelemetryItem & telemetryItem = telemetryItems[sensor]; + TelemetrySensor & telemetrySensor = g_model.telemetrySensors[sensor]; + + if (telemetrySensor.unit == UNIT_DATETIME) { + drawDate(x, y, telemetryItem, flags); + } + else if (telemetrySensor.unit == UNIT_GPS) { + drawGPSSensorValue(x, y, telemetryItem, flags); + } + else if (telemetrySensor.unit == UNIT_BITFIELD) { + if (IS_FRSKY_SPORT_PROTOCOL()) { + if (telemetrySensor.id >= RBOX_STATE_FIRST_ID && telemetrySensor.id <= RBOX_STATE_LAST_ID) { + if (telemetrySensor.subId == 0) { + if (value == 0) { + lcdDrawText(x, y, "OK", flags); + } + else { + for (uint8_t i=0; i<16; i++) { + if (value & (1 << i)) { + char s[] = "CH__ KO"; + strAppendUnsigned(&s[2], i+1, 2); + lcdDrawText(x, flags & DBLSIZE ? y+1 : y, s, flags & ~DBLSIZE); + break; + } + } + } + } + else { + if (value == 0) { + lcdDrawText(x, flags & DBLSIZE ? y+1 : y, "Rx OK", flags & ~DBLSIZE); + } + else { + static const char * const RXS_STATUS[] = { + "Rx1 Ovl", + "Rx2 Ovl", + "SBUS Ovl", + "Rx1 FS", + "Rx1 LF", + "Rx2 FS", + "Rx2 LF", + "Rx1 Lost", + "Rx2 Lost", + "Rx1 NS", + "Rx2 NS", + }; + for (uint8_t i=0; i 0) { + flags |= (telemetrySensor.prec==1 ? PREC1 : PREC2); + } + drawValueWithUnit(x, y, value, telemetrySensor.unit == UNIT_CELLS ? UNIT_VOLTS : telemetrySensor.unit, flags); + } +} + +void drawSourceCustomValue(coord_t x, coord_t y, source_t source, int32_t value, LcdFlags flags) +{ + if (source >= MIXSRC_FIRST_TELEM) { + source = (source-MIXSRC_FIRST_TELEM) / 3; + drawSensorCustomValue(x, y, source, value, flags); + } + else if (source >= MIXSRC_FIRST_TIMER || source == MIXSRC_TX_TIME) { + if (value < 0) flags |= BLINK|INVERS; + drawTimer(x, y, value, flags); + } + else if (source == MIXSRC_TX_VOLTAGE) { + lcdDrawNumber(x, y, value, flags|PREC1); + } +#if defined(INTERNAL_GPS) + else if (source == MIXSRC_TX_GPS) { + if (gpsData.fix) { + drawGPSPosition(x, y, gpsData.longitude, gpsData.latitude, flags); + } + else { + lcdDrawText(x, y, "sats: ", flags); + lcdDrawNumber(lcdNextPos, y, gpsData.numSat, flags); + } + } +#endif +#if defined(GVARS) + else if (source >= MIXSRC_FIRST_GVAR && source <= MIXSRC_LAST_GVAR) { + drawGVarValue(x, y, source - MIXSRC_FIRST_GVAR, value, flags); + } +#endif + else if (source < MIXSRC_FIRST_CH) { + lcdDrawNumber(x, y, calcRESXto100(value), flags); + } + else if (source <= MIXSRC_LAST_CH) { +#if defined(PPM_UNIT_PERCENT_PREC1) + lcdDrawNumber(x, y, calcRESXto1000(value), flags|PREC1); +#else + lcdDrawNumber(x, y, calcRESXto100(value), flags); +#endif + } + else { + lcdDrawNumber(x, y, value, flags); + } +} + +void drawSourceValue(coord_t x, coord_t y, source_t source, LcdFlags flags) +{ + getvalue_t value = getValue(source); + drawSourceCustomValue(x, y, source, value, flags); +} diff --git a/radio/src/gui/common/stdlcd/draw_functions.h b/radio/src/gui/common/stdlcd/draw_functions.h index 03ad2aaae8..855b8600c2 100644 --- a/radio/src/gui/common/stdlcd/draw_functions.h +++ b/radio/src/gui/common/stdlcd/draw_functions.h @@ -18,12 +18,13 @@ * GNU General Public License for more details. */ -#ifndef _COMMON_DRAW_FUNCTIONS_H_ -#define _COMMON_DRAW_FUNCTIONS_H_ +#ifndef _STDLCD_DRAW_FUNCTIONS_H_ +#define _STDLCD_DRAW_FUNCTIONS_H_ #include "lcd.h" void drawStringWithIndex(coord_t x, coord_t y, const char * str, uint8_t idx, LcdFlags att=0); +void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att=0); void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att = 0); void drawGVarName(coord_t x, coord_t y, int8_t index, LcdFlags flags=0); @@ -40,4 +41,7 @@ void drawStartupAnimation(uint32_t duration, uint32_t totalDuration); void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message); void drawSleepBitmap(); -#endif // _COMMON_DRAW_FUNCTIONS_H_ +void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags=0); +void drawTrimMode(coord_t x, coord_t y, uint8_t flightMode, uint8_t idx, LcdFlags att=0); + +#endif // _STDLCD_DRAW_FUNCTIONS_H_ diff --git a/radio/src/gui/common/widgets.cpp b/radio/src/gui/common/widgets.cpp deleted file mode 100644 index f913840e5e..0000000000 --- a/radio/src/gui/common/widgets.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * 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 "opentx.h" - -void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags) -{ - lcdDrawTextAtIndex(x, y, STR_MMMINV, 0, flags); -} - -#if defined(FLIGHT_MODES) -void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att) -{ - if (idx==0) { - lcdDrawMMM(x, y, att); - return; - } - // TODO this code was not included in Taranis! and used with abs(...) on Horus - if (idx < 0) { - lcdDrawChar(x-2, y, '!', att); - idx = -idx; - } -#if defined(CONDENSED) - if (att & CONDENSED) { - lcdDrawNumber(x+FW*1, y, idx-1, (att & ~CONDENSED), 1); - return; - } -#endif - drawStringWithIndex(x, y, STR_FM, idx-1, att); -} -#endif diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 7a0388eb27..c3ec84d099 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -72,7 +72,6 @@ bool isRssiSensorAvailable(int sensor) } } - bool isSensorAvailable(int sensor) { if (sensor == 0) diff --git a/radio/src/gui/gui_common.h b/radio/src/gui/gui_common.h index 3b63077da9..206508a969 100644 --- a/radio/src/gui/gui_common.h +++ b/radio/src/gui/gui_common.h @@ -95,7 +95,6 @@ void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att=0); swsrc_t checkIncDecMovedSwitch(swsrc_t val); -void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags flags); void drawCurveRef(coord_t x, coord_t y, CurveRef & curve, LcdFlags flags=0); void drawDate(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags=0); void drawTelemScreenDate(coord_t x, coord_t y, source_t sensor, LcdFlags flags=0); @@ -116,8 +115,6 @@ void drawFatalErrorScreen(const char * message); void runFatalErrorScreen(const char * message); #endif -void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags=0); - // model_setup Defines that are used in all uis in the same way #define INTERNAL_MODULE_CHANNELS_ROWS IF_INTERNAL_MODULE_ON((uint8_t)1) #define EXTERNAL_MODULE_CHANNELS_ROWS IF_EXTERNAL_MODULE_ON((isModuleDSM2(EXTERNAL_MODULE) || isModuleCrossfire(EXTERNAL_MODULE) || isModuleSBUS(EXTERNAL_MODULE) || (isModuleMultimodule(EXTERNAL_MODULE) && g_model.moduleData[EXTERNAL_MODULE].getMultiProtocol(true) != MODULE_SUBTYPE_MULTI_DSM2)) ? (uint8_t)0 : (uint8_t)1)