From bd4f932b77ecb0baf6aa95cdf9e024209d9ae0f5 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Mon, 19 Aug 2024 19:20:05 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E4=B8=BB=E7=95=8C=E9=9D=A2?= =?utf8?q?=E5=BF=83=E7=8E=87=E5=8D=A1=E7=89=87=EF=BC=9B=E4=BC=98=E5=8C=96?= =?utf8?q?=E5=BF=83=E7=8E=87=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../health_service/health_service.cpp | 9 ++-- .../health_service/health_service.h | 6 +-- .../heartrate/include/HeartChartView.h | 4 +- .../nativeui/heartrate/include/HeartModel.h | 11 ++-- .../nativeui/heartrate/src/HeartChartView.cpp | 47 ++++++++++++++++- .../nativeui/heartrate/src/HeartModel.cpp | 50 ++++++++++++++----- .../nativeui/heartrate/src/HeartRateView.cpp | 24 ++------- 7 files changed, 106 insertions(+), 45 deletions(-) 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 530bd00a1..c8760f731 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 @@ -473,6 +473,7 @@ namespace OHOS for (int i = 0; i < MAX_HOURS; ++i) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveDailyHeartRate:: Time is %d Heart is %d", i, dailyHeartRates[i]); if (!outFile.write(reinterpret_cast(&dailyHeartRates[i]), sizeof(dailyHeartRates[i]))) // 保存心率值 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Failed to write heart rate data."); @@ -497,7 +498,7 @@ namespace OHOS struct tm *timeInfo = localtime(×tamp); // 使用 localtime 获取本地时间 // 提取小时 - uint8_t hour = static_cast(timeInfo->tm_hour); + uint16_t hour = static_cast(timeInfo->tm_hour); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updating heart rate: 小时 %d, 心率值 %d", hour, heartRate); @@ -511,7 +512,7 @@ namespace OHOS currenthour = hour; } - uint8_t HealthService::GetHourlyHeartRate(uint8_t hour) + uint16_t HealthService::GetHourlyHeartRate(uint16_t hour) { // 返回指定小时的心率 if (hour < MAX_HOURS) @@ -521,9 +522,9 @@ namespace OHOS return 0; // 或者返回一个异常值 } - uint8_t HealthService::GetCurrentHour() + uint16_t HealthService::GetCurrentHour() { // 返回目前小时 - return currenthour; + return currenthour; } } 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 6760b2376..cd72638a5 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 @@ -108,16 +108,16 @@ namespace OHOS bool SaveDailyHeartRate(); bool LoadDailyHeartRate(); void UpdateHourlyHeartRate(time_t timestamp, uint16_t heartRate); - uint8_t GetHourlyHeartRate(uint8_t hour); + uint16_t GetHourlyHeartRate(uint16_t hour); void ClearHourlyHeartRates(); - uint8_t GetCurrentHour(); + uint16_t GetCurrentHour(); private: static const int MAX_HOURS = 24; uint16_t dailyHeartRates[MAX_HOURS]; // 使用数组来存储心率值 HealthState healthState_; time_t lastLoadTime; // 记录最后加载的时间 - uint8_t currenthour = 0; + uint16_t currenthour = 0; }; } #endif // HEALTH_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartChartView.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartChartView.h index ce0ba6619..ec5f27c63 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartChartView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartChartView.h @@ -45,7 +45,6 @@ namespace OHOS static HeartChartView *GetInstance(void); UIImageAnimatorView *GetImageAnimator(void); - void UpdateShowHeart(void); bool HeartViewInit(); void InitChartView(void); @@ -53,6 +52,9 @@ namespace OHOS void SetDataTopAndBottom(); void HeartImageAnimator(); + void UpdateShowHeart(void); + void Update_data_Chart(int serialIndex); + private: UILabelExt *CurrentHeartText{nullptr}; UILabelExt *MaxHeartText{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartModel.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartModel.h index 66f0359c1..6f1ba90d7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartModel.h @@ -134,6 +134,8 @@ extern "C" void UpHeartdata(uint16_t heart); uint16_t GetHeartdata(); uint16_t GetShowHeartdata(); + uint16_t GetShowMaxHeartdata(); + uint16_t GetShowMinHeartdata(); uint16_t GetIndex(); void SetIndex(uint16_t index); @@ -168,9 +170,12 @@ extern "C" bool wearStatus{true}; uint16_t index_ = 0; - uint16_t displayheart; // 显示心率 - uint16_t currentheart; // 保存心率 - uint32 timestamp_ms; // 检测时间(存(时、分),大于24小时,改为1天前,小于1分钟为刚刚) + uint16_t displayheart; // 显示心率 + uint16_t currentheart; // 保存心率 + uint16_t displayheart_max; // 显示最大心率 + uint16_t displayheart_min; // 显示最小心率 + + uint32 timestamp_ms; // 检测时间(存(时、分),大于24小时,改为1天前,小于1分钟为刚刚) bool initstatus = true; bool heartstate = false; diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp index 8e7bce409..e2623c8d1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp @@ -79,13 +79,58 @@ namespace OHOS { return g_pHeartCheckView; } - /*更新显示数据*/ + + /* 更新显示数据 */ void HeartChartView::UpdateShowHeart() { + // 获取当前心率 uint16_t heart_ = HeartModel::GetInstance()->GetShowHeartdata(); std::string heartrateStr = std::to_string(heart_); + + // 更新当前心率显示 if (CurrentHeartText != nullptr && heart_ != 0) + { CurrentHeartText->SetText(heartrateStr.c_str()); + } + + // 获取最大心率 + uint16_t heartmax_ = HeartModel::GetInstance()->GetShowMaxHeartdata(); + std::string heartmaxStr = std::to_string(heartmax_); + + // 更新最大心率显示 + if (MaxHeartText != nullptr && heartmax_ != 0) + { + MaxHeartText->SetText(heartmaxStr.c_str()); + } + + // 获取最小心率 + uint16_t heartmin_ = HeartModel::GetInstance()->GetShowMinHeartdata(); + std::string heartminStr = std::to_string(heartmin_); + + // 更新最小心率显示 + if (MinHeartText != nullptr && heartmin_ != 0) + { + MinHeartText->SetText(heartminStr.c_str()); + } + } + void HeartChartView::Update_data_Chart(int serialIndex) + { + if (heartchart == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Update_data_Chart fail %d", serialIndex); + return; + } + + heartdata[serialIndex].x = serialIndex; + heartdata[serialIndex].y = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex); + + heartSerial->AddPoints(heartdata, 24); + heartSerial->SetLineColor(Color::Red()); + heartSerial->SetFillColor(Color::Red()); + heartSerial->EnableGradient(true); + + heartchart->AddDataSerial(heartSerial); + heartchart->Invalidate(); } /*设置最大最小数据*/ void HeartChartView::SetDataTopAndBottom() 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 092e9e6c6..3c11ef44a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -8,6 +8,7 @@ #include "heartrate/include/HeartRateView.h" #include "heartrate/include/HeartDetectionPresenter.h" #include "heartrate/include/HeartResultPresenter.h" +#include "heartrate/include/HeartChartView.h" #include "DialModelHeartRate.h" #include @@ -20,7 +21,6 @@ #include #include -#include "heartrate/include/HeartRateView.h" #include "ui_service.h" #include "battery_hal.h" @@ -149,17 +149,21 @@ extern "C" heartInfo = nullptr; } } + /* Nextday 刷新*/ if (request->msgId == TOPIC_EVENT_NEXTDAY_UPDATE) { OHOS::HeartModel::GetInstance()->ClearHeartData(); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::HeartModel::Heart_Update_View, OHOS::HeartModel::GetInstance())); } + /* UTCTIME 刷新*/ if (request->msgId == TOPIC_EVENT_UTCTIME_UPDATE) { OHOS::HeartModel::GetInstance()->ClearHeartData(); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::HeartModel::Heart_Update_View, OHOS::HeartModel::GetInstance())); } - if (request->msgId == TOPIC_EVENT_WEARSTATE_UPDATE) - { - } + if (request->msgId == TOPIC_EVENT_WEARSTATE_UPDATE){} } #ifdef __cplusplus @@ -504,7 +508,14 @@ namespace OHOS { return displayheart; } - + uint16_t HeartModel::GetShowMaxHeartdata() + { + return displayheart_max; + } + uint16_t HeartModel::GetShowMinHeartdata() + { + return displayheart_min; + } uint32_t HeartModel::GetCheckTime() { return timestamp_ms; @@ -560,7 +571,10 @@ namespace OHOS void HeartModel::Heart_Start() { displayheart = 0; - SetResult(HeartResult::NOT_TESTED); // 成功检测 + displayheart_max = 0; // 显示最大心率 + displayheart_min = 0; // 显示最小心率 + + SetResult(HeartResult::NOT_TESTED); // 重置检测 // 进行初始化操作 if (!sensorstate) { @@ -718,6 +732,14 @@ namespace OHOS currentheart = displayheart; // 更新 currentheart valid_counter_++; // 增加有效计数器 disvalid_counter_ = 0; // 清空无效计数器 + if (displayheart_max == 0 || displayheart_min == 0) + { + displayheart_min = displayheart_max = displayheart; + } + if (displayheart_max < displayheart) + displayheart_max = displayheart; + if (displayheart_min > displayheart) + displayheart_min = displayheart; } else { @@ -744,14 +766,16 @@ namespace OHOS void HeartModel::Heart_Update_View(void) { - if (HeartRateView::GetInstance()) + int hour = HealthService::GetInstance()->GetCurrentHour(); + if (HeartRateView::GetInstance() != nullptr) { - int hour = HealthService::GetInstance()->GetCurrentHour(); - if (HeartRateView::GetInstance() != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "更新主界面卡片"); - HeartRateView::GetInstance()->Update_data_Chart(hour); - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "更新主界面卡片"); + HeartRateView::GetInstance()->Update_data_Chart(hour); + } + if (HeartChartView::GetInstance() != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "更新测量心率卡片"); + HeartChartView::GetInstance()->Update_data_Chart(hour); } } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartRateView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartRateView.cpp index 083fdcef4..258c3a6bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartRateView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartRateView.cpp @@ -309,23 +309,12 @@ namespace OHOS LabelInfo bottomLabel = {HEART_RATE_LIMIT_FONT_SIZE, BOTTOM_TEXT_X, BOTTOM_TEXT_Y, BOTTOM_TEXT_WIDTH, BOTTOM_TEXT_HEIGHT}; - LabelInfo restRateLabel = {REST_HEART_RATE_FONT_SIZE, REST_HEART_RATE_X, REST_HEART_RATE_Y, REST_HEART_RATE_WIDTH, - REST_HEART_RATE_HEIGHT}; - LabelInfo restRateTextLabel1 = {REST_HEART_TEXT_FONT_SIZE, REST_HEART_TEXT_X1, REST_HEART_TEXT_Y1, - REST_HEART_TEXT_WIDTH1, REST_HEART_TEXT_HEIGHT1}; - LabelInfo restRateTextLabel2 = {REST_HEART_TEXT_FONT_SIZE, REST_HEART_TEXT_X2, REST_HEART_TEXT_Y2, - REST_HEART_TEXT_WIDTH2, REST_HEART_TEXT_HEIGHT2}; - topRate = new UILabel(); bottomRate = new UILabel(); ratePerSec = new UILabel(); ratePerSecText = new UILabel(); - restRate = new UILabel(); - restRateText1 = new UILabel(); - restRateText2 = new UILabel(); - if (topRate == nullptr || bottomRate == nullptr || ratePerSec == nullptr || ratePerSecText == nullptr || - restRate == nullptr || restRateText1 == nullptr || restRateText2 == nullptr) + if (topRate == nullptr || bottomRate == nullptr || ratePerSec == nullptr || ratePerSecText == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartRateView::[HeartRateLabelDisplay] new UILabel fail"); } @@ -342,14 +331,6 @@ namespace OHOS SetLabel(bottomRate, bottomLabel); topRate->SetText("--"); bottomRate->SetText("--"); - - // 静息心率 - SetLabel(restRate, restRateLabel); - SetLabel(restRateText1, restRateTextLabel1); - SetLabel(restRateText2, restRateTextLabel2); - restRateText1->SetText("静息"); - restRate->SetText("--"); - restRateText2->SetText("次/分"); } void HeartRateView::HeartRateCoordinate(void) @@ -475,6 +456,9 @@ namespace OHOS return; } + /*清空原数据*/ + heartchart->DeleteDataSerial(heartSerial); + heartdata[serialIndex].x = serialIndex; heartdata[serialIndex].y = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex); -- 2.17.1