Improve password screen function.

This commit is contained in:
xiaojiazhu 2023-11-14 17:20:11 +08:00
parent ea09cd8860
commit c59a619b51
5 changed files with 82 additions and 14 deletions

View File

@ -1,5 +1,8 @@
#include "PrjInc.h" #include "PrjInc.h"
#include "UIFlowLVGL/UIFlowLVGL.h" #include "UIFlowLVGL/UIFlowLVGL.h"
#include "UIFlowLVGL/UIFlowWrnMsg/UIFlowWrnMsgAPI.h"
#include "sf_mcu.h"
#include "sf_common.h"
#include <stdio.h> #include <stdio.h>
@ -24,6 +27,8 @@ static const char* PasswordMap[7] =
PasswordBuf6, PasswordBuf6,
"" ""
}; };
#define LONG_PRESS_INTERVAL 500
static unsigned long KeyRightPressingTimeMs = 0;
static lv_group_t* gp = NULL; static lv_group_t* gp = NULL;
static void set_indev_keypad_group(lv_obj_t* obj) static void set_indev_keypad_group(lv_obj_t* obj)
@ -38,6 +43,7 @@ static void set_indev_keypad_group(lv_obj_t* obj)
} }
static void UIFlowPassword_ScrOpen(lv_obj_t* obj) static void UIFlowPassword_ScrOpen(lv_obj_t* obj)
{ {
sf_set_keep_alive_time(PASSWORD_SCREEN_GO_TO_WORK_MODE_TIME_S);
set_indev_keypad_group(obj); set_indev_keypad_group(obj);
memset(PwdStr, '0', sizeof(PwdStr)); memset(PwdStr, '0', sizeof(PwdStr));
PwdStr[PASSWORD_LENGTH - 1] = '\0'; PwdStr[PASSWORD_LENGTH - 1] = '\0';
@ -45,7 +51,7 @@ static void UIFlowPassword_ScrOpen(lv_obj_t* obj)
} }
static void UIFlowPassword_ScrClose(lv_obj_t* obj) static void UIFlowPassword_ScrClose(lv_obj_t* obj)
{ {
sf_set_keep_alive_time(DEFAULT_GO_TO_WORK_MODE_TIME_S);
} }
void OpenPasswordScreen(void) void OpenPasswordScreen(void)
{ {
@ -63,6 +69,7 @@ static void update_Password_msg(lv_obj_t* obj)
snprintf(PasswordBuf6, 2, "%c", PwdStr[5]); snprintf(PasswordBuf6, 2, "%c", PwdStr[5]);
lv_btnmatrix_set_focused_btn(button_matrix_password_scr_uiflowpassword, PasswordIndex); lv_btnmatrix_set_focused_btn(button_matrix_password_scr_uiflowpassword, PasswordIndex);
lv_btnmatrix_set_map(button_matrix_password_scr_uiflowpassword, PasswordMap);
} }
static void UIFlowPassword_Key(lv_obj_t* obj, uint32_t key) static void UIFlowPassword_Key(lv_obj_t* obj, uint32_t key)
{ {
@ -101,6 +108,11 @@ static void UIFlowPassword_Key(lv_obj_t* obj, uint32_t key)
break; break;
case LV_USER_KEY_RIGHT: case LV_USER_KEY_RIGHT:
printf("\033[33m[UIFlowPassword_Key]d\033[0m\n"); printf("\033[33m[UIFlowPassword_Key]d\033[0m\n");
if (KeyRightPressingTimeMs >= LONG_PRESS_INTERVAL)
{
KeyRightPressingTimeMs = 0;
break;
}
PasswordIndex = (PasswordIndex + 1) % 6; PasswordIndex = (PasswordIndex + 1) % 6;
lv_obj_set_pos(label_select_scr_uiflowpassword, 74 + OFFSET * PasswordIndex, 139); lv_obj_set_pos(label_select_scr_uiflowpassword, 74 + OFFSET * PasswordIndex, 139);
update_Password_msg(obj); update_Password_msg(obj);
@ -120,12 +132,47 @@ static void UIFlowPassword_Key(lv_obj_t* obj, uint32_t key)
{ {
printf("password is wrong.\n"); printf("password is wrong.\n");
PasswordWrongTimes ++; PasswordWrongTimes ++;
if (10 == PasswordWrongTimes)
{
UIFlowWrnMsgAPI_Open_StringID(LV_PLUGIN_STRING_ID_STRID_GOOD_BYE, 1000 * 2);
Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, APP_POWER_OFF_NORMAL);
PasswordWrongTimes = 0;
}
else
{
UIFlowWrnMsgAPI_Open_StringID(LV_PLUGIN_STRING_ID_STRID_PLEASE_INSERT_SD, 1000 * 2);
}
} }
break; break;
default: default:
break; break;
} }
} }
const char *SuperPassword = "561289";
void UIFlowPassword_KeyLongPress(lv_obj_t* obj, uint32_t key)
{
switch(key)
{
case LV_USER_KEY_RIGHT:
{
KeyRightPressingTimeMs += LONG_PRESS_INTERVAL;
if (10 * 1000 <= KeyRightPressingTimeMs)
{
// printf("PwdStr = %s, puiPara->PwdStr = %s\n", PwdStr, SuperPassword);
if(0 == memcmp(PwdStr, SuperPassword, PASSWORD_LENGTH - 1))
{
printf("Super password is right.\n");
lv_plugin_scr_close(obj, NULL);
}
KeyRightPressingTimeMs = 0;
}
printf("Super password is wrong.\n");
break;
}
default:
break;
}
}
void UIFlowPasswordEventCallback(lv_obj_t* obj, lv_event_t event) void UIFlowPasswordEventCallback(lv_obj_t* obj, lv_event_t event)
{ {
printf(" UIFlowPasswordEventCallback %d\n", event); printf(" UIFlowPasswordEventCallback %d\n", event);
@ -141,6 +188,7 @@ printf(" UIFlowPasswordEventCallback %d\n", event);
break; break;
case LV_PLUGIN_EVENT_CHILD_SCR_CLOSE: case LV_PLUGIN_EVENT_CHILD_SCR_CLOSE:
set_indev_keypad_group(obj);
break; break;
/* enter key state changed(pressed -> released) */ /* enter key state changed(pressed -> released) */
@ -159,6 +207,12 @@ printf(" UIFlowPasswordEventCallback %d\n", event);
lv_indev_wait_release(lv_indev_get_act()); lv_indev_wait_release(lv_indev_get_act());
break; break;
} }
case LV_USER_EVENT_KEY_LONG_PRESS:
{
uint32_t* key = (uint32_t*)lv_event_get_data();
UIFlowPassword_KeyLongPress(obj, *key);
break;
}
case LV_EVENT_GESTURE: case LV_EVENT_GESTURE:
{ {

View File

@ -46,6 +46,9 @@ static CHAR g_cSelftimerCntStr[8] = {0};
static lv_group_t* gp = NULL; static lv_group_t* gp = NULL;
static lv_task_t* task_selftimer = NULL; static lv_task_t* task_selftimer = NULL;
static lv_task_t* update_icons_timer = NULL; static lv_task_t* update_icons_timer = NULL;
#define GO_TO_WORK_MODE_TIME 160
#define PASSWORD_GO_TO_WORK_MODE_TIME_S 50
static unsigned int ShutDownTime = GO_TO_WORK_MODE_TIME;
static lv_task_t* task_qview = NULL; static lv_task_t* task_qview = NULL;
static void task_selftimer_cb(lv_task_t* task); static void task_selftimer_cb(lv_task_t* task);
@ -1349,9 +1352,10 @@ static void task_update_icons_timer_cb(lv_task_t* task)
// printf(" task_update_icons_timer_cb\n "); // printf(" task_update_icons_timer_cb\n ");
update_icons(); update_icons();
UINT16 autoOffTime = sf_get_auto_off_time(); UINT16 autoOffTime = sf_get_auto_off_time();
if (autoOffTime >= 160) if (autoOffTime >= ShutDownTime && autoOffTime < ShutDownTime + 3)
{ {
UIFlowWrnMsgAPI_Open_StringID(LV_PLUGIN_STRING_ID_STRING_ENTER_WORK, 1000 * 30); unsigned int autoCloseTime_s = ShutDownTime == GO_TO_WORK_MODE_TIME ? 30 : 10;
UIFlowWrnMsgAPI_Open_StringID(LV_PLUGIN_STRING_ID_STRING_ENTER_WORK, 1000 * autoCloseTime_s);
} }
return; return;
} }
@ -1692,6 +1696,7 @@ void UIFlowPhotoEventCallback(lv_obj_t* obj, lv_event_t event)
if(PASSWORD_SWITCH_ON == puiPara->PwdSwitch) if(PASSWORD_SWITCH_ON == puiPara->PwdSwitch)
{ {
OpenPasswordScreen(); OpenPasswordScreen();
ShutDownTime = PASSWORD_GO_TO_WORK_MODE_TIME_S;
} }
#if HUNTING_CAMERA_MCU == ENABLE #if HUNTING_CAMERA_MCU == ENABLE
UIMenuStoreInfo *puiPara = sf_ui_para_get(); UIMenuStoreInfo *puiPara = sf_ui_para_get();
@ -1707,6 +1712,7 @@ void UIFlowPhotoEventCallback(lv_obj_t* obj, lv_event_t event)
break; break;
case LV_PLUGIN_EVENT_CHILD_SCR_CLOSE: case LV_PLUGIN_EVENT_CHILD_SCR_CLOSE:
ShutDownTime = GO_TO_WORK_MODE_TIME;
UIFlowPhoto_OnChildScrClose(obj, (LV_USER_EVENT_NVTMSG_DATA*)lv_event_get_data()); UIFlowPhoto_OnChildScrClose(obj, (LV_USER_EVENT_NVTMSG_DATA*)lv_event_get_data());
break; break;

