mirror of
https://github.com/egzumer/uv-k5-firmware-custom
synced 2024-11-21 17:19:57 +00:00
Pulled in egzumer's battery percentage !
This commit is contained in:
parent
1fc1a102ea
commit
a9aa37e043
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
Binary file not shown.
@ -34,7 +34,52 @@ uint16_t gBatteryCheckCounter;
|
||||
|
||||
volatile uint16_t gPowerSave_10ms;
|
||||
|
||||
void BATTERY_GetReadings(bool bDisplayBatteryLevel)
|
||||
/*
|
||||
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
|
||||
*/
|
||||
unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
|
||||
{
|
||||
if (voltage_10mV > 814)
|
||||
return 100;
|
||||
if (voltage_10mV > 756)
|
||||
return ((132ul * voltage_10mV) / 100) - 974u;
|
||||
if (voltage_10mV > 729)
|
||||
return ((63ul * voltage_10mV) / 100) - 452u;
|
||||
if (voltage_10mV > 600)
|
||||
return ((52ul * voltage_10mV) / 1000) - 31u;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
|
||||
{
|
||||
const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel;
|
||||
const uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4;
|
||||
|
@ -33,7 +33,8 @@ extern uint16_t gBatteryCheckCounter;
|
||||
|
||||
extern volatile uint16_t gPowerSave_10ms;
|
||||
|
||||
void BATTERY_GetReadings(bool bDisplayBatteryLevel);
|
||||
unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV);
|
||||
void BATTERY_GetReadings(const bool bDisplayBatteryLevel);
|
||||
|
||||
#endif
|
||||
|
||||
|
4
misc.c
4
misc.c
@ -63,8 +63,8 @@ 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 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};
|
||||
|
||||
|
4
misc.h
4
misc.h
@ -128,8 +128,8 @@ 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 uint16_t gMax_bat_v;
|
||||
//extern const uint16_t gMin_bat_v;
|
||||
|
||||
extern const uint8_t gMicGain_dB2[5];
|
||||
|
||||
|
@ -752,8 +752,13 @@ 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);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
@ -734,9 +734,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);
|
||||
sprintf(String, "%u%%", percent);
|
||||
sprintf(String, "%u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage));
|
||||
UI_PrintString(String, menu_item_x1, menu_item_x2, 3, 8);
|
||||
#if 0
|
||||
sprintf(String, "Curr %u", gBatteryCurrent); // needs scaling into mA
|
||||
|
@ -169,10 +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;
|
||||
sprintf(s, "%u%%", percent);
|
||||
sprintf(s, "%u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage));
|
||||
space_needed = (7 * strlen(s));
|
||||
if (x2 >= (x1 + space_needed))
|
||||
UI_PrintStringSmallBuffer(s, line + x2 - space_needed);
|
||||
|
@ -65,15 +65,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
|
||||
|
Loading…
Reference in New Issue
Block a user