1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00

lcd.drawChannel(...) added. Possibility to write telemetry values using

different sizes
This commit is contained in:
bsongis 2014-07-01 17:36:28 +02:00
parent 4088abaafb
commit 1d1a815ef7
4 changed files with 56 additions and 16 deletions

View file

@ -1247,7 +1247,7 @@ void putsRotaryEncoderMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, Lc
#endif #endif
#if defined(FRSKY) || defined(CPUARM) #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); convertUnit(val, unit);
lcd_outdezAtt(x, y, val, att & (~NO_UNIT)); lcd_outdezAtt(x, y, val, att & (~NO_UNIT));
@ -1267,7 +1267,7 @@ const pm_uint8_t bchunit_ar[] PROGMEM = {
UNIT_DIST, // GPS Alt 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) { switch (channel) {
#if defined(CPUARM) && defined(RTCLOCK) #if defined(CPUARM) && defined(RTCLOCK)

View file

@ -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 putsVolts(xcoord_t x, uint8_t y, uint16_t volts, LcdFlags att);
void putsVBat(xcoord_t x, uint8_t y, 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) #if defined(CPUARM)
#define putstime_t int32_t #define putstime_t int32_t

View file

@ -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) static int luaGetValue(lua_State *L)
{ {
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
@ -155,19 +170,19 @@ static int luaGetValue(lua_State *L)
} }
else { else {
const char *what = luaL_checkstring(L, 1); const char *what = luaL_checkstring(L, 1);
if (!strcmp(what, "altitude-max")) { for (const LuaField * field = &luaFields[0]; field->name; field++) {
lua_pushnumber(L, frskyData.hub.maxAltitude); if (!strcmp(what, field->name)) {
return 1; 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")) { if (frskyData.hub.gpsFix) {
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 (!strcmp(what, "latitude")) { if (!strcmp(what, "latitude")) {
lua_pushnumber(L, gpsToDouble(frskyData.hub.gpsLatitudeNS=='S', frskyData.hub.gpsLatitude_bp, frskyData.hub.gpsLatitude_ap)); lua_pushnumber(L, gpsToDouble(frskyData.hub.gpsLatitudeNS=='S', frskyData.hub.gpsLatitude_bp, frskyData.hub.gpsLatitude_ap));
return 1; return 1;
@ -274,6 +289,29 @@ static int luaLcdDrawNumber(lua_State *L)
return 0; 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) static int luaLcdDrawSwitch(lua_State *L)
{ {
int x = luaL_checkinteger(L, 1); int x = luaL_checkinteger(L, 1);
@ -1101,6 +1139,7 @@ static const luaL_Reg lcdLib[] = {
{ "drawText", luaLcdDrawText }, { "drawText", luaLcdDrawText },
{ "drawTimer", luaLcdDrawTimer }, { "drawTimer", luaLcdDrawTimer },
{ "drawNumber", luaLcdDrawNumber }, { "drawNumber", luaLcdDrawNumber },
{ "drawChannel", luaLcdDrawChannel },
{ "drawSwitch", luaLcdDrawSwitch }, { "drawSwitch", luaLcdDrawSwitch },
{ "drawSource", luaLcdDrawSource }, { "drawSource", luaLcdDrawSource },
{ "drawPixmap", luaLcdDrawPixmap }, { "drawPixmap", luaLcdDrawPixmap },
@ -1142,6 +1181,7 @@ void luaInit()
lua_registerint(L, "MIDSIZE", MIDSIZE); lua_registerint(L, "MIDSIZE", MIDSIZE);
lua_registerint(L, "SMLSIZE", SMLSIZE); lua_registerint(L, "SMLSIZE", SMLSIZE);
lua_registerint(L, "INVERS", INVERS); lua_registerint(L, "INVERS", INVERS);
lua_registerint(L, "LEFT", LEFT);
lua_registerint(L, "PREC1", PREC1); lua_registerint(L, "PREC1", PREC1);
lua_registerint(L, "PREC2", PREC2); lua_registerint(L, "PREC2", PREC2);
lua_registerint(L, "BLINK", BLINK); lua_registerint(L, "BLINK", BLINK);

View file

@ -1555,7 +1555,7 @@ void checkFlashOnBeep();
#if defined(FRSKY) || defined(CPUARM) #if defined(FRSKY) || defined(CPUARM)
void convertUnit(getvalue_t & val, uint8_t & unit); // TODO check FORCEINLINE on stock 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 #else
#define convertUnit(...) #define convertUnit(...)
#endif #endif