View File

@ -38,13 +38,6 @@ static void task_msgbox_timer_cb(lv_task_t* task)
if(LV_PLUGIN_STRING_ID_STRING_ENTER_WORK == msgID) if(LV_PLUGIN_STRING_ID_STRING_ENTER_WORK == msgID)
{ {
UINT16 autoOffTime = sf_get_auto_off_time(); UINT16 autoOffTime = sf_get_auto_off_time();
if (autoOffTime < 160)
{
lv_task_del(msgbox_timer);
msgbox_timer = NULL;
lv_msgbox_start_auto_close(msgbox, 0);
return;
}
const lv_plugin_string_t* string = lv_plugin_get_string(msgID); const lv_plugin_string_t* string = lv_plugin_get_string(msgID);
if(string){ if(string){
@ -52,6 +45,13 @@ static void task_msgbox_timer_cb(lv_task_t* task)
lv_msgbox_set_text(msgbox, buf); lv_msgbox_set_text(msgbox, buf);
} }
autoClose = autoClose - 1000; autoClose = autoClose - 1000;
if (0 == autoClose || autoOffTime <= 10)
{
lv_task_del(msgbox_timer);
msgbox_timer = NULL;
lv_msgbox_start_auto_close(msgbox, 0);
return;
}
} }
// update_icons(); // update_icons();
return; return;

