611 lines
18 KiB
C
611 lines
18 KiB
C
/*----------------------------------------------------------------------------
|
||
* Copyright (c) Fenda Technologies Co., Ltd. 2021. All rights reserved.
|
||
*
|
||
* Description: task_ui.c
|
||
*
|
||
* Author: saimen
|
||
*
|
||
* Create: 2021-08-08
|
||
*--------------------------------------------------------------------------*/
|
||
//lib
|
||
#include <stdint.h>
|
||
//#include <stdio.h>
|
||
//#include <stdlib.h>
|
||
//#include <string.h>
|
||
//os
|
||
#include "FreeRTOS.h"
|
||
#include "task.h"
|
||
#include "semphr.h"
|
||
#include "timers.h"
|
||
//sdk
|
||
#include "am_util.h"
|
||
//drv
|
||
#include "rtc_api.h"
|
||
#include "log_api.h"
|
||
#include "tp_api.h"
|
||
#include "display_api.h"
|
||
#include "flash_api.h"
|
||
#include "fs_api.h"
|
||
#include "lv_port_disp.h"
|
||
#include "lv_port_indev.h"
|
||
#include "ui_port_resource.h"
|
||
#include "ui_port_fw.h"
|
||
#include "ui_port_fit.h"
|
||
#include "ui_common.h"
|
||
#include "ui_cache_obj.h"
|
||
#include "ui_event.h"
|
||
//user
|
||
#include "sys_typedef.h"
|
||
#include "sys_config.h"
|
||
#include "sys_memory.h"
|
||
#include "sys_adapter.h"
|
||
#include "sql_setting.h"
|
||
#include "ui_main_all.h"
|
||
#include "ui_sys_remind.h"
|
||
#include "ui_more_alarm.h"
|
||
#include "user_charge.h"
|
||
//#include "ancillary_adapter.h"
|
||
#include "user_pack_analysis.h"
|
||
#include "task_ui.h"
|
||
#include "task_watchdog.h"
|
||
|
||
#define ENABLE_STATIC_PRINT false
|
||
extern void ui_port_print(const char *pcFmt, ...);
|
||
#define static_print_remind(...) ui_port_print(__VA_ARGS__)
|
||
#if ENABLE_STATIC_PRINT
|
||
#define static_print_info(...) ui_port_print(__VA_ARGS__)
|
||
#else
|
||
#define static_print_info(...)
|
||
#endif
|
||
|
||
|
||
ui_ctrl_t g_ui_ctrl={
|
||
.long_bright_en = 0,
|
||
.busy_en = false,
|
||
.cache_use_en = false,
|
||
.tp_un = false,
|
||
};
|
||
|
||
uint8_t app_over_sports = 0;// add 18574手环在运动数据完成页熄屏5秒后不能返回表盘,添加标志位,表示此时不在运动界面
|
||
static TaskHandle_t g_ui_task_handle = NULL;
|
||
static QueueHandle_t g_ui_queue_handle = NULL;
|
||
static TimerHandle_t g_ui_auto_off_timer = NULL;
|
||
|
||
extern void am_bsp_debug_printf_disable(void);
|
||
extern void screen_always_on_timer_init(void);
|
||
|
||
//*****************************************************************************
|
||
//
|
||
// UI软关机
|
||
//
|
||
//*****************************************************************************
|
||
void task_ui_enter_sleep_mode(void)
|
||
{
|
||
touchpad_api_deinit();
|
||
// display_api_close(); //关机时在挂起UI任务时再下电,防止下电后其他模块发送UI消息导致亮屏
|
||
flash_api_close();
|
||
|
||
// vTaskSuspend(g_ui_task_handle);
|
||
task_ui_notify(UI_MSG_TASK_SUSPEND, 0, NULL, 0);
|
||
}
|
||
|
||
//*****************************************************************************
|
||
//
|
||
// UI事件通知
|
||
//
|
||
//*****************************************************************************
|
||
void task_ui_notify(uint32_t MsgId, uint32_t Data, void* buf, uint32_t buf_len)
|
||
{
|
||
BaseType_t HigherPriorityTaskWoken = pdFALSE;
|
||
TaskMessage_t Msg = {0};
|
||
|
||
if(!(g_ui_queue_handle && g_ui_task_handle))
|
||
{
|
||
return;
|
||
}
|
||
|
||
Msg.uMessageID = MsgId;
|
||
Msg.uData = Data;
|
||
Msg.buffer = buf;
|
||
Msg.buf_len = buf_len;
|
||
|
||
if(__get_IPSR() != 0)
|
||
{
|
||
xQueueSendToBackFromISR(g_ui_queue_handle, &Msg, &HigherPriorityTaskWoken);
|
||
portYIELD_FROM_ISR(HigherPriorityTaskWoken);
|
||
}
|
||
else
|
||
{
|
||
xQueueSendToBack(g_ui_queue_handle, &Msg, pdMS_TO_TICKS(1000));
|
||
}
|
||
}
|
||
|
||
void * task_ui_get_queue_handle(void)
|
||
{
|
||
return g_ui_queue_handle;
|
||
}
|
||
|
||
void * task_ui_get_timer_handle(void)
|
||
{
|
||
return g_ui_auto_off_timer;
|
||
}
|
||
|
||
//*****************************************************************************
|
||
//
|
||
// 自动关屏定时器
|
||
//
|
||
//*****************************************************************************
|
||
|
||
#define UI_AUTO_OFF_TIMER_TIMEOUT 5 //default
|
||
|
||
void task_ui_auto_off_timer_callback(TimerHandle_t TP_Test_Timer)
|
||
{
|
||
static_print_info("ui_auto_off_timer_callback\r\n");
|
||
|
||
if(screen_always_on_flag == true) //chang by hes -- BUG ID 15852
|
||
{
|
||
screen_always_on_flag = false;
|
||
// ui_auto_off_timer_restart();
|
||
}
|
||
task_ui_notify(UI_MSG_DISPLAY_CLOSE, 0, NULL, NULL);
|
||
}
|
||
|
||
void task_ui_auto_off_timer_init(void)
|
||
{
|
||
uint16_t auto_off_time = 0;
|
||
|
||
auto_off_time = ui_get_turn_off_screen_time();
|
||
if(auto_off_time == 0 || auto_off_time > 60)
|
||
{
|
||
auto_off_time = UI_AUTO_OFF_TIMER_TIMEOUT;
|
||
}
|
||
g_ui_auto_off_timer = xTimerCreate
|
||
("g_ui_auto_off_timer",
|
||
pdMS_TO_TICKS(auto_off_time * 1000),
|
||
//pdTRUE,
|
||
pdFALSE,
|
||
0,
|
||
task_ui_auto_off_timer_callback);
|
||
}
|
||
|
||
void task_ui_auto_off_timer_restart(void)
|
||
{
|
||
if(screen_always_on_flag == true)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if(g_ui_auto_off_timer != NULL)
|
||
{
|
||
uint16_t auto_off_time = ui_get_turn_off_screen_time();
|
||
static_print_info("auto_off_time %d timer restart \r\n", auto_off_time);
|
||
if(auto_off_time == 0 || auto_off_time > 60)
|
||
{
|
||
auto_off_time = UI_AUTO_OFF_TIMER_TIMEOUT;
|
||
}
|
||
xTimerChangePeriod(g_ui_auto_off_timer, pdMS_TO_TICKS(auto_off_time * 1000), pdMS_TO_TICKS(5));
|
||
}
|
||
}
|
||
|
||
void task_ui_auto_off_timer_start(void)
|
||
{
|
||
if(g_ui_auto_off_timer != NULL)
|
||
{
|
||
xTimerStart(g_ui_auto_off_timer, pdMS_TO_TICKS(5));
|
||
}
|
||
}
|
||
|
||
void task_ui_auto_off_timer_stop(void)
|
||
{
|
||
if(g_ui_auto_off_timer != NULL)
|
||
{
|
||
xTimerStop(g_ui_auto_off_timer, pdMS_TO_TICKS(5));
|
||
}
|
||
}
|
||
|
||
//*****************************************************************************
|
||
//
|
||
// 用于UI特别处理的功能接口
|
||
//
|
||
//*****************************************************************************
|
||
void task_ui_tick_add(void)
|
||
{
|
||
static uint32_t pre_tick = 0;
|
||
static uint32_t current_tick = 0;
|
||
|
||
current_tick = xTaskGetTickCount();
|
||
lv_tick_inc(current_tick - pre_tick);
|
||
pre_tick = current_tick;
|
||
}
|
||
|
||
|
||
//*****************************************************************************
|
||
//
|
||
// UI任务事件处理
|
||
//
|
||
//*****************************************************************************
|
||
|
||
static void task_ui_event_preprocess_handler(TaskMessage_t *rcvMsg)
|
||
{
|
||
static uint8_t timeout_count = 0;
|
||
struct tm* p_date_time;
|
||
|
||
switch(rcvMsg->uMessageID)
|
||
{
|
||
case EVENT_OTA_INSTALL_START:
|
||
case EVENT_OTA_TRANS_START:
|
||
case EVENT_OTA_INSTALLING:
|
||
case EVENT_OTA_SUCCESS:
|
||
case EVENT_OTA_FAIL:
|
||
case EVENT_OTA_FAIL_REMIND_TIMEOUT:
|
||
case EVENT_OTA_RESET:
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
uimanager_goto_screen(SCREEN_RESOURCE_OTA);
|
||
break;
|
||
|
||
//Add:解决18843勿扰状态下触摸不需要亮屏问题
|
||
case UI_MSG_TP_WAKEUP:
|
||
case UI_MSG_TP_DOWN:
|
||
case UI_MSG_TP_UP:
|
||
// if(adpt_get_no_disturb_state_now())
|
||
// {
|
||
// g_ui_ctrl.preprocess_status = UI_PERPROCESS_CLOSE;
|
||
// }
|
||
// else
|
||
{
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
}
|
||
break;
|
||
|
||
case UI_MSG_DISPLAY_OPEN:
|
||
case EVENT_BTN_UPDATA:
|
||
case EVENT_BTN_CLICK:
|
||
case UI_MSG_WRIST_UP:
|
||
case EVENT_BATT_CHARGE_EXIT:
|
||
case EVENT_BATT_CHARGE_FULL:
|
||
if(sql_setting_get_st_watchface_id() != 0)
|
||
{
|
||
StandbyWatchfaceTransitOut();
|
||
}
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
break;
|
||
|
||
case EVENT_STRESS_MEASURE_SWITCH:
|
||
if(rcvMsg->uData && (g_ui_ctrl.ate_en == false))
|
||
{
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
uimanager_goto_screen(SCREEN_APP_STRESS);
|
||
}
|
||
break;
|
||
case EVENT_BLOOD_PRESSURE_MEASURE_SWITCH:
|
||
|
||
if(g_ui_ctrl.ate_en == false)
|
||
{
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
g_ui_ctrl.bp_app_flag = true;
|
||
uimanager_goto_screen(SCREEN_BLOODPRESSURE);
|
||
}
|
||
break;
|
||
case EVENT_BTN_DOWN:
|
||
if(display_api_read_status()==false)
|
||
{
|
||
g_ui_ctrl.button_home_un = true;
|
||
}
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
break;
|
||
|
||
case EVENT_RTC_SECOND:
|
||
if(g_ui_ctrl.ate_en == false)
|
||
{
|
||
if(display_api_read_status())
|
||
{
|
||
timeout_count = 0;
|
||
}
|
||
else
|
||
{
|
||
if(timeout_count >= 5)
|
||
{
|
||
ui_main_activate_default();
|
||
}
|
||
else
|
||
{
|
||
timeout_count++;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
|
||
case EVENT_RTC_MINUTE:
|
||
if(sql_setting_get_st_watchface_id() != 0)
|
||
{
|
||
StandbyWatchfaceUpdate();
|
||
}
|
||
p_date_time = ui_port_get_local_time();
|
||
if(p_date_time->tm_hour==0&&p_date_time->tm_min==0)//天事件
|
||
{
|
||
task_ui_notify(EVENT_RTC_DAY, 0, NULL, NULL);
|
||
}
|
||
break;
|
||
|
||
case EVENT_TYPE_BLE_CLOSE:
|
||
// if(ui_exer_single_check_handle_ble_close())
|
||
{
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
}
|
||
break;
|
||
|
||
case EVENT_WORKOUT_SYNC:
|
||
if (ui_port_get_charge_state() == false)
|
||
{
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
ui_ble_sync_single_exercise(rcvMsg->uData);
|
||
}
|
||
break;
|
||
|
||
case EVENT_BATT_CHARGE_ENTER:
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
if(g_ui_ctrl.ate_en == false)
|
||
{
|
||
if(charge_api_get_usb_status())
|
||
{
|
||
uimanager_goto_screen(SCREEN_CHARGE);
|
||
}
|
||
}
|
||
break;
|
||
|
||
case EVENT_REMIND_BLE_OVER_DIS_DISCONNECT:
|
||
case EVENT_REMIND_BATTERY_LOW:
|
||
case EVENT_REMIND_CALL:
|
||
case EVENT_REMIND_FIND_BAND:
|
||
case EVENT_REMIND_ALARM:
|
||
case EVENT_REMIND_MESSAGE:
|
||
case EVENT_REMIND_SEDENTARY:
|
||
case EVENT_REMIND_STEP_GOAL:
|
||
case EVENT_REMIND_HR_HIGHT:
|
||
case EVENT_REMIND_HR_LOW:
|
||
case EVENT_REMIND_SPO2_LOW:
|
||
case EVENT_REMIND_PAIR:
|
||
case EVENT_REMIND_TIMING:
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
ui_sys_remind_event_entry(rcvMsg);
|
||
break;
|
||
|
||
case EVENT_WORKOUT_REMEND_DISTANCE:
|
||
case EVENT_WORKOUT_REMEND_CALORIE:
|
||
case EVENT_WORKOUT_REMEND_TIME:
|
||
case EVENT_WORKOUT_REMEND_CALORIE_PRE:
|
||
case EVENT_WORKOUT_REMEND_TIME_PRE:
|
||
case EVENT_WORKOUT_REMEND_KM:
|
||
case EVENT_WORKOUT_HEART_ALARM:
|
||
case EVENT_WORKOUT_SUMMARY_DATA:
|
||
case EVENT_WORKOUT_TIMEOUT:
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_OPEN;
|
||
break;
|
||
|
||
case EVENT_LANGUAGE_CHANGE:
|
||
static_print_remind("EVENT_LANGUAGE_CHANGE:%d-%d\r\n", g_ui_ctrl.curr_language,sql_setting_get_language());
|
||
if(g_ui_ctrl.curr_language != sql_setting_get_language())
|
||
{
|
||
g_ui_ctrl.curr_language = sql_setting_get_language();
|
||
uimanager_goto_screen_ext(uimanager_get_current_screenid(),NULL,NULL,SCREEN_ACT_SAVE,SCREEN_ACT_RECOVER,true);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
void task_ui_event_handler(void)
|
||
{
|
||
TaskMessage_t rcvMsg = {0};
|
||
uint32_t rt_tick = 0;
|
||
uint8_t is_event_continue_run = 1;
|
||
|
||
if(display_api_read_status())
|
||
{
|
||
if(xQueueReceive(g_ui_queue_handle, &rcvMsg, 10) != pdPASS)
|
||
{
|
||
task_ui_tick_add();
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(xQueueReceive(g_ui_queue_handle, &rcvMsg, 100) != pdPASS)
|
||
{
|
||
task_ui_tick_add();
|
||
return;
|
||
}
|
||
}
|
||
|
||
task_ui_tick_add();
|
||
rt_tick = xTaskGetTickCount();
|
||
static_print_info("\r\n%d ui_queue:0x%x-0x%x-%d-%d\r\n", rt_tick, rcvMsg.uMessageID, rcvMsg.uData,g_ui_ctrl.cache_use_en,g_ui_ctrl.busy_en);
|
||
#if 0
|
||
extern BaseType_t queue_messages_waiting( void *pxQueue );
|
||
if((g_ui_ctrl.busy_en == 1) && (temp_tick > 100) && queue_messages_waiting(ui_get_queue_handle()) == 0)
|
||
{
|
||
g_ui_ctrl.busy_en = 0;
|
||
task_ui_notify(UI_MSG_BUSY_OFF, 0, NULL, 0);
|
||
}
|
||
#endif
|
||
task_ui_event_preprocess_handler(&rcvMsg);
|
||
switch(rcvMsg.uMessageID)
|
||
{
|
||
case UI_MSG_TASK_SUSPEND:
|
||
display_api_close();
|
||
vTaskSuspend(NULL); //vTaskResume(g_ui_task_handle);
|
||
break;
|
||
|
||
case UI_MSG_DRAW:
|
||
//user_draw_buffer();
|
||
break;
|
||
|
||
case UI_MSG_TP_PALM:
|
||
case UI_MSG_DISPLAY_CLOSE:
|
||
case UI_MSG_WRIST_DOWN:
|
||
if(g_ui_ctrl.long_bright_en <= 0)
|
||
{
|
||
if(indev_touchpad->proc.state == LV_INDEV_STATE_PR)
|
||
{
|
||
task_ui_auto_off_timer_restart();
|
||
}
|
||
else if(display_api_read_status() == true)
|
||
{
|
||
log_api_record_action(rtc_api_get_utc_timestamp(), EVT_SCREEN_MANAGE, INFO1_SCR_SCREEN_OFF, 0, 0, NULL);
|
||
// display_api_close();
|
||
sys_burst_mode_switch(0, 0, false); //MCU 48MHz
|
||
if((sql_setting_get_st_watchface_id() != 0) && (rcvMsg.uMessageID == UI_MSG_DISPLAY_CLOSE))
|
||
{
|
||
StandbyWatchfaceTransitIn();
|
||
}
|
||
else
|
||
{
|
||
touchpad_api_enter_idle();
|
||
display_api_close();
|
||
}
|
||
}
|
||
}
|
||
#if (DEBUG_LOG == OFF)
|
||
// am_bsp_debug_printf_disable();
|
||
#endif
|
||
break;
|
||
|
||
case UI_MSG_START_TIMER:
|
||
task_ui_auto_off_timer_restart();
|
||
g_ui_ctrl.long_bright_en--;
|
||
break;
|
||
|
||
case UI_MSG_STOP_TIMER:
|
||
task_ui_auto_off_timer_stop();
|
||
g_ui_ctrl.long_bright_en++;
|
||
break;
|
||
|
||
default:
|
||
if(display_api_read_status() || g_ui_ctrl.preprocess_status == UI_PERPROCESS_OPEN)
|
||
{
|
||
if(rcvMsg.uMessageID == EVENT_BTN_CLICK && g_ui_ctrl.button_home_un)
|
||
{
|
||
g_ui_ctrl.button_home_un = false;
|
||
}
|
||
else
|
||
{
|
||
if(ui_get_resource_check_result())
|
||
{
|
||
ui_current_sys_remind_event_handle(rcvMsg.uMessageID, &is_event_continue_run);
|
||
}
|
||
if(is_event_continue_run)
|
||
{
|
||
uimanager_dispatch_event(rcvMsg.uMessageID, rcvMsg.uData, &rcvMsg);
|
||
}
|
||
}
|
||
}
|
||
|
||
if(g_ui_ctrl.preprocess_status == UI_PERPROCESS_OPEN)
|
||
{
|
||
task_ui_auto_off_timer_restart();
|
||
if(display_api_read_status() != true)
|
||
{
|
||
log_api_record_action(rtc_api_get_utc_timestamp(), EVT_SCREEN_MANAGE, INFO1_SCR_SCREEN_ON, 0, 0, NULL);
|
||
touchapd_api_exit_idle();
|
||
display_api_open();
|
||
sys_burst_mode_switch(0, 0, true); //MCU 96MHz
|
||
lv_obj_invalidate(lv_scr_act());
|
||
//ui_port_check_power();
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
g_ui_ctrl.preprocess_status = UI_PERPROCESS_NULL;
|
||
}
|
||
|
||
void task_ui_entry(void *pvParameters)
|
||
{
|
||
static_print_remind("task_ui_entry\r\n");
|
||
dispaly_api_logo_refresh();
|
||
sys_smart_delay_ms(3000);
|
||
uimanager_goto_default();
|
||
task_ui_auto_off_timer_restart();
|
||
screen_always_on_timer_init();
|
||
sys_burst_mode_switch(1, 0, true); //MCU 96MHz
|
||
|
||
while(1)
|
||
{
|
||
lv_task_handler();
|
||
task_ui_event_handler();
|
||
uint8_t conut = 0;
|
||
while(task_watchdog_get_timeout_status())
|
||
{
|
||
sys_smart_delay_ms(5);
|
||
//static_print_remind("ui_task_entry \r\n");
|
||
conut++;
|
||
if(conut > 200)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
static int scan_dir_cb(bool in, const char *path, int32_t size, void *arg)
|
||
{
|
||
int ret;
|
||
int fileSize;
|
||
bool isDir;
|
||
char file_data[64];
|
||
|
||
//fileSize = FSStat(path, &isDir);
|
||
//ret = FSFileLoad( path, 0, file_data, 64);
|
||
static_print_remind("scan_dir_cb: %s:%d \r\n", path,size);
|
||
return 0;
|
||
}
|
||
|
||
void task_ui_init(uint16_t stack_depth, uint16_t priority)
|
||
{
|
||
char *path_test = "/FD";
|
||
|
||
task_ui_auto_off_timer_init();
|
||
g_ui_queue_handle = xQueueCreate(16, sizeof(TaskMessage_t));
|
||
|
||
lv_init();
|
||
lv_port_disp_init();
|
||
lv_port_indev_init();
|
||
ui_common_init();
|
||
ui_cache_obj_init();
|
||
//初始化从文件读取保存亮度值
|
||
// port_ui_set_screen_brightness_pwr_on();
|
||
//包解析
|
||
// user_pack_analysis_dir(DIR_PACK);
|
||
// FSDirScan(path_test, scan_dir_cb, path_test);
|
||
user_pack_effect_dir(DIR_PACK);
|
||
// FSDirScan(path_test, scan_dir_cb, path_test);
|
||
// FSDirRemove("/FD/ui");
|
||
// ret = FSUnlink("/FD/received/en.yml");
|
||
static_print_remind("fs_api_unused()= 0x%x \r\n", fs_api_unused());
|
||
g_ui_ctrl.curr_language = sql_setting_get_language();
|
||
|
||
if(ui_resource_check() == true && ENTER_USER_PATTERN == sys_get_app_pattern_flag())
|
||
{
|
||
g_ui_ctrl.ate_en = false;
|
||
if(ui_port_get_band_state() == UI_STARTUP_NORMAL)
|
||
{
|
||
uimanager_set_default(SCREEN_MAIN);
|
||
}
|
||
else
|
||
{
|
||
uimanager_set_default(SCREEN_STARTUP);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
g_ui_ctrl.ate_en = true;
|
||
uimanager_set_default(SCREEN_ATE_MENU);
|
||
}
|
||
xTaskCreate(task_ui_entry, "task_ui_entry", stack_depth, 0, priority, &g_ui_task_handle);
|
||
if(g_ui_task_handle == NULL)
|
||
{
|
||
static_print_remind("task_ui_init() error\r\n");
|
||
}
|
||
}
|
||
|