From: xue <2144439972@qq.com> Date: Thu, 11 Jun 2026 09:00:42 +0000 (+0800) Subject: 适配优化后ECG函数 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=788b15794679d4af2eff7c38ecca62295ab97e61;p=mirrors%2FFD230.git 适配优化后ECG函数 --- diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h index 7c193ffda..92f779b5e 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h @@ -55,9 +55,10 @@ private: static constexpr int32_t kMeasureTickMs = 200; // 测量定时器周期 static constexpr int32_t kPollIntervalMs = 1000; // 测量定时器间隔 - bool screenAlwaysOnForEcg_{false}; // 屏幕长亮 - bool measureDataReceived_{false}; // 测量数据是否收到 - int32_t pollElapsedMs_{0}; // 测量定时器流逝时间 + bool screenAlwaysOnForEcg_{false};//屏幕长亮 + bool measureDataReceived_{false};//测量数据是否收到 + bool measureSessionActive_{false};//测量会话是否激活 + int32_t pollElapsedMs_{0};//测量定时器流逝时间 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMeasuringView.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMeasuringView.h index 934e06888..73be9c19d 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMeasuringView.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMeasuringView.h @@ -16,11 +16,11 @@ public: void ResetMeasurement(); void UpdateWaveformFromRaw(); void AppendHeartRatePoint(uint8_t hr); - /** 每 1s 调用一次,返回 true 表示 30s 倒计时已结束 */ + /** 每 1s 调用一次,返回 true 表示 60s 倒计时已结束 */ bool OnCountdownSecondTick(); void StopMeasurement(); - static constexpr int16_t kMeasureDurationSec = 30; + static constexpr int16_t kMeasureDurationSec = 60; private: void InitChart(); diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp index 478a3a9ba..f76da9ace 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp @@ -192,6 +192,7 @@ void ECGMainPresenter::StopPpgAfibSession() { void ECGMainPresenter::StartMeasureTimer() { StopMeasureTimer(); measureDataReceived_ = false; + measureSessionActive_ = true; pollElapsedMs_ = 0; uapi_set_screen_on_api(); SetScreenAlwaysOnForEcg(true); @@ -212,6 +213,7 @@ void ECGMainPresenter::StopMeasureTimer() { g_ecgMeasureTimer = nullptr; } measureDataReceived_ = false; + measureSessionActive_ = false; pollElapsedMs_ = 0; } @@ -234,15 +236,23 @@ bool ECGMainPresenter::PollAfibResult() { #ifdef SUPPORT_PPG_SERVICE uint8_t ecgHr = 0; uint8_t afibResult = PPG_ECG_AFIB_RESULT_INVALID; - ppg_get_ecg_afib(&ecgHr, &afibResult); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ECG] poll hr=%u afib=%u", ecgHr, afibResult); + uint8_t status = PPG_ECG_AFIB_STATUS_IDLE; + ppg_get_ecg_afib(&ecgHr, &afibResult, &status); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ECG] poll hr=%u afib=%u status=%u", ecgHr, + afibResult, status); ECGMeasuringView *view = ECGMeasuringView::GetInstance(); if (view != nullptr && ecgHr > 0) { view->AppendHeartRatePoint(ecgHr); } - if (afibResult != PPG_ECG_AFIB_RESULT_INVALID) { + if (status == PPG_ECG_AFIB_STATUS_FAILED) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ECG] measure failed (status=2)"); + OnMeasureTimeout(); + return false; + } + + if (status == PPG_ECG_AFIB_STATUS_SUCCESS) { ECGModel *model = ECGModel::GetInstance(); model->SetMeasureResult(ecgHr, afibResult); model->SaveMeasureRecord(ecgHr, afibResult); @@ -266,7 +276,7 @@ void ECGMainPresenter::OnMeasureTimeout() { /** 测量定时器回调 */ void ECGMainPresenter::OnMeasureTimerTick() { - if (measureDataReceived_) { + if (measureDataReceived_ || !measureSessionActive_) { return; } @@ -286,8 +296,11 @@ void ECGMainPresenter::OnMeasureTimerTick() { FinishMeasuringFlow(mainView); return; } + if (!measureSessionActive_) { + return; + } if (view->OnCountdownSecondTick()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ECG] measure timeout without afib result"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[ECG] measure timeout (60s)"); OnMeasureTimeout(); return; } diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMeasuringView.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMeasuringView.cpp index 84748ca88..83889108d 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMeasuringView.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMeasuringView.cpp @@ -194,7 +194,7 @@ UIViewGroup *ECGMeasuringView::InitView() { group_->Add(chart_); } - InitUILabel(countdownLabel_, 183, 300, 100, 50, "ecg_measuring_countdown", "30s", + InitUILabel(countdownLabel_, 183, 300, 100, 50, "ecg_measuring_countdown", "60s", DEFAULT_VECTOR_FONT_FILENAME, 40); countdownLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);