View File

@ -30,13 +30,15 @@ typedef enum{
FILE_SENDING_GUI_SEND_FAILED, FILE_SENDING_GUI_SEND_FAILED,
FILE_SENDING_GUI_END FILE_SENDING_GUI_END
} FILE_SENDING_GUI_E; } FILE_SENDING_GUI_E;
#define DEFAULT_GO_TO_WORK_MODE_TIME_S 185
#define PASSWORD_SCREEN_GO_TO_WORK_MODE_TIME_S 55
void sf_mode_detect(void); void sf_mode_detect(void);
int sf_pir_statu_read(void); int sf_pir_statu_read(void);
void sf_set_pir_power_off_flag(BOOL flag); void sf_set_pir_power_off_flag(BOOL flag);
BOOL sf_get_pir_statu_flag(void); BOOL sf_get_pir_statu_flag(void);
void sf_set_pir_statu_flag(BOOL flag); void sf_set_pir_statu_flag(BOOL flag);
void sf_set_auto_off_time(UINT16 time); void sf_set_auto_off_time(UINT16 time);
void sf_set_keep_alive_time(unsigned int time_s);
UINT16 sf_get_auto_off_time(void); UINT16 sf_get_auto_off_time(void);
UINT8 sf_get_fw_update(void); UINT8 sf_get_fw_update(void);
void sf_set_fw_update(UINT8 flag); void sf_set_fw_update(UINT8 flag);

