Skip to content

Commit 140b5f4

Browse files
committed
Added second discharge curve for 2200mAh type battery and hidden BatTyp menu entry
1 parent 3e0ea6f commit 140b5f4

File tree

8 files changed

+85
-50
lines changed

8 files changed

+85
-50
lines changed

app/menu.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,13 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
331331
#endif
332332

333333
case MENU_BATCAL:
334-
*pMin = 1600; // 0
335-
*pMax = 2200; // 2300
334+
*pMin = 1600;
335+
*pMax = 2200;
336+
break;
337+
338+
case MENU_BATTYP:
339+
*pMin = 0;
340+
*pMax = 1;
336341
break;
337342

338343
case MENU_F1SHRT:
@@ -772,17 +777,21 @@ void MENU_AcceptSetting(void)
772777
#endif
773778

774779
case MENU_BATCAL:
775-
{
780+
{ // voltages are averages between discharge curves of 1600 and 2200 mAh
776781
gBatteryCalibration[0] = (520ul * gSubMenuSelection) / 760; // 5.20V empty, blinking above this value, reduced functionality below
777-
gBatteryCalibration[1] = (700ul * gSubMenuSelection) / 760; // 7.00V, ~5%, 1 bars above this value
778-
gBatteryCalibration[2] = (745ul * gSubMenuSelection) / 760; // 7.45V, ~17%, 2 bars above this value
782+
gBatteryCalibration[1] = (689ul * gSubMenuSelection) / 760; // 6.89V, ~5%, 1 bars above this value
783+
gBatteryCalibration[2] = (724ul * gSubMenuSelection) / 760; // 7.24V, ~17%, 2 bars above this value
779784
gBatteryCalibration[3] = gSubMenuSelection; // 7.6V, ~29%, 3 bars above this value
780-
gBatteryCalibration[4] = (788ul * gSubMenuSelection) / 760; // 7.88V, ~65%, 4 bars above this value
785+
gBatteryCalibration[4] = (771ul * gSubMenuSelection) / 760; // 7.71V, ~65%, 4 bars above this value
781786
gBatteryCalibration[5] = 2300;
782787
SETTINGS_SaveBatteryCalibration(gBatteryCalibration);
783788
return;
784789
}
785790

791+
case MENU_BATTYP:
792+
gEeprom.BATTERY_TYPE = gSubMenuSelection;
793+
break;
794+
786795
case MENU_F1SHRT:
787796
case MENU_F1LONG:
788797
case MENU_F2SHRT:
@@ -1170,6 +1179,10 @@ void MENU_ShowCurrentSetting(void)
11701179
gSubMenuSelection = gBatteryCalibration[3];
11711180
break;
11721181

1182+
case MENU_BATTYP:
1183+
gSubMenuSelection = gEeprom.BATTERY_TYPE;
1184+
break;
1185+
11731186
case MENU_F1SHRT:
11741187
case MENU_F1LONG:
11751188
case MENU_F2SHRT:

board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ void BOARD_EEPROM_Init(void)
614614
#endif
615615
gEeprom.ROGER = (Data[1] < 3) ? Data[1] : ROGER_MODE_OFF;
616616
gEeprom.REPEATER_TAIL_TONE_ELIMINATION = (Data[2] < 11) ? Data[2] : 0;
617-
gEeprom.TX_VFO = (Data[3] < 2) ? Data[3] : 0;
617+
gEeprom.TX_VFO = (Data[3] < 2) ? Data[3] : 0;
618+
gEeprom.BATTERY_TYPE = (Data[4] < BATTERY_TYPE_UNKNOWN) ? Data[4] : BATTERY_TYPE_1600_MAH;
618619

619620
// 0ED0..0ED7
620621
EEPROM_ReadBuffer(0x0ED0, Data, 8);

helper/battery.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "battery.h"
1818
#include "driver/backlight.h"
1919
#include "misc.h"
20+
#include "settings.h"
2021
#include "ui/battery.h"
2122
#include "ui/menu.h"
2223
#include "ui/ui.h"
@@ -34,48 +35,47 @@ uint16_t gBatteryCheckCounter;
3435

3536
volatile uint16_t gPowerSave_10ms;
3637

37-
/*
38-
Based on real measurement
39-
40-
Volts Percent Volts Percent Volts Percent Volts Percent
41-
8.28 100 7.95099 73 7.7184 46 7.48116 19
42-
8.22 99 7.94188 72 7.71091 45 7.46364 18
43-
8.17 98 7.9338 71 7.70911 44 7.44789 17
44-
8.13632 97 7.92684 70 7.70098 43 7.43318 16
45-
8.12308 96 7.9178 69 7.69619 42 7.41864 15
46-
8.09688 95 7.90823 68 7.69018 41 7.40579 14
47-
8.08124 94 7.89858 67 7.68473 40 7.39289 13
48-
8.06912 93 7.88667 66 7.67911 39 7.37839 12
49-
8.05826 92 7.87673 65 7.67087 38 7.36017 11
50-
8.05008 91 7.86864 64 7.66601 37 7.33704 10
51-
8.04192 90 7.85802 63 7.6599 36 7.3079 9
52-
8.03866 89 7.84816 62 7.65418 35 7.26793 8
53-
8.03089 88 7.83744 61 7.64775 34 7.21291 7
54-
8.0284 87 7.82748 60 7.64065 33 7.13416 6
55-
8.02044 86 7.81983 59 7.63136 32 7.02785 5
56-
8.01832 85 7.80929 58 7.6244 31 6.89448 4
57-
8.01072 84 7.79955 57 7.61636 30 6.72912 3
58-
8.00965 83 7.79017 56 7.60738 29 6.5164 2
59-
8.00333 82 7.78107 55 7.597 28 6.19272 1
60-
7.99973 81 7.77167 54 7.5876 27 5.63138 0
61-
7.99218 80 7.76509 53 7.57732 26
62-
7.98999 79 7.75649 52 7.56563 25
63-
7.98234 78 7.74939 51 7.55356 24
64-
7.97892 77 7.7411 50 7.54088 23
65-
7.97043 76 7.73648 49 7.52683 22
66-
7.96478 75 7.72911 48 7.51285 21
67-
7.95983 74 7.72097 47 7.49832 20
68-
*/
38+
6939
unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
7040
{
71-
if (voltage_10mV > 814)
72-
return 100;
73-
if (voltage_10mV > 756)
74-
return ((132ul * voltage_10mV) / 100) - 974u;
75-
if (voltage_10mV > 729)
76-
return ((63ul * voltage_10mV) / 100) - 452u;
77-
if (voltage_10mV > 600)
78-
return ((52ul * voltage_10mV) / 1000) - 31u;
41+
const uint16_t crv1600[][2] = {
42+
{814, 100},
43+
{756, 24 },
44+
{729, 7 },
45+
{597, 0 },
46+
{0, 0}
47+
};
48+
49+
const uint16_t crv2200[][2] = {
50+
{823, 100},
51+
{740, 60},
52+
{707, 21},
53+
{680, 5},
54+
{505, 0},
55+
{0, 0}
56+
};
57+
58+
const BATTERY_Type_t type = gEeprom.BATTERY_TYPE;
59+
const uint16_t(*crv)[2];
60+
uint8_t size;
61+
if (type == BATTERY_TYPE_2200_MAH) {
62+
crv = crv2200;
63+
size = ARRAY_SIZE(crv2200);
64+
}
65+
else {
66+
crv = crv1600;
67+
size = ARRAY_SIZE(crv1600);
68+
}
69+
70+
const int mulipl = 1000;
71+
for (int i = 1; i < size; i++) {
72+
if (voltage_10mV > crv[i][0]) {
73+
int a = (crv[i - 1][1] - crv[i][1]) * mulipl / (crv[i - 1][0] - crv[i][0]);
74+
int b = crv[i][1] - a * crv[i][0] / mulipl;
75+
int p = a * voltage_10mV / mulipl + b;
76+
return MIN(p, 100);
77+
}
78+
}
7979
return 0;
8080
}
8181

helper/battery.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ extern uint16_t gBatteryCheckCounter;
3333

3434
extern volatile uint16_t gPowerSave_10ms;
3535

36+
typedef enum {
37+
BATTERY_TYPE_1600_MAH,
38+
BATTERY_TYPE_2200_MAH,
39+
BATTERY_TYPE_UNKNOWN
40+
} BATTERY_Type_t;
41+
3642
unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV);
3743
void BATTERY_GetReadings(const bool bDisplayBatteryLevel);
3844

settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void SETTINGS_SaveSettings(void)
137137
State[1] = gEeprom.ROGER;
138138
State[2] = gEeprom.REPEATER_TAIL_TONE_ELIMINATION;
139139
State[3] = gEeprom.TX_VFO;
140+
State[4] = gEeprom.BATTERY_TYPE;
140141
EEPROM_WriteBuffer(0x0EA8, State);
141142

142143
State[0] = gEeprom.DTMF_SIDE_TONE;

settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdint.h>
2222

2323
#include "frequencies.h"
24+
#include <helper/battery.h>
2425
#include "radio.h"
2526

2627
enum POWER_OnDisplayMode_t {
@@ -230,6 +231,7 @@ typedef struct {
230231
uint8_t KEY_M_LONG_PRESS_ACTION;
231232
uint8_t BACKLIGHT_MIN;
232233
uint8_t BACKLIGHT_MAX;
234+
BATTERY_Type_t BATTERY_TYPE;
233235
} EEPROM_Config_t;
234236

235237
extern EEPROM_Config_t gEeprom;

ui/menu.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const t_menu_item MenuList[] =
134134
{"FrCali", VOICE_ID_INVALID, MENU_F_CALI }, // reference xtal calibration
135135
#endif
136136
{"BatCal", VOICE_ID_INVALID, MENU_BATCAL }, // battery voltage calibration
137+
{"BatTyp", VOICE_ID_INVALID, MENU_BATTYP }, // battery type 1600/2200mAh
137138
{"Reset", VOICE_ID_INITIALISATION, MENU_RESET }, // might be better to move this to the hidden menu items ?
138139

139140
{"", VOICE_ID_INVALID, 0xff } // end of list - DO NOT delete or move this this
@@ -316,6 +317,12 @@ const char gSubMenu_BAT_TXT[3][8] =
316317
"PERCENT"
317318
};
318319

