Refactoring, cleanup, comments

This commit is contained in:
Krzysiek Egzmont 2023-10-19 14:26:27 +02:00
parent 2f7042056a
commit 1d95737088
7 changed files with 36 additions and 37 deletions

View File

@ -589,7 +589,6 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
gEeprom.ScreenChannel[vfo] = channel;
gEeprom.VfoInfo[vfo].CHANNEL_SAVE = channel;
gEeprom.TX_VFO = vfo;
RADIO_SelectVfos();
RADIO_ApplyOffset(gRxVfo);

3
misc.c
View File

@ -73,9 +73,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};

2
misc.h
View File

@ -280,7 +280,7 @@ extern ReceptionMode_t gRxReceptionMode;
extern scan_next_chan_t gCurrentScanList;
extern uint32_t gRestoreFrequency;
extern bool gRxVfoIsActive;
extern bool gRxVfoIsActive; //TRUE when dual watch is momentarly suspended and RX_VFO is locked to either last TX or RX
extern uint8_t gAlarmToneCounter;
extern uint16_t gAlarmRunningCounter;
extern bool gKeyBeingHeld;

View File

@ -555,11 +555,15 @@ void RADIO_ApplyOffset(VFO_Info_t *pInfo)
static void RADIO_SelectCurrentVfo(void)
{
gCurrentVfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gRxVfo : &gEeprom.VfoInfo[gEeprom.TX_VFO];
// if crossband is active the current is gTxVfo (gTxVfo/TX_VFO is only ever changed by the user)
// otherwise it is set to gRxVfo (gRxVfo/RX_VFO is equal to TX when dual watch is turned off)
// so in the end gCurrentVfo is equal to gTxVfo unless dual watch changes it on incomming transmition (again, this can only happen when XB off)
gCurrentVfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gRxVfo : gTxVfo;
}
void RADIO_SelectVfos(void)
{
// if crossband is used then RX_VFO is the opposite to the TX_VFO
gEeprom.RX_VFO = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gEeprom.TX_VFO : !gEeprom.TX_VFO;
gTxVfo = &gEeprom.VfoInfo[gEeprom.TX_VFO];
@ -923,10 +927,9 @@ void RADIO_PrepareTX(void)
if (!gRxVfoIsActive)
{ // use the current RX vfo
gEeprom.RX_VFO = gEeprom.TX_VFO;
gRxVfo = &gEeprom.VfoInfo[gEeprom.TX_VFO];
gRxVfo = gTxVfo;
gRxVfoIsActive = true;
}
gCurrentVfo = gRxVfo;
// let the user see that DW is not active
gDualWatchActive = false;

View File

@ -115,8 +115,16 @@ typedef struct VFO_Info_t
char Name[16];
} VFO_Info_t;
// Settings of the main VFO that is selected by the user
// The pointer follows gEeprom.RX_VFO index
extern VFO_Info_t *gTxVfo;
// Settings of the actual VFO that is now used for RX,
// It is being alternated by dual watch, and flipped by crossband
// The pointer follows gEeprom.RX_VFO
extern VFO_Info_t *gRxVfo;
// Equal to gTxVfo unless dual watch changes it on incomming transmition (this can only happen when XB off and DW on)
extern VFO_Info_t *gCurrentVfo;
extern DCS_CodeType_t gSelectedCodeType;

View File

@ -121,7 +121,13 @@ typedef struct {
#ifdef ENABLE_NOAA
uint8_t NoaaChannel[2];
#endif
// The actual VFO index (0-upper/1-lower) that is now used for RX,
// It is being alternated by dual watch, and flipped by crossband
uint8_t RX_VFO;
// The main VFO index (0-upper/1-lower) selected by the user
//
uint8_t TX_VFO;
uint8_t field7_0xa;

View File

@ -277,12 +277,6 @@ void UI_DisplayMain(void)
center_line = CENTER_LINE_NONE;
// #ifdef SINGLE_VFO_CHAN
// const bool single_vfo = (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? true : false;
// #else
const bool single_vfo = false;
// #endif
// clear the screen
memset(gFrameBuffer, 0, sizeof(gFrameBuffer));
@ -293,23 +287,17 @@ void UI_DisplayMain(void)
ST7565_BlitFullScreen();
return;
}
// dual watch turned on and locked
unsigned int activeTxVFO = (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gRxVfoIsActive) ? gEeprom.RX_VFO : gEeprom.TX_VFO;
for (vfo_num = 0; vfo_num < 2; vfo_num++)
{
const unsigned int line = (vfo_num == 0) ? line0 : line1;
const bool isTxVFO = (vfo_num == gEeprom.TX_VFO);
const bool isSelectedVFO = (vfo_num == gEeprom.TX_VFO);
uint8_t *p_line0 = gFrameBuffer[line + 0];
uint8_t *p_line1 = gFrameBuffer[line + 1];
unsigned int mode = 0;
if (single_vfo)
{ // we're in single VFO mode - screen is dedicated to just one VFO
if (!isTxVFO)
continue; // skip the unused vfo
}
if (activeTxVFO != vfo_num)
{
if (gDTMF_CallState != DTMF_CALL_STATE_NONE || gDTMF_IsTx || gDTMF_InputMode)
@ -355,12 +343,12 @@ void UI_DisplayMain(void)
}
// highlight the selected/used VFO with a marker
if (!single_vfo && isTxVFO)
if (isSelectedVFO)
memmove(p_line0 + 0, BITMAP_VFO_Default, sizeof(BITMAP_VFO_Default));
}
else if (!single_vfo)
else
{ // highlight the selected/used VFO with a marker
if (isTxVFO)
if (isSelectedVFO)
memmove(p_line0 + 0, BITMAP_VFO_Default, sizeof(BITMAP_VFO_Default));
else
memmove(p_line0 + 0, BITMAP_VFO_NotDefault, sizeof(BITMAP_VFO_NotDefault));
@ -369,11 +357,11 @@ void UI_DisplayMain(void)
if (gCurrentFunction == FUNCTION_TRANSMIT)
{ // transmitting
#ifdef ENABLE_ALARM
if (gAlarmState == ALARM_STATE_ALARM)
mode = 2;
else
#endif
#ifdef ENABLE_ALARM
if (gAlarmState == ALARM_STATE_ALARM)
mode = 2;
else
#endif
{
activeTxVFO = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gEeprom.RX_VFO : gEeprom.TX_VFO;
if (activeTxVFO == vfo_num)
@ -418,7 +406,8 @@ void UI_DisplayMain(void)
{ // frequency mode
// show the frequency band number
const unsigned int x = 2;
sprintf(String, "FB%u", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST);
char * buf = gEeprom.VfoInfo[vfo_num].pRX->Frequency < 100000000 ? "" : "+";
sprintf(String, "F%u%s", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST, buf);
UI_PrintStringSmall(String, x, 0, line + 1);
}
#ifdef ENABLE_NOAA
@ -461,8 +450,6 @@ void UI_DisplayMain(void)
const char * ascii = INPUTBOX_GetAscii();
sprintf(String, "%.3s.%.3s", ascii, ascii + 3);
UI_DisplayFrequency(String, 32, line, false);
// center_line = CENTER_LINE_IN_USE;
}
else
{
@ -477,22 +464,21 @@ void UI_DisplayMain(void)
if (gEeprom.ScreenChannel[vfo_num] <= MR_CHANNEL_LAST)
{ // it's a channel
// show the channel symbols
// show the scan list assigment symbols
const uint8_t attributes = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]];
if (attributes & MR_CH_SCANLIST1)
memmove(p_line0 + 113, BITMAP_ScanList1, sizeof(BITMAP_ScanList1));
if (attributes & MR_CH_SCANLIST2)
memmove(p_line0 + 120, BITMAP_ScanList2, sizeof(BITMAP_ScanList2));
// compander symbol
#ifndef ENABLE_BIG_FREQ
if ((attributes & MR_CH_COMPAND) > 0)
memmove(p_line0 + 120 + LCD_WIDTH, BITMAP_compand, sizeof(BITMAP_compand));
#else
// TODO: // find somewhere else to put the symbol
#endif
switch (gEeprom.CHANNEL_DISPLAY_MODE)
{
case MDF_FREQUENCY: // show the channel frequency