Animate the battery symbols on OSD based on voltage
This commit is contained in:
parent
f3502662b9
commit
d95331323e
|
@ -151,6 +151,25 @@ static char osdGetAltitudeSymbol()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets average battery cell voltage in 0.01V units.
|
||||||
|
*/
|
||||||
|
static int osdGetBatteryAverageCellVoltage(void)
|
||||||
|
{
|
||||||
|
return (getBatteryVoltage() * 10) / getBatteryCellCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
static char osdGetBatterySymbol(int cellVoltage)
|
||||||
|
{
|
||||||
|
if(getBatteryState() == BATTERY_CRITICAL) {
|
||||||
|
return SYM_MAIN_BATT; // FIXME: currently the BAT- symbol, ideally replace with a battery with exclamation mark
|
||||||
|
} else {
|
||||||
|
/* Calculate a symbol offset using cell voltage over full cell voltage range */
|
||||||
|
int symOffset = scaleRange(cellVoltage, batteryConfig()->vbatmincellvoltage * 10, batteryConfig()->vbatmaxcellvoltage * 10, 0, 7);
|
||||||
|
return SYM_BATT_EMPTY - constrain(symOffset, 0, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts altitude based on the current unit system.
|
* Converts altitude based on the current unit system.
|
||||||
* @param alt Raw altitude (i.e. as taken from BaroAlt)
|
* @param alt Raw altitude (i.e. as taken from BaroAlt)
|
||||||
|
@ -195,7 +214,7 @@ static void osdDrawSingleElement(uint8_t item)
|
||||||
}
|
}
|
||||||
|
|
||||||
case OSD_MAIN_BATT_VOLTAGE:
|
case OSD_MAIN_BATT_VOLTAGE:
|
||||||
buff[0] = SYM_BATT_5;
|
buff[0] = osdGetBatterySymbol(osdGetBatteryAverageCellVoltage());
|
||||||
tfp_sprintf(buff + 1, "%d.%1dV", getBatteryVoltage() / 10, getBatteryVoltage() % 10);
|
tfp_sprintf(buff + 1, "%d.%1dV", getBatteryVoltage() / 10, getBatteryVoltage() % 10);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -443,8 +462,8 @@ static void osdDrawSingleElement(uint8_t item)
|
||||||
|
|
||||||
case OSD_AVG_CELL_VOLTAGE:
|
case OSD_AVG_CELL_VOLTAGE:
|
||||||
{
|
{
|
||||||
const int cellV = getBatteryVoltage() * 10 / getBatteryCellCount();
|
const int cellV = osdGetBatteryAverageCellVoltage();
|
||||||
buff[0] = SYM_BATT_5;
|
buff[0] = osdGetBatterySymbol(cellV);
|
||||||
tfp_sprintf(buff + 1, "%d.%02dV", cellV / 100, cellV % 100);
|
tfp_sprintf(buff + 1, "%d.%02dV", cellV / 100, cellV % 100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,7 +433,6 @@ uint8_t getBatteryCellCount(void)
|
||||||
return batteryCellCount;
|
return batteryCellCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t getAmperage(void) {
|
int32_t getAmperage(void) {
|
||||||
return currentMeter.amperage;
|
return currentMeter.amperage;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue