增加血压ecg低电量判断 3462/2 3462/head 3463/target/1
authorxue <2144439972@qq.com>
Fri, 12 Jun 2026 08:13:45 +0000 (16:13 +0800)
committerxue <2144439972@qq.com>
Fri, 12 Jun 2026 08:13:45 +0000 (16:13 +0800)
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainPresenter.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h
code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp [new file with mode: 0644]
code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h [new file with mode: 0644]
code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp

index 039664e..6f1b73a 100644 (file)
@@ -47,6 +47,7 @@ private:
   void RequestStopConfirm(int16_t fromView);
   void StartMeasureFlow(BPMainView *mainView);
   void StartCalibrationFlow(BPMainView *mainView, uint8_t round);
+  bool BlockIfBatteryTooLow();
   void StartProgressSession(BPProgressMode mode);
   void PauseProgressSession();
   void ResumeProgressSession();
index 23f714f..8238672 100644 (file)
@@ -5,6 +5,7 @@
 #include "bloodpressure/include/BPValueInputView.h"
 #include "bloodpressure/include/BPModel.h"
 #include "bloodpressure/include/BPViewClickIds.h"
+#include "health/HealthMeasureBattery.h"
 #include "bloodpressure/include/BPCalibStopView.h"
 #include "bloodpressure/include/BPMeasuringView.h"
 #include "bloodpressure/include/BPAbnormalView.h"
@@ -464,7 +465,18 @@ void BPMainPresenter::OnSwipe(UISwipeView &view) {
 }
 
 /** 开始测量流程 */
