Switched 'v_bat' and 'charge' fields of state struct from float to, respectively, uint16_t and uint8_t and updated UI functions accordingly. Rationale for this change is providing better support for future platforms without hardware floating point unit.
This commit is contained in:
parent
46819ba993
commit
4d3eacc144
|
|
@ -288,7 +288,7 @@ void gfx_printError(const char *text, fontSize_t size);
|
|||
* @param height: battery icon height
|
||||
* @param percentage: battery charge percentage
|
||||
*/
|
||||
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, float percentage);
|
||||
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height, uint8_t percentage);
|
||||
|
||||
/**
|
||||
* Function to draw Smeter of arbitrary size.
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ typedef struct
|
|||
{
|
||||
bool radioStateUpdated;
|
||||
curTime_t time;
|
||||
float v_bat;
|
||||
float charge;
|
||||
uint16_t v_bat;
|
||||
uint8_t charge;
|
||||
float rssi;
|
||||
|
||||
uint8_t ui_screen;
|
||||
|
|
|
|||
|
|
@ -561,13 +561,13 @@ void gfx_printError(const char *text, fontSize_t size)
|
|||
*
|
||||
*/
|
||||
void gfx_drawBattery(point_t start, uint16_t width, uint16_t height,
|
||||
float percentage)
|
||||
uint8_t percentage)
|
||||
{
|
||||
color_t white = {255, 255, 255, 255};
|
||||
color_t black = {0, 0, 0 , 255};
|
||||
|
||||
// Cap percentage to 1
|
||||
percentage = (percentage > 1.0f) ? 1.0f : percentage;
|
||||
percentage = (percentage > 100) ? 100 : percentage;
|
||||
|
||||
#ifdef PIX_FMT_RGB565
|
||||
color_t green = {0, 255, 0 , 255};
|
||||
|
|
@ -576,9 +576,9 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height,
|
|||
|
||||
// Select color according to percentage
|
||||
color_t bat_color = yellow;
|
||||
if (percentage < 0.3)
|
||||
if (percentage < 30)
|
||||
bat_color = red;
|
||||
else if (percentage > 0.6)
|
||||
else if (percentage > 60)
|
||||
bat_color = green;
|
||||
#elif defined PIX_FMT_BW
|
||||
color_t bat_color = white;
|
||||
|
|
@ -589,8 +589,8 @@ void gfx_drawBattery(point_t start, uint16_t width, uint16_t height,
|
|||
|
||||
// Draw the battery fill
|
||||
point_t fill_start = {start.x + 2, start.y + 2};
|
||||
gfx_drawRect(fill_start, (int)(((float)(width - 4)) * percentage),
|
||||
height - 4, bat_color, true);
|
||||
int fillWidth = ((width - 4) * percentage) / 100;
|
||||
gfx_drawRect(fill_start, fillWidth, height - 4, bat_color, true);
|
||||
|
||||
// Round corners
|
||||
point_t top_left = start;
|
||||
|
|
|
|||
|
|
@ -225,9 +225,14 @@ void *dev_task(void *arg)
|
|||
state.time = rtc_getTime();
|
||||
#endif
|
||||
|
||||
// Low-pass filtering with a time constant of 10s when updated at 1Hz
|
||||
float vbat = platform_getVbat();
|
||||
state.v_bat = 0.02*vbat + 0.98*state.v_bat;
|
||||
/*
|
||||
* Low-pass filtering with a time constant of 10s when updated at 1Hz
|
||||
* Original computation: state.v_bat = 0.02*vbat + 0.98*state.v_bat
|
||||
* Peak error is 18mV when input voltage is 49mV.
|
||||
*/
|
||||
uint16_t vbat = platform_getVbat();
|
||||
state.v_bat -= (state.v_bat * 2) / 100;
|
||||
state.v_bat += (vbat * 2) / 100;
|
||||
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ void _ui_drawLowBatteryScreen()
|
|||
uint16_t bat_width = SCREEN_WIDTH / 2;
|
||||
uint16_t bat_height = SCREEN_HEIGHT / 3;
|
||||
point_t bat_pos = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 8};
|
||||
gfx_drawBattery(bat_pos, bat_width, bat_height, 0.1f);
|
||||
gfx_drawBattery(bat_pos, bat_width, bat_height, 10);
|
||||
point_t text_pos_1 = {0, SCREEN_HEIGHT * 2 / 3};
|
||||
point_t text_pos_2 = {0, SCREEN_HEIGHT * 2 / 3 + 16};
|
||||
|
||||
|
|
|
|||
|
|
@ -188,10 +188,16 @@ int _ui_getInfoValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
snprintf(buf, max_len, "%s", GIT_VERSION);
|
||||
break;
|
||||
case 1: // Battery voltage
|
||||
snprintf(buf, max_len, "%.1fV", last_state.v_bat);
|
||||
{
|
||||
// Compute integer part and mantissa of voltage value, adding 50mV
|
||||
// to mantissa for rounding to nearest integer
|
||||
uint16_t volt = last_state.v_bat / 1000;
|
||||
uint16_t mvolt = ((last_state.v_bat - volt * 1000) + 50) / 100;
|
||||
snprintf(buf, max_len, "%d.%dV", volt, mvolt);
|
||||
}
|
||||
break;
|
||||
case 2: // Battery charge
|
||||
snprintf(buf, max_len, "%.1f%%", last_state.charge * 100);
|
||||
snprintf(buf, max_len, "%d%%", last_state.charge);
|
||||
break;
|
||||
case 3: // RSSI
|
||||
snprintf(buf, max_len, "%.1fdBm", last_state.rssi);
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ float radio_getRssi()
|
|||
if(rxFreq < 401035000) offset_index = 0;
|
||||
if(rxFreq > 479995000) offset_index = 8;
|
||||
|
||||
float rssi_mv = adc1_getMeasurement(ADC_RSSI_CH);
|
||||
float rssi_mv = ((float) adc1_getMeasurement(ADC_RSSI_CH));
|
||||
float rssi_dbm = (rssi_mv - rssi_offset[offset_index]) / rssi_gain;
|
||||
return rssi_dbm;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue