增加校准过程中曲线更新
authorxue <2144439972@qq.com>
Fri, 11 Jul 2025 02:27:18 +0000 (10:27 +0800)
committerxue <2144439972@qq.com>
Fri, 11 Jul 2025 02:27:18 +0000 (10:27 +0800)
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPSecUnderCalibrationView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPUnderCalibrationView.h
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPLastCalibrationTimeView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPSecUnderCalibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPUnderCalibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/detection/BPDetectFirstView.cpp

index 5f3ac27..5fb4fe3 100644 (file)
@@ -87,7 +87,8 @@ namespace OHOS
 
     /* ---------------------------------时间处理 --------------------------------- */
     std::string GetCurrentTimeStr(); // 获取当前时间年月日时分字符串
-    std::string GetCurrentTimeStr(uint32_t timeStamp);
+    std::string GetSingleLineCurrentTimeStr(uint32_t timeStamp);
+    std::string GetDoubleLineCurrentTimeStr(uint32_t timeStamp);
     uint32_t GetCurrentTime(); // 获取当前时间戳
     std::string GetLastCalibrationTime();
     bool IsCalibrationOver();
@@ -150,6 +151,8 @@ namespace OHOS
 
     // 获取过程值数据
     std::vector<uint8_t> GetBPCheckDataArray(void);
+    LAST_CHECK_DATA GetLastData(void);
+    std::deque<LAST_CHECK_DATA> GetlastCheckData();
 
     /* --------------------------------- 数据存储 --------------------------------- */
     static constexpr const char *BP_DATA_PATH = "/user/userdata/health/bp/";
@@ -167,10 +170,10 @@ namespace OHOS
     BPState current_state = BPState::BP_IDLE;
     uint8_t custom_sbp = SBP_VALUE;
     uint8_t custom_dbp = DBP_VALUE;
-    std::map<uint8_t, std::pair<uint8_t, uint8_t>> bp_check_value_map; // 记录获取的sbp和dbp值
-    std::vector<uint8_t> bp_check_value_vector;                        // 测量值-----没用了
-    std::string LastCalibrationTime;
-    uint8_t CalibrationFlag = 0;
+    std::map<uint8_t, std::pair<uint8_t, uint8_t>> bp_check_value_map; // 记录获取的sbp和dbp值----这个真没用
+    std::vector<uint8_t> bp_check_value_vector;                        // 过程测量值
+    std::string LastCalibrationTime;            //上次校准时间
+    uint8_t CalibrationFlag = 0;                //校准标志位用于界面切换
     LAST_CHECK_DATA lastData;                   // 上一次测量的数据
     BPRESULT bp_resullt = BPRESULT::NOT_TESTED; // 测量状态
   };
index c4ee025..682bc72 100644 (file)
@@ -27,6 +27,7 @@ namespace OHOS
         void InitChartView();
 
         void UpdateTimeText(int data);
+        void UpdateChartData();
 
     private:
         UIImageView *background = nullptr;
index 6a887d4..7cb3701 100644 (file)
@@ -27,6 +27,7 @@ namespace OHOS
         void InitChartView();
 
         void UpdateTimeText(int data);
+        void UpdateChartData();
 
     private:
         UIImageView *background = nullptr;
index f3ea34f..5528f8b 100644 (file)
@@ -107,7 +107,7 @@ namespace OHOS
         timeLabel->SetPosition((HORIZONTAL_RESOLUTION - 300) / 2, y, 300, 30);
         timeLabel->SetStyle(STYLE_TEXT_FONT, 26);
         timeLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-        timeLabel->SetText("2025/05/21 09:59");
+        timeLabel->SetText("0000/00/00 00:00");
         timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
         timeLabel->SetRollSpeed(23);
         timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
index 85bddcd..563d535 100644 (file)
@@ -74,6 +74,7 @@ namespace OHOS
     static BPModel instance;
     return &instance;
   }
+  /////////////////////////时间操作函数//////////////////////////////////////////
   // 获取当前时间戳字符串
   std::string BPModel::GetCurrentTimeStr()
   {
@@ -134,13 +135,38 @@ namespace OHOS
 
     return binFilePath;
   }
-  std::string BPModel::GetCurrentTimeStr(uint32_t timeStamp)
+  std::string BPModel::GetSingleLineCurrentTimeStr(uint32_t timeStamp)
   {
 
     if (timeStamp < 0)
     {
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to GetCurrentTimeStr");
-      return "----/--/-- \n --/--";
+      return "----/--/--  --/--";
+    }
+
+    // 将时间戳转换为 time_t 类型
+    time_t rawtime = static_cast<time_t>(timeStamp);
+    struct tm *timeinfo = localtime(&rawtime);
+
+    if (timeinfo == NULL)
+    {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to convert time");
+      return "----/--/--  --/--";
+    }
+
+    // 格式化时间为字符串
+    char buffer[20]; // 格式: YYYY-MM-DD HH:MM
+    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d   %H:%M", timeinfo);
+
+    return std::string(buffer);
+  }
+  std::string BPModel::GetDoubleLineCurrentTimeStr(uint32_t timeStamp)
+  {
+
+    if (timeStamp < 0)
+    {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to GetCurrentTimeStr");
+      return "----/--/--\n --/--";
     }
 
     // 将时间戳转换为 time_t 类型
@@ -155,10 +181,11 @@ namespace OHOS
 
     // 格式化时间为字符串
     char buffer[20]; // 格式: YYYY-MM-DD HH:MM
-    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d  \n %H:%M", timeinfo);
+    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d \n %H:%M", timeinfo);
 
     return std::string(buffer);
   }
+
   // 获取当前时间戳
   uint32_t BPModel::GetCurrentTime()
   {
@@ -187,7 +214,7 @@ namespace OHOS
 
     // 将 int 转换为 uint32_t(确保非负)
     uint32_t FirstTime = static_cast<uint32_t>(FirstCalibrationTime);
-    LastCalibrationTime = GetCurrentTimeStr(FirstTime);
+    LastCalibrationTime = GetSingleLineCurrentTimeStr(FirstTime);
     if (LastCalibrationTime.empty())
     {
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to format timestamp %u", FirstTime);
@@ -392,7 +419,7 @@ namespace OHOS
       UpdateHealthData(lastData, BP_STORAGE_TYPE::TODAY_DATA);
       UpdateHealthData(lastData, BP_STORAGE_TYPE::LAST_MEASURE_DATA);
     }
-    else if (lastData.last_check_sbp_value < 90 || lastData.last_check_dbp_value < 60) // 正常血压:收缩压(高压)<120 mmHg 且 舒张压(低压)<80 mmHg。
+    else if (lastData.last_check_sbp_value < 120 || lastData.last_check_dbp_value < 80) // 正常血压:收缩压(高压)<120 mmHg 且 舒张压(低压)<80 mmHg。
     {
       BP_SetResultState(BPRESULT::SUCCESS);
       UpdateHealthData(lastData, BP_STORAGE_TYPE::TODAY_DATA);
@@ -548,7 +575,7 @@ namespace OHOS
     if (Time != BP_ANLYSISI_TIME_MAX)
       Time = BP_ANLYSISI_TIME_MAX; // 重置时间
   }
-  /////////////////////////////////////////////////////////
+  ////////////////////////接口函数/////////////////////////////////
   // 机器校准收缩压与舒张压的数值
   void BPModel::BP_SetValue(BP_VALUE_TYPE type, bool set_value)
   {
@@ -678,6 +705,18 @@ namespace OHOS
     return bp_check_value_vector;
   }
 
+  // 获取上次测量数据
+  LAST_CHECK_DATA BPModel::GetLastData()
+  {
+    return lastData;
+  }
+
+  // 获取今日测量数据
+  std::deque<LAST_CHECK_DATA> BPModel::GetlastCheckData()
+  {
+    return lastCheckData; // 存储最近检测数据
+  }
+
   // nextday清空血压数据
   bool BPModel::CleanBPData(void)
   {
@@ -757,19 +796,20 @@ namespace OHOS
     if (current_state == BPState::BP_DETECTING)
     {
       BP_STOP();                              // 停止检测
-      BP_SetState(BPState::BP_End);           // 分析测量结果
+      BP_Control(BPState::BP_End);            // 分析测量结果
       if (bp_resullt == BPRESULT::NOT_TESTED) // 未测量到数据
       {
         BP_SetResultState(BPRESULT::TIMEOUT); // 测量超时
       }
       BP_SetState(BPState::BP_IDLE);
 
-      if (bpDetectionView &&
-          (bp_resullt == BPRESULT::HIGH_RESULT ||
-           bp_resullt == BPRESULT::SUCCESS ||
-           bp_resullt == BPRESULT::LOW_RESULT)) // 数据有效
+      if (bpDetectionView && bp_resullt == BPRESULT::SUCCESS)
       {
-        bpDetectionView->ChangeView(CALIBRATION_BPVIEW, RESULT_BPVIEW); // 成功进入结果界面
+        bpDetectionView->ChangeView(CALIBRATION_BPVIEW, RESULT_BPVIEW); // 成功且正常进入结果界面
+      }
+      else if (bpDetectionView && (bp_resullt == BPRESULT::HIGH_RESULT || bp_resullt == BPRESULT::LOW_RESULT))
+      {
+        bpDetectionView->ChangeView(CALIBRATION_BPVIEW, ERROR_BPVIEW); // 成功但异常进入结果界面
       }
       else
       {
@@ -910,14 +950,24 @@ namespace OHOS
       {
         view->UpdateTimeText(data);
       }
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
       {
-
-        BP_GetData(&lastData.last_check_sbp_value, &lastData.last_check_dbp_value);
-        if (bp_resullt == BPRESULT::NOT_TESTED && lastData.last_check_sbp_value > 0 && lastData.last_check_dbp_value > 0) // 检测到数据
+        uint8_t sbp = 0;
+        uint8_t dbp = 0;
+        BP_GetData(&sbp, &dbp);
+        if (Time == 1) // 测试数据用于验证
         {
           lastData.timestamp = BPModel::GetCurrentTime(); // 获取时间戳
+          lastData.last_check_sbp_value = rand() % 40 + 90;
+          lastData.last_check_dbp_value = rand() % 40 + 60;
+          // 测量完成
+          bp_resullt == BPRESULT::SUCCESS;
+        }
+        if (bp_resullt == BPRESULT::NOT_TESTED && sbp > 0 && dbp > 0) // 检测到数据
+        {
+          lastData.timestamp = BPModel::GetCurrentTime(); // 获取时间戳
+          lastData.last_check_sbp_value = sbp;
+          lastData.last_check_dbp_value = dbp;
           // 测量完成
           bp_resullt == BPRESULT::SUCCESS;
         }
@@ -933,14 +983,17 @@ namespace OHOS
       {
         view->UpdateTimeText(data);
       }
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
       {
 
-        BP_GetData(&lastData.last_check_sbp_value, &lastData.last_check_dbp_value);
-        if (bp_resullt == BPRESULT::NOT_TESTED && lastData.last_check_sbp_value > 0 && lastData.last_check_dbp_value > 0) // 检测到数据
+        uint8_t sbp = 0;
+        uint8_t dbp = 0;
+        BP_GetData(&sbp, &dbp);
+        if (bp_resullt == BPRESULT::NOT_TESTED && sbp > 0 && dbp > 0) // 检测到数据
         {
           lastData.timestamp = BPModel::GetCurrentTime(); // 获取时间戳
+          lastData.last_check_sbp_value = sbp;
+          lastData.last_check_dbp_value = dbp;
           // 测量完成
           bp_resullt == BPRESULT::SUCCESS;
         }
@@ -954,14 +1007,17 @@ namespace OHOS
       {
         view->UpdateTimeText(data);
       }
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Time: %d", Time);
       if (Time > 0 && Time < 30) // 一分钟后获取数据
       {
 
-        BP_GetData(&lastData.last_check_sbp_value, &lastData.last_check_dbp_value);
-        if (bp_resullt == BPRESULT::NOT_TESTED && lastData.last_check_sbp_value > 0 && lastData.last_check_dbp_value > 0) // 检测到数据
+        uint8_t sbp = 0;
+        uint8_t dbp = 0;
+        BP_GetData(&sbp, &dbp);
+        if (bp_resullt == BPRESULT::NOT_TESTED && sbp > 0 && dbp > 0) // 检测到数据
         {
           lastData.timestamp = BPModel::GetCurrentTime(); // 获取时间戳
+          lastData.last_check_sbp_value = sbp;
+          lastData.last_check_dbp_value = dbp;
           // 测量完成
           bp_resullt == BPRESULT::SUCCESS;
         }
@@ -1118,10 +1174,17 @@ namespace OHOS
     }
 
     // 更新UI 测试更新
-    BPDetectBeginView *view = BPDetectBeginView::GetInstance();
-    if (view)
+    if (BPDetectBeginView::GetInstance())
+    {
+      BPDetectBeginView::GetInstance()->UpdateChartData();
+    }
+    else if (BPUnderCalibrationView::GetInstance())
+    {
+      BPUnderCalibrationView::GetInstance()->UpdateChartData();
+    }
+    else if (BPSecUnderCalibrationView::GetInstance())
     {
-      view->UpdateChartData();
+      BPSecUnderCalibrationView::GetInstance()->UpdateChartData();
     }
   }
   /*
@@ -1363,19 +1426,19 @@ namespace OHOS
       {
 
         lastCheckData.push_back(data); // 存入数组中
-#if 1
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                      "timestamp:%d", data.timestamp);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                      "last_check_sbp_value:%d", data.last_check_sbp_value);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                      "last_check_dbp_value:%d", data.last_check_dbp_value);
-#endif
       }
       else if (StorageType == BP_STORAGE_TYPE::LAST_MEASURE_DATA)
       {
         lastData = data; // 加载上次测量时间
       }
+#if 1
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "timestamp:%d", data.timestamp);
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "last_check_sbp_value:%d", data.last_check_sbp_value);
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "last_check_dbp_value:%d", data.last_check_dbp_value);
+#endif
     }
     // 关闭文件
     ifs.close();
index 43a2c50..d6ee991 100644 (file)
@@ -90,30 +90,29 @@ namespace OHOS
         {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
-        // int takeCount = 60;
-        // int inputSize = input.size();
-        // int actualCount = std::min({takeCount, inputSize});
-
-        // if (actualCount <= 0)
-        //     return; // 无有效数据可赋值
-
-        // // 计算input中起始索引
-        // int startIndex = inputSize - actualCount;
-
-        // // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
-        // for (int i = 0; i < actualCount; ++i)
-        // {
-        //     testData[i].y = input[startIndex + i];
-        // }
-
-        // // 更新图表数据
-        // if (datachart && dataSerial)
-        // {
-        //     dataSerial->ClearData();
-        //     dataSerial->AddPoints(testData, 60);
-        //     datachart->AddDataSerial(dataSerial);
-        //     RootView::GetInstance()->Invalidate();
-        // }
+    }
+        //更新曲线图
+    void BPSecUnderCalibrationView::UpdateChartData()
+    {
+        if (dataSerial == nullptr || datachart == nullptr)
+            return;
+        
+        std ::vector<uint8> bp_check_value_vector = BPModel::GetInstance()->GetBPCheckDataArray();
+        size_t bp_check_value_vectorSize = bp_check_value_vector.size();
+        if (bp_check_value_vectorSize == 0)
+            return;
+
+        for (int i = 0; i < bp_check_value_vectorSize; ++i)
+        {
+            // 获取数据
+            testData[i].y = bp_check_value_vector[i];
+        }
+
+        // 更新图表数据
+        dataSerial->ClearData();
+        dataSerial->AddPoints(testData, 100);
+        datachart->AddDataSerial(dataSerial);
+        RootView::GetInstance()->Invalidate();
     }
 
     void BPSecUnderCalibrationView::InitChartView()
index f3e89db..3aeb045 100644 (file)
@@ -90,30 +90,29 @@ namespace OHOS
         {
             timenumLabel->SetText(std::to_string(data).c_str());
         }
-        // int takeCount = 60;
-        // int inputSize = input.size();
-        // int actualCount = std::min({takeCount, inputSize});
-
-        // if (actualCount <= 0)
-        //     return; // 无有效数据可赋值
-
-        // // 计算input中起始索引
-        // int startIndex = inputSize - actualCount;
-
-        // // 赋值:将input最后actualCount个元素赋值给testData的前actualCount个位置
-        // for (int i = 0; i < actualCount; ++i)
-        // {
-        //     testData[i].y = input[startIndex + i];
-        // }
-
-        // // 更新图表数据
-        // if (datachart && dataSerial)
-        // {
-        //     dataSerial->ClearData();
-        //     dataSerial->AddPoints(testData, 60);
-        //     datachart->AddDataSerial(dataSerial);
-        //     RootView::GetInstance()->Invalidate();
-        // }
+    }
+        //更新曲线图
+    void BPUnderCalibrationView::UpdateChartData()
+    {
+        if (dataSerial == nullptr || datachart == nullptr)
+            return;
+        
+        std ::vector<uint8> bp_check_value_vector = BPModel::GetInstance()->GetBPCheckDataArray();
+        size_t bp_check_value_vectorSize = bp_check_value_vector.size();
+        if (bp_check_value_vectorSize == 0)
+            return;
+
+        for (int i = 0; i < bp_check_value_vectorSize; ++i)
+        {
+            // 获取数据
+            testData[i].y = bp_check_value_vector[i];
+        }
+
+        // 更新图表数据
+        dataSerial->ClearData();
+        dataSerial->AddPoints(testData, 100);
+        datachart->AddDataSerial(dataSerial);
+        RootView::GetInstance()->Invalidate();
     }
 
     void BPUnderCalibrationView::InitChartView()
index e065e03..99207bc 100644 (file)
@@ -112,7 +112,7 @@ namespace OHOS
         }
         /*获取上次测量的数据*/
         BPModel::GetInstance()->GetLastData();
-        uint32_t time = BPModel::GetInstance()->GetLastData().timestamp;
+        uint32_t time = BPModel::GetInstance()->GetLastData().timestamp; 
         std::string timeStr = BPModel::GetInstance()->GetDoubleLineCurrentTimeStr(time);
         timeLabel->SetText(timeStr.c_str());
         DBPText->SetText(std::to_string(BPModel::GetInstance()->GetLastData().last_check_dbp_value).c_str());