menu enc key added

This commit is contained in:
Nunu 2024-01-24 15:45:39 +01:00
parent 0f60145b07
commit 4fbdcbb352
4 changed files with 86 additions and 7 deletions

View File

@ -1183,7 +1183,13 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0)
if (edit_index >= 0 && (
UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME
#ifdef ENABLE_ENCRYPTION
|| UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY
#endif
))
{ // currently editing the channel name
if (edit_index < 10)
@ -1455,15 +1461,42 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
return;
}
#ifdef ENABLE_ENCRYPTION
if (UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY)
{
if (edit_index < 0)
{ // enter encryption key edit mode
// pad the encryption key out with '_'
// TODO: Extract to shared function - common with MENU_MEM_NAME below
edit_index = strlen(edit);
while (edit_index < 10)
edit[edit_index++] = '_';
edit[edit_index] = 0;
edit_index = 0; // 'edit_index' is going to be used as the cursor position
return;
}
else if (edit_index >= 0 && edit_index < 10)
{ // editing the encryption key characters
if (++edit_index < 10)
return; // next char
// exit, save encryption key
memcpy(gEeprom.ENC_KEY, edit, sizeof(gEeprom.ENC_KEY));
}
}
#endif
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME)
{
if (edit_index < 0)
{ // enter channel name edit mode
if (!RADIO_CheckValidChannel(gSubMenuSelection, false, 0))
return;
return;
SETTINGS_FetchChannelName(edit, gSubMenuSelection);
// pad the channel name out with '_'
edit_index = strlen(edit);
while (edit_index < 10)
@ -1613,10 +1646,19 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
uint8_t Channel;
bool bCheckScanList;
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && gIsInSubMenu && edit_index >= 0)
if (gIsInSubMenu &&
edit_index >= 0 &&
(
UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME
#ifdef ENABLE_ENCRYPTION
|| UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY
#endif
)
)
{ // change the character
if (bKeyPressed && edit_index < 10 && Direction != 0)
{
// TODO: Allow special chars when setting encryption key
const char unwanted[] = "$%&!\"':;?^`|{}";
char c = edit[edit_index] + Direction;
unsigned int i = 0;
@ -1747,8 +1789,16 @@ void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
MENU_Key_STAR(bKeyPressed, bKeyHeld);
break;
case KEY_F:
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0)
{ // currently editing the channel name
if (edit_index >= 0 &&
(
UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME
#ifdef ENABLE_ENCRYPTION
|| UI_MENU_GetCurrentMenuId() == MENU_ENC_KEY
#endif
)
)
{ // adds space,
// currently editing the channel name or enc_key
if (!bKeyHeld && bKeyPressed)
{
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;

View File

@ -245,6 +245,9 @@ typedef struct {
#ifdef ENABLE_PWRON_PASSWORD
uint32_t POWER_ON_PASSWORD;
uint8_t PASSWORD_WRONG_ATTEMPTS;
#endif
#ifdef ENABLE_ENCRYPTION
char ENC_KEY[10];
#endif
uint16_t VOX1_THRESHOLD;
uint16_t VOX0_THRESHOLD;

View File

@ -111,6 +111,9 @@ const t_menu_item MenuList[] =
{"RxMode", VOICE_ID_DUAL_STANDBY, MENU_TDR },
#ifdef ENABLE_PWRON_PASSWORD
{"Passwd", VOICE_ID_INVALID, MENU_PASSWORD }, // power on password
#endif
#ifdef ENABLE_ENCRYPTION
{"EncKey", VOICE_ID_INVALID, MENU_ENC_KEY }, // encryption key
#endif
{"Sql", VOICE_ID_SQUELCH, MENU_SQL },
// hidden menu items from here on
@ -721,6 +724,26 @@ void UI_DisplayMenu(void)
already_printed = true;
break;
}
#ifdef ENABLE_ENCRYPTION
case MENU_ENC_KEY:
{
if (!gIsInSubMenu)
{ // show the key
strcpy(String, "****");
UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8);
}
else
{ // show the key being edited
sprintf(String, "%s", gEeprom.ENC_KEY);
UI_PrintString(edit, (menu_item_x1 -2), 0, 2, 8);
if (edit_index != -1 && edit_index < 10)
UI_PrintString( "^", (menu_item_x1 -2) + (8 * edit_index), 0, 4, 8); // show the cursor
}
already_printed = true;
break;
}
#endif
case MENU_SAVE:
strcpy(String, gSubMenu_SAVE[gSubMenuSelection]);

View File

@ -61,6 +61,9 @@ enum
MENU_TDR,
#ifdef ENABLE_PWRON_PASSWORD
MENU_PASSWORD,
#endif
#ifdef ENABLE_ENCRYPTION
MENU_ENC_KEY,
#endif
MENU_BEEP,
#ifdef ENABLE_VOICE