Check tab only...

This commit is contained in:
Armel FAUVEAU
2024-08-16 00:11:09 +02:00
parent 7c53df8d2b
commit 74862d1ac2
95 changed files with 15257 additions and 15258 deletions

View File

@@ -40,207 +40,207 @@ bool gLowBatteryConfirmed;
uint16_t gBatteryCheckCounter;
typedef enum {
BATTERY_LOW_INACTIVE,
BATTERY_LOW_ACTIVE,
BATTERY_LOW_CONFIRMED
BATTERY_LOW_INACTIVE,
BATTERY_LOW_ACTIVE,
BATTERY_LOW_CONFIRMED
} BatteryLow_t;
uint16_t lowBatteryCountdown;
const uint16_t lowBatteryPeriod = 30;
const uint16_t lowBatteryPeriod = 30;
volatile uint16_t gPowerSave_10ms;
const uint16_t Voltage2PercentageTable[][7][3] = {
[BATTERY_TYPE_1600_MAH] = {
{828, 100},
{814, 97 },
{760, 25 },
{729, 6 },
{630, 0 },
{0, 0 },
{0, 0 },
},
[BATTERY_TYPE_1600_MAH] = {
{828, 100},
{814, 97 },
{760, 25 },
{729, 6 },
{630, 0 },
{0, 0 },
{0, 0 },
},
[BATTERY_TYPE_2200_MAH] = {
{832, 100},
{813, 95 },
{740, 60 },
{707, 21 },
{682, 5 },
{630, 0 },
{0, 0 },
},
[BATTERY_TYPE_2200_MAH] = {
{832, 100},
{813, 95 },
{740, 60 },
{707, 21 },
{682, 5 },
{630, 0 },
{0, 0 },
},
[BATTERY_TYPE_3500_MAH] = {
{837, 100},
{826, 95 },
{750, 50 },
{700, 25 },
{620, 5 },
{600, 0 },
{0, 0 },
},
[BATTERY_TYPE_3500_MAH] = {
{837, 100},
{826, 95 },
{750, 50 },
{700, 25 },
{620, 5 },
{600, 0 },
{0, 0 },
},
};
static_assert(
(ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_1600_MAH]) ==
ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH])) &&
(ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH]) ==
ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_3500_MAH]))
);
(ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_1600_MAH]) ==
ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH])) &&
(ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH]) ==
ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_3500_MAH]))
);
unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
{
const uint16_t (*crv)[3] = Voltage2PercentageTable[gEeprom.BATTERY_TYPE];
const int mulipl = 1000;
for (unsigned int i = 1; i < ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH]); i++) {
if (voltage_10mV > crv[i][0]) {
const int a = (crv[i - 1][1] - crv[i][1]) * mulipl / (crv[i - 1][0] - crv[i][0]);
const int b = crv[i][1] - a * crv[i][0] / mulipl;
const int p = a * voltage_10mV / mulipl + b;
return MIN(p, 100);
}
}
const uint16_t (*crv)[3] = Voltage2PercentageTable[gEeprom.BATTERY_TYPE];
const int mulipl = 1000;
for (unsigned int i = 1; i < ARRAY_SIZE(Voltage2PercentageTable[BATTERY_TYPE_2200_MAH]); i++) {
if (voltage_10mV > crv[i][0]) {
const int a = (crv[i - 1][1] - crv[i][1]) * mulipl / (crv[i - 1][0] - crv[i][0]);
const int b = crv[i][1] - a * crv[i][0] / mulipl;
const int p = a * voltage_10mV / mulipl + b;
return MIN(p, 100);
}
}
return 0;
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;
const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel;
const uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4;
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
if(gBatteryVoltageAverage > 890)
gBatteryDisplayLevel = 7; // battery overvoltage
else if(gBatteryVoltageAverage < 630 && (gEeprom.BATTERY_TYPE == BATTERY_TYPE_1600_MAH || gEeprom.BATTERY_TYPE == BATTERY_TYPE_2200_MAH))
gBatteryDisplayLevel = 0; // battery critical
else if(gBatteryVoltageAverage < 600 && (gEeprom.BATTERY_TYPE == BATTERY_TYPE_3500_MAH))
gBatteryDisplayLevel = 0; // battery critical
else {
gBatteryDisplayLevel = 1;
const uint8_t levels[] = {5,17,41,65,88};
uint8_t perc = BATTERY_VoltsToPercent(gBatteryVoltageAverage);
//char str[64];
//LogUart("----------\n");
//sprintf(str, "%d %d %d %d %d %d %d\n", gBatteryVoltages[0], gBatteryVoltages[1], gBatteryVoltages[2], gBatteryVoltages[3], Voltage, gBatteryVoltageAverage, perc);
//LogUart(str);
if(gBatteryVoltageAverage > 890)
gBatteryDisplayLevel = 7; // battery overvoltage
else if(gBatteryVoltageAverage < 630 && (gEeprom.BATTERY_TYPE == BATTERY_TYPE_1600_MAH || gEeprom.BATTERY_TYPE == BATTERY_TYPE_2200_MAH))
gBatteryDisplayLevel = 0; // battery critical
else if(gBatteryVoltageAverage < 600 && (gEeprom.BATTERY_TYPE == BATTERY_TYPE_3500_MAH))
gBatteryDisplayLevel = 0; // battery critical
else {
gBatteryDisplayLevel = 1;
const uint8_t levels[] = {5,17,41,65,88};
uint8_t perc = BATTERY_VoltsToPercent(gBatteryVoltageAverage);
//char str[64];
//LogUart("----------\n");
//sprintf(str, "%d %d %d %d %d %d %d\n", gBatteryVoltages[0], gBatteryVoltages[1], gBatteryVoltages[2], gBatteryVoltages[3], Voltage, gBatteryVoltageAverage, perc);
//LogUart(str);
for(uint8_t i = 6; i >= 2; i--){
//sprintf(str, "%d %d %d\n", perc, levels[i-2], i);
//LogUart(str);
if (perc > levels[i-2]) {
gBatteryDisplayLevel = i;
break;
}
}
}
for(uint8_t i = 6; i >= 2; i--){
//sprintf(str, "%d %d %d\n", perc, levels[i-2], i);
//LogUart(str);
if (perc > levels[i-2]) {
gBatteryDisplayLevel = i;
break;
}
}
}
if ((gScreenToDisplay == DISPLAY_MENU) && UI_MENU_GetCurrentMenuId() == MENU_VOL)
gUpdateDisplay = true;
if ((gScreenToDisplay == DISPLAY_MENU) && UI_MENU_GetCurrentMenuId() == MENU_VOL)
gUpdateDisplay = true;
if (gBatteryCurrent < 501)
{
if (gChargingWithTypeC)
{
gUpdateStatus = true;
gUpdateDisplay = true;
}
if (gBatteryCurrent < 501)
{
if (gChargingWithTypeC)
{
gUpdateStatus = true;
gUpdateDisplay = true;
}
gChargingWithTypeC = false;
}
else
{
if (!gChargingWithTypeC)
{
gUpdateStatus = true;
gUpdateDisplay = true;
BACKLIGHT_TurnOn();
}
gChargingWithTypeC = false;
}
else
{
if (!gChargingWithTypeC)
{
gUpdateStatus = true;
gUpdateDisplay = true;
BACKLIGHT_TurnOn();
}
gChargingWithTypeC = true;
}
gChargingWithTypeC = true;
}
if (PreviousBatteryLevel != gBatteryDisplayLevel)
{
if(gBatteryDisplayLevel > 2)
gLowBatteryConfirmed = false;
else if (gBatteryDisplayLevel < 2)
{
gLowBattery = true;
}
else
{
gLowBattery = false;
if (PreviousBatteryLevel != gBatteryDisplayLevel)
{
if(gBatteryDisplayLevel > 2)
gLowBatteryConfirmed = false;
else if (gBatteryDisplayLevel < 2)
{
gLowBattery = true;
}
else
{
gLowBattery = false;
if (bDisplayBatteryLevel)
UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink);
}
if (bDisplayBatteryLevel)
UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink);
}
if(!gLowBatteryConfirmed)
gUpdateDisplay = true;
if(!gLowBatteryConfirmed)
gUpdateDisplay = true;
lowBatteryCountdown = 0;
}
lowBatteryCountdown = 0;
}
}
void BATTERY_TimeSlice500ms(void)
{
if (!gLowBattery) {
return;
}
if (!gLowBattery) {
return;
}
gLowBatteryBlink = ++lowBatteryCountdown & 1;
gLowBatteryBlink = ++lowBatteryCountdown & 1;
UI_DisplayBattery(0, gLowBatteryBlink);
UI_DisplayBattery(0, gLowBatteryBlink);
if (gCurrentFunction == FUNCTION_TRANSMIT) {
return;
}
if (gCurrentFunction == FUNCTION_TRANSMIT) {
return;
}
// not transmitting
// not transmitting
if (lowBatteryCountdown < lowBatteryPeriod) {
if (lowBatteryCountdown == lowBatteryPeriod-1 && !gChargingWithTypeC && !gLowBatteryConfirmed) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
}
return;
}
if (lowBatteryCountdown < lowBatteryPeriod) {
if (lowBatteryCountdown == lowBatteryPeriod-1 && !gChargingWithTypeC && !gLowBatteryConfirmed) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
}
return;
}
lowBatteryCountdown = 0;
lowBatteryCountdown = 0;
if (gChargingWithTypeC) {
return;
}
if (gChargingWithTypeC) {
return;
}
// not on charge
if (!gLowBatteryConfirmed) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
// not on charge
if (!gLowBatteryConfirmed) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE);
AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE);
#endif
}
}
if (gBatteryDisplayLevel != 0) {
if (gBatteryDisplayLevel != 0) {
#ifdef ENABLE_VOICE
AUDIO_PlaySingleVoice(false);
AUDIO_PlaySingleVoice(false);
#endif
return;
}
return;
}
#ifdef ENABLE_VOICE
AUDIO_PlaySingleVoice(true);
AUDIO_PlaySingleVoice(true);
#endif
gReducedService = true;
gReducedService = true;
FUNCTION_Select(FUNCTION_POWER_SAVE);
FUNCTION_Select(FUNCTION_POWER_SAVE);
ST7565_HardwareReset();
ST7565_HardwareReset();
if (gEeprom.BACKLIGHT_TIME < 61) {
BACKLIGHT_TurnOff();
}
if (gEeprom.BACKLIGHT_TIME < 61) {
BACKLIGHT_TurnOff();
}
}

