From f77978e0893c3acdf4b3d671b2b48fd04b69da93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Thu, 8 Aug 2024 07:40:12 +0000 Subject: [PATCH] Merge #660 into sdk602patch0626 from refs/changes/660/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/660/head: (11 commits squashed) - 屏蔽血氧监测过程中的数值显示 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 增加表盘星期string类model - 增加血氧&心率数据重启之后恢复 - 筛选表盘血氧无效数据 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 修复星期显示 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 适配早安闹钟小睡功能 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/660 --- .../nativeui/sleep/include/SleepModel.h | 4 + .../nativeui/sleep/src/SleepModel.cpp | 78 +++++++++++++++++++ .../include/notify/sleep_notification.h | 7 ++ .../msg_center/src/msg_center_customer.cpp | 6 +- .../src/notify/sleep_notification.cpp | 23 ++++-- 5 files changed, 112 insertions(+), 6 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h index 8aec31223..88c848f37 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -115,6 +115,10 @@ namespace OHOS void UpdateSleepView(); + /*定时器相关*/ + void Sleep_StartTimer(uint32_t interval); + void Sleep_StopTimer(void); + private: SleepModel(); SleepModel(const SleepModel &); diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp index 6d7cea9e4..be9e7086e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -33,6 +33,13 @@ #include #include +#include "broadcast_feature.h" +#include "broadcast_service.h" +#include +#include +#include "thread_adapter.h" +#include "cmsis_os.h" + extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format); extern "C" int get_sleep_time_from_config_model(void); extern "C" int get_wake_up_time_from_config_model(); @@ -672,4 +679,75 @@ namespace OHOS { return sleepstate_; } + /* ---------------------------------- 睡眠定时器 --------------------------------- */ + + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + + /*定时器到期时的处理*/ + static void Sleep_TimerCallbackProc(int data) + { + // 发起新闹钟 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Sleep_TimerCallbackProc"); + SleepModel::GetInstance().Sleep_StopTimer(); // 关闭定时器 + CustomEventPublish(TOPIC_EVENT_SLEEPNOTE, NULL, 0); // 发送睡眠弹窗 + } + + static void Sleep_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(Sleep_TimerCallbackProc, data)); + } + + void SleepModel::Sleep_StartTimer(uint32_t interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepModel::Sleep_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)Sleep_TimerCallback, osTimerOnce, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + } + g_timer = NULL; + return; + } + return; + } + + void SleepModel::Sleep_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + } + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h index c5bb150f0..1d1bfe78e 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-07-02 10:15:59 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-07 10:50:45 + * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h + */ #ifndef SLEEP_NOTIFICATION #define SLEEP_NOTIFICATION @@ -73,6 +79,7 @@ namespace OHOS bool GetSleepNotifyFlag(void); void SetSleepNotifyFlag(bool flag); + private: SleepViewEventListener(); ~SleepViewEventListener(); 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 90b0d60dd..ff6278562 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 @@ -694,10 +694,12 @@ void MsgCenterNotifyMessageProc(const Topic topic, Request* req) //睡眠提醒通知 void MsgCenterNotifySleepProc(const Topic topic, Request* req) { - unused(topic); unused(req); + unused(topic); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifySleepProc %d!",SleepModel::GetInstance().get_sleep_state()); + /*早安闹钟*/ if(SleepModel::GetInstance().get_sleep_state()==SLEEPSTATE::WAKE) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); @@ -710,7 +712,9 @@ void MsgCenterNotifySleepProc(const Topic topic, Request* req) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); } + NotificationManager::GetInstance()->ShowNotify(showSleepNotify, (uint16_t)topic, true); + } #endif diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp index a324d04e3..bdcb482e5 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp @@ -66,6 +66,8 @@ namespace OHOS return nullptr; } SleepGroupView->SetOnDragListener(dragListener); + // 注册释放notify + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeSleepView); /*获取最新sleep*/ SLEEPSTATE sleepsate = SleepModel::GetInstance().get_sleep_state(); UIResourceTextId textId = STR_MORNNING; @@ -153,7 +155,7 @@ namespace OHOS int32_t timeout = 5000; // 亮屏操作 5000ms 5秒关闭 SendMsgToUIService(SCREEN_TURN_ON_TO_UI, 0, &timeout, sizeof(int32_t)); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeSleepView); + return SleepGroupView; } @@ -270,16 +272,25 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::OnRelease"); UNUSED(event); + /* 知道了 按键*/ if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) { NotificationManager::GetInstance()->StopNotify(); } + /*关闭闹钟*/ if (strcmp(view.GetViewId(), CLOSEBUTTON) == 0) { - SleepRingPlayStop(); - // SetSleepNotifyFlag(false); + AlarmClockModel::GetInstance()->PopInterCancelMusic(); + NotificationManager::GetInstance()->StopNotify(); + } + /*小睡按键*/ + if (strcmp(view.GetViewId(), NOPBUTTON) == 0) + { + AlarmClockModel::GetInstance()->PopInterCancelMusic(); + SleepModel::GetInstance().Sleep_StartTimer(300000); // 开启一个5分钟的定时器 NotificationManager::GetInstance()->StopNotify(); } + return true; } bool SleepViewEventListener::OnDrag(UIView &view, const DragEvent &event) @@ -294,8 +305,9 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - SleepRingPlayStop(); - // SetSleepNotifyFlag(false); + // 如果是早安闹钟需要关闭闹钟 + if (SLEEPSTATE::WAKE == SleepModel::GetInstance().get_sleep_state()) + AlarmClockModel::GetInstance()->PopInterCancelMusic(); NotificationManager::GetInstance()->StopNotify(); } return true; @@ -551,4 +563,5 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRewindToComplete test"); // 此处实现代码处理进度控制完成的事件 } + } \ No newline at end of file -- 2.17.1