From a24d1ffe18bd9d429fcb4eece17bd78343b63198 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Wed, 2 Oct 2024 23:36:39 +0000 Subject: [PATCH] Merge #1081 into sdk602patch0626 from refs/changes/1081/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 设置睡眠存储runtime,优化加锁逻辑 * refs/changes/1081/head: (1 commits squashed) - 设置睡眠存储runtime,优化加锁逻辑 降低gsensor功耗(10uA左右) Signed-off-by: aliyun6865282430 <1624952103@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1081 --- .../nativeui/sleep/src/SleepModel.cpp | 43 +++++++++++-------- .../drivers/peripheral/cywee/src/main_dml.c | 7 +++ .../drivers/peripheral/utils/custom_runtime.c | 15 +++++++ .../drivers/peripheral/utils/custom_runtime.h | 7 +++ 4 files changed, 54 insertions(+), 18 deletions(-) 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 86040315a..056eb7509 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: SLEPPNOTIFY24-06-26 19:36:48 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-09-30 11:47:04 + * @LastEditTime: 2024-10-02 17:56:07 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp * @Description: * @@ -44,6 +44,7 @@ #include "power_display_service.h" #include "MainModel.h" #include "cywee_service.h" +#include "custom_runtime.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); @@ -92,14 +93,6 @@ namespace OHOS bool save_nap_data(NAP_T *data) { - errcode_t ret; - ret = osal_mutex_lock(&sleep_mutex); - if (ret != ERRCODE_SUCC) - { - PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret); - return false; - } - struct stat info; char dir_path[64] = {0}; char file_path[64] = {0}; @@ -111,7 +104,6 @@ namespace OHOS { if (mkdir("user/userdata/sleep", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { - osal_mutex_unlock(&sleep_mutex); return false; // Failed to create folder } } @@ -121,7 +113,6 @@ namespace OHOS if (mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mkdir fail %s", dir_path); - osal_mutex_unlock(&sleep_mutex); return false; // Failed to create folder } } @@ -135,7 +126,6 @@ namespace OHOS if (fp == NULL) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data fopen fail"); - osal_mutex_unlock(&sleep_mutex); return false; } @@ -169,8 +159,6 @@ namespace OHOS fclose(fp); - osal_mutex_unlock(&sleep_mutex); - return true; } @@ -178,7 +166,19 @@ namespace OHOS { memset(&nap_data, 0, sizeof(NAP_T)); memcpy_s(&nap_data, sizeof(NAP_T), data, sizeof(NAP_T)); + + //睡眠存储加锁与设runtime状态统一在外面处理 + uapi_dev_runtime_set_sleep_storage_status(1); + errcode_t ret = osal_mutex_lock(&sleep_mutex); + if (ret != ERRCODE_SUCC) + { + PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret); + uapi_dev_runtime_set_sleep_storage_status(0); + return; + } save_nap_data(&nap_data); + osal_mutex_unlock(&sleep_mutex); + uapi_dev_runtime_set_sleep_storage_status(0); } uint32_t read_sleep_nap_data(char *data, uint32_t size, FILE *fp) @@ -296,7 +296,6 @@ namespace OHOS if (fp == NULL) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail"); - osal_mutex_unlock(&sleep_mutex); return false; } @@ -375,7 +374,6 @@ namespace OHOS if(fp == NULL) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail"); - osal_mutex_unlock(&sleep_mutex); return false; } // if(data->wake_up_timestamp != 0) @@ -424,8 +422,6 @@ namespace OHOS } fclose(fp); - osal_mutex_unlock(&sleep_mutex); - return true; } @@ -509,7 +505,18 @@ namespace OHOS { memset(&sleep_data, 0, sizeof(SLEEP_T)); memcpy_s(&sleep_data, sizeof(SLEEP_T), data, sizeof(SLEEP_T)); + //睡眠存储加锁与设runtime状态统一在外面处理 + uapi_dev_runtime_set_sleep_storage_status(1); + errcode_t ret = osal_mutex_lock(&sleep_mutex); + if (ret != ERRCODE_SUCC) + { + PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret); + uapi_dev_runtime_set_sleep_storage_status(0); + return; + } save_sleep_data(&sleep_data); + osal_mutex_unlock(&sleep_mutex); + uapi_dev_runtime_set_sleep_storage_status(0); // 刷新model里面的数据 // SleepModel::GetInstance().update_sleep(&sleep_data); } diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 455a5e1b2..9b86a82d4 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -1225,6 +1225,13 @@ int cywee_main_dml(void) // for(int i = 0 ; i < 80 ; i++) // printf("%d",buffer[i]); // printf("\n"); + + //降功耗 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 2; + CWM_SettingControl(SCL_SENS_CALI_CONFIG, &scl); + CWM_LibPostInit(CWM_AP_SensorListen); //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index b59b37457..35e0d6a79 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -92,6 +92,7 @@ typedef struct uint8_t lock_flag_training;//训练 uint8_t lock_flag_heartrate;//心率 uint8_t lock_flag_blood;//血氧 + uint8_t lock_flag_sleep;//睡眠 } runtime_status_t; @@ -472,6 +473,11 @@ uint8_t uapi_dev_runtime_get_rwlock_status(void) //血氧存储 g_runtime.rwlock_status = 1; } + if(g_runtime.lock_flag_sleep) + { + //睡眠存储 + g_runtime.rwlock_status = 1; + } return g_runtime.rwlock_status; } //设置运动存储 @@ -501,6 +507,15 @@ uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void) { return g_runtime.lock_flag_blood; } +//设置睡眠存储 +void uapi_dev_runtime_set_sleep_storage_status(uint8_t status) +{ + g_runtime.lock_flag_sleep = status; +} +uint8_t uapi_dev_runtime_get_sleep_storage_status(void) +{ + return g_runtime.lock_flag_sleep; +} //后续还需要补充。。。 // 设置被动心率检测状态 diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 358c2d3f7..6e71c8ffd 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -141,6 +141,13 @@ uint8_t uapi_dev_runtime_get_heartrate_storage_status(void); void uapi_dev_runtime_set_bloodoxygen_storage_status(uint8_t status); uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void); +/* + 睡眠存储 + 0 未存储 + 1 正在存储 +*/ +void uapi_dev_runtime_set_sleep_storage_status(uint8_t status); +uint8_t uapi_dev_runtime_get_sleep_storage_status(void); /*运动识别*/ void uapi_dev_runtime_set_motion_recognition_status(uint8_t status); -- 2.17.1