From a4402053733a951343a5e9a0be4d2aa36587023e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Sat, 30 Nov 2024 03:35:08 +0000 Subject: [PATCH] Merge #1474 into sdk602patch0911 from refs/changes/1474/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/1474/head: (4 commits squashed) - 心率血氧:优化异常数据存储 - 消息:优化大量消息的处理 - 心率:优化心率数据的debug界面 - 系统:优化部分UI操作 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Merged-by: aliyun6865282430 <1624952103@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1474 --- .../bloodoxygen/src/BloodOxygenModel.cpp | 16 +- .../health_service/health_service.cpp | 43 ++ .../health_service/health_service.h | 5 + .../nativeui/heartrate/src/HeartModel.cpp | 61 +- .../nativeui/message/src/MessageModel.cpp | 90 +-- .../takephotos/src/TakephotosModel.cpp | 2 + .../msg_center/src/msg_center_customer.cpp | 18 +- .../msg_center/src/msg_center_customerC.h | 17 + .../debug_output_notification.cpp | 7 +- .../src/notify/message_notification.cpp | 638 +++++++++--------- .../peripheral/config/include/ConfigModelC.h | 11 +- .../peripheral/config/src/ConfigModel.cpp | 21 +- .../utils/custom_fileoperate_service.c | 4 + .../drivers/peripheral/utils/custom_utils.h | 2 + .../peripheral/utils/custom_utils_at_cmd.c | 63 +- .../components/ui_image_animator.cpp | 2 +- 16 files changed, 568 insertions(+), 432 deletions(-) create mode 100644 code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index 9cf112a33..f8d5a614d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -159,12 +159,14 @@ namespace OHOS { uint16_t MiniBlood = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_OXYGEN_THRESHOLD_VALUE); - // 检查当前血氧值并设置结果 - if (currentspo2 < MiniBlood && currentspo2 != 0) - { - // 测量结果小于最小血氧值 - bloodresult_ = BloodResult::LOW_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况, currentspo2 = %d, MiniBlood = %d", currentspo2, MiniBlood); + // 检查当前血氧值并设置结果 需要检测成功 + if(bloodresult_ == BloodResult::SUCCESS){ + if (currentspo2 < MiniBlood && currentspo2 != 0) + { + // 测量结果小于最小血氧值 + bloodresult_ = BloodResult::LOW_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况, currentspo2 = %d, MiniBlood = %d", currentspo2, MiniBlood); + } } // 根据结果进行处理 @@ -197,6 +199,8 @@ namespace OHOS healthState.resultStatus = LOW; healthState.checkResult = MiniBlood; HealthService::GetInstance()->SetHealthCurrent(healthState); + //保存异常数据 + Blood_Save(); NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID); break; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index 629ae1d2a..5a7f32400 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -692,4 +692,47 @@ void HealthService::send_blood_save() { do_custom_fileoperate_service_check_msg( CUSTOM_FILEOPERATE_MSG_TYPE_BLOODXYGEN_SAVE, nullptr, 0); } + +std::string HealthService::formatTime(uint32_t time) { + char labelTime[20]; + if (uapi_get_TIME_STR(time, labelTime, '.', ':', DATE_Y_M_D_H_M) != + ERRCODE_SUCC) { + return "--"; // 默认值 + } else { + return labelTime; // 成功获取时间 + } +} +// 读取心率数据 +std::string HealthService::get_heart_data() { + std::string binFilePath = GetBinFilePath(HEALTH_TYPE_HEART); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "binFilePath %s", binFilePath.c_str()); + FILE *fp = fopen(binFilePath.c_str(), "rb"); // 以二进制读取模式打开文件 + if (fp == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to open binary file for reading"); + return "Error: Unable to open file \n"; // 返回错误信息 + } + + std::string result; + HeartRateData data; + + result += "file:" + binFilePath + "\n"; + + // 读取数据直到文件结束 + while (fread(&data, sizeof(HeartRateData), 1, fp) == 1) { + // 将数据格式化为字符串,拼接到结果中 + result += + formatTime(data.timestamp) + "," + std::to_string(data.Heart) + "\n"; + } + + if (ferror(fp)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Error reading data from binary file"); + fclose(fp); + return "Error: Reading error \n"; // 返回读取错误信息 + } + + fclose(fp); // 关闭文件 + return result.empty() ? "No data found \n" : result; // 检查是否读取到数据 +} } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h index 4ab119d10..f7df7d823 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h @@ -13,6 +13,7 @@ #include #include #include +#include #define HEART_MAX_POINTS 360 #define MSG_SAVE_TEST 0 @@ -100,6 +101,10 @@ namespace OHOS void send_heart_save(); void send_blood_save(); + std::string get_heart_data(); + std::string get_blood_data(); + std::string formatTime(uint32_t time); + private: static const int MAX_HOURS = 24; HeartRateData dailyHeartRates[MAX_HOURS]; // 存储心率值,检测时间戳?使用结构体? diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp index 38ac39b37..ee2c95a5a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -21,6 +21,7 @@ #include "uiservice/include/ui_service.h" #include "wearable_log.h" #include + #include #include #include @@ -40,6 +41,8 @@ #include "languagecode/LanguageInit.h" #include "ui_service.h" +#include "hx3695.h" + #ifdef __cplusplus extern "C" { #endif @@ -475,6 +478,7 @@ void HeartModel::Heart_Stop() { Heart_Control(HeartState::End, HeartCheck::PASSIVITY); return; } + //呼吸训练模式下不进行息屏与保存 if (sensorstate && uapi_dev_runtime_get_respiratory_training_status() != 1) { // 恢复正常亮屏 HeartModel::GetInstance()->heart_stop_screen60s_timer(); @@ -514,34 +518,39 @@ void HeartModel::Heart_Save() { } void HeartModel::Heart_Result() { - // 获取心率提醒状态和阈值 - heartRemindState = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND); - thresholdValue = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE); - - if (heartRemindState) { - // 获取当前心率状态 - thresholdState = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); - - if (currentheart != 0) { - if (thresholdState == 0 && currentheart < thresholdValue) { - // 当前心率低于阈值 - heartresult_ = HeartResult::LOW_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "检测结果:低结果情况,currentheart=%d,ThresholdValue=%d", - currentheart, thresholdValue); - } else if (thresholdState == 1 && currentheart > thresholdValue) { - // 当前心率高于阈值 - heartresult_ = HeartResult::HIGH_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "检测结果:高结果情况,currentheart=%d,ThresholdValue=%d", - currentheart, thresholdValue); + + if (heartresult_ == HeartResult::SUCCESS) { + // 获取心率提醒状态和阈值 + heartRemindState = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND); + thresholdValue = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "心率提醒状态:%d,阈值:%d,當前值:%d", + heartRemindState, thresholdValue, currentheart); + + if (heartRemindState) { + // 获取当前心率状态 + thresholdState = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); + + if (currentheart != 0) { + if (thresholdState == 0 && currentheart < thresholdValue) { + // 当前心率低于阈值 + heartresult_ = HeartResult::LOW_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "检测结果:低结果情况,currentheart=%d,ThresholdValue=%d", + currentheart, thresholdValue); + } else if (thresholdState == 1 && currentheart > thresholdValue) { + // 当前心率高于阈值 + heartresult_ = HeartResult::HIGH_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "检测结果:高结果情况,currentheart=%d,ThresholdValue=%d", + currentheart, thresholdValue); + } } } } - // 根据结果进行处理 handleHeartResult(); } @@ -565,10 +574,12 @@ void HeartModel::handleHeartResult() { break; case HeartResult::LOW_RESULT: + Heart_Save(); handleLowHeartRate(); break; case HeartResult::HIGH_RESULT: + Heart_Save(); handleHighHeartRate(); break; diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp index 07d077e5e..41a0f97ad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -43,6 +43,8 @@ #include "message/include/MessageControlView.h" #include "message/include/MessageView.h" +#include "traing/include/TraingModel.h" + #define MESSAGE_JSON_FILE "user/userdata/ancs.json" #define MESSAGE_JSON_DIR "user/userdata/message/" #define PRINTFDATA 0 @@ -110,11 +112,7 @@ void MessageUnsubscribeTopic(Topic topic) { } // 存储消息更新的定时器 -static std::chrono::milliseconds updateDelay(500); // 设置更新延迟,0.5s -static std::chrono::steady_clock::time_point lastUpdateTime; -static bool shouldDisplayMessage = false; -static ancs_data_info_t *lastMessageInfo = NULL; -static std::mutex messageMutex; // 互斥锁 +static uint32_t messageTimestamp = 0; static void Notify(void *args, const Topic topic, Request *request) { UNUSED(args); @@ -132,18 +130,18 @@ static void Notify(void *args, const Topic topic, Request *request) { "Processing TOPIC_EVENT_MESSAGE_UPDATA"); // 创建新的消息信息 - ancs_data_info_t *messageInfo = new ancs_data_info_t(); - if (messageInfo == NULL) { + ancs_data_info_t *messageInfo = new (std::nothrow) ancs_data_info_t(); + if (messageInfo == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for ancs_data_info_t"); - return; + return; // 直接返回,不需要释放 } // 复制请求数据到新的消息信息 int rets = memcpy_s(messageInfo, sizeof(ancs_data_info_t), (ancs_data_info_t *)request->data, request->len); if (rets != EOK) { - delete messageInfo; + delete messageInfo; // 释放内存 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s ancs_data_info_t failed, ret = %d", rets); return; @@ -152,53 +150,30 @@ static void Notify(void *args, const Topic topic, Request *request) { // 更新到模型里面的数组 MessageModel::GetInstance().AddMessageData(messageInfo); -#if 0 - // 加锁以保护共享变量 - { - std::lock_guard lock(messageMutex); - shouldDisplayMessage = true; // 标记需要显示新消息 - - // 设置最后更新时间 - lastUpdateTime = std::chrono::steady_clock::now(); - } - // 直接尝试显示消息(用于单条消息的情况) - { - std::lock_guard lock(messageMutex); // 加锁以保护共享变量 - - // 检查是否达到延迟时间 - auto now = std::chrono::steady_clock::now(); - auto timeDiff = now - lastUpdateTime; - WEARABLE_LOGD( - WEARABLE_LOG_MODULE_APP, "Time since last update: %lld milliseconds", - std::chrono::duration_cast(timeDiff) - .count()); - if (timeDiff>=updateDelay) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "Displaying new message after time delay"); - // 发送完毕,重置标志 - shouldDisplayMessage = false; // 重置状态 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "Reset shouldDisplayMessage to false"); - } else { - WEARABLE_LOGE( WEARABLE_LOG_MODULE_APP, "Message display delayed, waiting for next opportunity %lld ms %lld ms", - std::chrono::duration_cast(timeDiff).count(), - std::chrono::duration_cast(updateDelay).count()); - } + // 检查时间戳 + uint32_t currentTimestamp = + OHOS::TraingModel::GetInstance()->get_current_time(); + if (currentTimestamp - messageTimestamp <= 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageTimestamp too short"); + delete messageInfo; // 确保释放内存 + return; } -#endif - // 发送信息进行弹窗 + messageTimestamp = currentTimestamp; + + // 检查训练模式 if (uapi_dev_runtime_get_train_status() || uapi_dev_runtime_get_saveele_status() || uapi_dev_runtime_get_respiratory_training_status()) { - // 增加训练模式下,不弹窗 - // 省电模式,不弹窗 - // 呼吸训练,不弹窗 + // 在这些状态下不弹窗 + delete messageInfo; // 确保释放内存 return; } - // 发送弹窗通知 会自动查询到数组的最新一个 + // 发送弹窗通知 CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Message popup sent"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message popup sent"); + + delete messageInfo; // 在成功完成后释放内存 } } void saveancsdata() { @@ -423,6 +398,7 @@ void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { return; } + // 创建并填充 MessageData MessageData data; data.isRead = messageInfo->read; data.labelDetails = messageInfo->msg; @@ -430,30 +406,32 @@ void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { data.timestamp = messageInfo->time; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "AddMessageData data.isRead is %d,data.labelDetails is " - "%s,data.labelTitle is %s,data.timestamp is %d", + "AddMessageData data.isRead is %d, data.labelDetails is %s, " + "data.labelTitle is %s, data.timestamp is %d", data.isRead, data.labelDetails.c_str(), data.labelTitle.c_str(), data.timestamp); + // 处理时间字符串 char labelTime[20]; if (uapi_get_TIME_STR(data.timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { - data.labelTime = std::string("--"); + data.labelTime = "--"; // 默认值 } else { - data.labelTime = std::string(labelTime); + data.labelTime = labelTime; // 直接使用 labelTime } - // 添加数据 + // 添加数据到消息向量 MessageVector.push_back(data); // 删除多余的数据 - while (MessageVector.size() > MaxMessageListCount) { - MessageVector.erase(MessageVector.begin()); + if (MessageVector.size() > MaxMessageListCount) { + MessageVector.erase(MessageVector.begin(), + MessageVector.begin() + + (MessageVector.size() - MaxMessageListCount)); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo add is ok"); } - // 获取目前的项 MessageData *MessageModel::GetCurrentMessageData() { if (currentIndex_ < MessageVector.size()) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp index c89e73b1d..46281f457 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp @@ -111,6 +111,8 @@ static void Notify(void *args, const Topic topic, Request *request) { int16_t curviewid = OHOS::NativeAbility::GetInstance().GetCurSliceId(); //已经处于遥控拍照界面 if (curviewid == VIEW_TAKEPHOTOS) { + // 点亮屏幕 + uapi_set_screen_on_api(); NativeAbility::GetInstance().Back( TransitionType::TRANSITION_BACK_TO_HEXAGONS); cameraSend(3); 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 e64a62393..dd9a16171 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 @@ -81,6 +81,7 @@ #include "DialModelCalorie.h" #include "DialModelDistance.h" #include "DialModelStepgoal.h" +#include "msg_center_customerC.h" #define DIALDATASET 1 //#include "Systemupgrade.h" @@ -323,9 +324,10 @@ static OHOS::UIViewGroup* showSOSNotify(void) } /*显示消息提醒*/ -static OHOS::UIViewGroup* showMessageNotify(void) -{ - return OHOS::CreateMessageView(); +static OHOS::UIViewGroup *showMessageNotify(void) { + OHOS::UIViewGroup *view = OHOS::CreateMessageView(); + printf("showMessageNotify %p",view); + return view; } /*显示睡眠提醒*/ static OHOS::UIViewGroup* showSleepNotify(void) @@ -991,8 +993,7 @@ void MsgCenterNotifyMessageProc(const Topic topic, Request* req) unused(req); // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyMessageProc !"); if (CheckPriority(topic)) { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); - NotificationManager::GetInstance()->ShowNotify(showMessageNotify, (uint16_t)topic, true); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY, nullptr, 0); } } @@ -1943,6 +1944,13 @@ void MsgCenterReportBtStatusToJS(uint16_t msgId) WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "unexpected msgId %d", msgId); } } + +void show_notify_messgae() { + printf("show_notify_messgae\n"); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); + NotificationManager::GetInstance()->ShowNotify(showMessageNotify, TOPIC_EVENT_MESSAGENOTE, true); +} + #endif #ifdef __cplusplus diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h b/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h new file mode 100644 index 000000000..10c26cfa8 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h @@ -0,0 +1,17 @@ +#ifndef MAG_CENTER_CUSTOMER_C_H +#define MAG_CENTER_CUSTOMER_C_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +void show_notify_messgae(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index c6589d240..7fd0c5f6c 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -578,8 +578,13 @@ namespace OHOS << "Time: " << timestr << "\n"; result << "=====================\n"; + + // 3.读取文件里面的心率数据 + auto healthService = HealthService::GetInstance(); + result << healthService->get_heart_data(); + result << "=====================\n"; - // 3. 获取一天的心率列表 + // 4. 获取一天的心率列表 result << "Today's HeartRate list\n"; for (int serialIndex = 0; serialIndex < 24; ++serialIndex) { uint32_t heartRate = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp index d468f229a..22a30e9f1 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -1,21 +1,23 @@ -#include "notification_manager.h" -#include "wearable_log.h" -#include "components/ui_button.h" -#include -#include "ui_service.h" -#include #include "bleEvent.h" +#include "components/ui_button.h" #include "components/ui_label_ext.h" +#include "notification_manager.h" +#include "ui_service.h" #include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include +#include #ifdef FD230 #include "message/include/MessageModel.h" #endif -#include "message_notification.h" -#include "string" -#include "vibrator_service.h" +#include "../../../../../../../drivers/peripheral/config/include/ConfigModel.h" +#include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" #include "ConfigModel.h" #include "iostream" +#include "message_notification.h" +#include "string" #include "uicomponents/UIComponents.h" +#include "vibrator_service.h" #include #include #include @@ -24,326 +26,348 @@ #include #include #include -#include "../../../../../../../drivers/peripheral/config/include/ConfigModel.h" -#include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" -namespace OHOS -{ +namespace OHOS { - UIViewGroup *MessageGroupView{nullptr}; +UIViewGroup *MessageGroupView{nullptr}; - UILabel *titleLabel{nullptr}; // 标题 - UILabel *timeLabel{nullptr}; // 时间 - UILabel *messageLabel{nullptr}; // 详细label - UILabelButtonExt *deleteButton{nullptr}; // 删除按键 +UILabel *titleLabel{nullptr}; // 标题 +UILabel *timeLabel{nullptr}; // 时间 +UILabel *messageLabel{nullptr}; // 详细label +UILabelButtonExt *deleteButton{nullptr}; // 删除按键 - static std::string titleStr, timeStr, messageStr; - const char *buttonImgSrc = "/user/res/466x100button.bin"; +static std::string titleStr, timeStr, messageStr; +const char *buttonImgSrc = "/user/res/466x100button.bin"; #define DELETEBUTTON "delete_button" - MessageViewEventListener::MessageViewEventListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::MessageViewEventListener"); - } +MessageViewEventListener::MessageViewEventListener() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::MessageViewEventListener"); +} - MessageViewEventListener::~MessageViewEventListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::~MessageViewEventListener"); - } +MessageViewEventListener::~MessageViewEventListener() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::~MessageViewEventListener"); +} - MessageViewEventListener &MessageViewEventListener::GetInstance() - { - static MessageViewEventListener instance; - return instance; - } - bool MessageViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease"); - UNUSED(event); - if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) - { - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); - } - - return true; +MessageViewEventListener &MessageViewEventListener::GetInstance() { + static MessageViewEventListener instance; + return instance; +} +bool MessageViewEventListener::OnRelease(UIView &view, + const ReleaseEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease"); + UNUSED(event); + if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) { + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + } + + return true; +} +bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag"); + UNUSED(view); + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + return true; +} + +bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + NotificationManager::GetInstance()->StopNotify(); + } + return true; +} + +/*创建信息弹窗*/ +UIViewGroup *CreateMessageView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateMessageView"); + if (MessageGroupView == nullptr) { + MessageGroupView = new UIViewGroup(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new %p", + MessageGroupView); + if (MessageGroupView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new fail!!"); + return nullptr; } - bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag"); - UNUSED(view); - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); - return true; + MessageGroupView->SetPosition(0, 0, 466, 466); + // MessageGroupView->SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x00, 165, 230).full); + // MessageGroupView->SetStyle(STYLE_BACKGROUND_OPA, 255); // 127 : background opacity + MessageGroupView->SetViewId("messagenotify"); + MessageGroupView->SetTouchable(true); + MessageGroupView->SetDraggable(true); + UIView::OnDragListener *dragListener = + static_cast( + &MessageViewEventListener::GetInstance()); + if (dragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] dragListener new fail!!"); + return nullptr; } - bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NotificationManager::GetInstance()->StopNotify(); - } - return true; + MessageGroupView->SetOnDragListener(dragListener); + } + /*获取最新message*/ + MessageData *data = MessageModel::GetInstance().GetNewMessage(); + if (data != nullptr) { + titleStr = data->labelTitle; + timeStr = data->labelTime; + messageStr = data->labelDetails; + } else { + titleStr = "--"; + timeStr = "--"; + messageStr = "--"; + } + /*初始化label*/ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView"); + /* --------------------------------------------------------------------------*/ + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel %p", + titleLabel); + if (titleLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + titleLabel->SetPosition(83, 60, 300, 35); + titleLabel->SetText(titleStr.c_str()); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + // titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + titleLabel->SetLineBreakMode( + UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 + titleLabel->SetRollSpeed(70); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + titleLabel->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel is ok!"); + } + /* -------------------------------------------------------------------------- + */ + if (timeLabel == nullptr) { + timeLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel %p", + timeLabel); + if (timeLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 } + timeLabel->SetPosition(73, 104, 320, 33); + timeLabel->SetViewId("timeLabel"); + timeLabel->SetText(timeStr.c_str()); + timeLabel->SetTextColor(Color::Gray()); + timeLabel->SetStyle(STYLE_TEXT_FONT, 28); + timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeLabel->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel is ok!"); + } + /* -------------------------------------------------------------------------- + */ + /*初始化消息内容*/ + if (messageLabel == nullptr) { + messageLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel %p", + messageLabel); + if (messageLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + messageLabel->SetPosition(53, 170, 360, 144); + messageLabel->SetViewId("messageLabel"); + messageLabel->SetText(messageStr.c_str()); + messageLabel->SetTextColor(Color::Gray()); + messageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + messageLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); // 换行裁剪 + messageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, + TEXT_ALIGNMENT_CENTER); // 居中显示 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel is ok"); + } + /*加载清除按键*/ + if (deleteButton == nullptr) { + deleteButton = new UILabelButtonExt(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "deleteButton:: new UILabelButtonExt %p", deleteButton); - /*创建信息弹窗*/ - UIViewGroup *CreateMessageView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateMessageView"); - MessageGroupView = new UIViewGroup(); - if (MessageGroupView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] MessageGroupView new fail!!"); - return nullptr; - } - MessageGroupView->SetPosition(0, 0, 466, 466); - MessageGroupView->SetViewId("messagenotify"); - MessageGroupView->SetTouchable(true); - MessageGroupView->SetDraggable(true); - UIView::OnDragListener *dragListener = static_cast(&MessageViewEventListener::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] dragListener new fail!!"); - return nullptr; - } - MessageGroupView->SetOnDragListener(dragListener); -#ifdef FD230 - /*获取最新message*/ - MessageData *data = MessageModel::GetInstance().GetNewMessage(); - if (data != nullptr) - { - titleStr = data->labelTitle; - timeStr = data->labelTime; - messageStr = data->labelDetails; - } - else - { - titleStr = "--"; - timeStr = "--"; - messageStr = "--"; - } -#endif - /*初始化label*/ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitView"); - /* -------------------------------------------------------------------------- */ - titleLabel = new UILabel(); - if (titleLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - titleLabel->SetPosition(83, 60, 300, 35); - titleLabel->SetText(titleStr.c_str()); - titleLabel->SetStyle(STYLE_TEXT_FONT, 30); - // titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 - titleLabel->SetRollSpeed(70); - titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - titleLabel->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "titleLabel is ok!"); - /* -------------------------------------------------------------------------- */ - timeLabel = new UILabel(); - if (timeLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - timeLabel->SetPosition(73, 104, 320, 33); - timeLabel->SetViewId("timeLabel"); - timeLabel->SetText(timeStr.c_str()); - timeLabel->SetTextColor(Color::Gray()); - timeLabel->SetStyle(STYLE_TEXT_FONT, 28); - timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); - timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - timeLabel->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timeLabel is ok!"); - /* -------------------------------------------------------------------------- */ - /*初始化消息内容*/ - messageLabel = new UILabel(); - if (messageLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - messageLabel->SetPosition(53, 170, 360, 144); - messageLabel->SetViewId("messageLabel"); - messageLabel->SetText(messageStr.c_str()); - messageLabel->SetTextColor(Color::Gray()); - messageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - messageLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); // 换行裁剪 - messageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); // 居中显示 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "messageLabel is ok"); - - /*加载清除按键*/ -#ifdef FD230 - InitButtonExt(deleteButton, 0, 366, 466, 100, DELETEBUTTON, STR_CLOSE, 30); -#else - deleteButton = new UILabelButtonExt(); - if (deleteButton == nullptr) - { - return nullptr; // 内存分配失败,返回 - } - deleteButton->SetPosition(0, 366); - deleteButton->Resize(466, 100); - deleteButton->SetViewId(DELETEBUTTON); - deleteButton->SetText("Close"); - deleteButton->SetStyle(STYLE_TEXT_FONT, 30); - deleteButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - deleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - deleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - deleteButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - deleteButton->SetVisible(true); -#endif - deleteButton->SetImageSrc(buttonImgSrc, buttonImgSrc); - UIView::OnTouchListener *TouchListener = static_cast(&MessageViewEventListener::GetInstance()); - if (TouchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] TouchListener new fail!!"); - return nullptr; - } - deleteButton->SetOnTouchListener(TouchListener); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "deleteButton"); - /* -------------------------------------------------------------------------- */ - MessageGroupView->Add(titleLabel); - MessageGroupView->Add(timeLabel); - MessageGroupView->Add(messageLabel); - MessageGroupView->Add(deleteButton); - - ScreenTurnOn(3000); // 亮屏操作 3000ms 3秒关闭 - - if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) - { - // 震动提醒 - ui_api_vibrate_once_func(); - } - - MessageViewEventListener::GetInstance().Message_StartTimer(); // 开启一个3s后弹窗自动销毁定时器 - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMessageView); - return MessageGroupView; + if (deleteButton == nullptr) { + return nullptr; // 内存分配失败,返回 } - /*释放消息弹窗视图*/ - void FreeMessageView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); - - //销毁定时器 - MessageViewEventListener::GetInstance().Message_StopTimer(); - - if (MessageGroupView != nullptr) - { - MessageGroupView->RemoveAll(); - - delete titleLabel; - titleLabel = nullptr; - - delete timeLabel; - timeLabel = nullptr; - - delete messageLabel; - messageLabel = nullptr; - - delete deleteButton; - deleteButton = nullptr; - - RootView::GetInstance()->Remove(MessageGroupView); - delete MessageGroupView; - MessageGroupView = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); - } - ScreenTurnOff(); - return; + deleteButton->SetPosition(0, 366); + deleteButton->Resize(466, 100); + deleteButton->SetViewId(DELETEBUTTON); + deleteButton->SetTextId(STR_CLOSE); + deleteButton->SetStyle(STYLE_TEXT_FONT, 30); + deleteButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + deleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + deleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, + UIButton::PRESSED); + deleteButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, + UIButton::PRESSED); + deleteButton->SetVisible(true); + deleteButton->SetImageSrc(buttonImgSrc, buttonImgSrc); + UIView::OnTouchListener *TouchListener = + static_cast( + &MessageViewEventListener::GetInstance()); + if (TouchListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] TouchListener new fail!!"); + return nullptr; } + deleteButton->SetOnTouchListener(TouchListener); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton"); + } + /* -------------------------------------------------------------------------- + */ + MessageGroupView->Add(titleLabel); + MessageGroupView->Add(timeLabel); + MessageGroupView->Add(messageLabel); + MessageGroupView->Add(deleteButton); - /* -------------------------------------------------------------------------- */ + ScreenTurnOn(3000); // 亮屏操作 3000ms 3秒关闭 - // 声明定时器变量 - static osTimerId_t g_timer = NULL; + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && + (!uapi_sleep_mode_flag_get())) { + // 震动提醒 + ui_api_vibrate_once_func(); + } - /*定时器到期时的处理*/ - static void Message_TimerCallbackProc(int data) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message_TimerCallbackProc"); - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + MessageViewEventListener::GetInstance() + .Message_StartTimer(); // 开启一个3s后弹窗自动销毁定时器 - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMessageView); + return MessageGroupView; +} +/*释放消息弹窗视图*/ +void FreeMessageView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); - /* - * @brief 回调函数 - */ - static void Message_TimerCallback(int data) - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(Message_TimerCallbackProc, data)); - } + // //销毁定时器 + MessageViewEventListener::GetInstance().Message_StopTimer(); + + if (MessageGroupView != nullptr) { + MessageGroupView->RemoveAll(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel %p", titleLabel); + delete titleLabel; + titleLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel %p", timeLabel); + delete timeLabel; + timeLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel %p", messageLabel); + delete messageLabel; + messageLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton %p", deleteButton); + delete deleteButton; + deleteButton = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageGroupView %p", + MessageGroupView); + + delete MessageGroupView; + MessageGroupView = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); + } + ScreenTurnOff(); + return; +} + +/* -------------------------------------------------------------------------- */ + +// 声明定时器变量 +static osTimerId_t g_timer = NULL; + +/*定时器到期时的处理*/ +static void Message_TimerCallbackProc(int data) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message_TimerCallbackProc"); + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); +} + +/* + * @brief 回调函数 + */ +static void Message_TimerCallback(int data) { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(Message_TimerCallbackProc, data)); +} + +/* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ +void MessageViewEventListener::Message_StartTimer(uint32_t interval) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_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)Message_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); - /* - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void MessageViewEventListener::Message_StartTimer(uint32_t interval) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::Message_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)Message_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; + /* --------------------------------- 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; +} - /* - * @brief 停止定时器 - */ - void MessageViewEventListener::Message_StopTimer(void) - { - // 检查定时器是否存在 - if (g_timer != NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::Message_StopTimer"); - osTimerStop(g_timer); - // 删除定时器并置为 NULL - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_timer = NULL; - } +/* + * @brief 停止定时器 + */ +void MessageViewEventListener::Message_StopTimer(void) { + // 检查定时器是否存在 + if (g_timer != NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_StopTimer"); + osTimerStop(g_timer); + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "osTimerDelete failed, ret = %lx!!", ret); } -} \ No newline at end of file + g_timer = NULL; + } +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h index 6d998b528..de2fb6ad2 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h @@ -107,8 +107,17 @@ int get_sedentary_time_from_config_model(void); int get_sedentary_interval_from_config_model(void); bool get_motion_recognition_from_config_model(void); int get_config_heart_from_config_model(void); -//设置睡眠频率 + +/* ---------------------------------- 健康管理 ---------------------------------- */ +//设置心率周期检测频率 void set_config_heart(int heartRateDetectionFreq); +//設置心率最高值 +void set_config_heart_max(int heartRateMax); +//設置心率最低值 +void set_config_heart_min(int heartRateMin); +//設置血氧最低值 +void set_config_spo2_min(int spo2Min); +/* -------------------------------------------------------------------------- */ // sleep mode switch void mmi_sleep_mode_switch_read(void); diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 04da1a3a5..46d350db0 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -1472,10 +1472,9 @@ int get_wake_up_time_from_config_model(void) wake_up_time = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_GET_UP); return wake_up_time; } - +// 设置心率检测频率 void set_config_heart(int heartRateDetectionFreq) { - // 设置心率检测频率 OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED, heartRateDetectionFreq); } @@ -1486,7 +1485,23 @@ int get_config_heart_from_config_model(void) time = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED); return time; } - +//设置最大心率 +void set_config_heart_max(int heartRateMax) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE, heartRateMax); +} +//设置最小心率 +void set_config_heart_min(int heartRateMin) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN, 0); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE, heartRateMin); +} +//设置最小血氧 +void set_config_spo2_min(int spo2Min) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int( + OHOS::ConfigModel::CONFIGMODEL_ITEM_OXYGEN_THRESHOLD_VALUE, spo2Min); +} //获取久坐提醒开关 int get_sedentary_switch_from_config_model(void) { diff --git a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c index f7e755625..eadd410ea 100644 --- a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c @@ -191,6 +191,10 @@ static void custom_fileoperate_service_check_task(void const *arg) battery_save_data(); break; + case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY: + show_notify_messgae(); + break; + PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd); break; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index c0b4e3dd5..8ef093f0a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -296,6 +296,8 @@ errcode_t do_custom_cmd_service_check_msg_head(int cmd, void *params, int paraml #define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_READ 0x14 //读取电池数据 #define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_SAVE 0x15 //存储电池数据 +#define CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY 0x16 //消息数据 + errcode_t uapi_custom_fileoperate_service_init(void); errcode_t do_custom_fileoperate_service_check_msg(int cmd, void *params, int paramlen); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 863f79814..fdaf34e25 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -776,37 +776,44 @@ static uint32_t custom_mem_debug(uint8_t *para, uint32_t paraLen, char *strCommo wstp_print("Restoring Factory Settings...\n"); return ERRCODE_SUCC; } - -#if 1 - /*设置心率检测频率*/ - static uint32_t custom_set_heart(uint8_t *para, uint32_t paraLen, char *strCommonCmd) - { - UNUSED(strCommonCmd); + static uint32_t custom_set_health(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { + UNUSED(strCommonCmd); uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = {0}; uint32_t argc = 0; - int ret = ConvertCmdToParam(para, paraLen, argv, &argc); - if (ret != CUSTOM_UTILS_SUCCESS) - { - wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); - return ERRCODE_FAIL; - } - - if (argc != 1) - { - wstp_print("CUSTOM_UTILSTEST power_test ATCMD Set Parameter Failed argc %d\r\n"); - return ERRCODE_FAIL; - } - int heartRateDetectionFreq = atol((char *)argv[0]); - - // 设置心率检测频率 - set_config_heart(heartRateDetectionFreq); - - wstp_print("heartRateDetectionFreq is %d\n", heartRateDetectionFreq); - return ERRCODE_SUCC; + wstp_print("開始設置健康數據\n"); + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD 转换命令失败\n"); + return ERRCODE_FAIL; + } + + int set_health_type = atol((char *)argv[0]); + int data = atol((char *)argv[1]); + wstp_print("設置健康數據 %d %d\n", set_health_type, data); + + switch (set_health_type) { + case 0: // 心率检测周期 + set_config_heart(data); + break; + case 1: // 心率最高值 + set_config_heart_max(data); + break; + case 2: // 心率最低值 + set_config_heart_min(data); + break; + case 3: // 血氧最低值 + set_config_spo2_min(data); + break; + default: + wstp_print("错误:无效的健康类型 %d\n", set_health_type); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; // 成功 } -#endif static uint32_t custom_get_cywee_chip_info(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { @@ -1513,7 +1520,9 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^MEMDEBUG", custom_mem_debug, (char *)" " }, {(char *)"AT^RESTORE", custom_restore_factory_settings, (char *)" "}, - {(char *)"AT^SETHEART", custom_set_heart, (char *)" "}, + {(char *)"AT^SETHEALTH", custom_set_health, (char *)" "}, + + {(char *)"AT^LSFD", custom_lsfd, (char *)" "}, {(char *)"AT^GETMAC", custom_get_bt_addr, (char *)" "}, diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_animator.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_animator.cpp index 621ff5d88..90ee583c6 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_animator.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_animator.cpp @@ -113,7 +113,7 @@ void UIImageAnimatorView::SetImageAnimatorSrc(const ImageAnimatorInfo imageAnima void UIImageAnimatorView::ClearImagesCache() { - if (imageSrc_ != nullptr) { + if (imageSrc_ == nullptr) { ///11.29海思修改 return; } -- 2.17.1