From 3a604f1f3a8e4c9863cd2f7751f9429b1a9d3596 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 9 Jul 2024 15:07:41 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=9D=A1=E7=9C=A0=E6=A8=A1?= =?utf8?q?=E5=BC=8F=EF=BC=8C=E5=B0=8F=E7=9D=A1=E6=A8=A1=E5=BC=8F=EF=BC=8C?= =?utf8?q?=E4=B9=85=E5=9D=90=E6=8F=90=E9=86=92=E4=B8=BA=E6=97=B6=E9=97=B4?= =?utf8?q?=E6=AE=B5=E8=A7=A6=E5=8F=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/AlarmClockTimerConfig.h | 2 + .../src/AlarmClockTimerConfig.cpp | 108 ++++++++++++++---- .../service/ble_service/blemoder/bletest.cpp | 3 +- .../msg_center/src/msg_center_customer.cpp | 2 +- .../drivers/peripheral/utils/custom_runtime.c | 31 +++++ .../drivers/peripheral/utils/custom_runtime.h | 8 ++ 6 files changed, 127 insertions(+), 27 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h index c386badd5..6b00037f1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h @@ -69,6 +69,8 @@ int32_t AlarmGetCurrentTimeInfo(struct tm *timeInfo); void set_sleep_and_wake_time(void); void set_sedentary_data(void); void get_sleep_time_notify(void); +void clean_sleep_flag(void); +void clean_sedentary_flag(void); #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 5ec486dfe..5754880bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -29,6 +29,7 @@ #include "heartrate/include/HeartModel.h" #include "sleep/include/SleepModel.h" #include "cat1_server_hal.h" +#include "custom_runtime.h" #ifdef __cplusplus extern "C" @@ -46,19 +47,63 @@ extern "C" static int sleep_notify_time = 0; static int sleep_time_hour = 0; static int sleep_time_min = 0; + static int wake_time_hour = 0; + static int wake_time_min = 0; static int sedentary_switch = 0; static int sedentary_time = 0; + static int sedentary_start_hour = 0; + static int sedentary_start_min = 0; + static int sedentary_stop_hour = 0; + static int sedentary_stop_min = 0; + + static int sleep_notify_time_min = 0; + static int sleep_notify_time_hour = 0; + + #define SEDENTARY_TIME_RANGE (((curTime.tm_hour > sedentary_start_hour) || (curTime.tm_hour == sedentary_start_hour && curTime.tm_min >= sedentary_start_min)) && \ + ((curTime.tm_hour < sedentary_stop_hour) || (curTime.tm_hour == sedentary_stop_hour && curTime.tm_min < sedentary_stop_min))) + + #define WAKE_TIME_RANGE (((wake_time_hour < sleep_time_hour) && \ + ((curTime.tm_hour > wake_time_hour) || \ + (curTime.tm_hour == wake_time_hour && curTime.tm_min >= wake_time_min)) && \ + ((curTime.tm_hour < sleep_time_hour) || \ + (curTime.tm_hour == sleep_time_hour && curTime.tm_min < sleep_time_min))) || \ + ((wake_time_hour >= sleep_time_hour) && \ + (((curTime.tm_hour > wake_time_hour) || \ + (curTime.tm_hour == wake_time_hour && curTime.tm_min >= wake_time_min)) || \ + ((curTime.tm_hour < sleep_time_hour) || \ + (curTime.tm_hour == sleep_time_hour && curTime.tm_min < sleep_time_min))) || \ + ((curTime.tm_hour > wake_time_hour) && (curTime.tm_hour < sleep_time_hour)))) + // 设置目标睡眠时间 void set_sleep_and_wake_time(void) { sleep_time = get_sleep_time_from_config_model(); wake_up_time = get_wake_up_time_from_config_model(); + sleep_time_hour = (sleep_time & 0xFFFF0000) >> 16; + sleep_time_min = sleep_time & 0x0000FFFF; + wake_time_hour = (wake_up_time & 0xFFFF0000) >> 16; + wake_time_min = wake_up_time & 0x0000FFFF; } void set_sedentary_data(void) { sedentary_switch = get_sedentary_switch_from_config_model(); sedentary_time = get_sedentary_time_from_config_model(); + sedentary_start_hour = (sedentary_time & 0XFF000000) >> 24; + sedentary_start_min = (sedentary_time & 0X00FF0000) >> 16; + sedentary_stop_hour = (sedentary_time & 0X0000FF00) >> 8; + sedentary_stop_min = sedentary_time & 0X000000FF; + } + + void clean_sleep_flag(void) + { + uapi_dev_runtime_set_sleep_status(0); + uapi_dev_runtime_set_nap_status(0); + } + + void clean_sedentary_flag(void) + { + uapi_dev_runtime_set_sedentary_status(0); } // 设置睡眠提醒时间 @@ -68,17 +113,17 @@ extern "C" int goal_min = (sleep_time & 0X0000FFFF); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_hour:%d goal_min:%d", goal_hour, goal_min); - sleep_time_min = (goal_min >= SLEPPNOTIFY) ? goal_min - SLEPPNOTIFY : ((goal_min + 60) - SLEPPNOTIFY); // 避免分钟数为负 - sleep_time_hour = goal_hour; + sleep_notify_time_min = (goal_min >= SLEPPNOTIFY) ? goal_min - SLEPPNOTIFY : ((goal_min + 60) - SLEPPNOTIFY); // 避免分钟数为负 + sleep_notify_time_hour = goal_hour; if (goal_min < SLEPPNOTIFY) { // 如果需要借位 - sleep_time_hour -= 1; // 小时减1 + sleep_notify_time_hour -= 1; // 小时减1 } // 确保小时数正确 - sleep_time_hour = (sleep_time_hour < 0) ? 23 : sleep_time_hour; // 处理从0点前20分钟的情况,变为前一天的23点40分 + sleep_notify_time_hour = (sleep_notify_time_hour < 0) ? 23 : sleep_notify_time_hour; // 处理从0点前20分钟的情况,变为前一天的23点40分 - sleep_notify_time = (sleep_time_hour << 16) | sleep_time_min; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_time_hour:%d sleep_time_min:%d sleep_notify_time:%d", sleep_time_hour, sleep_time_min, sleep_notify_time); + sleep_notify_time = (sleep_notify_time_hour << 16) | sleep_notify_time_min; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_time_hour:%d sleep_time_min:%d sleep_notify_time:%d", sleep_notify_time_hour, sleep_notify_time_min, sleep_notify_time); } void AlarmEventPublish(uint16_t topic, uint8_t *data, uint32_t size) { @@ -252,21 +297,44 @@ extern "C" if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_REMIND)) { // 提醒一次 - if ((curTime.tm_hour == sleep_time_hour) && (curTime.tm_min == sleep_time_min) && (curTime.tm_sec == 0)) + if ((curTime.tm_hour == sleep_notify_time_hour) && (curTime.tm_min == sleep_notify_time_min) && (curTime.tm_sec == 0)) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's bedtime in 20 minutes"); - printf("20分钟后要睡觉啦!\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "20分钟后要睡觉啦!"); AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); // 设置状态为睡眠提醒 OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEEPNOTIFY); } } - // 进入睡眠模式 - if (curTime.tm_hour == ((sleep_time & 0XFFFF0000) >> 16) && curTime.tm_min == (sleep_time & 0X0000FFFF) && curTime.tm_sec == 0) + // 退出睡眠模式 + if (WAKE_TIME_RANGE && (uapi_dev_runtime_get_nap_status() == 0)) { + uapi_dev_runtime_set_sleep_status(0); + uapi_dev_runtime_set_nap_status(1); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "起床啦!"); + if(curTime.tm_hour == wake_time_hour && curTime.tm_min == wake_time_min && curTime.tm_sec == 0) + { + // 早安提醒 + AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); + } + if(OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) + { + OHOS::ConfigModel::GetInstance()->SetDnotdisturb(false);//关闭勿扰 + } + // 设置状态为小睡 + OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::WAKE); + LOS_Msleep(1000); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); + } + //进入睡眠模式 + else if ((!WAKE_TIME_RANGE) && (uapi_dev_runtime_get_sleep_status() == 0)) + { + uapi_dev_runtime_set_sleep_status(1); + uapi_dev_runtime_set_nap_status(0); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); // 睡眠弹窗 - printf("要睡觉啦!\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "要睡觉啦!"); AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); // 设置状态为睡眠 OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEPP); @@ -274,28 +342,18 @@ extern "C" LOS_Msleep(1000); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL); } - // 退出睡眠模式 - else if (curTime.tm_hour == ((wake_up_time & 0XFFFF0000) >> 16) && curTime.tm_min == (wake_up_time & 0X0000FFFF) && curTime.tm_sec == 0) - { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); - printf("起床啦!\r\n"); - // 早安提醒 - AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); - // 设置状态为小睡 - OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::WAKE); - LOS_Msleep(1000); - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); - } } // 久坐提醒 if (sedentary_switch) { - if (curTime.tm_hour == ((sedentary_time & 0XFF000000) >> 24) && curTime.tm_min == ((sedentary_time & 0X00FF0000) >> 16) && curTime.tm_sec == 0) + if (SEDENTARY_TIME_RANGE && (uapi_dev_runtime_get_sedentary_status() == 0)) { + uapi_dev_runtime_set_sedentary_status(1); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_SEDENTARY, NULL); } - else if (curTime.tm_hour == ((sedentary_time & 0X0000FF00) >> 8) && curTime.tm_min == (sedentary_time & 0X000000FF) && curTime.tm_sec == 0) + else if ((!SEDENTARY_TIME_RANGE) && (uapi_dev_runtime_get_sedentary_status() == 1)) { + uapi_dev_runtime_set_sedentary_status(0); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_SEDENTARY, NULL); } } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 423cdb293..55dfaf5ce 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -525,7 +525,7 @@ void set_sedent_param( msg_sedent_set_param_info_t * data) p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SEDENTARY_INTERVAL,data->frequenc); set_sedentary_data(); - + clean_sedentary_flag(); return; } @@ -708,6 +708,7 @@ void ble_set_sleep_remind(msg_get_sleep_param_info_t data) //更新睡眠配置 OHOS::SleepModel::GetInstance().set_sleep_goal(); set_sleep_and_wake_time(); + clean_sleep_flag(); get_sleep_time_notify(); } return; diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index b4d32781d..278c72bcb 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -502,7 +502,7 @@ void MsgCenterNotifyHfpWatchProc(const Topic topic, Request* req) #ifdef SUPPORT_SPO2_NOTIFICATION_TEST -uint32_t md = PPG_SERVICE_CMD_TYPE_DO_PPG_TEST; + //灰卡测试 void MsgCenterNotifyCardProc(const Topic topic, Request* req) { diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index 8c23033f2..f8a717f2e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -69,6 +69,9 @@ typedef struct cat1_runtime_status_t cat1_runtime; char current_dial_name[32]; uint8_t time_hour_show_model; + uint8_t sleep_status; + uint8_t nap_status; + uint8_t sedentary_status; } runtime_status_t; @@ -280,3 +283,31 @@ uint8_t uapi_dev_runtime_get_vibmod(void) { return g_runtime.vibmod; } + +void uapi_dev_runtime_set_sleep_status(uint8_t status) +{ + g_runtime.sleep_status=status; +} +uint8_t uapi_dev_runtime_get_sleep_status(void) +{ + return g_runtime.sleep_status; +} + +void uapi_dev_runtime_set_nap_status(uint8_t status) +{ + g_runtime.nap_status=status; +} +uint8_t uapi_dev_runtime_get_nap_status(void) +{ + return g_runtime.nap_status; +} + +void uapi_dev_runtime_set_sedentary_status(uint8_t status) +{ + g_runtime.sedentary_status=status; +} +uint8_t uapi_dev_runtime_get_sedentary_status(void) +{ + return g_runtime.sedentary_status; +} + diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index ae905a276..dba14183b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -46,6 +46,14 @@ char* uapi_dev_runtime_get_dialname(void); void uapi_dev_runtime_set_vibmod(uint8_t vibmod); uint8_t uapi_dev_runtime_get_vibmod(void); + +void uapi_dev_runtime_set_sleep_status(uint8_t status); +uint8_t uapi_dev_runtime_get_sleep_status(void); +void uapi_dev_runtime_set_nap_status(uint8_t status); +uint8_t uapi_dev_runtime_get_nap_status(void); +void uapi_dev_runtime_set_sedentary_status(uint8_t status); +uint8_t uapi_dev_runtime_get_sedentary_status(void); + /***************************************cat1 runtime 变量设置获取函数**************************************************/ -- 2.17.1