From 05382584f4de463b9e7da1865f21ce624b604e21 Mon Sep 17 00:00:00 2001 From: Dual Tachyon Date: Mon, 28 Aug 2023 20:13:33 +0100 Subject: [PATCH] More restructuring of functions and variables. --- Makefile | 8 +- app/app.c | 10 +- app/generic.c | 3 +- app/main.c | 2 +- app/menu.c | 2 +- audio.c | 2 +- board.c | 2 +- driver/keyboard.c | 5 + driver/keyboard.h | 8 + functions.c | 7 +- gui.c | 306 ---------------------------------- helper.c | 8 +- helper.h | 4 - battery.c => helper/battery.c | 5 +- battery.h => helper/battery.h | 0 main.c | 9 +- misc.c | 4 +- misc.h | 4 +- radio.c | 2 +- scheduler.c | 3 +- ui/battery.c | 53 ++++++ ui/battery.h | 26 +++ ui/fmradio.c | 2 +- ui/lock.c | 122 ++++++++++++++ ui/lock.h | 23 +++ ui/menu.c | 14 +- ui/rssi.c | 2 +- ui/scanner.c | 1 - ui/status.c | 81 +++++++++ ui/status.h | 23 +++ ui/ui.c | 82 +++++++++ gui.h => ui/ui.h | 9 - ui/welcome.c | 52 ++++++ ui/welcome.h | 23 +++ 34 files changed, 542 insertions(+), 365 deletions(-) delete mode 100644 gui.c rename battery.c => helper/battery.c (96%) rename battery.h => helper/battery.h (100%) create mode 100644 ui/battery.c create mode 100644 ui/battery.h create mode 100644 ui/lock.c create mode 100644 ui/lock.h create mode 100644 ui/status.c create mode 100644 ui/status.h create mode 100644 ui/ui.c rename gui.h => ui/ui.h (82%) create mode 100644 ui/welcome.c create mode 100644 ui/welcome.h diff --git a/Makefile b/Makefile index 8f680ff..a8de88e 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,6 @@ OBJS += app/generic.o OBJS += app/main.o OBJS += app/menu.o OBJS += audio.o -OBJS += battery.o OBJS += bitmaps.o OBJS += board.o OBJS += dcs.o @@ -49,20 +48,25 @@ OBJS += fm.o OBJS += font.o OBJS += frequencies.o OBJS += functions.o -OBJS += gui.o OBJS += helper.o +OBJS += helper/battery.o OBJS += misc.o OBJS += radio.o OBJS += scheduler.o OBJS += settings.o OBJS += ui/aircopy.o +OBJS += ui/battery.o OBJS += ui/fmradio.o OBJS += ui/helper.o OBJS += ui/inputbox.o +OBJS += ui/lock.o OBJS += ui/main.o OBJS += ui/menu.o OBJS += ui/rssi.o OBJS += ui/scanner.o +OBJS += ui/status.o +OBJS += ui/ui.o +OBJS += ui/welcome.o OBJS += main.o diff --git a/app/app.c b/app/app.c index 87242e9..5b34b54 100644 --- a/app/app.c +++ b/app/app.c @@ -21,7 +21,6 @@ #include "app/main.h" #include "app/menu.h" #include "audio.h" -#include "battery.h" #include "board.h" #include "bsp/dp32g030/gpio.h" #include "driver/backlight.h" @@ -36,15 +35,18 @@ #include "fm.h" #include "frequencies.h" #include "functions.h" -#include "gui.h" #include "helper.h" +#include "helper/battery.h" #include "misc.h" #include "radio.h" #include "settings.h" #include "sram-overlay.h" +#include "ui/battery.h" #include "ui/inputbox.h" #include "ui/menu.h" #include "ui/rssi.h" +#include "ui/status.h" +#include "ui/ui.h" static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); void FUN_000069f8(FUNCTION_Type_t Function); @@ -1047,7 +1049,7 @@ void APP_TimeSlice10ms(void) if (gCurrentFunction != FUNCTION_TRANSMIT) { if (g_2000036F == 1) { - GUI_DisplayStatusLine(); + UI_DisplayStatus(); g_2000036F = 0; } if (gUpdateDisplay) { @@ -1291,7 +1293,7 @@ LAB_00004b08: if (gLowBattery) { gLowBatteryBlink = ++g_20000400 & 1; - GUI_DisplayBatteryLevel(g_20000400); + UI_DisplayBattery(g_20000400); if (gCurrentFunction != FUNCTION_TRANSMIT) { if (g_20000400 < 30) { if (g_20000400 == 29 && gChargingWithTypeC == false) { diff --git a/app/generic.c b/app/generic.c index 0b0a0b2..43c9e42 100644 --- a/app/generic.c +++ b/app/generic.c @@ -1,13 +1,14 @@ #include "app/generic.h" #include "audio.h" +#include "driver/keyboard.h" #include "dtmf.h" #include "external/printf/printf.h" #include "fm.h" #include "functions.h" -#include "gui.h" #include "misc.h" #include "settings.h" #include "ui/inputbox.h" +#include "ui/ui.h" extern void FUN_0000773c(void); extern void PlayFMRadio(void); diff --git a/app/main.c b/app/main.c index 3fe98d6..ac723a9 100644 --- a/app/main.c +++ b/app/main.c @@ -4,11 +4,11 @@ #include "dtmf.h" #include "fm.h" #include "frequencies.h" -#include "gui.h" #include "misc.h" #include "radio.h" #include "settings.h" #include "ui/inputbox.h" +#include "ui/ui.h" extern void APP_SwitchToFM(void); extern void FUN_0000773c(void); diff --git a/app/menu.c b/app/menu.c index 03fc8be..2e2a2e9 100644 --- a/app/menu.c +++ b/app/menu.c @@ -7,12 +7,12 @@ #include "driver/gpio.h" #include "driver/keyboard.h" #include "frequencies.h" -#include "gui.h" #include "misc.h" #include "settings.h" #include "sram-overlay.h" #include "ui/inputbox.h" #include "ui/menu.h" +#include "ui/ui.h" static const VOICE_ID_t MenuVoices[] = { VOICE_ID_SQUELCH, diff --git a/audio.c b/audio.c index 8a37263..b7ddfed 100644 --- a/audio.c +++ b/audio.c @@ -23,9 +23,9 @@ #include "driver/systick.h" #include "fm.h" #include "functions.h" -#include "gui.h" #include "misc.h" #include "settings.h" +#include "ui/ui.h" static const uint8_t VoiceClipLengthChinese[58] = { 0x32, 0x32, 0x32, 0x37, 0x37, 0x32, 0x32, 0x32, diff --git a/board.c b/board.c index 4b56dc4..a4d7e7a 100644 --- a/board.c +++ b/board.c @@ -16,7 +16,6 @@ */ #include -#include "battery.h" #include "board.h" #include "bsp/dp32g030/gpio.h" #include "bsp/dp32g030/portcon.h" @@ -34,6 +33,7 @@ #include "dtmf.h" #include "fm.h" #include "frequencies.h" +#include "helper/battery.h" #include "misc.h" #include "settings.h" #include "sram-overlay.h" diff --git a/driver/keyboard.c b/driver/keyboard.c index 0aa736e..f90c37e 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -20,6 +20,11 @@ #include "driver/keyboard.h" #include "driver/systick.h" +KEY_Code_t gKeyReading0; +KEY_Code_t gKeyReading1; +uint8_t gDebounceCounter; +bool gWasFKeyPressed; + KEY_Code_t KEYBOARD_Poll(void) { KEY_Code_t Key = KEY_INVALID; diff --git a/driver/keyboard.h b/driver/keyboard.h index 3c40505..58a7da3 100644 --- a/driver/keyboard.h +++ b/driver/keyboard.h @@ -18,6 +18,9 @@ #ifndef DRIVER_KEYBOARD_H #define DRIVER_KEYBOARD_H +#include +#include + enum KEY_Code_t { KEY_0 = 0, KEY_1 = 1, @@ -43,6 +46,11 @@ enum KEY_Code_t { typedef enum KEY_Code_t KEY_Code_t; +extern KEY_Code_t gKeyReading0; +extern KEY_Code_t gKeyReading1; +extern uint8_t gDebounceCounter; +extern bool gWasFKeyPressed; + KEY_Code_t KEYBOARD_Poll(void); #endif diff --git a/functions.c b/functions.c index 6deacc7..9e28446 100644 --- a/functions.c +++ b/functions.c @@ -15,7 +15,6 @@ */ #include -#include "battery.h" #include "bsp/dp32g030/gpio.h" #include "dcs.h" #include "driver/bk1080.h" @@ -26,10 +25,12 @@ #include "external/printf/printf.h" #include "fm.h" #include "functions.h" -#include "gui.h" +#include "helper/battery.h" #include "misc.h" #include "radio.h" #include "settings.h" +#include "ui/status.h" +#include "ui/ui.h" FUNCTION_Type_t gCurrentFunction; @@ -81,7 +82,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) if (Function != FUNCTION_POWER_SAVE) { BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable(); gThisCanEnable_BK4819_Rxon = false; - GUI_DisplayStatusLine(); + UI_DisplayStatus(); } } diff --git a/gui.c b/gui.c deleted file mode 100644 index 7e07d34..0000000 --- a/gui.c +++ /dev/null @@ -1,306 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "audio.h" -#include "battery.h" -#include "bitmaps.h" -#include "driver/eeprom.h" -#include "driver/keyboard.h" -#include "driver/st7565.h" -#include "external/printf/printf.h" -#include "fm.h" -#include "functions.h" -#include "gui.h" -#include "helper.h" -#include "misc.h" -#include "settings.h" -#include "ui/aircopy.h" -#include "ui/fmradio.h" -#include "ui/helper.h" -#include "ui/inputbox.h" -#include "ui/main.h" -#include "ui/menu.h" -#include "ui/scanner.h" - -GUI_DisplayType_t gScreenToDisplay; -volatile int8_t gStepDirection; -GUI_DisplayType_t gRequestDisplayScreen; -uint8_t g_200003BB; -bool gWasFKeyPressed; - -uint8_t gAskForConfirmation; -bool gAskToSave; -bool gAskToDelete; - -void GUI_DisplayBatteryLevel(uint8_t BatteryLevel) -{ - const uint8_t *pBitmap; - bool bClearMode = false; - - if (gCurrentFunction != 1) { - switch (BatteryLevel) { - case 0: - pBitmap = NULL; - bClearMode = 1; - break; - case 1: - pBitmap = BITMAP_BatteryLevel1; - break; - case 2: - pBitmap = BITMAP_BatteryLevel2; - break; - case 3: - pBitmap = BITMAP_BatteryLevel3; - break; - case 4: - pBitmap = BITMAP_BatteryLevel4; - break; - default: - pBitmap = BITMAP_BatteryLevel5; - break; - } - ST7565_DrawLine(110, 0, 18, pBitmap, bClearMode); - } -} - -void GUI_Welcome(void) -{ - char WelcomeString0[16]; - char WelcomeString1[16]; - - memset(gStatusLine, 0, sizeof(gStatusLine)); - memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - - if (gEeprom.POWER_ON_DISPLAY_MODE == POWER_ON_DISPLAY_MODE_FULL_SCREEN) { - ST7565_FillScreen(0xFF); - } else { - memset(WelcomeString0, 0, sizeof(WelcomeString0)); - memset(WelcomeString1, 0, sizeof(WelcomeString1)); - if (gEeprom.POWER_ON_DISPLAY_MODE == POWER_ON_DISPLAY_MODE_VOLTAGE) { - sprintf(WelcomeString0, "VOLTAGE"); - sprintf(WelcomeString1, "%.2fV", gBatteryVoltageAverage * 0.01); - } else { - EEPROM_ReadBuffer(0x0EB0, WelcomeString0, 16); - EEPROM_ReadBuffer(0x0EC0, WelcomeString1, 16); - } - UI_PrintString(WelcomeString0, 0, 127, 1, 10, true); - UI_PrintString(WelcomeString1, 0, 127, 3, 10, true); - ST7565_BlitStatusLine(); - ST7565_BlitFullScreen(); - } -} - -void GUI_PasswordScreen(void) -{ - KEY_Code_t Key; - BEEP_Type_t Beep; - - gUpdateDisplay = true; - memset(gInputBox, 10, sizeof(gInputBox)); - - while (1) { - while (!gNextTimeslice) { - } - // TODO: Original code doesn't do the below, but is needed for proper key debounce. - gNextTimeslice = false; - Key = KEYBOARD_Poll(); - if (gKeyReading0 == Key) { - gDebounceCounter++; - if (gDebounceCounter == 2) { - if (Key == KEY_INVALID) { - gKeyReading1 = KEY_INVALID; - } else { - gKeyReading1 = Key; - switch (Key) { - case KEY_0: case KEY_1: case KEY_2: case KEY_3: - case KEY_4: case KEY_5: case KEY_6: case KEY_7: - case KEY_8: case KEY_9: - INPUTBOX_Append(Key - KEY_0); - if (gInputBoxIndex < 6) { - Beep = BEEP_1KHZ_60MS_OPTIONAL; - } else { - uint32_t Password; - - gInputBoxIndex = 0; - NUMBER_Get(gInputBox, &Password); - if ((gEeprom.POWER_ON_PASSWORD * 100) == Password) { - AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); - return; - } - memset(gInputBox, 10, sizeof(gInputBox)); - Beep = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - } - AUDIO_PlayBeep(Beep); - gUpdateDisplay = true; - break; - case KEY_EXIT: // Delete digit - if (gInputBoxIndex) { - gInputBoxIndex -= 1; - gInputBox[gInputBoxIndex] = 10; - gUpdateDisplay = true; - } - AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); - default: - break; - } - } - gKeyBeingHeld = false; - } - } else { - gDebounceCounter = 0; - gKeyReading0 = Key; - } -#if 0 - if (UART_CheckForCommand()) { - __disable_irq(); - ProcessUartCommand(); - __enable_irq(); - } -#endif - if (gUpdateDisplay) { - GUI_LockScreen(); - gUpdateDisplay = false; - } - } -} - -void GUI_LockScreen(void) -{ - char String[7]; - uint8_t i; - - memset(gStatusLine, 0, sizeof(gStatusLine)); - memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - strcpy(String, "LOCK"); - UI_PrintString(String, 0, 127, 1, 10, true); - for (i = 0; i < 6; i++) { - if (gInputBox[i] == 10) { - String[i] = '-'; - } else { - String[i] = '*'; - } - } - String[6] = 0; - UI_PrintString(String, 0, 127, 3, 12, true); - ST7565_BlitStatusLine(); - ST7565_BlitFullScreen(); -} - -void GUI_DisplayStatusLine(void) -{ - memset(gStatusLine, 0, sizeof(gStatusLine)); - if (gCurrentFunction == FUNCTION_POWER_SAVE) { - memcpy(gStatusLine, BITMAP_PowerSave, sizeof(BITMAP_PowerSave)); - } - if (gBatteryDisplayLevel < 2) { - if (gLowBatteryBlink == 1) { - memcpy(gStatusLine + 110, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); - } - } else { - if (gBatteryDisplayLevel == 2) { - memcpy(gStatusLine + 110, BITMAP_BatteryLevel2, sizeof(BITMAP_BatteryLevel2)); - } else if (gBatteryDisplayLevel == 3) { - memcpy(gStatusLine + 110, BITMAP_BatteryLevel3, sizeof(BITMAP_BatteryLevel3)); - } else if (gBatteryDisplayLevel == 4) { - memcpy(gStatusLine + 110, BITMAP_BatteryLevel4, sizeof(BITMAP_BatteryLevel4)); - } else { - memcpy(gStatusLine + 110, BITMAP_BatteryLevel5, sizeof(BITMAP_BatteryLevel5)); - } - } - if (gChargingWithTypeC) { - memcpy(gStatusLine + 100, BITMAP_USB_C, sizeof(BITMAP_USB_C)); - } - if (gEeprom.KEY_LOCK) { - memcpy(gStatusLine + 90, BITMAP_KeyLock, sizeof(BITMAP_KeyLock)); - } else if (gWasFKeyPressed) { - memcpy(gStatusLine + 90, BITMAP_F_Key, sizeof(BITMAP_F_Key)); - } - - if (gEeprom.VOX_SWITCH) { - memcpy(gStatusLine + 71, BITMAP_VOX, sizeof(BITMAP_VOX)); - } - if (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) { - memcpy(gStatusLine + 58, BITMAP_WX, sizeof(BITMAP_WX)); - } - if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { - memcpy(gStatusLine + 45, BITMAP_TDR, sizeof(BITMAP_TDR)); - } - if (gEeprom.VOICE_PROMPT != VOICE_PROMPT_OFF) { - memcpy(gStatusLine + 34, BITMAP_VoicePrompt, sizeof(BITMAP_VoicePrompt)); - } - if (gSetting_KILLED) { - memset(gStatusLine + 21, 0xFF, 10); - } - else if (gFmRadioMode) { - memcpy(gStatusLine + 21, BITMAP_FM, sizeof(BITMAP_FM)); - } - if (gIsNoaaMode) { - memcpy(gStatusLine + 7, BITMAP_NOAA, sizeof(BITMAP_NOAA)); - } - ST7565_BlitStatusLine(); -} - -// - -void GUI_DisplayScreen(void) -{ - switch (gScreenToDisplay) { - case DISPLAY_MAIN: - UI_DisplayMain(); - break; - case DISPLAY_FM: - UI_DisplayFM(); - break; - case DISPLAY_MENU: - UI_DisplayMenu(); - break; - case DISPLAY_SCANNER: - UI_DisplayScanner(); - break; - case DISPLAY_AIRCOPY: - UI_DisplayAircopy(); - break; - default: - break; - } -} - -void GUI_SelectNextDisplay(GUI_DisplayType_t Display) -{ - if (Display != DISPLAY_INVALID) { - if (gScreenToDisplay != Display) { - gInputBoxIndex = 0; - gIsInSubMenu = false; - g_20000381 = 0; - gStepDirection = 0; - g_20000390 = 0; - gAskForConfirmation = 0; - g_200003BA = 0; - g_200003BB = 0; - gF_LOCK = false; - gAskToSave = false; - gAskToDelete = false; - if (gWasFKeyPressed) { - gWasFKeyPressed = false; - g_2000036F = 1; - } - } - gUpdateDisplay = true; - gScreenToDisplay = Display; - } -} - diff --git a/helper.c b/helper.c index a6f4028..4a4bc11 100644 --- a/helper.c +++ b/helper.c @@ -20,16 +20,12 @@ #include "driver/keyboard.h" #include "driver/gpio.h" #include "driver/system.h" -#include "gui.h" #include "helper.h" #include "misc.h" #include "radio.h" #include "settings.h" #include "ui/menu.h" - -KEY_Code_t gKeyReading0; -KEY_Code_t gKeyReading1; -uint8_t g_2000042A; +#include "ui/ui.h" uint8_t HELPER_GetKey(void) { @@ -48,7 +44,7 @@ uint8_t HELPER_GetKey(void) if (Keys[0] == Keys[1]) { gKeyReading0 = Keys[0]; gKeyReading1 = Keys[0]; - g_2000042A = 2; + gDebounceCounter = 2; if (i == KEY_SIDE1) { ret = 1; } else if (i == KEY_SIDE2) { diff --git a/helper.h b/helper.h index ece1304..fc02ce8 100644 --- a/helper.h +++ b/helper.h @@ -20,10 +20,6 @@ #include #include "driver/keyboard.h" -extern KEY_Code_t gKeyReading0; -extern KEY_Code_t gKeyReading1; -extern uint8_t g_2000042A; - uint8_t HELPER_GetKey(void); void HELPER_CheckBootKey(uint8_t KeyType); diff --git a/battery.c b/helper/battery.c similarity index 96% rename from battery.c rename to helper/battery.c index 8b065fd..7f659b6 100644 --- a/battery.c +++ b/helper/battery.c @@ -16,9 +16,10 @@ #include "battery.h" #include "driver/backlight.h" -#include "gui.h" #include "misc.h" +#include "ui/battery.h" #include "ui/menu.h" +#include "ui/ui.h" uint16_t gBatteryCalibration[6]; uint16_t gBatteryCurrentVoltage; @@ -83,7 +84,7 @@ void BATTERY_GetReadings(bool bDisplayBatteryLevel) } else { gLowBattery = false; if (bDisplayBatteryLevel) { - GUI_DisplayBatteryLevel(gBatteryDisplayLevel); + UI_DisplayBattery(gBatteryDisplayLevel); } } g_20000400 = 0; diff --git a/battery.h b/helper/battery.h similarity index 100% rename from battery.h rename to helper/battery.h diff --git a/main.c b/main.c index 131284b..766ade8 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,6 @@ #include "app/app.h" #include "audio.h" -#include "battery.h" #include "bsp/dp32g030/gpio.h" #include "bsp/dp32g030/portcon.h" #include "bsp/dp32g030/syscon.h" @@ -40,11 +39,13 @@ #include "dtmf.h" #include "external/printf/printf.h" #include "functions.h" -#include "gui.h" #include "helper.h" +#include "helper/battery.h" #include "misc.h" #include "radio.h" #include "settings.h" +#include "ui/lock.h" +#include "ui/welcome.h" static const char Version[] = "UV-K5 Firmware, v0.01 Open Edition\r\n"; @@ -104,7 +105,7 @@ void Main(void) uint8_t KeyType; uint8_t Channel; - GUI_Welcome(); + UI_DisplayWelcome(); BACKLIGHT_TurnOn(); SYSTEM_DelayMs(1000); gMenuListCount = 51; @@ -113,7 +114,7 @@ void Main(void) KeyType = HELPER_GetKey(); if (gEeprom.POWER_ON_PASSWORD < 1000000) { g_2000036E = 1; - GUI_PasswordScreen(); + UI_DisplayLock(); g_2000036E = 0; } diff --git a/misc.c b/misc.c index 7736144..7b6034b 100644 --- a/misc.c +++ b/misc.c @@ -106,6 +106,7 @@ uint8_t g_200003B4; uint16_t g_200003B6; uint16_t g_200003B8; uint8_t g_200003BA; +uint8_t g_200003BB; uint8_t g_200003BC; uint8_t g_200003BD; uint8_t g_200003BE; @@ -165,7 +166,6 @@ uint8_t gNoaaChannel; bool gUpdateDisplay; uint8_t gFmRadioCountdown; uint8_t gA_Scan_Channel; -uint8_t gDebounceCounter; uint8_t gDTMF_AUTO_RESET_TIME; bool gF_LOCK; uint8_t gScanChannel; @@ -194,6 +194,8 @@ int16_t gFM_FrequencyDeviation; uint16_t gCurrentRSSI; +volatile int8_t gStepDirection; + // -------- void NUMBER_Get(char *pDigits, uint32_t *pInteger) diff --git a/misc.h b/misc.h index 959cf0c..791c545 100644 --- a/misc.h +++ b/misc.h @@ -115,6 +115,7 @@ extern uint8_t g_200003B4; extern uint16_t g_200003B6; extern uint16_t g_200003B8; extern uint8_t g_200003BA; +extern uint8_t g_200003BB; extern uint8_t g_200003BC; extern uint8_t g_200003BD; extern uint8_t g_200003BE; @@ -174,7 +175,6 @@ extern uint8_t gNoaaChannel; extern bool gUpdateDisplay; extern uint8_t gFmRadioCountdown; extern uint8_t gA_Scan_Channel; -extern uint8_t gDebounceCounter; extern uint8_t gDTMF_AUTO_RESET_TIME; extern bool gF_LOCK; extern uint8_t gScanChannel; @@ -202,6 +202,8 @@ extern int16_t gFM_FrequencyDeviation; extern uint16_t gCurrentRSSI; +extern volatile int8_t gStepDirection; + // -------- void NUMBER_Get(char *pDigits, uint32_t *pInteger); diff --git a/radio.c b/radio.c index 38c6b1f..27aab9c 100644 --- a/radio.c +++ b/radio.c @@ -16,7 +16,6 @@ #include #include "audio.h" -#include "battery.h" #include "bsp/dp32g030/gpio.h" #include "dcs.h" #include "driver/bk4819.h" @@ -26,6 +25,7 @@ #include "fm.h" #include "frequencies.h" #include "functions.h" +#include "helper/battery.h" #include "misc.h" #include "radio.h" #include "settings.h" diff --git a/scheduler.c b/scheduler.c index 8f80c6e..40fa6eb 100644 --- a/scheduler.c +++ b/scheduler.c @@ -15,9 +15,8 @@ */ #include "audio.h" -#include "battery.h" #include "functions.h" -#include "gui.h" +#include "helper/battery.h" #include "misc.h" #include "settings.h" diff --git a/ui/battery.c b/ui/battery.c new file mode 100644 index 0000000..e96e595 --- /dev/null +++ b/ui/battery.c @@ -0,0 +1,53 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "bitmaps.h" +#include "driver/st7565.h" +#include "functions.h" +#include "ui/battery.h" + +void UI_DisplayBattery(uint8_t Level) +{ + const uint8_t *pBitmap; + bool bClearMode = false; + + if (gCurrentFunction != 1) { + switch (Level) { + case 0: + pBitmap = NULL; + bClearMode = 1; + break; + case 1: + pBitmap = BITMAP_BatteryLevel1; + break; + case 2: + pBitmap = BITMAP_BatteryLevel2; + break; + case 3: + pBitmap = BITMAP_BatteryLevel3; + break; + case 4: + pBitmap = BITMAP_BatteryLevel4; + break; + default: + pBitmap = BITMAP_BatteryLevel5; + break; + } + ST7565_DrawLine(110, 0, 18, pBitmap, bClearMode); + } +} + diff --git a/ui/battery.h b/ui/battery.h new file mode 100644 index 0000000..899aea6 --- /dev/null +++ b/ui/battery.h @@ -0,0 +1,26 @@ + +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_BATTERY_H +#define UI_BATTERY_H + +#include + +void UI_DisplayBattery(uint8_t Level); + +#endif + diff --git a/ui/fmradio.c b/ui/fmradio.c index 4464dd0..8b6d74c 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -18,12 +18,12 @@ #include "driver/st7565.h" #include "external/printf/printf.h" #include "fm.h" -#include "gui.h" #include "misc.h" #include "settings.h" #include "ui/fmradio.h" #include "ui/helper.h" #include "ui/inputbox.h" +#include "ui/ui.h" void UI_DisplayFM(void) { diff --git a/ui/lock.c b/ui/lock.c new file mode 100644 index 0000000..eabd1b6 --- /dev/null +++ b/ui/lock.c @@ -0,0 +1,122 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "audio.h" +#include "driver/keyboard.h" +#include "driver/st7565.h" +#include "misc.h" +#include "settings.h" +#include "ui/helper.h" +#include "ui/inputbox.h" +#include "ui/lock.h" + +static void Render(void) +{ + char String[7]; + uint8_t i; + + memset(gStatusLine, 0, sizeof(gStatusLine)); + memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); + strcpy(String, "LOCK"); + UI_PrintString(String, 0, 127, 1, 10, true); + for (i = 0; i < 6; i++) { + if (gInputBox[i] == 10) { + String[i] = '-'; + } else { + String[i] = '*'; + } + } + String[6] = 0; + UI_PrintString(String, 0, 127, 3, 12, true); + ST7565_BlitStatusLine(); + ST7565_BlitFullScreen(); +} + +void UI_DisplayLock(void) +{ + KEY_Code_t Key; + BEEP_Type_t Beep; + + gUpdateDisplay = true; + memset(gInputBox, 10, sizeof(gInputBox)); + + while (1) { + while (!gNextTimeslice) { + } + // TODO: Original code doesn't do the below, but is needed for proper key debounce. + gNextTimeslice = false; + Key = KEYBOARD_Poll(); + if (gKeyReading0 == Key) { + gDebounceCounter++; + if (gDebounceCounter == 2) { + if (Key == KEY_INVALID) { + gKeyReading1 = KEY_INVALID; + } else { + gKeyReading1 = Key; + switch (Key) { + case KEY_0: case KEY_1: case KEY_2: case KEY_3: + case KEY_4: case KEY_5: case KEY_6: case KEY_7: + case KEY_8: case KEY_9: + INPUTBOX_Append(Key - KEY_0); + if (gInputBoxIndex < 6) { + Beep = BEEP_1KHZ_60MS_OPTIONAL; + } else { + uint32_t Password; + + gInputBoxIndex = 0; + NUMBER_Get(gInputBox, &Password); + if ((gEeprom.POWER_ON_PASSWORD * 100) == Password) { + AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); + return; + } + memset(gInputBox, 10, sizeof(gInputBox)); + Beep = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + } + AUDIO_PlayBeep(Beep); + gUpdateDisplay = true; + break; + case KEY_EXIT: // Delete digit + if (gInputBoxIndex) { + gInputBoxIndex -= 1; + gInputBox[gInputBoxIndex] = 10; + gUpdateDisplay = true; + } + AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); + default: + break; + } + } + gKeyBeingHeld = false; + } + } else { + gDebounceCounter = 0; + gKeyReading0 = Key; + } +#if 0 + if (UART_CheckForCommand()) { + __disable_irq(); + ProcessUartCommand(); + __enable_irq(); + } +#endif + if (gUpdateDisplay) { + Render(); + gUpdateDisplay = false; + } + } +} + diff --git a/ui/lock.h b/ui/lock.h new file mode 100644 index 0000000..4ad4f49 --- /dev/null +++ b/ui/lock.h @@ -0,0 +1,23 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_LOCK_H +#define UI_LOCK_H + +void UI_DisplayLock(void); + +#endif + diff --git a/ui/menu.c b/ui/menu.c index 8c5e43e..6548681 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -15,28 +15,18 @@ */ #include -//#include "app/aircopy.h" -//#include "audio.h" -#include "battery.h" #include "bitmaps.h" #include "dcs.h" -//#include "driver/eeprom.h" -//#include "driver/keyboard.h" #include "driver/st7565.h" #include "dtmf.h" #include "external/printf/printf.h" -//#include "font.h" -//#include "fm.h" -//#include "functions.h" -#include "gui.h" -//#include "helper.h" +#include "helper/battery.h" #include "misc.h" #include "settings.h" -//#include "ui/aircopy.h" -//#include "ui/fmradio.h" #include "ui/helper.h" #include "ui/inputbox.h" #include "ui/menu.h" +#include "ui/ui.h" static const char MenuList[][7] = { // 0x00 diff --git a/ui/rssi.c b/ui/rssi.c index 162b0db..23907c4 100644 --- a/ui/rssi.c +++ b/ui/rssi.c @@ -18,10 +18,10 @@ #include "bitmaps.h" #include "driver/st7565.h" #include "functions.h" -#include "gui.h" #include "misc.h" #include "settings.h" #include "ui/rssi.h" +#include "ui/ui.h" static void Render(uint8_t RssiLevel, uint8_t VFO) { diff --git a/ui/scanner.c b/ui/scanner.c index 084fd75..fc55991 100644 --- a/ui/scanner.c +++ b/ui/scanner.c @@ -19,7 +19,6 @@ #include "dcs.h" #include "driver/st7565.h" #include "external/printf/printf.h" -#include "gui.h" #include "misc.h" #include "ui/helper.h" #include "ui/scanner.h" diff --git a/ui/status.c b/ui/status.c new file mode 100644 index 0000000..4a0c32e --- /dev/null +++ b/ui/status.c @@ -0,0 +1,81 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "bitmaps.h" +#include "driver/keyboard.h" +#include "driver/st7565.h" +#include "fm.h" +#include "functions.h" +#include "helper/battery.h" +#include "misc.h" +#include "settings.h" +#include "ui/status.h" + +void UI_DisplayStatus(void) +{ + memset(gStatusLine, 0, sizeof(gStatusLine)); + if (gCurrentFunction == FUNCTION_POWER_SAVE) { + memcpy(gStatusLine, BITMAP_PowerSave, sizeof(BITMAP_PowerSave)); + } + if (gBatteryDisplayLevel < 2) { + if (gLowBatteryBlink == 1) { + memcpy(gStatusLine + 110, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1)); + } + } else { + if (gBatteryDisplayLevel == 2) { + memcpy(gStatusLine + 110, BITMAP_BatteryLevel2, sizeof(BITMAP_BatteryLevel2)); + } else if (gBatteryDisplayLevel == 3) { + memcpy(gStatusLine + 110, BITMAP_BatteryLevel3, sizeof(BITMAP_BatteryLevel3)); + } else if (gBatteryDisplayLevel == 4) { + memcpy(gStatusLine + 110, BITMAP_BatteryLevel4, sizeof(BITMAP_BatteryLevel4)); + } else { + memcpy(gStatusLine + 110, BITMAP_BatteryLevel5, sizeof(BITMAP_BatteryLevel5)); + } + } + if (gChargingWithTypeC) { + memcpy(gStatusLine + 100, BITMAP_USB_C, sizeof(BITMAP_USB_C)); + } + if (gEeprom.KEY_LOCK) { + memcpy(gStatusLine + 90, BITMAP_KeyLock, sizeof(BITMAP_KeyLock)); + } else if (gWasFKeyPressed) { + memcpy(gStatusLine + 90, BITMAP_F_Key, sizeof(BITMAP_F_Key)); + } + + if (gEeprom.VOX_SWITCH) { + memcpy(gStatusLine + 71, BITMAP_VOX, sizeof(BITMAP_VOX)); + } + if (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) { + memcpy(gStatusLine + 58, BITMAP_WX, sizeof(BITMAP_WX)); + } + if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { + memcpy(gStatusLine + 45, BITMAP_TDR, sizeof(BITMAP_TDR)); + } + if (gEeprom.VOICE_PROMPT != VOICE_PROMPT_OFF) { + memcpy(gStatusLine + 34, BITMAP_VoicePrompt, sizeof(BITMAP_VoicePrompt)); + } + if (gSetting_KILLED) { + memset(gStatusLine + 21, 0xFF, 10); + } + else if (gFmRadioMode) { + memcpy(gStatusLine + 21, BITMAP_FM, sizeof(BITMAP_FM)); + } + if (gIsNoaaMode) { + memcpy(gStatusLine + 7, BITMAP_NOAA, sizeof(BITMAP_NOAA)); + } + ST7565_BlitStatusLine(); +} + diff --git a/ui/status.h b/ui/status.h new file mode 100644 index 0000000..cfa32a5 --- /dev/null +++ b/ui/status.h @@ -0,0 +1,23 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_STATUS_H +#define UI_STATUS_H + +void UI_DisplayStatus(void); + +#endif + diff --git a/ui/ui.c b/ui/ui.c new file mode 100644 index 0000000..6bb7cc3 --- /dev/null +++ b/ui/ui.c @@ -0,0 +1,82 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "driver/keyboard.h" +#include "misc.h" +#include "ui/aircopy.h" +#include "ui/fmradio.h" +#include "ui/inputbox.h" +#include "ui/main.h" +#include "ui/menu.h" +#include "ui/scanner.h" +#include "ui/ui.h" + +GUI_DisplayType_t gScreenToDisplay; +GUI_DisplayType_t gRequestDisplayScreen; + +uint8_t gAskForConfirmation; +bool gAskToSave; +bool gAskToDelete; + +void GUI_DisplayScreen(void) +{ + switch (gScreenToDisplay) { + case DISPLAY_MAIN: + UI_DisplayMain(); + break; + case DISPLAY_FM: + UI_DisplayFM(); + break; + case DISPLAY_MENU: + UI_DisplayMenu(); + break; + case DISPLAY_SCANNER: + UI_DisplayScanner(); + break; + case DISPLAY_AIRCOPY: + UI_DisplayAircopy(); + break; + default: + break; + } +} + +void GUI_SelectNextDisplay(GUI_DisplayType_t Display) +{ + if (Display != DISPLAY_INVALID) { + if (gScreenToDisplay != Display) { + gInputBoxIndex = 0; + gIsInSubMenu = false; + g_20000381 = 0; + gStepDirection = 0; + g_20000390 = 0; + gAskForConfirmation = 0; + g_200003BA = 0; + g_200003BB = 0; + gF_LOCK = false; + gAskToSave = false; + gAskToDelete = false; + if (gWasFKeyPressed) { + gWasFKeyPressed = false; + g_2000036F = 1; + } + } + gUpdateDisplay = true; + gScreenToDisplay = Display; + } +} + diff --git a/gui.h b/ui/ui.h similarity index 82% rename from gui.h rename to ui/ui.h index 5729f60..f2809a1 100644 --- a/gui.h +++ b/ui/ui.h @@ -32,21 +32,12 @@ enum GUI_DisplayType_t { typedef enum GUI_DisplayType_t GUI_DisplayType_t; extern GUI_DisplayType_t gScreenToDisplay; -extern volatile int8_t gStepDirection; extern GUI_DisplayType_t gRequestDisplayScreen; -extern uint8_t g_200003BB; -extern bool gWasFKeyPressed; extern uint8_t gAskForConfirmation; extern bool gAskToSave; extern bool gAskToDelete; -void GUI_DisplayBatteryLevel(uint8_t BatteryLevel); -void GUI_Welcome(void); -void GUI_PasswordScreen(void); -void GUI_LockScreen(void); -void GUI_DisplayStatusLine(void); - void GUI_DisplayScreen(void); void GUI_SelectNextDisplay(GUI_DisplayType_t Display); diff --git a/ui/welcome.c b/ui/welcome.c new file mode 100644 index 0000000..dda9ad5 --- /dev/null +++ b/ui/welcome.c @@ -0,0 +1,52 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "driver/eeprom.h" +#include "driver/st7565.h" +#include "external/printf/printf.h" +#include "helper/battery.h" +#include "settings.h" +#include "ui/helper.h" +#include "ui/welcome.h" + +void UI_DisplayWelcome(void) +{ + char WelcomeString0[16]; + char WelcomeString1[16]; + + memset(gStatusLine, 0, sizeof(gStatusLine)); + memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); + + if (gEeprom.POWER_ON_DISPLAY_MODE == POWER_ON_DISPLAY_MODE_FULL_SCREEN) { + ST7565_FillScreen(0xFF); + } else { + memset(WelcomeString0, 0, sizeof(WelcomeString0)); + memset(WelcomeString1, 0, sizeof(WelcomeString1)); + if (gEeprom.POWER_ON_DISPLAY_MODE == POWER_ON_DISPLAY_MODE_VOLTAGE) { + sprintf(WelcomeString0, "VOLTAGE"); + sprintf(WelcomeString1, "%.2fV", gBatteryVoltageAverage * 0.01); + } else { + EEPROM_ReadBuffer(0x0EB0, WelcomeString0, 16); + EEPROM_ReadBuffer(0x0EC0, WelcomeString1, 16); + } + UI_PrintString(WelcomeString0, 0, 127, 1, 10, true); + UI_PrintString(WelcomeString1, 0, 127, 3, 10, true); + ST7565_BlitStatusLine(); + ST7565_BlitFullScreen(); + } +} + diff --git a/ui/welcome.h b/ui/welcome.h new file mode 100644 index 0000000..1f7c6dd --- /dev/null +++ b/ui/welcome.h @@ -0,0 +1,23 @@ +/* Copyright 2023 Dual Tachyon + * https://github.com/DualTachyon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_WELCOME_H +#define UI_WELCOME_H + +void UI_DisplayWelcome(void); + +#endif +