View File

@@ -17,7 +17,7 @@
#include <string.h>
#ifdef ENABLE_AIRCOPY
#include "app/aircopy.h"
#include "app/aircopy.h"
#endif
#include "bsp/dp32g030/gpio.h"
#include "driver/bk4819.h"
@@ -33,81 +33,81 @@
BOOT_Mode_t BOOT_GetMode(void)
{
unsigned int i;
KEY_Code_t Keys[2];
unsigned int i;
KEY_Code_t Keys[2];
for (i = 0; i < 2; i++)
{
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT))
return BOOT_MODE_NORMAL; // PTT not pressed
Keys[i] = KEYBOARD_Poll();
SYSTEM_DelayMs(20);
}
for (i = 0; i < 2; i++)
{
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT))
return BOOT_MODE_NORMAL; // PTT not pressed
Keys[i] = KEYBOARD_Poll();
SYSTEM_DelayMs(20);
}
if (Keys[0] == Keys[1])
{
gKeyReading0 = Keys[0];
gKeyReading1 = Keys[0];
if (Keys[0] == Keys[1])
{
gKeyReading0 = Keys[0];
gKeyReading1 = Keys[0];
gDebounceCounter = 2;
gDebounceCounter = 2;
if (Keys[0] == KEY_SIDE1)
return BOOT_MODE_F_LOCK;
if (Keys[0] == KEY_SIDE1)
return BOOT_MODE_F_LOCK;
#ifdef ENABLE_AIRCOPY
if (Keys[0] == KEY_SIDE2)
return BOOT_MODE_AIRCOPY;
#endif
}
#ifdef ENABLE_AIRCOPY
if (Keys[0] == KEY_SIDE2)
return BOOT_MODE_AIRCOPY;
#endif
}
return BOOT_MODE_NORMAL;
return BOOT_MODE_NORMAL;
}
void BOOT_ProcessMode(BOOT_Mode_t Mode)
{
if (Mode == BOOT_MODE_F_LOCK)
{
GUI_SelectNextDisplay(DISPLAY_MENU);
}
#ifdef ENABLE_AIRCOPY
else
if (Mode == BOOT_MODE_AIRCOPY)
{
gEeprom.DUAL_WATCH = DUAL_WATCH_OFF;
gEeprom.BATTERY_SAVE = 0;
#ifdef ENABLE_VOX
gEeprom.VOX_SWITCH = false;
#endif
gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
gEeprom.AUTO_KEYPAD_LOCK = false;
gEeprom.KEY_1_SHORT_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_1_LONG_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_2_SHORT_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_2_LONG_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_M_LONG_PRESS_ACTION = ACTION_OPT_NONE;
if (Mode == BOOT_MODE_F_LOCK)
{
GUI_SelectNextDisplay(DISPLAY_MENU);
}
#ifdef ENABLE_AIRCOPY
else
if (Mode == BOOT_MODE_AIRCOPY)
{
gEeprom.DUAL_WATCH = DUAL_WATCH_OFF;
gEeprom.BATTERY_SAVE = 0;
#ifdef ENABLE_VOX
gEeprom.VOX_SWITCH = false;
#endif
gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
gEeprom.AUTO_KEYPAD_LOCK = false;
gEeprom.KEY_1_SHORT_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_1_LONG_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_2_SHORT_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_2_LONG_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_M_LONG_PRESS_ACTION = ACTION_OPT_NONE;
RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_LAST - 1, 43400000); // LPD
RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_LAST - 1, 43400000); // LPD
gRxVfo->CHANNEL_BANDWIDTH = BANDWIDTH_NARROW;
gRxVfo->OUTPUT_POWER = OUTPUT_POWER_LOW1;
gRxVfo->CHANNEL_BANDWIDTH = BANDWIDTH_NARROW;
gRxVfo->OUTPUT_POWER = OUTPUT_POWER_LOW1;
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
gCurrentVfo = gRxVfo;
gCurrentVfo = gRxVfo;
RADIO_SetupRegisters(true);
BK4819_SetupAircopy();
BK4819_ResetFSK();
RADIO_SetupRegisters(true);
BK4819_SetupAircopy();
BK4819_ResetFSK();
gAircopyState = AIRCOPY_READY;
gAircopyState = AIRCOPY_READY;
gEeprom.BACKLIGHT_TIME = 61;
gEeprom.BACKLIGHT_TIME = 61;
GUI_SelectNextDisplay(DISPLAY_AIRCOPY);
}
#endif
else
{
GUI_SelectNextDisplay(DISPLAY_MAIN);
}
GUI_SelectNextDisplay(DISPLAY_AIRCOPY);
}
#endif
else
{
GUI_SelectNextDisplay(DISPLAY_MAIN);
}
}

View File

@@ -22,11 +22,11 @@
enum BOOT_Mode_t
{
BOOT_MODE_NORMAL = 0,
BOOT_MODE_F_LOCK,
#ifdef ENABLE_AIRCOPY
BOOT_MODE_AIRCOPY
#endif
BOOT_MODE_NORMAL = 0,
BOOT_MODE_F_LOCK,
#ifdef ENABLE_AIRCOPY
BOOT_MODE_AIRCOPY
#endif
};
typedef enum BOOT_Mode_t BOOT_Mode_t;