Bsongis/refactoring before x10 ui merge (#6678)

UI functions refactoring
This commit is contained in:
Bertrand Songis
2019-08-28 17:31:26 +02:00
committed by GitHub
parent ebb1cb7cb3
commit f6646b0190
20 changed files with 409 additions and 256 deletions
+1 -1
View File
@@ -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
@@ -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<DIM(RXS_STATUS); i++) {
if (value & (1<<i)) {
lcdDrawText(x, flags & DBLSIZE ? y+1 : y, RXS_STATUS[i], flags & ~DBLSIZE);
break;
}
}
}
}
}
}
}
else if (telemetrySensor.unit == UNIT_TEXT) {
lcdDrawSizedText(x, flags & DBLSIZE ? y+1 : y, telemetryItem.text, sizeof(telemetryItem.text), flags & ~DBLSIZE);
}
else {
if (telemetrySensor.prec > 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);
}
+7 -3
View File
@@ -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_