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

Re #2671: fixes difference between top and main LCD TX battery bars, code made more readable with macros

This commit is contained in:
Damjan Adamic 2015-08-12 21:01:37 +02:00 committed by Bertrand Songis
parent 00a5437dde
commit 5b4f0a0bbb
9 changed files with 29 additions and 23 deletions

View file

@ -8,6 +8,7 @@
<li>Timers range extended (it was limited to around 9 hours before) (<a href=https://github.com/opentx/opentx/issues/2702>#2702</a>)</li> <li>Timers range extended (it was limited to around 9 hours before) (<a href=https://github.com/opentx/opentx/issues/2702>#2702</a>)</li>
<li>Fixed: Playing two background sounds at once causes sound to stop (<a href=https://github.com/opentx/opentx/issues/2704>#2704</a>)</li> <li>Fixed: Playing two background sounds at once causes sound to stop (<a href=https://github.com/opentx/opentx/issues/2704>#2704</a>)</li>
<li>Several fixes to the SD card manager menu (<a href=https://github.com/opentx/opentx/issues/2623>#2623</a>)</li> <li>Several fixes to the SD card manager menu (<a href=https://github.com/opentx/opentx/issues/2623>#2623</a>)</li>
<li>Fixed the difference between top and main LCD TX battery bars on 9Xe (<a href=https://github.com/opentx/opentx/issues/2671>#2671</a>)</li>
</ul> </ul>
[Sky9x / 9XR-PRO] [Sky9x / 9XR-PRO]

View file

@ -587,7 +587,7 @@ void drawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, Lc
void lcdDrawTelemetryTopBar() void lcdDrawTelemetryTopBar()
{ {
putsModelName(0, 0, g_model.header.name, g_eeGeneral.currModel, 0); putsModelName(0, 0, g_model.header.name, g_eeGeneral.currModel, 0);
uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK : 0); uint8_t att = (IS_TXBATT_WARNING() ? BLINK : 0);
putsVBat(14*FW,0,att); putsVBat(14*FW,0,att);
if (g_model.timers[0].mode) { if (g_model.timers[0].mode) {
att = (timersStates[0].val<0 ? BLINK : 0); att = (timersStates[0].val<0 ? BLINK : 0);

View file

@ -208,13 +208,13 @@ void displayBattVoltage()
putsVBat(VBATT_X-8, VBATT_Y+1, 0); putsVBat(VBATT_X-8, VBATT_Y+1, 0);
drawFilledRect(VBATT_X-25, VBATT_Y+9, 22, 5); drawFilledRect(VBATT_X-25, VBATT_Y+9, 22, 5);
lcd_vline(VBATT_X-3, VBATT_Y+10, 3); lcd_vline(VBATT_X-3, VBATT_Y+10, 3);
uint8_t count = limit<uint8_t>(2, 20 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 20); uint8_t count = GET_TXBATT_BARS();
for (uint8_t i=0; i<count; i+=2) for (uint8_t i=0; i<count; i+=2)
lcd_vline(VBATT_X-24+i, VBATT_Y+10, 3); lcd_vline(VBATT_X-24+i, VBATT_Y+10, 3);
if (g_vbat100mV > g_eeGeneral.vBatWarn || BLINK_ON_PHASE) if (!IS_TXBATT_WARNING() || BLINK_ON_PHASE)
drawFilledRect(VBATT_X-26, VBATT_Y, 25, 15); drawFilledRect(VBATT_X-26, VBATT_Y, 25, 15);
#else #else
LcdFlags att = (g_vbat100mV <= g_eeGeneral.vBatWarn ? BLINK|INVERS : 0) | BIGSIZE; LcdFlags att = (IS_TXBATT_WARNING() ? BLINK|INVERS : 0) | BIGSIZE;
putsVBat(VBATT_X-1, VBATT_Y, att|NO_UNIT); putsVBat(VBATT_X-1, VBATT_Y, att|NO_UNIT);
lcd_putc(VBATT_X, VBATTUNIT_Y, 'V'); lcd_putc(VBATT_X, VBATTUNIT_Y, 'V');
#endif #endif
@ -223,15 +223,15 @@ void displayBattVoltage()
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
void displayVoltageOrAlarm() void displayVoltageOrAlarm()
{ {
if (g_vbat100mV > g_eeGeneral.vBatWarn && g_eeGeneral.temperatureWarn && getTemperature() >= g_eeGeneral.temperatureWarn) { if (IS_TXBATT_WARNING()) {
displayBattVoltage();
}
else if (g_eeGeneral.temperatureWarn && getTemperature() >= g_eeGeneral.temperatureWarn) {
putsValueWithUnit(6*FW-1, 2*FH, getTemperature(), UNIT_TEMPERATURE, BLINK|INVERS|DBLSIZE); putsValueWithUnit(6*FW-1, 2*FH, getTemperature(), UNIT_TEMPERATURE, BLINK|INVERS|DBLSIZE);
} }
else if (g_vbat100mV > g_eeGeneral.vBatWarn && g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.currentCalib)/8192/36) / 500 >= g_eeGeneral.mAhWarn) { else if (g_eeGeneral.mAhWarn && (g_eeGeneral.mAhUsed + Current_used * (488 + g_eeGeneral.currentCalib)/8192/36) / 500 >= g_eeGeneral.mAhWarn) {
putsValueWithUnit(7*FW-1, 2*FH, (g_eeGeneral.mAhUsed + Current_used*(488 + g_eeGeneral.currentCalib)/8192/36)/10, UNIT_MAH, BLINK|INVERS|DBLSIZE); putsValueWithUnit(7*FW-1, 2*FH, (g_eeGeneral.mAhUsed + Current_used*(488 + g_eeGeneral.currentCalib)/8192/36)/10, UNIT_MAH, BLINK|INVERS|DBLSIZE);
} }
else {
displayBattVoltage();
}
} }
#else #else
#define displayVoltageOrAlarm() displayBattVoltage() #define displayVoltageOrAlarm() displayBattVoltage()

View file

@ -547,7 +547,7 @@ void drawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, Lc
void lcdDrawTelemetryTopBar() void lcdDrawTelemetryTopBar()
{ {
putsModelName(0, 0, g_model.header.name, g_eeGeneral.currModel, 0); putsModelName(0, 0, g_model.header.name, g_eeGeneral.currModel, 0);
uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK : 0); uint8_t att = (IS_TXBATT_WARNING() ? BLINK : 0);
putsVBat(16*FW+1,0,att); putsVBat(16*FW+1,0,att);
if (g_model.timers[0].mode) { if (g_model.timers[0].mode) {
att = (timersStates[0].val<0 ? BLINK : 0); att = (timersStates[0].val<0 ? BLINK : 0);

View file

@ -209,7 +209,6 @@ void displayTopBarGauge(coord_t x, int count, bool blinking=false)
{ {
if (!blinking || BLINK_ON_PHASE) if (!blinking || BLINK_ON_PHASE)
drawFilledRect(x+1, BAR_Y+2, 11, 5, SOLID, ERASE); drawFilledRect(x+1, BAR_Y+2, 11, 5, SOLID, ERASE);
count = min(10, count);
for (int i=0; i<count; i+=2) for (int i=0; i<count; i+=2)
lcd_vline(x+2+i, BAR_Y+3, 3); lcd_vline(x+2+i, BAR_Y+3, 3);
} }
@ -300,8 +299,7 @@ void displayTopBar()
drawFilledRect(BAR_X, BAR_Y, BAR_W, BAR_H, SOLID, FILL_WHITE|GREY(12)|ROUND); drawFilledRect(BAR_X, BAR_Y, BAR_W, BAR_H, SOLID, FILL_WHITE|GREY(12)|ROUND);
/* The inside of the Batt gauge */ /* The inside of the Batt gauge */
int count = 10 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin); displayTopBarGauge(batt_icon_x+FW, GET_TXBATT_BARS(), IS_TXBATT_WARNING());
displayTopBarGauge(batt_icon_x+FW, count, g_vbat100mV <= g_eeGeneral.vBatWarn);
/* The inside of the RSSI gauge */ /* The inside of the RSSI gauge */
if (TELEMETRY_RSSI() > 0) { if (TELEMETRY_RSSI() > 0) {

View file

@ -191,8 +191,7 @@ void perMain()
setTopSecondTimer(g_eeGeneral.globalTimer + sessionTimer); setTopSecondTimer(g_eeGeneral.globalTimer + sessionTimer);
setTopRssi(TELEMETRY_RSSI()); setTopRssi(TELEMETRY_RSSI());
setTopBatteryValue(g_vbat100mV); setTopBatteryValue(g_vbat100mV);
int state = 5 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin); setTopBatteryState(GET_TXBATT_BARS(), IS_TXBATT_WARNING());
setTopBatteryState(state, g_vbat100mV <= g_eeGeneral.vBatWarn);
topLcdRefreshEnd(); topLcdRefreshEnd();
#endif #endif

View file

@ -2054,7 +2054,7 @@ void checkBattery()
} }
else else
#endif #endif
if (g_vbat100mV <= g_eeGeneral.vBatWarn && g_vbat100mV>50) { if (IS_TXBATT_WARNING() && g_vbat100mV>50) {
AUDIO_TX_BATTERY_LOW(); AUDIO_TX_BATTERY_LOW();
} }
#if defined(PCBSKY9X) #if defined(PCBSKY9X)

View file

@ -1127,6 +1127,14 @@ extern const char vers_stamp[];
#endif #endif
extern uint8_t g_vbat100mV; extern uint8_t g_vbat100mV;
#if defined(CPUARM)
#define GET_TXBATT_BARS() (min(10, 10 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin)))
#else
#define GET_TXBATT_BARS() (limit<uint8_t>(2, 20 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 20))
#endif
#define IS_TXBATT_WARNING() (g_vbat100mV <= g_eeGeneral.vBatWarn)
#define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms) #define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms)
extern uint8_t g_beepCnt; extern uint8_t g_beepCnt;
extern uint8_t g_beepVal[5]; extern uint8_t g_beepVal[5];

View file

@ -347,13 +347,13 @@ void setTopBatteryState(int state, uint8_t blinking)
Ht1621Data1[4] |= 0x40; // Battery border // TODO this is not working for me, the border is ALWAYS on Ht1621Data1[4] |= 0x40; // Battery border // TODO this is not working for me, the border is ALWAYS on
if (state > 0) if (state > 0)
Ht1621Data1[7] |= 0x80; Ht1621Data1[7] |= 0x80;
if (state > 1)
Ht1621Data1[9] |= 0x80;
if (state > 2) if (state > 2)
Ht1621Data1[5] |= 0x80; Ht1621Data1[9] |= 0x80;
if (state > 3)
Ht1621Data1[10] |= 0x80;
if (state > 4) if (state > 4)
Ht1621Data1[5] |= 0x80;
if (state > 6)
Ht1621Data1[10] |= 0x80;
if (state > 8)
Ht1621Data1[4] |= 0x80; Ht1621Data1[4] |= 0x80;
} }
} }