From 1d1a815ef798142a4a4b7d5522d963c8b1b030b5 Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 1 Jul 2014 17:36:28 +0200 Subject: [PATCH] lcd.drawChannel(...) added. Possibility to write telemetry values using different sizes --- radio/src/lcd.cpp | 4 +-- radio/src/lcd.h | 2 +- radio/src/lua.cpp | 64 +++++++++++++++++++++++++++++++++++++--------- radio/src/opentx.h | 2 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/radio/src/lcd.cpp b/radio/src/lcd.cpp index 6be30dfd2..4c3b358d1 100644 --- a/radio/src/lcd.cpp +++ b/radio/src/lcd.cpp @@ -1247,7 +1247,7 @@ void putsRotaryEncoderMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, Lc #endif #if defined(FRSKY) || defined(CPUARM) -void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, uint8_t att) +void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, LcdFlags att) { convertUnit(val, unit); lcd_outdezAtt(x, y, val, att & (~NO_UNIT)); @@ -1267,7 +1267,7 @@ const pm_uint8_t bchunit_ar[] PROGMEM = { UNIT_DIST, // GPS Alt }; -void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, uint8_t att) +void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, LcdFlags att) { switch (channel) { #if defined(CPUARM) && defined(RTCLOCK) diff --git a/radio/src/lcd.h b/radio/src/lcd.h index 021fcdae2..63f57aedc 100644 --- a/radio/src/lcd.h +++ b/radio/src/lcd.h @@ -202,7 +202,7 @@ void putsChnLetter(xcoord_t x, uint8_t y, uint8_t idx, LcdFlags attr); void putsVolts(xcoord_t x, uint8_t y, uint16_t volts, LcdFlags att); void putsVBat(xcoord_t x, uint8_t y, LcdFlags att); -void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, uint8_t att=0); +void putsTelemetryChannel(xcoord_t x, uint8_t y, uint8_t channel, lcdint_t val, LcdFlags att=0); #if defined(CPUARM) #define putstime_t int32_t diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index ff6a297bc..964e634f0 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -146,6 +146,21 @@ static void luaGetValueAndPush(int src) } } +struct LuaField { + const char * name; + const uint8_t id; + const uint8_t attr; +}; + +const LuaField luaFields[] = { + { "altitude-max", MIXSRC_FIRST_TELEM+TELEM_MAX_ALT-1, 0 }, + { "altitude", MIXSRC_FIRST_TELEM+TELEM_ALT-1, PREC2 }, + { "vario", MIXSRC_FIRST_TELEM+TELEM_VSPEED-1, PREC2 }, + { "tx-voltage", MIXSRC_FIRST_TELEM+TELEM_TX_VOLTAGE-1, PREC1 }, + { "rpm", MIXSRC_FIRST_TELEM+TELEM_RPM-1, 0 }, + { NULL, 0, 0 }, +}; + static int luaGetValue(lua_State *L) { if (lua_isnumber(L, 1)) { @@ -155,19 +170,19 @@ static int luaGetValue(lua_State *L) } else { const char *what = luaL_checkstring(L, 1); - if (!strcmp(what, "altitude-max")) { - lua_pushnumber(L, frskyData.hub.maxAltitude); - return 1; + for (const LuaField * field = &luaFields[0]; field->name; field++) { + if (!strcmp(what, field->name)) { + getvalue_t value = getValue(field->id); + if (field->attr == PREC1) + lua_pushnumber(L, double(value)/10); + else if (field->attr == PREC2) + lua_pushnumber(L, double(value)/100); + else + lua_pushnumber(L, value); + return 1; + } } - else if (!strcmp(what, "altitude")) { - lua_pushnumber(L, double(frskyData.hub.baroAltitude)/100); - return 1; - } - else if (!strcmp(what, "vario")) { - lua_pushnumber(L, double(frskyData.hub.varioSpeed)/100); - return 1; - } - else if (frskyData.hub.gpsFix) { + if (frskyData.hub.gpsFix) { if (!strcmp(what, "latitude")) { lua_pushnumber(L, gpsToDouble(frskyData.hub.gpsLatitudeNS=='S', frskyData.hub.gpsLatitude_bp, frskyData.hub.gpsLatitude_ap)); return 1; @@ -274,6 +289,29 @@ static int luaLcdDrawNumber(lua_State *L) return 0; } +static int luaLcdDrawChannel(lua_State *L) +{ + int x = luaL_checkinteger(L, 1); + int y = luaL_checkinteger(L, 2); + int channel = -1; + if (lua_isnumber(L, 3)) { + channel = luaL_checkinteger(L, 3); + } + else { + const char *what = luaL_checkstring(L, 3); + for (const LuaField * field = &luaFields[0]; field->name; field++) { + if (!strcmp(what, field->name)) { + channel = field->id; + break; + } + } + } + int att = luaL_checkinteger(L, 4); + getvalue_t value = getValue(channel); + putsTelemetryChannel(x, y, channel-MIXSRC_FIRST_TELEM, value, att); + return 0; +} + static int luaLcdDrawSwitch(lua_State *L) { int x = luaL_checkinteger(L, 1); @@ -1101,6 +1139,7 @@ static const luaL_Reg lcdLib[] = { { "drawText", luaLcdDrawText }, { "drawTimer", luaLcdDrawTimer }, { "drawNumber", luaLcdDrawNumber }, + { "drawChannel", luaLcdDrawChannel }, { "drawSwitch", luaLcdDrawSwitch }, { "drawSource", luaLcdDrawSource }, { "drawPixmap", luaLcdDrawPixmap }, @@ -1142,6 +1181,7 @@ void luaInit() lua_registerint(L, "MIDSIZE", MIDSIZE); lua_registerint(L, "SMLSIZE", SMLSIZE); lua_registerint(L, "INVERS", INVERS); + lua_registerint(L, "LEFT", LEFT); lua_registerint(L, "PREC1", PREC1); lua_registerint(L, "PREC2", PREC2); lua_registerint(L, "BLINK", BLINK); diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 3f34305be..af9367a10 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1555,7 +1555,7 @@ void checkFlashOnBeep(); #if defined(FRSKY) || defined(CPUARM) void convertUnit(getvalue_t & val, uint8_t & unit); // TODO check FORCEINLINE on stock -void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, uint8_t att); +void putsTelemetryValue(xcoord_t x, uint8_t y, lcdint_t val, uint8_t unit, LcdFlags att); #else #define convertUnit(...) #endif