diff --git a/App/app/action.c b/App/app/action.c index bc8893a5..97da7c59 100644 --- a/App/app/action.c +++ b/App/app/action.c @@ -472,7 +472,7 @@ static void ACTION_Scan_FM(bool bRestart) static void ACTION_AlarmOr1750(const bool b1750) { - if(gEeprom.KEY_LOCK && gEeprom.KEY_LOCK_PTT) + if(gEeprom.KEY_LOCK && (gSetting_set_lck & SET_LCK_PTT)) return; #if defined(ENABLE_ALARM) diff --git a/App/app/app.c b/App/app/app.c index b6b02ecf..e81e09ba 100644 --- a/App/app/app.c +++ b/App/app/app.c @@ -2308,7 +2308,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_FEAT_F4HWN // Disable PTT if KEY_LOCK bool lck_condition = (gEeprom.KEY_LOCK || lowBatPopup) && gCurrentFunction != FUNCTION_TRANSMIT; - if(!gSetting_set_lck) + if((gSetting_set_lck & SET_LCK_PTT) == 0) lck_condition = lck_condition && Key != KEY_PTT; if (lck_condition) @@ -2325,6 +2325,12 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } + // The ACTIONS restriction only applies when the keypad is actually + // locked: this block is also entered for the low battery popup, where + // action keys must keep working as before + const bool passActionKey = ((gSetting_set_lck & SET_LCK_ACTIONS) == 0 || !gEeprom.KEY_LOCK) && + (Key == KEY_SIDE1 || Key == KEY_SIDE2 || (Key == KEY_MENU && bKeyHeld)); + if (Key == KEY_F) { // function/key-lock key if (!bKeyPressed) return; @@ -2339,8 +2345,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) // KEY_MENU has a special treatment here, because we want to pass hold event to ACTION_Handle // but we don't want it to complain when initial press happens // we want to react on realese instead - else if (Key != KEY_SIDE1 && Key != KEY_SIDE2 && // pass side buttons - !(Key == KEY_MENU && bKeyHeld)) // pass KEY_MENU held + else if (!passActionKey) { if ((!bKeyPressed || bKeyHeld || (Key == KEY_MENU && bKeyPressed)) && // prevent released or held, prevent KEY_MENU pressed !(Key == KEY_MENU && !bKeyPressed)) // pass KEY_MENU released diff --git a/App/app/menu.c b/App/app/menu.c index 4ce70cef..1155455e 100644 --- a/App/app/menu.c +++ b/App/app/menu.c @@ -426,7 +426,7 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) #endif case MENU_SET_LCK: //*pMin = 0; - *pMax = ARRAY_SIZE(gSubMenu_SET_LCK) - 1; + *pMax = SET_LCK_LEN - 1; break; case MENU_SET_MET: case MENU_SET_GUI: diff --git a/App/misc.c b/App/misc.c index 5adf4648..63242354 100644 --- a/App/misc.c +++ b/App/misc.c @@ -127,7 +127,7 @@ enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; uint8_t gSetting_set_ctr = 10; bool gSetting_set_inv = false; uint8_t gSetting_set_eot = 0; - bool gSetting_set_lck = false; + uint8_t gSetting_set_lck = SET_LCK_KEYS; bool gSetting_set_met = 0; bool gSetting_set_gui = 0; #ifdef ENABLE_FEAT_F4HWN_AUDIO diff --git a/App/misc.h b/App/misc.h index 9d904dd1..465aa296 100644 --- a/App/misc.h +++ b/App/misc.h @@ -181,6 +181,19 @@ extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; #endif #ifdef ENABLE_FEAT_F4HWN + // Keypad lock scope. Values are BOTH a bitmask (ACTIONS/PTT bits tested + // individually) AND a contiguous 0..3 menu index: the order must stay + // aligned with gSubMenu_SET_LCK[] and any new entry must keep the range + // contiguous so that SET_LCK_LEN remains valid as menu bound and EEPROM + // range check. + enum SET_LCK_t { + SET_LCK_KEYS = 0u, + SET_LCK_ACTIONS = 1u, + SET_LCK_PTT = 2u, + SET_LCK_ACTIONS_PTT = SET_LCK_ACTIONS | SET_LCK_PTT, + SET_LCK_LEN + }; + #ifdef ENABLE_FEAT_F4HWN_LOGO_SAV enum SET_SAV_t { SET_SAV_OFF, @@ -197,7 +210,7 @@ extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; extern uint8_t gSetting_set_ctr; extern bool gSetting_set_inv; extern uint8_t gSetting_set_eot; - extern bool gSetting_set_lck; + extern uint8_t gSetting_set_lck; extern bool gSetting_set_met; extern bool gSetting_set_gui; #ifdef ENABLE_FEAT_F4HWN_AUDIO diff --git a/App/settings.c b/App/settings.c index 21dcd0a0..83fb8182 100644 --- a/App/settings.c +++ b/App/settings.c @@ -477,7 +477,6 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE int tmp = ((Data[5] & 0xF0) >> 4); gSetting_set_inv = (((tmp >> 0) & 0x01) < 2) ? ((tmp >> 0) & 0x01): 0; - gSetting_set_lck = (((tmp >> 1) & 0x01) < 2) ? ((tmp >> 1) & 0x01): 0; gSetting_set_met = (((tmp >> 2) & 0x01) < 2) ? ((tmp >> 2) & 0x01): 0; gSetting_set_gui = (((tmp >> 3) & 0x01) < 2) ? ((tmp >> 3) & 0x01): 0; gSetting_set_ctr = (((Data[5] & 0x0F)) > 00 && ((Data[5] & 0x0F)) < 16) ? ((Data[5] & 0x0F)) : 10; @@ -492,7 +491,7 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE #else gSetting_set_inv = 0; #endif - gSetting_set_lck = (tmp >> 1) & 0x01; + gSetting_set_lck = (Data[2] < SET_LCK_LEN) ? Data[2] : SET_LCK_KEYS; gSetting_set_met = (tmp >> 2) & 0x01; gSetting_set_gui = (tmp >> 3) & 0x01; @@ -510,7 +509,6 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE // And set special session settings for actions gSetting_set_ptt_session = gSetting_set_ptt; - gEeprom.KEY_LOCK_PTT = gSetting_set_lck; #endif } @@ -1119,8 +1117,6 @@ void SETTINGS_SaveSettings(void) if(gSetting_set_inv == 1) tmp = tmp | (1 << 0); - if (gSetting_set_lck == 1) - tmp = tmp | (1 << 1); if (gSetting_set_met == 1) tmp = tmp | (1 << 2); if (gSetting_set_gui == 1) @@ -1134,10 +1130,10 @@ void SETTINGS_SaveSettings(void) #endif tmp = (gSetting_set_inv << 0) | - (gSetting_set_lck << 1) | (gSetting_set_met << 2) | (gSetting_set_gui << 3); + State[2] = gSetting_set_lck; State[5] = ((tmp << 4) | (gSetting_set_ctr & 0x0F)); State[6] = ((gSetting_set_tot << 4) | (gSetting_set_eot & 0x0F)); uint8_t set_ptt_scn_sav = gSetting_set_ptt & 0x01; @@ -1151,8 +1147,6 @@ void SETTINGS_SaveSettings(void) State[7] = ((gSetting_set_pwr << 4) | set_ptt_scn_sav); - gEeprom.KEY_LOCK_PTT = gSetting_set_lck; - PY25Q16_WriteBuffer(0x00A158, SecBuf, 8, false); #endif diff --git a/App/settings.h b/App/settings.h index da1b04fd..1f0153f9 100644 --- a/App/settings.h +++ b/App/settings.h @@ -199,7 +199,6 @@ typedef struct { uint8_t TX_TIMEOUT_TIMER; bool KEY_LOCK; #ifdef ENABLE_FEAT_F4HWN - bool KEY_LOCK_PTT; bool SET_NAV; #endif #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS diff --git a/App/ui/menu.c b/App/ui/menu.c index 445e4ebd..65975b1a 100644 --- a/App/ui/menu.c +++ b/App/ui/menu.c @@ -421,7 +421,9 @@ const char* const gSubMenu_SCRAMBLER[] = const char* const gSubMenu_SET_LCK[] = { "KEYS", - "KEYS+PTT" + "KEYS\nACTIONS", + "KEYS\nPTT", + "KEYS\nACTIONS\nPTT" }; const char* const gSubMenu_SET_MET[] = diff --git a/App/ui/menu.h b/App/ui/menu.h index 313692cb..06970139 100644 --- a/App/ui/menu.h +++ b/App/ui/menu.h @@ -195,7 +195,7 @@ extern const char* const gSubMenu_D_RSP[4]; extern const char* const gSubMenu_SET_PWR[7]; extern const char* const gSubMenu_SET_PTT[2]; extern const char* const gSubMenu_SET_TOT[4]; - extern const char* const gSubMenu_SET_LCK[2]; + extern const char* const gSubMenu_SET_LCK[]; extern const char* const gSubMenu_SET_MET[2]; #ifdef ENABLE_FEAT_F4HWN_SCAN_FASTER extern const char* const gSubMenu_SET_SCN[2];