mirror of
https://github.com/kamilsss655/uv-k5-firmware-custom
synced 2024-11-22 02:08:48 +00:00
Refactor and introduce new shared helper function GetSLevelAttributes to unify S-level representations.
This commit is contained in:
parent
59412c9f42
commit
5581e03c7c
@ -134,8 +134,6 @@ static uint8_t DBm2S(int dbm) {
|
||||
return i;
|
||||
}
|
||||
|
||||
static int Rssi2DBm(uint16_t rssi) { return (rssi >> 1) - 160; }
|
||||
|
||||
static uint16_t GetRegMenuValue(uint8_t st) {
|
||||
RegisterSpec s = registerSpecs[st];
|
||||
return (BK4819_ReadRegister(s.num) >> s.offset) & s.mask;
|
||||
|
22
misc.c
22
misc.c
@ -294,3 +294,25 @@ bool IsValueInArray(int val, const int *arr, const int size) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
sLevelAttributes GetSLevelAttributes(const int16_t rssi, const uint32_t frequency)
|
||||
{
|
||||
sLevelAttributes att;
|
||||
// S0 .. base level
|
||||
int16_t s0_dBm = -130;
|
||||
|
||||
// adjust S-level for bands above HF
|
||||
if(frequency > HF_FREQUENCY)
|
||||
s0_dBm-=20;
|
||||
|
||||
att.dBmRssi = Rssi2DBm(rssi);
|
||||
att.sLevel = MIN(MAX((att.dBmRssi - s0_dBm) / 6, 0), 9);
|
||||
att.over = MIN(MAX(att.dBmRssi - (s0_dBm + 9*6), 0), 99);
|
||||
|
||||
return att;
|
||||
}
|
||||
|
||||
int Rssi2DBm(uint16_t rssi)
|
||||
{
|
||||
return (rssi >> 1) - 160;
|
||||
}
|
9
misc.h
9
misc.h
@ -205,6 +205,13 @@ extern ChannelFrequencyAttributes gMR_ChannelFrequencyAttributes[200];
|
||||
|
||||
extern ChannelAttributes_t gMR_ChannelAttributes[207];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t sLevel;
|
||||
uint8_t over;
|
||||
int dBmRssi;
|
||||
} __attribute__((packed)) sLevelAttributes;
|
||||
|
||||
extern volatile uint16_t gBatterySaveCountdown_10ms;
|
||||
|
||||
extern volatile bool gPowerSaveCountdownExpired;
|
||||
@ -354,6 +361,8 @@ int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit,
|
||||
unsigned long StrToUL(const char * str);
|
||||
|
||||
bool IsValueInArray(int val, const int *arr, const int size);
|
||||
sLevelAttributes GetSLevelAttributes (const int16_t rssi, const uint32_t frequency);
|
||||
int Rssi2DBm(uint16_t rssi);
|
||||
|
||||
#endif
|
||||
|
||||
|
18
ui/main.c
18
ui/main.c
@ -176,29 +176,23 @@ static void DisplayRSSIBar(const int16_t rssi, const bool now)
|
||||
if (now)
|
||||
memset(p_line, 0, LCD_WIDTH);
|
||||
|
||||
int16_t s0_dBm = -130; // S0 .. base level
|
||||
sLevelAttributes sLevelAtt;
|
||||
|
||||
// adjust S-level for bands above HF
|
||||
if(gRxVfo->freq_config_RX.Frequency > HF_FREQUENCY)
|
||||
s0_dBm-=20;
|
||||
sLevelAtt = GetSLevelAttributes(rssi, gRxVfo->freq_config_RX.Frequency);
|
||||
|
||||
const int16_t rssi_dBm = (rssi / 2) - 160;
|
||||
|
||||
const uint8_t s_level = MIN(MAX((rssi_dBm - s0_dBm) / 6, 0), 9); // S0 - S9
|
||||
uint8_t overS9dBm = MIN(MAX(rssi_dBm - (s0_dBm + 9*6), 0), 99);
|
||||
uint8_t overS9Bars = MIN(overS9dBm/10, 4);
|
||||
uint8_t overS9Bars = MIN(sLevelAtt.over/10, 4);
|
||||
|
||||
if(overS9Bars == 0) {
|
||||
sprintf(str, "% 4d S%d", rssi_dBm, s_level);
|
||||
sprintf(str, "% 4d S%d", sLevelAtt.dBmRssi, sLevelAtt.sLevel);
|
||||
}
|
||||
else {
|
||||
sprintf(str, "% 4d %2d", rssi_dBm, overS9dBm);
|
||||
sprintf(str, "% 4d %2d", sLevelAtt.dBmRssi, sLevelAtt.over);
|
||||
memcpy(p_line + 2 + 7*5, &plus, ARRAY_SIZE(plus));
|
||||
}
|
||||
|
||||
UI_PrintStringSmall(str, 2, 0, line);
|
||||
|
||||
DrawLevelBar(bar_x, line, s_level + overS9Bars);
|
||||
DrawLevelBar(bar_x, line, sLevelAtt.sLevel + overS9Bars);
|
||||
}
|
||||
#else
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user