From 23d5a780ce1df804eb525e1b500af2349ba4f4d3 Mon Sep 17 00:00:00 2001 From: cheng Date: Mon, 19 Aug 2024 16:40:59 +0800 Subject: [PATCH] sleep mode --- .../src/AlarmClockTimerConfig.cpp | 27 +++--------- .../nativeui/applist/src/ApplistPresenter.cpp | 6 +++ .../src/DisplayBrightnessView.cpp | 5 +++ .../nativeui/sleep/include/SleepModel.h | 11 +++++ .../nativeui/sleep/src/SleepModel.cpp | 44 +++++++++++++++++++ .../service/ble_service/blemoder/bletest.cpp | 6 +++ 6 files changed, 78 insertions(+), 21 deletions(-) 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 748388c39..5a9c34785 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -383,11 +383,7 @@ extern "C" // uapi_dev_runtime_set_sleep_status(0); // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "起床啦!"); - if (OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) - { - OHOS::ConfigModel::GetInstance()->SetDnotdisturb(false); // 关闭勿扰 - SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0); - } + if (curTime.tm_hour == wake_time_hour && curTime.tm_min == wake_time_min && curTime.tm_sec == 0) { OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::WAKE); @@ -396,12 +392,9 @@ extern "C" OHOS::SleepModel::GetInstance().ReInitData(); // 更新睡眠数据 SendMsgToUIService(UI_UPDATE_SLEEP_DATA, 0, nullptr, 0); } - { - mmi_sleep_mode_flag_set(false); // switch off + + OHOS::SleepModel::GetInstance().ExitSleepModeAction(); - const power_display_svr_api_t *display_api = power_display_svr_get_api(); - display_api->set_brightness(OHOS::ConfigModel::GetInstance()->GetBrightness()); - } if (uapi_dev_runtime_get_sleep_status() == 0) { // 设置状态为小睡 @@ -427,17 +420,9 @@ extern "C" AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); OHOS::SleepModel::GetInstance().DeleteSleepData(); // 清空前一天睡眠数据 } - if (!OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) - { - OHOS::ConfigModel::GetInstance()->SetDnotdisturb(true); // 开启勿扰 - SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0); - } - { - mmi_sleep_mode_flag_set(true); // switch on - mmi_flip_wrist_switch_set(false); // switch off - const power_display_svr_api_t *display_api = power_display_svr_get_api(); - display_api->set_brightness(51); - } + + OHOS::SleepModel::GetInstance().EnterSleepModeAction(); + LOS_Msleep(1000); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp index 01821c221..74a3c8116 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp @@ -16,6 +16,7 @@ #include #include "heart_blood/health_service/health_service.h" #include "battery_hal.h" +#include "ConfigModelC.h" namespace OHOS { @@ -172,6 +173,11 @@ namespace OHOS HealthService::GetInstance()->SetHealthCurrent(highHealthState); viewId = VIEW_CHECK_INVALID; } + if(true == mmi_sleep_mode_flag_get()) + { + if(VIEW_DNOTDISTURB == viewId) + return false; + } NativeAbility::GetInstance().EnterSlice(viewId, type); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index 7fdfd3474..9d42149d5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -2,6 +2,7 @@ #include "displaybrightness/include/DisplayBrightnessModel.h" #include "wearable_log.h" #include "ConfigModel.h" +#include "ConfigModelC.h" #include "ui_resource_string.h" #include namespace OHOS @@ -348,6 +349,10 @@ namespace OHOS return false; } RaiseToBrightnessCheckBoxButton->SetOnChangeListener(presenter_); + if(true == mmi_sleep_mode_flag_get()) + { + RaiseToBrightnessCheckBoxButton->SetTouchable(false); + } return true; } 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 88c848f37..d8a32e928 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -119,6 +119,10 @@ namespace OHOS void Sleep_StartTimer(uint32_t interval); void Sleep_StopTimer(void); + // + void EnterSleepModeAction(void); + void ExitSleepModeAction(void); + private: SleepModel(); SleepModel(const SleepModel &); @@ -137,6 +141,13 @@ namespace OHOS int goal_total_time = 0; SLEEPSTATE sleepstate_ = SLEEPSTATE::WAKE; + + typedef struct + { + bool DnotdisturbFlag; + bool FlipWristFlag; + }DeviceStateBeforeSleep; + DeviceStateBeforeSleep DeviceStateBeforeSleep_ = {0}; }; } 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 a1bc6a07b..1de307fcf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -40,6 +40,8 @@ #include "thread_adapter.h" #include "cmsis_os.h" #include "ui_service.h" +#include "ConfigModelC.h" +#include "power_display_service.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); @@ -754,4 +756,46 @@ namespace OHOS g_timer = NULL; } } + + void SleepModel::EnterSleepModeAction(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d]:EnterSleepModeAction]", __LINE__); + // switch on + mmi_sleep_mode_flag_set(true); + + // switch on donotdisturb + DeviceStateBeforeSleep_.DnotdisturbFlag = OHOS::ConfigModel::GetInstance()->GetDnotdisturb(); + OHOS::ConfigModel::GetInstance()->SetDnotdisturb(true); // 开启勿扰 + SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0); + + // switch off flip wrist + DeviceStateBeforeSleep_.FlipWristFlag = mmi_flip_wrist_switch_get(); + mmi_flip_wrist_switch_set(false); // switch off + + // turn down brightness + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->set_brightness(51); + + } + + void SleepModel::ExitSleepModeAction(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d]:ExitSleepModeAction]", __LINE__); + // switch off + mmi_sleep_mode_flag_set(false); + + // reset donotdisturb + bool DnotdisturbFlag = DeviceStateBeforeSleep_.DnotdisturbFlag; + OHOS::ConfigModel::GetInstance()->SetDnotdisturb(DnotdisturbFlag); + SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0); + + // reset flip wrist + bool FlipWristFlag = DeviceStateBeforeSleep_.FlipWristFlag; + mmi_flip_wrist_switch_set(FlipWristFlag); + + // reset brightness + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->set_brightness(OHOS::ConfigModel::GetInstance()->GetBrightness()); + + } } \ No newline at end of file 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 4169bff40..669cf3aad 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -25,6 +25,7 @@ #include "cat1_server.h" // #include "TraingCardPresenter.h" #include "../../../../../../drivers/peripheral/vibrator/service/vibrator_service.h" +#include "../../../../../../drivers/peripheral/config/include/ConfigModelC.h" #ifdef FD230 #include "uiservice/include/ui_service.h" @@ -1794,6 +1795,11 @@ int get_ScreenDuration(void) //获取亮屏时长 } void Set_RaiseToWake(bool value) //抬婉亮屏开关 { + if(true == mmi_sleep_mode_flag_get()) + { + return; + } + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); p_ConfigModel->SetRaiseToWake(value); #ifdef FD230 -- 2.17.1