From 1d95737088210569b4af761e95e43301d344d718 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Thu, 19 Oct 2023 14:26:27 +0200 Subject: [PATCH] Refactoring, cleanup, comments --- app/main.c | 1 - misc.c | 3 --- misc.h | 2 +- radio.c | 9 ++++++--- radio.h | 8 ++++++++ settings.h | 6 ++++++ ui/main.c | 44 +++++++++++++++----------------------------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/app/main.c b/app/main.c index 67a830f..c1acbc1 100644 --- a/app/main.c +++ b/app/main.c @@ -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); diff --git a/misc.c b/misc.c index d39c1b2..76b6a21 100644 --- a/misc.c +++ b/misc.c @@ -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}; diff --git a/misc.h b/misc.h index 17e75c2..85c12cb 100644 --- a/misc.h +++ b/misc.h @@ -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; diff --git a/radio.c b/radio.c index 2927daf..d2eae78 100644 --- a/radio.c +++ b/radio.c @@ -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; diff --git a/radio.h b/radio.h index e1d03da..70f0fad 100644 --- a/radio.h +++ b/radio.h @@ -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; diff --git a/settings.h b/settings.h index 0d30239..7b3f3c9 100644 --- a/settings.h +++ b/settings.h @@ -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; diff --git a/ui/main.c b/ui/main.c index 308ac67..e2b3186 100644 --- a/ui/main.c +++ b/ui/main.c @@ -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