+bool BPMainPresenter::BlockIfBatteryTooLow() {
+  if (!IsBatteryTooLowForMeasure()) {
+    return false;
+  }
+  ShowHealthMeasureLowBatteryNotify();
+  return true;
+}
+
 void BPMainPresenter::StartMeasureFlow(BPMainView *mainView) {
+  if (BlockIfBatteryTooLow()) {
+    return;
+  }
   int16_t hide = mainView->GetCurrentViewId();
   mainView->ChangeView(hide, BP_MEASURING_VIEW);
   StartProgressSession(BPProgressMode::Measure);
@@ -472,6 +484,9 @@ void BPMainPresenter::StartMeasureFlow(BPMainView *mainView) {
 
 /** 开始校准流程 */
 void BPMainPresenter::StartCalibrationFlow(BPMainView *mainView, uint8_t round) {
+  if (BlockIfBatteryTooLow()) {
+    return;
+  }
   BPModel *model = BPModel::GetInstance();
   model->SetCalibrationRound(round);
   model->ResetInputValues();
@@ -540,6 +555,9 @@ bool BPMainPresenter::OnClick(UIView &view, const ClickEvent &event) {
   }
   /** 处理值确认事件 */
   if (viewId == BP_CLICK_VALUE_CONFIRM) {
+    if (BlockIfBatteryTooLow()) {
+      return true;
+    }
     if (model->GetInputSbp() > model->GetInputDbp()) {
       mainView->ChangeView(BP_VALUE_CONFIRM_VIEW, BP_CALIBRATING_VIEW);
       StartProgressSession(BPProgressMode::Calibrate);
@@ -592,6 +610,9 @@ bool BPMainPresenter::OnClick(UIView &view, const ClickEvent &event) {
   if (viewId == BP_CLICK_RETRY) {
     if (current == BP_ABNORMAL_VIEW) {
       if (lastTimeoutMode_ == BPProgressMode::Calibrate) {
+        if (BlockIfBatteryTooLow()) {
+          return true;
+        }
         mainView->ChangeView(BP_ABNORMAL_VIEW, BP_CALIBRATING_VIEW);
         StartProgressSession(BPProgressMode::Calibrate);
       } else {
index 83fec2a..4ef9ce7 100644 (file)
@@ -44,6 +44,7 @@ private:
   bool HandleSwipeBack();
   bool IsFlowSubPage(int16_t viewId) const;
   void StartMeasureFlow(ECGMainView *mainView);
+  bool BlockIfBatteryTooLow();
   void ShowWaitContact(ECGMainView *mainView);
   void ShowContactGood(ECGMainView *mainView);
   bool IsWaitingContact(ECGMainView *mainView) const;
index 4df4411..3b76b7d 100644 (file)
@@ -6,6 +6,7 @@
 #include "ecg/include/ECGMeasureCompleteView.h"
 #include "ecg/include/ECGModel.h"
 #include "ecg/include/ECGViewClickIds.h"
+#include "health/HealthMeasureBattery.h"
 #include "NativeRegisterManager.h"
 #include "NativeAbility.h"
 #include "UiConfig.h"
@@ -343,10 +344,21 @@ void ECGMainPresenter::OnMeasureTimerTick() {
 }
 
 void ECGMainPresenter::StartMeasureFlow(ECGMainView *mainView) {
+  if (BlockIfBatteryTooLow()) {
+    return;
+  }
   ShowWaitContact(mainView);
   StartMeasureTimer();
 }
 
+bool ECGMainPresenter::BlockIfBatteryTooLow() {
+  if (!IsBatteryTooLowForMeasure()) {
+    return false;
+  }
+  ShowHealthMeasureLowBatteryNotify();
+  return true;
+}
+
 void ECGMainPresenter::FinishMeasuringFlow(ECGMainView *mainView) {
   if (measureDataReceived_ == false) {
     return;
diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp
new file mode 100644 (file)
index 0000000..cfd45b8
--- /dev/null
@@ -0,0 +1,45 @@
+#include "health/HealthMeasureBattery.h"
+
+#include "broadcast_feature.h"
+#include "custom_utils.h"
+#include "graphic_service.h"
+#include "msg_center.h"
+#include "notification_manager.h"
+#include "notify/charge_notification.h"
+
+#ifdef SUPPORT_BATTERY_SERVICE
+#include "battery_hal.h"
+#endif
+
+namespace OHOS {
+
+namespace {
+
+UIViewGroup *CreateHealthMeasureLowPowerNotifyView() { return lowPowerShow(); }
+
+void ShowHealthMeasureLowBatteryNotifyImpl() {
+  uapi_set_screen_on_api();
+  set_lowpower_falg(0);
+  NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+  NotificationManager::GetInstance()->ShowNotify(
+      CreateHealthMeasureLowPowerNotifyView, TOPIC_EVENT_LOWPOWER_ALARM, true);
+}
+
+} // namespace
+
+bool IsBatteryTooLowForMeasure() {
+#ifdef SUPPORT_BATTERY_SERVICE
+  float voltage = 0.0f;
+  int percent = battery_get_voltage(&voltage);
+  return percent < kHealthMeasureMinBatteryPercent;
+#else
+  return false;
+#endif
+}
+
+void ShowHealthMeasureLowBatteryNotify() {
+  // 推迟到下一帧 UI 线程,避免在按钮 OnClick 栈里同步建 Notify 造成点击卡顿
+  GraphicService::GetInstance()->PostGraphicEvent(ShowHealthMeasureLowBatteryNotifyImpl);
+}
+
+} // namespace OHOS
diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h
new file mode 100644 (file)
index 0000000..1878614
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef HEALTH_MEASURE_BATTERY_H
+#define HEALTH_MEASURE_BATTERY_H
+
+namespace OHOS {
+
+static constexpr int kHealthMeasureMinBatteryPercent = 80;
+
+/** 电量低于 10% 时不允许开始测量/校准 */
+bool IsBatteryTooLowForMeasure();
+
+/** 复用系统低电量充电提醒弹窗(charge_notification::lowPowerShow) */
+void ShowHealthMeasureLowBatteryNotify();
+
+} // namespace OHOS
+
+#endif
index 64a4183..9c56845 100644 (file)
@@ -612,14 +612,17 @@ namespace OHOS
         UIViewGroup_lowpower->SetTouchable(true);
         alarm_labelbutton->SetTouchable(true);
 
-        ShowUpShutDownAnimatorView();
-        if (group)
-            UIViewGroup_lowpower->Add(group);
-        if (battery_falg >= 3)
-        {
-            group->SetVisible(true);
-            ShutDownImageAnimatorView->Start();
-            ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏
+        // 充电提醒(flag=0)不需要关机动画资源,避免同步加载 30 帧导致卡顿
+        if (battery_falg != 0) {
+            ShowUpShutDownAnimatorView();
+            if (group)
+                UIViewGroup_lowpower->Add(group);
+            if (battery_falg >= 3)
+            {
+                group->SetVisible(true);
+                ShutDownImageAnimatorView->Start();
+                ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏
+            }
         }
         NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower);
         return UIViewGroup_lowpower;