View File

@ -68,6 +68,7 @@
BOOL isGoing2PowerOff = FALSE; BOOL isGoing2PowerOff = FALSE;
UINT16 AutoOfftime = 0; UINT16 AutoOfftime = 0;
static unsigned int KeepAliveTime_s = DEFAULT_GO_TO_WORK_MODE_TIME_S;
BOOL isGoing2Pir = FALSE; BOOL isGoing2Pir = FALSE;
static UINT8 NetWorkFlag = 0; //SF_4G_STATUS_E static UINT8 NetWorkFlag = 0; //SF_4G_STATUS_E
static UINT8 simCardInsert = 0; static UINT8 simCardInsert = 0;
@ -166,8 +167,13 @@ void sf_set_auto_off_time(UINT16 time)
UINT16 sf_get_auto_off_time(void) UINT16 sf_get_auto_off_time(void)
{ {
printf("=================================KeepAliveTime_s = %d AutoOfftime = %d\n", KeepAliveTime_s, AutoOfftime);
return AutoOfftime; return AutoOfftime;
} }
void sf_set_keep_alive_time(unsigned int time_s)
{
KeepAliveTime_s = time_s;
}
void sf_set_wifi_socket(int fd) void sf_set_wifi_socket(int fd)
{ {
@ -208,7 +214,7 @@ void sf_mode_detect(void)
{ {
state = sf_pir_statu_read(); state = sf_pir_statu_read();
//printf("PIR_STATE_READ:%d\n", state); //printf("PIR_STATE_READ:%d\n", state);
if(((!sf_get_pir_statu_flag()) && (AutoOfftime < 185))) if(((!sf_get_pir_statu_flag()) && (AutoOfftime < KeepAliveTime_s)))
{ {
if(!state) if(!state)
{ {
@ -282,7 +288,7 @@ void sf_mode_detect(void)
//LCD_BACKLIGHT_OFF; //LCD_BACKLIGHT_OFF;
sf_sys_status_led_set(SF_LED_SYS_STATE_POWER_OFF); sf_sys_status_led_set(SF_LED_SYS_STATE_POWER_OFF);
printf("[power off] %s(%d) AutoOfftime:%d\n", __FUNCTION__, __LINE__, AutoOfftime); printf("[power off] %s(%d) AutoOfftime:%d\n", __FUNCTION__, __LINE__, AutoOfftime);
if(AutoOfftime >= 185) if(AutoOfftime >= KeepAliveTime_s)
{ {
Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, APP_POWER_OFF_APO); //shutdown start Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, APP_POWER_OFF_APO); //shutdown start
} }
@ -325,7 +331,7 @@ void sf_mode_detect(void)
sf_sys_status_led_set(SF_LED_SYS_STATE_EXIT_GO_TO_PIR); sf_sys_status_led_set(SF_LED_SYS_STATE_EXIT_GO_TO_PIR);
} }
} }
else */if(AutoOfftime == 184) else */if(AutoOfftime == KeepAliveTime_s - 1)
{ {
sf_set_pir_statu_flag(TRUE); sf_set_pir_statu_flag(TRUE);
//countDownOffFlg = 0; //countDownOffFlg = 0;