void UpdateSleepView();
+ /*定时器相关*/
+ void Sleep_StartTimer(uint32_t interval);
+ void Sleep_StopTimer(void);
+
private:
SleepModel();
SleepModel(const SleepModel &);
#include <string.h>
#include <dirent.h>
+#include "broadcast_feature.h"
+#include "broadcast_service.h"
+#include <cmsis_os2.h>
+#include <service/graphic_service.h>
+#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();
{
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
+/***
+ * @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
bool GetSleepNotifyFlag(void);
void SetSleepNotifyFlag(bool flag);
+
private:
SleepViewEventListener();
~SleepViewEventListener();
//睡眠提醒通知
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);
{
NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE);
}
+
NotificationManager::GetInstance()->ShowNotify(showSleepNotify, (uint16_t)topic, true);
+
}
#endif
return nullptr;
}
SleepGroupView->SetOnDragListener(dragListener);
+ // 注册释放notify
+ NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeSleepView);
/*获取最新sleep*/
SLEEPSTATE sleepsate = SleepModel::GetInstance().get_sleep_state();
UIResourceTextId textId = STR_MORNNING;
int32_t timeout = 5000; // 亮屏操作 5000ms 5秒关闭
SendMsgToUIService(SCREEN_TURN_ON_TO_UI, 0, &timeout, sizeof(int32_t));
- NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeSleepView);
+
return SleepGroupView;
}
{
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)
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;
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRewindToComplete test");
// 此处实现代码处理进度控制完成的事件
}
+
}
\ No newline at end of file