diff --git a/helper/battery.c b/helper/battery.c index 1084fe1..84ae055 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -34,6 +34,52 @@ uint16_t gBatteryCheckCounter; volatile uint16_t gPowerSave_10ms; +/* +Based on real measurement + +Volts Percent Volts Percent Volts Percent Volts Percent +8.28 100 7.95099 73 7.7184 46 7.48116 19 +8.22 99 7.94188 72 7.71091 45 7.46364 18 +8.17 98 7.9338 71 7.70911 44 7.44789 17 +8.13632 97 7.92684 70 7.70098 43 7.43318 16 +8.12308 96 7.9178 69 7.69619 42 7.41864 15 +8.09688 95 7.90823 68 7.69018 41 7.40579 14 +8.08124 94 7.89858 67 7.68473 40 7.39289 13 +8.06912 93 7.88667 66 7.67911 39 7.37839 12 +8.05826 92 7.87673 65 7.67087 38 7.36017 11 +8.05008 91 7.86864 64 7.66601 37 7.33704 10 +8.04192 90 7.85802 63 7.6599 36 7.3079 9 +8.03866 89 7.84816 62 7.65418 35 7.26793 8 +8.03089 88 7.83744 61 7.64775 34 7.21291 7 +8.0284 87 7.82748 60 7.64065 33 7.13416 6 +8.02044 86 7.81983 59 7.63136 32 7.02785 5 +8.01832 85 7.80929 58 7.6244 31 6.89448 4 +8.01072 84 7.79955 57 7.61636 30 6.72912 3 +8.00965 83 7.79017 56 7.60738 29 6.5164 2 +8.00333 82 7.78107 55 7.597 28 6.19272 1 +7.99973 81 7.77167 54 7.5876 27 5.63138 0 +7.99218 80 7.76509 53 7.57732 26 +7.98999 79 7.75649 52 7.56563 25 +7.98234 78 7.74939 51 7.55356 24 +7.97892 77 7.7411 50 7.54088 23 +7.97043 76 7.73648 49 7.52683 22 +7.96478 75 7.72911 48 7.51285 21 +7.95983 74 7.72097 47 7.49832 20 +*/ +uint8_t BATTERY_VoltsToPercent(uint16_t voltage_10mV) +{ + if(voltage_10mV>814) + return 100; + else if(voltage_10mV>756) + return 132*voltage_10mV/100-974; + else if(voltage_10mV>729) + return 63*voltage_10mV/100-452; + else if(voltage_10mV>600) + return 52*voltage_10mV/1000-31; + else + return 0; +} + void BATTERY_GetReadings(bool bDisplayBatteryLevel) { const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel; diff --git a/helper/battery.h b/helper/battery.h index ea0d1b0..08a013a 100644 --- a/helper/battery.h +++ b/helper/battery.h @@ -33,6 +33,7 @@ extern uint16_t gBatteryCheckCounter; extern volatile uint16_t gPowerSave_10ms; +uint8_t BATTERY_VoltsToPercent(uint16_t voltage_10mV); void BATTERY_GetReadings(bool bDisplayBatteryLevel); #endif diff --git a/misc.c b/misc.c index bf08a36..c040d68 100644 --- a/misc.c +++ b/misc.c @@ -63,9 +63,6 @@ const uint16_t NOAA_countdown_10ms = 5000 / 10; // 5 seconds const uint16_t NOAA_countdown_2_10ms = 500 / 10; // 500ms const uint16_t NOAA_countdown_3_10ms = 200 / 10; // 200ms -const uint16_t gMax_bat_v = 840; // 8.4V -const uint16_t gMin_bat_v = 660; // 6.6V - const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; const uint8_t gMicGain_dB2[5] = {3, 8, 16, 24, 31}; diff --git a/misc.h b/misc.h index dd7708a..08a53da 100644 --- a/misc.h +++ b/misc.h @@ -128,9 +128,6 @@ extern const uint16_t scan_pause_delay_in_2_10ms; extern const uint16_t scan_pause_delay_in_3_10ms; extern const uint16_t scan_pause_delay_in_4_10ms; -extern const uint16_t gMax_bat_v; -extern const uint16_t gMin_bat_v; - extern const uint8_t gMicGain_dB2[5]; extern bool gSetting_350TX; diff --git a/ui/main.c b/ui/main.c index 8b67ee4..0d9294c 100644 --- a/ui/main.c +++ b/ui/main.c @@ -728,10 +728,9 @@ void UI_DisplayMain(void) else if (gChargingWithTypeC) { // charging .. show the battery state - const uint16_t volts = (gBatteryVoltageAverage < gMin_bat_v) ? gMin_bat_v : gBatteryVoltageAverage; - const uint16_t percent = (100 * (volts - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v); - sprintf(String, "Charge %u.%02uV %u%%", gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100, percent); - UI_PrintStringSmall(String, 2, 0, 3); + const uint16_t percent = BATTERY_VoltsToPercent(gBatteryVoltageAverage); + sprintf(String, "Charge %u.%02uV %u%%", gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100, percent); + UI_PrintStringSmall(String, 2, 0, 3); } #endif } diff --git a/ui/menu.c b/ui/menu.c index 24d4d09..9025160 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -669,8 +669,7 @@ void UI_DisplayMenu(void) { // 2nd text line .. percentage UI_PrintString(String, menu_item_x1, menu_item_x2, 1, 8); - const uint16_t volts = (gBatteryVoltageAverage < gMin_bat_v) ? gMin_bat_v : gBatteryVoltageAverage; - const uint16_t percent = (100 * (volts - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v); + const uint16_t percent = BATTERY_VoltsToPercent(gBatteryVoltageAverage); sprintf(String, "%u%%", percent); UI_PrintString(String, menu_item_x1, menu_item_x2, 3, 8); #if 0 diff --git a/ui/status.c b/ui/status.c index bc2dd6a..60b802b 100644 --- a/ui/status.c +++ b/ui/status.c @@ -169,9 +169,7 @@ void UI_DisplayStatus(const bool test_display) case 2: // percentage { - const uint16_t voltage = (gBatteryVoltageAverage < gMin_bat_v) ? gMin_bat_v : gBatteryVoltageAverage; - const uint16_t percent = (100 * (voltage - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v); -// const uint16_t percent = gBatteryDisplayLevel; + const uint16_t percent = BATTERY_VoltsToPercent(gBatteryVoltageAverage); sprintf(s, "%u%%", percent); space_needed = (7 * strlen(s)); if (x2 >= (x1 + space_needed)) diff --git a/ui/welcome.c b/ui/welcome.c index 8ef677c..74d3606 100644 --- a/ui/welcome.c +++ b/ui/welcome.c @@ -53,15 +53,11 @@ void UI_DisplayWelcome(void) if (gEeprom.POWER_ON_DISPLAY_MODE == POWER_ON_DISPLAY_MODE_VOLTAGE) { - const uint16_t volts = (gBatteryVoltageAverage < gMin_bat_v) ? gMin_bat_v : - (gBatteryVoltageAverage > gMax_bat_v) ? gMax_bat_v : - gBatteryVoltageAverage; - strcpy(WelcomeString0, "VOLTAGE"); sprintf(WelcomeString1, "%u.%02uV %u%%", gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100, - (100 * (volts - gMin_bat_v)) / (gMax_bat_v - gMin_bat_v)); + BATTERY_VoltsToPercent(gBatteryVoltageAverage)); #if 0 sprintf(WelcomeString2, "Current %u", gBatteryCurrent); // needs scaling into mA