320+
const char gSubMenu_BATTYP[2][9] =
321+
{
322+
"1600mAh",
323+
"2200mAh"
324+
};
325+
319326
const char gSubMenu_SCRAMBLER[11][7] =
320327
{
321328
"OFF",
@@ -835,7 +842,11 @@ void UI_DisplayMenu(void)
835842
sprintf(String, "%u.%02uV\n%u", vol / 100, vol % 100, gSubMenuSelection);
836843
break;
837844
}
838-
845+
846+
case MENU_BATTYP:
847+
strcpy(String, gSubMenu_BATTYP[gSubMenuSelection]);
848+
break;
849+
839850
case MENU_F1SHRT:
840851
case MENU_F1LONG:
841852
case MENU_F2SHRT:

ui/menu.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ enum
120120
MENU_F1LONG,
121121
MENU_F2SHRT,
122122
MENU_F2LONG,
123-
MENU_MLONG
123+
MENU_MLONG,
124+
MENU_BATTYP
124125
};
125126

126127
extern const uint8_t FIRST_HIDDEN_MENU_ITEM;
@@ -154,7 +155,7 @@ extern const char gSubMenu_RX_TX[4][6];
154155
extern const char gSubMenu_AM_fix_test1[4][8];
155156
#endif
156157
extern const char gSubMenu_BAT_TXT[3][8];
157-
158+
extern const char gSubMenu_BATTYP[2][9];
158159
extern const char gSubMenu_SCRAMBLER[11][7];
159160

160161
typedef struct {char* name; uint8_t id;} t_sidefunction;

0 commit comments

Comments
 (0)