mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 22:35:12 +03:00
Telemetry refactoring - Fixes #1634
This commit is contained in:
parent
7d8ca6931b
commit
88d9691d16
105 changed files with 5789 additions and 3449 deletions
|
@ -310,6 +310,19 @@ void lcd_putsiAtt(coord_t x, coord_t y, const pm_char * s,uint8_t idx, LcdFlags
|
|||
lcd_putsnAtt(x, y, s+length*idx, length, flags & ~(BSS|ZCHAR));
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
void lcd_outhex4(coord_t x, coord_t y, uint32_t val, LcdFlags flags)
|
||||
{
|
||||
x += FWNUM*4+1;
|
||||
for (int i=0; i<4; i++) {
|
||||
x -= FWNUM;
|
||||
char c = val & 0xf;
|
||||
c = c>9 ? c+'A'-10 : c+'0';
|
||||
lcd_putcAtt(x, y, c, flags|(c>='A' ? CONDENSED : 0));
|
||||
val >>= 4;
|
||||
}
|
||||
}
|
||||
#else
|
||||
void lcd_outhex4(coord_t x, coord_t y, uint16_t val)
|
||||
{
|
||||
x += FWNUM*4+1;
|
||||
|
@ -321,6 +334,7 @@ void lcd_outhex4(coord_t x, coord_t y, uint16_t val)
|
|||
val >>= 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void lcd_outdez8(coord_t x, coord_t y, int8_t val)
|
||||
{
|
||||
|
@ -497,7 +511,7 @@ void lcd_hline(coord_t x, coord_t y, coord_t w, LcdFlags att)
|
|||
lcd_hlineStip(x, y, w, 0xff, att);
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
#if defined(CPUARM) && !defined(BOOT)
|
||||
void lcd_line(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att)
|
||||
{
|
||||
int dx = x2-x1; /* the horizontal distance of the line */
|
||||
|
@ -582,12 +596,12 @@ void lcdDrawTelemetryTopBar()
|
|||
if (g_model.timers[0].mode) {
|
||||
att = (timersStates[0].val<0 ? BLINK : 0);
|
||||
putsTimer(22*FW+5*FWNUM+3, 0, timersStates[0].val, att, att);
|
||||
lcd_putsiAtt(18*FW+2, 1, STR_VTELEMCHNS, TELEM_TIMER1, SMLSIZE);
|
||||
putsMixerSource(18*FW+2, 1, MIXSRC_TIMER1, SMLSIZE);
|
||||
}
|
||||
if (g_model.timers[1].mode) {
|
||||
att = (timersStates[1].val<0 ? BLINK : 0);
|
||||
putsTimer(31*FW+5*FWNUM+3, 0, timersStates[1].val, att, att);
|
||||
lcd_putsiAtt(27*FW+2, 1, STR_VTELEMCHNS, TELEM_TIMER2, SMLSIZE);
|
||||
putsMixerSource(27*FW+2, 1, MIXSRC_TIMER2, SMLSIZE);
|
||||
}
|
||||
lcd_invert_line(0);
|
||||
}
|
||||
|
@ -608,7 +622,7 @@ void lcdDrawTelemetryTopBar()
|
|||
#if defined(CPUARM) && defined(RTCLOCK)
|
||||
void putsRtcTime(coord_t x, coord_t y, LcdFlags att)
|
||||
{
|
||||
putsTimer(x, y, getValue(MIXSRC_FIRST_TELEM-1+TELEM_TX_TIME), att, att);
|
||||
putsTimer(x, y, getValue(MIXSRC_TX_TIME), att, att);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -663,7 +677,7 @@ void putsTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att, LcdFlags att2
|
|||
lcd_outdezNAtt(lcdNextPos, y, qr.rem, att2|LEADING0|LEFT, 2);
|
||||
}
|
||||
|
||||
// TODO to be optimized with putsTelemetryValue
|
||||
// TODO to be optimized with putsValueWithUnit
|
||||
void putsVolts(coord_t x, coord_t y, uint16_t volts, LcdFlags att)
|
||||
{
|
||||
lcd_outdezAtt(x, y, (int16_t)volts, (~NO_UNIT) & (att | ((att&PREC2)==PREC2 ? 0 : PREC1)));
|
||||
|
@ -685,13 +699,13 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
|||
{
|
||||
#if defined(PCBTARANIS)
|
||||
if (idx == 0) {
|
||||
lcd_putsiAtt(x, y, STR_VSRCRAW, 0, att);
|
||||
lcd_putsiAtt(x, y, STR_VSRCRAW, 0, att); // TODO macro
|
||||
}
|
||||
else if (idx <= MIXSRC_LAST_INPUT) {
|
||||
lcd_putcAtt(x+2, y+1, CHR_INPUT, TINSIZE);
|
||||
lcd_filled_rect(x, y, 7, 7);
|
||||
if (ZEXIST(g_model.inputNames[idx-MIXSRC_FIRST_INPUT]))
|
||||
lcd_putsnAtt(x+8, y, g_model.inputNames[idx-MIXSRC_FIRST_INPUT], 4, ZCHAR|att);
|
||||
lcd_putsnAtt(x+8, y, g_model.inputNames[idx-MIXSRC_FIRST_INPUT], LEN_INPUT_NAME, ZCHAR|att);
|
||||
else
|
||||
lcd_outdezNAtt(x+8, y, idx, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
|
@ -723,7 +737,6 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
|||
lcd_putsiAtt(x, y, STR_VSRCRAW, idx, att);
|
||||
else if (idx < MIXSRC_SW1)
|
||||
putsSwitches(x, y, idx-MIXSRC_THR+1+3*(1/*+EXTRA_3POS*/), att);
|
||||
// TODO would perhaps save flash if those switches were in VSRCRAW
|
||||
#endif
|
||||
else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH)
|
||||
putsSwitches(x, y, SWSRC_SW1+idx-MIXSRC_SW1, att);
|
||||
|
@ -742,8 +755,26 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
|||
else if (idx <= MIXSRC_LAST_GVAR)
|
||||
putsStrIdx(x, y, STR_GV, idx-MIXSRC_GVAR1+1, att);
|
||||
#endif
|
||||
|
||||
else if (idx < MIXSRC_FIRST_TELEM) {
|
||||
#if defined(PCBTARANIS)
|
||||
lcd_putsiAtt(x, y, STR_VSRCRAW, idx-MIXSRC_Rud+1-NUM_LOGICAL_SWITCH-NUM_TRAINER-NUM_CHNOUT-MAX_GVARS, att);
|
||||
#else
|
||||
lcd_putsiAtt(x, y, STR_VSRCRAW, idx-MIXSRC_Rud+1-(MIXSRC_SW1-MIXSRC_THR)-NUM_LOGICAL_SWITCH-NUM_TRAINER-NUM_CHNOUT-MAX_GVARS, att);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CPUARM)
|
||||
else {
|
||||
idx -= MIXSRC_FIRST_TELEM;
|
||||
div_t qr = div(idx, 3);
|
||||
lcd_putsnAtt(x, y, g_model.telemetrySensors[qr.quot].label, ZLEN(g_model.telemetrySensors[qr.quot].label), ZCHAR|att);
|
||||
if (qr.rem) lcd_putcAtt(lcdLastPos, y, qr.rem==2 ? '+' : '-', att);
|
||||
}
|
||||
#else
|
||||
else
|
||||
lcd_putsiAtt(x, y, STR_VTELEMCHNS, idx-MIXSRC_FIRST_TELEM+1, att);
|
||||
#endif
|
||||
}
|
||||
|
||||
void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
||||
|
@ -905,8 +936,142 @@ void putsRotaryEncoderMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, Lcd
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(FRSKY) || defined(CPUARM)
|
||||
void putsTelemetryValue(coord_t x, coord_t y, lcdint_t val, uint8_t unit, LcdFlags att)
|
||||
#if defined(CPUARM)
|
||||
const pm_uint8_t bchunit_ar[] PROGMEM = {
|
||||
UNIT_DIST, // Alt
|
||||
UNIT_RAW, // Rpm
|
||||
UNIT_PERCENT, // Fuel
|
||||
UNIT_TEMPERATURE, // T1
|
||||
UNIT_TEMPERATURE, // T2
|
||||
UNIT_KTS, // Speed
|
||||
UNIT_DIST, // Dist
|
||||
UNIT_DIST, // GPS Alt
|
||||
};
|
||||
|
||||
void putsValueWithUnit(coord_t x, coord_t y, lcdint_t val, uint8_t unit, LcdFlags att)
|
||||
{
|
||||
// convertUnit(val, unit);
|
||||
lcd_outdezAtt(x, y, val, att & (~NO_UNIT));
|
||||
if (!(att & NO_UNIT) && unit != UNIT_RAW) {
|
||||
lcd_putsiAtt(lcdLastPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void displayGpsCoord(coord_t x, coord_t y, char direction, int16_t bp, int16_t ap, LcdFlags att, bool seconds=true)
|
||||
{
|
||||
if (!direction) direction = '-';
|
||||
lcd_outdezAtt(x, y, bp / 100, att); // ddd before '.'
|
||||
lcd_putcAtt(lcdLastPos, y, '@', att);
|
||||
uint8_t mn = bp % 100; // TODO div_t
|
||||
if (g_eeGeneral.gpsFormat == 0) {
|
||||
lcd_outdezNAtt(lcdNextPos, y, mn, att|LEFT|LEADING0, 2); // mm before '.'
|
||||
lcd_vline(lcdLastPos, y, 2);
|
||||
if (seconds) {
|
||||
uint16_t ss = ap * 6 / 10;
|
||||
lcd_outdezNAtt(lcdLastPos+3, y, ss / 100, att|LEFT|LEADING0, 2); // ''
|
||||
lcd_plot(lcdLastPos, y+FH-2, 0); // small decimal point
|
||||
lcd_outdezNAtt(lcdLastPos+2, y, ss % 100, att|LEFT|LEADING0, 2); // ''
|
||||
lcd_vline(lcdLastPos, y, 2);
|
||||
lcd_vline(lcdLastPos+2, y, 2);
|
||||
}
|
||||
lcd_putc(lcdLastPos+2, y, direction);
|
||||
}
|
||||
else {
|
||||
lcd_outdezNAtt(lcdLastPos+FW, y, mn, att|LEFT|LEADING0, 2); // mm before '.'
|
||||
lcd_plot(lcdLastPos, y+FH-2, 0); // small decimal point
|
||||
lcd_outdezNAtt(lcdLastPos+2, y, ap, att|LEFT|UNSIGN|LEADING0, 4); // after '.'
|
||||
lcd_putc(lcdLastPos+1, y, direction);
|
||||
}
|
||||
}
|
||||
|
||||
void displayDate(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags att)
|
||||
{
|
||||
if (att & DBLSIZE) {
|
||||
x -= 42;
|
||||
att &= ~0x0F00; // TODO constant
|
||||
lcd_outdezNAtt(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos-1, y, '-', att);
|
||||
lcd_outdezNAtt(lcdNextPos-1, y, telemetryItem.datetime.month, att|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos-1, y, '-', att);
|
||||
lcd_outdezAtt(lcdNextPos-1, y, telemetryItem.datetime.year, att|LEFT);
|
||||
y += FH;
|
||||
lcd_outdezNAtt(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos, y, ':', att);
|
||||
lcd_outdezNAtt(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos, y, ':', att);
|
||||
lcd_outdezNAtt(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
else {
|
||||
lcd_outdezNAtt(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos, y, ':', att);
|
||||
lcd_outdezNAtt(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcd_putcAtt(lcdLastPos, y, ':', att);
|
||||
lcd_outdezNAtt(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void displayGpsCoords(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags att)
|
||||
{
|
||||
if (att & DBLSIZE) {
|
||||
x -= (g_eeGeneral.gpsFormat == 0 ? 54 : 51);
|
||||
att &= ~0x0F00; // TODO constant
|
||||
displayGpsCoord(x, y, telemetryItem.gps.longitudeEW, telemetryItem.gps.longitude_bp, telemetryItem.gps.longitude_ap, att);
|
||||
displayGpsCoord(x, y+FH, telemetryItem.gps.latitudeNS, telemetryItem.gps.latitude_bp, telemetryItem.gps.latitude_ap, att);
|
||||
}
|
||||
else {
|
||||
displayGpsCoord(x, y, telemetryItem.gps.longitudeEW, telemetryItem.gps.longitude_bp, telemetryItem.gps.longitude_ap, att, false);
|
||||
displayGpsCoord(lcdNextPos+FWNUM, y, telemetryItem.gps.latitudeNS, telemetryItem.gps.latitude_bp, telemetryItem.gps.latitude_ap, att, false);
|
||||
}
|
||||
}
|
||||
|
||||
void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t value, LcdFlags att)
|
||||
{
|
||||
TelemetryItem & telemetryItem = telemetryItems[channel];
|
||||
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[channel];
|
||||
if (telemetrySensor.unit == UNIT_DATETIME) {
|
||||
displayDate(x, y, telemetryItem, att);
|
||||
}
|
||||
else if (telemetrySensor.unit == UNIT_GPS) {
|
||||
displayGpsCoords(x, y, telemetryItem, att);
|
||||
}
|
||||
else {
|
||||
LcdFlags flags = att;
|
||||
if (telemetrySensor.prec==2)
|
||||
flags |= PREC2;
|
||||
else if (telemetrySensor.prec==1)
|
||||
flags |= PREC1;
|
||||
putsValueWithUnit(x, y, value, telemetrySensor.unit == UNIT_CELLS ? UNIT_VOLTS : telemetrySensor.unit, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void putsChannelValue(coord_t x, coord_t y, source_t channel, lcdint_t value, LcdFlags att)
|
||||
{
|
||||
if (channel >= MIXSRC_FIRST_TELEM) {
|
||||
channel = (channel-MIXSRC_FIRST_TELEM) / 3;
|
||||
putsTelemetryChannelValue(x, y, channel, value, att);
|
||||
}
|
||||
else if (channel >= MIXSRC_FIRST_TIMER || channel == MIXSRC_TX_TIME) {
|
||||
putsTimer(x, y, value, att, att);
|
||||
}
|
||||
else if (channel == MIXSRC_TX_VOLTAGE) {
|
||||
lcd_outdezAtt(x, y, value, att|PREC1);
|
||||
}
|
||||
else {
|
||||
if (channel <= MIXSRC_LAST_CH) {
|
||||
value = calcRESXto100(value);
|
||||
}
|
||||
lcd_outdezAtt(x, y, value, att);
|
||||
}
|
||||
}
|
||||
|
||||
void putsChannel(coord_t x, coord_t y, source_t channel, LcdFlags att)
|
||||
{
|
||||
getvalue_t value = getValue(channel);
|
||||
putsChannelValue(x, y, channel, value, att);
|
||||
}
|
||||
|
||||
#elif defined(FRSKY)
|
||||
void putsValueWithUnit(coord_t x, coord_t y, lcdint_t val, uint8_t unit, LcdFlags att)
|
||||
{
|
||||
convertUnit(val, unit);
|
||||
lcd_outdezAtt(x, y, val, att & (~NO_UNIT));
|
||||
|
@ -926,7 +1091,7 @@ const pm_uint8_t bchunit_ar[] PROGMEM = {
|
|||
UNIT_DIST, // GPS Alt
|
||||
};
|
||||
|
||||
void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, LcdFlags att)
|
||||
void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t val, LcdFlags att)
|
||||
{
|
||||
switch (channel) {
|
||||
#if defined(CPUARM) && defined(RTCLOCK)
|
||||
|
@ -941,7 +1106,7 @@ void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, L
|
|||
#if defined(CPUARM)
|
||||
case TELEM_TIMER3-1:
|
||||
#endif
|
||||
att &= ~NO_UNIT;
|
||||
att &= ~NO_UNIT;
|
||||
putsTimer(x, y, val, att, att);
|
||||
break;
|
||||
#if defined(FRSKY)
|
||||
|
@ -979,14 +1144,14 @@ void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, L
|
|||
}
|
||||
#endif
|
||||
}
|
||||
putsTelemetryValue(x, y, converted_value, g_model.frsky.channels[channel].type, att);
|
||||
putsValueWithUnit(x, y, converted_value, g_model.frsky.channels[channel].type, att);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case TELEM_CELL-1:
|
||||
case TELEM_MIN_CELL-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_VOLTS, att|PREC2);
|
||||
putsValueWithUnit(x, y, val, UNIT_VOLTS, att|PREC2);
|
||||
break;
|
||||
|
||||
case TELEM_TX_VOLTAGE-1:
|
||||
|
@ -994,36 +1159,36 @@ void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, L
|
|||
case TELEM_CELLS_SUM-1:
|
||||
case TELEM_MIN_CELLS_SUM-1:
|
||||
case TELEM_MIN_VFAS-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_VOLTS, att|PREC1);
|
||||
putsValueWithUnit(x, y, val, UNIT_VOLTS, att|PREC1);
|
||||
break;
|
||||
|
||||
case TELEM_CURRENT-1:
|
||||
case TELEM_MAX_CURRENT-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_AMPS, att|PREC1);
|
||||
putsValueWithUnit(x, y, val, UNIT_AMPS, att|PREC1);
|
||||
break;
|
||||
|
||||
case TELEM_CONSUMPTION-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_MAH, att);
|
||||
putsValueWithUnit(x, y, val, UNIT_MAH, att);
|
||||
break;
|
||||
|
||||
case TELEM_POWER-1:
|
||||
case TELEM_MAX_POWER-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_WATTS, att);
|
||||
putsValueWithUnit(x, y, val, UNIT_WATTS, att);
|
||||
break;
|
||||
|
||||
case TELEM_ACCx-1:
|
||||
case TELEM_ACCy-1:
|
||||
case TELEM_ACCz-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_RAW, att|PREC2);
|
||||
putsValueWithUnit(x, y, val, UNIT_RAW, att|PREC2);
|
||||
break;
|
||||
|
||||
case TELEM_VSPEED-1:
|
||||
putsTelemetryValue(x, y, div10_and_round(val), UNIT_RAW, att|PREC1);
|
||||
putsValueWithUnit(x, y, div10_and_round(val), UNIT_RAW, att|PREC1);
|
||||
break;
|
||||
|
||||
case TELEM_ASPEED-1:
|
||||
case TELEM_MAX_ASPEED-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_KTS, att|PREC1);
|
||||
putsValueWithUnit(x, y, val, UNIT_KTS, att|PREC1);
|
||||
break;
|
||||
|
||||
#if defined(CPUARM)
|
||||
|
@ -1031,23 +1196,23 @@ void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, L
|
|||
#endif
|
||||
case TELEM_RSSI_TX-1:
|
||||
case TELEM_RSSI_RX-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_RAW, att);
|
||||
putsValueWithUnit(x, y, val, UNIT_RAW, att);
|
||||
break;
|
||||
|
||||
case TELEM_HDG-1:
|
||||
putsTelemetryValue(x, y, val, UNIT_HDG, att);
|
||||
putsValueWithUnit(x, y, val, UNIT_HDG, att);
|
||||
break;
|
||||
|
||||
#if defined(FRSKY_SPORT)
|
||||
case TELEM_ALT-1:
|
||||
putsTelemetryValue(x, y, div10_and_round(val), UNIT_DIST, att|PREC1);
|
||||
putsValueWithUnit(x, y, div10_and_round(val), UNIT_DIST, att|PREC1);
|
||||
break;
|
||||
#elif defined(WS_HOW_HIGH)
|
||||
case TELEM_ALT-1:
|
||||
case TELEM_MIN_ALT-1:
|
||||
case TELEM_MAX_ALT-1:
|
||||
if (IS_IMPERIAL_ENABLE() && IS_USR_PROTO_WS_HOW_HIGH()) {
|
||||
putsTelemetryValue(x, y, val, UNIT_FEET, att);
|
||||
putsValueWithUnit(x, y, val, UNIT_FEET, att);
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
@ -1062,13 +1227,13 @@ void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, L
|
|||
unit = channel + 1 - TELEM_ALT;
|
||||
if (channel >= TELEM_MIN_ALT-1 && channel <= TELEM_MAX_ALT-1)
|
||||
unit = 0;
|
||||
putsTelemetryValue(x, y, val, pgm_read_byte(bchunit_ar+unit), att);
|
||||
putsValueWithUnit(x, y, val, pgm_read_byte(bchunit_ar+unit), att);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else // defined(FRSKY)
|
||||
void putsTelemetryChannel(coord_t x, coord_t y, uint8_t channel, lcdint_t val, uint8_t att)
|
||||
void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t val, uint8_t att)
|
||||
{
|
||||
switch (channel) {
|
||||
case TELEM_TIMER1-1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue