diff --git a/app/dtmf.c b/app/dtmf.c index 2b801ef..9437073 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -138,13 +138,14 @@ bool DTMF_ValidateCodes(char *pCode, const unsigned int size) #ifdef ENABLE_DTMF_CALLING bool DTMF_GetContact(const int Index, char *pContact) { - int i = -1; - if (Index >= 0 && Index < MAX_DTMF_CONTACTS && pContact != NULL) - { - EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16); - i = (int)pContact[0] - ' '; + if (Index < 0 || Index >= MAX_DTMF_CONTACTS || pContact == NULL) { + return false; } - return (i >= 0 && i < 95); + + EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16); + + // check whether the first character is printable or not + return (pContact[0] >= ' ' && pContact[0] < 127); } bool DTMF_FindContact(const char *pContact, char *pResult) @@ -331,13 +332,12 @@ void DTMF_HandleRequest(void) if (gDTMF_RX_index >= 2) { // look for ACK reply + char *pPrintStr = "AB"; - strcpy(String, "AB"); + Offset = gDTMF_RX_index - strlen(pPrintStr); - Offset = gDTMF_RX_index - strlen(String); - - if (CompareMessage(gDTMF_RX + Offset, String, strlen(String), true)) - { // ends with "AB" + if (CompareMessage(gDTMF_RX + Offset, pPrintStr, strlen(pPrintStr), true)) { + // ends with "AB" if (gDTMF_ReplyState != DTMF_REPLY_NONE) // 1of11 // if (gDTMF_CallState != DTMF_CALL_STATE_NONE) // 1of11 diff --git a/ui/aircopy.c b/ui/aircopy.c index 164c421..cc43997 100644 --- a/ui/aircopy.c +++ b/ui/aircopy.c @@ -29,18 +29,18 @@ void UI_DisplayAircopy(void) { - char String[16]; + char String[16] = {0}; + char *pPrintStr = { 0 }; - memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); + if (gAircopyState == AIRCOPY_READY) { + pPrintStr = "AIR COPY(RDY)"; + } else if (gAircopyState == AIRCOPY_TRANSFER) { + pPrintStr = "AIR COPY"; + } else { + pPrintStr = "AIR COPY(CMP)"; + } - if (gAircopyState == AIRCOPY_READY) - strcpy(String, "AIR COPY(RDY)"); - else - if (gAircopyState == AIRCOPY_TRANSFER) - strcpy(String, "AIR COPY"); - else - strcpy(String, "AIR COPY(CMP)"); - UI_PrintString(String, 2, 127, 0, 8); + UI_PrintString(pPrintStr, 2, 127, 0, 8); if (gInputBoxIndex == 0) { diff --git a/ui/fmradio.c b/ui/fmradio.c index d5b5fc8..a74ad73 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -30,82 +30,57 @@ void UI_DisplayFM(void) { - unsigned int i; - char String[16]; - + char String[16] = {0}; + char *pPrintStr = String; memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - memset(String, 0, sizeof(String)); - strcpy(String, "FM"); - UI_PrintString(String, 0, 127, 0, 12); + UI_PrintString("FM", 0, 127, 0, 12); - memset(String, 0, sizeof(String)); - if (gAskToSave) - { - strcpy(String, "SAVE?"); - } - else - if (gAskToDelete) - { - strcpy(String, "DEL?"); - } - else - { - if (gFM_ScanState == FM_SCAN_OFF) - { - if (!gEeprom.FM_IsMrMode) - { - for (i = 0; i < 20; i++) - { - if (gEeprom.FM_FrequencyPlaying == gFM_Channels[i]) - { - sprintf(String, "VFO(CH%02u)", i + 1); - break; - } + if (gAskToSave) { + pPrintStr = "SAVE?"; + } else if (gAskToDelete) { + pPrintStr = "DEL?"; + } else if (gFM_ScanState == FM_SCAN_OFF) { + if (gEeprom.FM_IsMrMode) { + sprintf(String, "MR(CH%02u)", gEeprom.FM_SelectedChannel + 1); + pPrintStr = String; + } else { + pPrintStr = "VFO"; + for (unsigned int i = 0; i < 20; i++) { + if (gEeprom.FM_FrequencyPlaying == gFM_Channels[i]) { + sprintf(String, "VFO(CH%02u)", i + 1); + pPrintStr = String; + break; } - - if (i == 20) - strcpy(String, "VFO"); } - else - sprintf(String, "MR(CH%02u)", gEeprom.FM_SelectedChannel + 1); - } - else - { - if (!gFM_AutoScan) - strcpy(String, "M-SCAN"); - else - sprintf(String, "A-SCAN(%u)", gFM_ChannelPosition + 1); } + } else if (gFM_AutoScan) { + sprintf(String, "A-SCAN(%u)", gFM_ChannelPosition + 1); + pPrintStr = String; + } else { + pPrintStr = "M-SCAN"; } - UI_PrintString(String, 0, 127, 2, 10); + + UI_PrintString(pPrintStr, 0, 127, 2, 10); memset(String, 0, sizeof(String)); - if (gAskToSave || (gEeprom.FM_IsMrMode && gInputBoxIndex > 0)) - { + if (gAskToSave || (gEeprom.FM_IsMrMode && gInputBoxIndex > 0)) { UI_GenerateChannelString(String, gFM_ChannelPosition); - } - else - if (!gAskToDelete) - { - if (gInputBoxIndex == 0) - { + } else if (gAskToDelete) { + sprintf(String, "CH-%02u", gEeprom.FM_SelectedChannel + 1); + } else { + if (gInputBoxIndex == 0) { sprintf(String, "%3d.%d", gEeprom.FM_FrequencyPlaying / 10, gEeprom.FM_FrequencyPlaying % 10); - UI_DisplayFrequency(String, 32, 4, true); - } - else { + } else { const char * ascii = INPUTBOX_GetAscii(); sprintf(String, "%.3s.%.1s",ascii, ascii + 3); - UI_DisplayFrequency(String, 32, 4, false); } + UI_DisplayFrequency(String, 32, 4, gInputBoxIndex == 0); ST7565_BlitFullScreen(); return; } - else - { - sprintf(String, "CH-%02u", gEeprom.FM_SelectedChannel + 1); - } + UI_PrintString(String, 0, 127, 4, 10); ST7565_BlitFullScreen(); diff --git a/ui/helper.c b/ui/helper.c index a9a3cc3..9005577 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -46,21 +46,23 @@ void UI_GenerateChannelString(char *pString, const uint8_t Channel) void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber) { - if (gInputBoxIndex > 0) - { - unsigned int i; - for (i = 0; i < 3; i++) + if (gInputBoxIndex > 0) { + for (unsigned int i = 0; i < 3; i++) { pString[i] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0'; + } + + pString[3] = 0; return; } - if (bShowPrefix) + if (bShowPrefix) { + // BUG here? Prefixed NULLs are allowed sprintf(pString, "CH-%03u", ChannelNumber + 1); - else - if (ChannelNumber == 0xFF) + } else if (ChannelNumber == 0xFF) { strcpy(pString, "NULL"); - else + } else { sprintf(pString, "%03u", ChannelNumber + 1); + } } void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width) @@ -112,10 +114,10 @@ void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_ { const size_t Length = strlen(pString); size_t i; - + if (End > Start) Start += (((End - Start) - (Length * 8)) + 1) / 2; - + const unsigned int char_width = ARRAY_SIZE(gFontSmallBold[0]); const unsigned int char_spacing = char_width + 1; uint8_t *pFb = gFrameBuffer[Line] + Start; @@ -171,7 +173,7 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center) *pFb1 = 0x60; pFb0++; pFb1++; continue; } - + } else if (center) { pFb0 -= 6; @@ -182,7 +184,7 @@ void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center) } } -void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black) +void UI_DrawPixelBuffer(uint8_t (*buffer)[128], uint8_t x, uint8_t y, bool black) { const uint8_t pattern = 1 << (y % 8); if(black) @@ -228,7 +230,7 @@ void UI_DrawRectangleBuffer(uint8_t (*buffer)[128], int16_t x1, int16_t y1, int1 UI_DrawLineBuffer(buffer, x1,y2, x2,y2, black); } -void UI_DisplayPopup(const char *string) +void UI_DisplayPopup(const char *string) { for(uint8_t i = 0; i < 7; i++) { memset(gFrameBuffer[i], 0x00, 128); diff --git a/ui/lock.c b/ui/lock.c index 71ab91f..a16e5d5 100644 --- a/ui/lock.c +++ b/ui/lock.c @@ -37,8 +37,7 @@ static void Render(void) memset(gStatusLine, 0, sizeof(gStatusLine)); memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - strcpy(String, "LOCK"); - UI_PrintString(String, 0, 127, 1, 10); + UI_PrintString("LOCK", 0, 127, 1, 10); for (i = 0; i < 6; i++) String[i] = (gInputBox[i] == 10) ? '-' : '*'; String[6] = 0; diff --git a/ui/main.c b/ui/main.c index 168934d..48050a9 100644 --- a/ui/main.c +++ b/ui/main.c @@ -773,8 +773,7 @@ void UI_DisplayMain(void) center_line = CENTER_LINE_DTMF_DEC; - strcpy(String, "DTMF "); - strcat(String, gDTMF_RX_live + idx); + sprintf(String, "DTMF %s", gDTMF_RX_live + idx); UI_PrintStringSmall(String, 2, 0, 3); } #else @@ -789,8 +788,7 @@ void UI_DisplayMain(void) center_line = CENTER_LINE_DTMF_DEC; - strcpy(String, "DTMF "); - strcat(String, gDTMF_RX + idx); + sprintf(String, "DTMF %s", gDTMF_RX_live + idx); UI_PrintStringSmall(String, 2, 0, 3); } #endif diff --git a/ui/menu.c b/ui/menu.c index 73fb848..90d0b95 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -475,9 +475,8 @@ void UI_DisplayMenu(void) else if (menu_index >= 0 && menu_index < (int)gMenuListCount) { // current menu item - strcpy(String, MenuList[menu_index].name); // strcat(String, ":"); - UI_PrintString(String, 0, 0, 0, 8); + UI_PrintString(MenuList[menu_index].name, 0, 0, 0, 8); // UI_PrintStringSmall(String, 0, 0, 0); } } @@ -675,24 +674,20 @@ void UI_DisplayMenu(void) if (!gIsInSubMenu || edit_index < 0) { // show the channel name SETTINGS_FetchChannelName(String, gSubMenuSelection); - if (String[0] == 0) - strcpy(String, "--"); - UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8); + char *pPrintStr = String[0] ? String : "--"; + UI_PrintString(pPrintStr, menu_item_x1, menu_item_x2, 2, 8); } else { // show the channel name being edited UI_PrintString(edit, menu_item_x1, 0, 2, 8); if (edit_index < 10) - UI_PrintString( "^", menu_item_x1 + (8 * edit_index), 0, 4, 8); // show the cursor + UI_PrintString("^", menu_item_x1 + (8 * edit_index), 0, 4, 8); // show the cursor } if (!gAskForConfirmation) { // show the frequency so that the user knows the channels frequency sprintf(String, "%u.%05u", frequency / 100000, frequency % 100000); - if (!gIsInSubMenu || edit_index < 0) - UI_PrintString(String, menu_item_x1, menu_item_x2, 4, 8); - else - UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); + UI_PrintString(String, menu_item_x1, menu_item_x2, 4 + (gIsInSubMenu && edit_index >= 0), 8); } } @@ -908,45 +903,34 @@ void UI_DisplayMenu(void) if (UI_MENU_GetCurrentMenuId() == MENU_SLIST1 || UI_MENU_GetCurrentMenuId() == MENU_SLIST2) { i = (UI_MENU_GetCurrentMenuId() == MENU_SLIST1) ? 0 : 1; + char *pPrintStr = String; -// if (gSubMenuSelection == 0xFF) - if (gSubMenuSelection < 0) - strcpy(String, "NULL"); - else + if (gSubMenuSelection < 0) { + pPrintStr = "NULL"; + } else { UI_GenerateChannelStringEx(String, true, gSubMenuSelection); - -// if (gSubMenuSelection == 0xFF || !gEeprom.SCAN_LIST_ENABLED[i]) - if (gSubMenuSelection < 0 || !gEeprom.SCAN_LIST_ENABLED[i]) - { - // channel number - UI_PrintString(String, menu_item_x1, menu_item_x2, 0, 8); - - // channel name - SETTINGS_FetchChannelName(String, gSubMenuSelection); - if (String[0] == 0) - strcpy(String, "--"); - UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8); + pPrintStr = String; } - else - { - // channel number - UI_PrintString(String, menu_item_x1, menu_item_x2, 0, 8); - // channel name - SETTINGS_FetchChannelName(String, gSubMenuSelection); - if (String[0] == 0) - strcpy(String, "--"); - UI_PrintStringSmall(String, menu_item_x1, menu_item_x2, 2); + // channel number + UI_PrintString(pPrintStr, menu_item_x1, menu_item_x2, 0, 8); - if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH1[i])) - { - sprintf(String, "PRI1:%u", gEeprom.SCANLIST_PRIORITY_CH1[i] + 1); + SETTINGS_FetchChannelName(String, gSubMenuSelection); + pPrintStr = String[0] ? String : "--"; + + // channel name and scan-list + if (gSubMenuSelection < 0 || !gEeprom.SCAN_LIST_ENABLED[i]) { + UI_PrintString(pPrintStr, menu_item_x1, menu_item_x2, 2, 8); + } else { + UI_PrintStringSmall(pPrintStr, menu_item_x1, menu_item_x2, 2); + + if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH1[i])) { + sprintf(String, "PRI%d:%u", 1, gEeprom.SCANLIST_PRIORITY_CH1[i] + 1); UI_PrintString(String, menu_item_x1, menu_item_x2, 3, 8); } - if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH2[i])) - { - sprintf(String, "PRI2:%u", gEeprom.SCANLIST_PRIORITY_CH2[i] + 1); + if (IS_MR_CHANNEL(gEeprom.SCANLIST_PRIORITY_CH2[i])) { + sprintf(String, "PRI%d:%u", 2, gEeprom.SCANLIST_PRIORITY_CH2[i] + 1); UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); } } @@ -958,20 +942,18 @@ void UI_DisplayMenu(void) { // display the channel name char s[11]; SETTINGS_FetchChannelName(s, gSubMenuSelection); - if (s[0] == 0) - strcpy(s, "--"); - UI_PrintString(s, menu_item_x1, menu_item_x2, 2, 8); + char *pPrintStr = s[0] ? s : "--"; + UI_PrintString(pPrintStr, menu_item_x1, menu_item_x2, 2, 8); } if ((UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || UI_MENU_GetCurrentMenuId() == MENU_R_DCS) && gCssBackgroundScan) UI_PrintString("SCAN", menu_item_x1, menu_item_x2, 4, 8); #ifdef ENABLE_DTMF_CALLING - if (UI_MENU_GetCurrentMenuId() == MENU_D_LIST && gIsDtmfContactValid) - { + if (UI_MENU_GetCurrentMenuId() == MENU_D_LIST && gIsDtmfContactValid) { Contact[11] = 0; memcpy(&gDTMF_ID, Contact + 8, 4); - sprintf(String, "ID:%s", Contact + 8); + sprintf(String, "ID:%4s", gDTMF_ID); UI_PrintString(String, menu_item_x1, menu_item_x2, 4, 8); } #endif @@ -983,9 +965,7 @@ void UI_DisplayMenu(void) #ifdef ENABLE_DTMF_CALLING || UI_MENU_GetCurrentMenuId() == MENU_D_LIST #endif - ) - - { + ) { sprintf(String, "%2d", gSubMenuSelection); UI_PrintStringSmall(String, 105, 0, 0); } @@ -995,8 +975,8 @@ void UI_DisplayMenu(void) UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME || UI_MENU_GetCurrentMenuId() == MENU_DEL_CH) && gAskForConfirmation) { // display confirmation - strcpy(String, (gAskForConfirmation == 1) ? "SURE?" : "WAIT!"); - UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); + char *pPrintStr = (gAskForConfirmation == 1) ? "SURE?" : "WAIT!"; + UI_PrintString(pPrintStr, menu_item_x1, menu_item_x2, 5, 8); } ST7565_BlitFullScreen(); diff --git a/ui/scanner.c b/ui/scanner.c index da9d3a8..302d2bd 100644 --- a/ui/scanner.c +++ b/ui/scanner.c @@ -26,56 +26,58 @@ void UI_DisplayScanner(void) { - char String[16]; - bool bCentered; + char String[16] = {0}; + char *pPrintStr = String; + bool bCentered; uint8_t Start; memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - memset(String, 0, sizeof(String)); - if (gScanSingleFrequency || (gScanCssState != SCAN_CSS_STATE_OFF && gScanCssState != SCAN_CSS_STATE_FAILED)) + if (gScanSingleFrequency || (gScanCssState != SCAN_CSS_STATE_OFF && gScanCssState != SCAN_CSS_STATE_FAILED)) { sprintf(String, "FREQ:%u.%05u", gScanFrequency / 100000, gScanFrequency % 100000); - else - strcpy(String, "FREQ:**.*****"); - UI_PrintString(String, 2, 0, 1, 8); + pPrintStr = String; + } else { + pPrintStr = "FREQ:**.*****"; + } - memset(String, 0, sizeof(String)); - if (gScanCssState < SCAN_CSS_STATE_FOUND || !gScanUseCssResult) - strcpy(String, "CTC:******"); - else - if (gScanCssResultType == CODE_TYPE_CONTINUOUS_TONE) + UI_PrintString(pPrintStr, 2, 0, 1, 8); + + if (gScanCssState < SCAN_CSS_STATE_FOUND || !gScanUseCssResult) { + pPrintStr = "CTC:******"; + } else if (gScanCssResultType == CODE_TYPE_CONTINUOUS_TONE) { sprintf(String, "CTC:%u.%uHz", CTCSS_Options[gScanCssResultCode] / 10, CTCSS_Options[gScanCssResultCode] % 10); - else + pPrintStr = String; + } else { sprintf(String, "DCS:D%03oN", DCS_Options[gScanCssResultCode]); - UI_PrintString(String, 2, 0, 3, 8); + pPrintStr = String; + } + UI_PrintString(pPrintStr, 2, 0, 3, 8); memset(String, 0, sizeof(String)); - if (gScannerSaveState == SCAN_SAVE_CHANNEL) - { - strcpy(String, "SAVE?"); - + if (gScannerSaveState == SCAN_SAVE_CHANNEL) { + pPrintStr = "SAVE?"; Start = 0; bCentered = 1; - } - else - { + } else { + Start = 2; + bCentered = 0; + if (gScannerSaveState == SCAN_SAVE_CHAN_SEL) { strcpy(String, "SAVE:"); UI_GenerateChannelStringEx(String + 5, gShowChPrefix, gScanChannel); - } - else if (gScanCssState < SCAN_CSS_STATE_FOUND) { + pPrintStr = String; + } else if (gScanCssState < SCAN_CSS_STATE_FOUND) { strcpy(String, "SCAN"); memset(String + 4, '.', (gScanProgressIndicator & 7) + 1); + pPrintStr = String; + } else if (gScanCssState == SCAN_CSS_STATE_FOUND) { + pPrintStr = "SCAN CMP."; + } else { + pPrintStr = "SCAN FAIL."; } - else if (gScanCssState == SCAN_CSS_STATE_FOUND) - strcpy(String, "SCAN CMP."); - else - strcpy(String, "SCAN FAIL."); - - Start = 2; - bCentered = 0; } - UI_PrintString(String, Start, bCentered ? 127 : 0, 5, 8); - + + UI_PrintString(pPrintStr, Start, bCentered ? 127 : 0, 5, 8); + ST7565_BlitFullScreen(); }