From f96c57a5446f2dd2a63725b4049fc0c065e934a0 Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 17 Jun 2025 12:23:10 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=A1=80=E5=8E=8B=E6=A3=80?= =?utf8?q?=E6=B5=8BUI=EF=BC=9B=E5=A2=9E=E5=8A=A0=E8=A1=80=E5=8E=8Bmodel?= =?utf8?q?=E6=9C=8D=E5=8A=A1=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 1 + .../bloodpressure/include/BPDetectBeginView.h | 41 +++++ .../bloodpressure/include/BPDetectEndView.h | 0 .../bloodpressure/include/BPDetectErrorView.h | 0 .../bloodpressure/include/BPDetectionView.h | 3 + .../nativeui/bloodpressure/include/BPModel.h | 30 +++- .../bloodpressure/src/BPDetectBeginView.cpp | 153 ++++++++++++++++++ .../bloodpressure/src/BPDetectFirstView.cpp | 2 +- .../src/BPDetectionPresenter.cpp | 12 +- .../bloodpressure/src/BPDetectionView.cpp | 28 ++++ .../nativeui/bloodpressure/src/BPModel.cpp | 118 ++++++++++++-- 11 files changed, 365 insertions(+), 23 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectBeginView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectEndView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectErrorView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectBeginView.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 4bbb6a1c5..1c4cf4c39 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -235,6 +235,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodpressure/src/BPDetectionPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodpressure/src/BPDetectFirstView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodpressure/src/BPDetectSOSView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodpressure/src/BPDetectBeginView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectBeginView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectBeginView.h new file mode 100644 index 000000000..426a91309 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectBeginView.h @@ -0,0 +1,41 @@ + +#ifndef BP_DetectBegin_VIEW_H +#define BP_DetectBegin_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_label_button.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_button_ext.h" +namespace OHOS +{ + + class BPDetectBeginView + { + public: + BPDetectBeginView(); + ~BPDetectBeginView(); + static BPDetectBeginView *GetInstance(); + UIViewGroup * BPDetectBeginInit(); + void DeInit(); + bool AddButton(); + bool InitLable(); + bool Initbackground(); + + + void UpdateTimeText(int data); + + private: + UIImageView *background = nullptr; + UILabelExt *calibrationLabel = nullptr; + UILabelExt *remindLabel = nullptr; + UILabelExt *timeLabel = nullptr; + UILabel*timenumLabel = nullptr; + + UIViewGroup *group{nullptr}; + }; +} + +#endif // 血压主界面 \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectEndView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectEndView.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectErrorView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectErrorView.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectionView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectionView.h index 9ac3ad3d5..99a6a7250 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectionView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPDetectionView.h @@ -32,6 +32,7 @@ #include "bloodpressure/include/BPDetectionPresenter.h" #include "bloodpressure/include/BPDetectFirstView.h" #include "bloodpressure/include/BPDetectSOSView.h" +#include "bloodpressure/include/BPDetectBeginView.h" #define CLICK_BLOOD_PRESSURE "click_bloodpressure" namespace OHOS { @@ -72,11 +73,13 @@ public: bool ChangeBPDetectFirstView(int16_t thisView); bool ChangeBPDetectSOSView(int16_t thisView); + bool ChangeBPDetectBeginView(int16_t thisView); private: UIViewGroup *group[MAX_BPDECETVIEW]{nullptr}; BPDetectFirstView *g_pBPDetectFirstView = nullptr; BPDetectSOSView *g_pBPDetectSOSView = nullptr; + BPDetectBeginView *g_pBPDetectBeginView = nullptr; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h index 6fcdad54d..49b003cb2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/include/BPModel.h @@ -8,8 +8,20 @@ namespace OHOS { // 血压检测状态 enum class BPState { - End = 0, - Start, + //结束检测 + BP_End = 0, + //第一次校准血压中 30s + BP_CALIBRATING_FIRSTTIME, + //第二次校准血压中 30s + BP_CALIBRATING_SECONDTIME, + //检测血压中 30s + BP_DETECTING, + //普通状态 + BP_NORMAL, + //暂停检测 + BP_PAUSE, + + BP_STATE_MAX, }; // 血压检测结果 enum class BPRESULT { @@ -21,6 +33,8 @@ enum class BPRESULT { LOW_RESULT, // 检测结果过低 INVALID_DATA // 无效数据 }; + +#define BP_CHECK_TIME_MAX 30 class BPModel { public: BPModel(); @@ -29,11 +43,19 @@ public: //获取当前时间年月日时分字符串 std::string GetCurrentTimeStr(); - // 定时器管理 - void BP_StartTimer(uint32_t interval = 1000); + //当前状态管理 + void BP_SetState(BPState state); + BPState GetCurrentState(); + //控制血压检测 + void BP_Control(BPState state); + + /////////////////////////////////////////////// + void BP_StartTimer(uint32_t interval = 1*1000);// 1s定时器 void BP_StopTimer(void); + private: + BPState current_state = BPState::BP_NORMAL; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectBeginView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectBeginView.cpp new file mode 100644 index 000000000..096ae0a57 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectBeginView.cpp @@ -0,0 +1,153 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-31 14:36:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodpressure/src/BPDetectBeginView.cpp + */ + +#include "ui_resource_image.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "uicomponents/UIComponents.h" +#include "bloodpressure/include/BPDetectionPresenter.h" +#include "bloodpressure/include/BPDetectBeginView.h" +#include "bloodpressure/include/BPModel.h" + +namespace OHOS +{ + static BPDetectBeginView *g_pBPDetectBeginView{nullptr}; + static const char *BPBACKPATH = "/user/res/BPCalibration/calibration_background.bin"; + BPDetectBeginView::BPDetectBeginView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPDetectBeginView::BPDetectBeginView"); + g_pBPDetectBeginView = this; + } + BPDetectBeginView::~BPDetectBeginView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BPDetectBeginView::~BPDetectBeginView"); + DeInit(); + g_pBPDetectBeginView = nullptr; + } + BPDetectBeginView *BPDetectBeginView::GetInstance() + { + return g_pBPDetectBeginView; + } + void BPDetectBeginView::DeInit() + { + if(group) + { + group->RemoveAll(); + if (background != nullptr) + { + delete background; + background = nullptr; + } + if (calibrationLabel != nullptr) + { + delete calibrationLabel; + calibrationLabel = nullptr; + } + if(remindLabel != nullptr) + { + delete remindLabel; + remindLabel = nullptr; + } + if(timeLabel != nullptr) + { + delete timeLabel; + timeLabel = nullptr; + } + if(timenumLabel != nullptr) + { + delete timenumLabel; + timenumLabel = nullptr; + } + } + delete group; + group = nullptr; + + } + /* -------------------------------------------------------------------------- */ + //倒计时更新时间文本 + void BPDetectBeginView::UpdateTimeText(int data) + { + if(timenumLabel != nullptr && data >= 0 && data <= BP_CHECK_TIME_MAX) + { + timenumLabel->SetText(std::to_string(data).c_str()); + } + } + /* -------------------------------------------------------------------------- */ + /*** + * @description: + * @return 初始化标签是否成功 + */ + bool BPDetectBeginView::InitLable() + { + + InitLabel(calibrationLabel, 83, 32, 300, 40, "calibration", "测量中...", DEFAULT_VECTOR_FONT_FILENAME, 35); + InitLabel(remindLabel, 63, 278, 360, 35, "remind", "测量中,过程中尽量保持静止,呼吸均匀平衡", DEFAULT_VECTOR_FONT_FILENAME, 30); + remindLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + remindLabel->SetTextColor(Color::Red()); + InitLabel(timeLabel, 165, 400, 300, 35, "timeLabel", "秒", DEFAULT_VECTOR_FONT_FILENAME, 30); + + InitUILabel(timenumLabel, 133, 300, 200, 200, "timenumLabel", "30", DEFAULT_VECTOR_FONT_FILENAME, 100); + + group->Add(calibrationLabel); + group->Add(remindLabel); + group->Add(timeLabel); + group->Add(timenumLabel); + + return true; + } + /*** + * @description: + * @return 初始化背景是否成功 + */ + bool BPDetectBeginView::Initbackground() + { + background = new UIImageView(); + background->SetPosition(0, 0, 466, 466); + background->SetSrc(BPBACKPATH); + + background = new UIImageView(); + background->SetPosition(0, 0, 466, 466); + background->SetSrc(BPBACKPATH); + + background = new UIImageView(); + background->SetPosition(0, 0, 466, 466); + background->SetSrc(BPBACKPATH); + + + group->Add(background); + return true; + } + /*** + * @description: + * @return 是否初始化成功 + */ + UIViewGroup *BPDetectBeginView::BPDetectBeginInit() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bool BPDetectBeginView::InitView()"); + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmPopUpView::group null!"); + return nullptr; + } + group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + if (!Initbackground()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Initbackground error!"); + return nullptr; + }; + if (!InitLable()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLable error!"); + return nullptr; + }; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bool BPDetectBeginView::InitView()"); + + return group; + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectFirstView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectFirstView.cpp index 4662e47ed..53b85df14 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectFirstView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectFirstView.cpp @@ -106,7 +106,7 @@ namespace OHOS */ UIViewGroup *BPDetectFirstView::BPDetectFirstInit() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bool BPDetectFirstView::InitView()"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bool BPDetectFirstView::InitView()"); group = new UIViewGroup(); group->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionPresenter.cpp index 7c8791c08..71081e8b8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionPresenter.cpp @@ -7,15 +7,13 @@ #include "bloodpressure/include/BPDetectionView.h" #include "bloodpressure/include/BPDetectionPresenter.h" +#include "bloodpressure/include/BPModel.h" #include "AppViewIDs.h" #include "NativeAbility.h" #include "common/key_code.h" #include "KeyInputListener.h" #include "custom_utils.h" -#include "displaybrightness/include/DisplayBrightnessModel.h" -#include "bloodpressure/include/BPModel.h" -#include "MainModel.h" namespace OHOS { @@ -40,6 +38,8 @@ namespace OHOS } void BPDetectionPresenter::NavigateBack() { + //重置状态 + BPModel::GetInstance()->BP_Control(BPState::BP_NORMAL); NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } void BPDetectionPresenter::OnStart() @@ -81,8 +81,10 @@ namespace OHOS if (strcmp(view.GetViewId(), CLICK_BLOOD_PRESSURE) == 0) { // NavigateBack(); - //切换到sos界面 test - BPDetectionView::GetInstance()->ChangeView(MAIN_BPVIEW,SOS_BPVIEW); + //设置状态为检测状态 + BPModel::GetInstance()->BP_Control(BPState::BP_DETECTING); + BPDetectionView::GetInstance()->ChangeView(MAIN_BPVIEW,CALIBRATION_BPVIEW); + BPModel::GetInstance()->BP_StartTimer();//开始计时器,计时结束后自动切换到主界面 } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionView.cpp index b7d8b04c8..36343f102 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPDetectionView.cpp @@ -45,6 +45,12 @@ namespace OHOS g_pBPDetectSOSView = nullptr; } + if(g_pBPDetectBeginView) + { + delete g_pBPDetectBeginView; + g_pBPDetectBeginView = nullptr; + } + for(int i = 0; i < MAX_BPDECETVIEW; ++i) { @@ -154,6 +160,27 @@ namespace OHOS return true; } + bool BPDetectionView::ChangeBPDetectBeginView(int16_t thisView) + { + // 检查视图是否已初始化,避免重复创建 + if (group[thisView] == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodPressureView::ChangeBPDetectBeginView"); + // 创建首次校准视图实例 + g_pBPDetectBeginView = new BPDetectBeginView(); + if (g_pBPDetectBeginView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "BloodPressureView::ChangeBPDetectBeginView new BPDetectBeginView fail"); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = g_pBPDetectBeginView->BPDetectBeginInit(); + container_->Add(group[thisView]); + } + return true; + } + /** * 视图映射结构体 - 将视图ID映射到对应的视图切换函数 @@ -167,6 +194,7 @@ namespace OHOS static const BPViewMapper ViewMapper[] = { {MAIN_BPVIEW, &BPDetectionView::ChangeBPDetectFirstView}, {SOS_BPVIEW, &BPDetectionView::ChangeBPDetectSOSView}, + {CALIBRATION_BPVIEW, &BPDetectionView::ChangeBPDetectBeginView}, }; bool BPDetectionView::ClickFunc(int16_t interface) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp index fee1d7e77..731f4d3ff 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodpressure/src/BPModel.cpp @@ -1,15 +1,20 @@ #include "bloodpressure/include/BPModel.h" #include "bloodpressure/include/BPMainPresenter.h" +#include "bloodpressure/include/BPMainView.h" -#include "heart_blood/health_service/health_service.h" -#include "wearable_log.h" +#include "bloodpressure/include/BPDetectionPresenter.h" +#include "bloodpressure/include/BPDetectionView.h" +#include "bloodpressure/include/BPDetectFirstView.h" +#include "bloodpressure/include/BPDetectSOSView.h" +#include "bloodpressure/include/BPDetectBeginView.h" +// #include "bloodpressure/include/BPDetectResultView.h" +// #include "bloodpressure/include/BPDetectEndView.h" +#include "wearable_log.h" #include #include #include - - #include "AppViewIDs.h" #include "ConfigModel.h" #include "NativeAbility.h" @@ -21,6 +26,7 @@ #define MAX_UNWARE_COUNT 10 #define MAX_VALID_SPO2_COUNT 30 #define MAX_DISVALID_SPO2_COUNT 100 + // 声明定时器变量 static osTimerId_t g_timer = nullptr; static int Time = 30; @@ -74,27 +80,112 @@ std::string BPModel::GetCurrentTimeStr() { return std::string(buffer); } +//管理当前状态 +void BPModel::BP_SetState(BPState state) { current_state = state; } +BPState BPModel::GetCurrentState() { return current_state; } + +//进行传感器、定时器等控制 +void BPModel::BP_Control(BPState state) +{ + if(state == current_state) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_Control: Already in current state"); + return; + } + switch (state) + { + case BPState::BP_NORMAL:{ + /* + 关闭定时器 + 关闭传感器 + 关闭常亮 + */ + BP_StopTimer(); + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + break; + } + case BPState::BP_DETECTING: + /* + 开启定时器 + 开启传感器 + 开启常亮 + */ + BP_StartTimer(); + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);//后期 周期被动状态 需要做区别 + break; + case BPState::BP_CALIBRATING_FIRSTTIME: + break; + case BPState::BP_CALIBRATING_SECONDTIME: + break; + default: + /*未知状态,全部状态重置*/ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_Control: Invalid state"); + BP_SetState(BPState::BP_NORMAL); + BP_StopTimer(); + return; + } + //更新状态 + BP_SetState(state); +} + /////////////////////////////////////////////////////////////////////////////////////// /*定时器到期时的处理*/ static void BP_TimerCallbackProc(int data) { - // 等待完成的定时器 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BP_TimerCallbackProc,Time = %d", - Time); - if (Time < 0) // 如果校准超时30s,进入完成界面 + + // 提前检查无效时间 + if (Time < 0) { BPModel::GetInstance()->BP_StopTimer(); - //TODO:加判断?界面没有存在 直接就挂了 - BPMainView::GetInstance()->ChangeView(BPUNDERCALIBRATIONVIEW, BPVALUEVIEW); + BPMainView* mainView = BPMainView::GetInstance(); + if (mainView) + { + mainView->ChangeView(BPUNDERCALIBRATIONVIEW, BPVALUEVIEW); + } + else if (BPDetectionView::GetInstance()) + { + BPDetectionView::GetInstance()->ChangeView(CALIBRATION_BPVIEW, MAIN_BPVIEW); + } + return; } - return; + + // 倒计时 + Time--; + + BPState current_state_time = BPModel::GetInstance()->GetCurrentState(); + // 根据状态处理 + switch (current_state_time) { + case BPState::BP_NORMAL: + BPModel::GetInstance()->BP_StopTimer(); + return; + + case BPState::BP_DETECTING: { + BPDetectBeginView* view = BPDetectBeginView::GetInstance(); + if (view) { + view->UpdateTimeText(Time); + } + break; + } + + case BPState::BP_CALIBRATING_FIRSTTIME: + break; + case BPState::BP_CALIBRATING_SECONDTIME: + break; + + default: + BPModel::GetInstance()->BP_StopTimer(); + // 显示错误界面提示 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "current_state is error!!"); + return; + } + } /* * @brief 回调函数 */ static void BP_TimerCallback(int data) { - Time -= 1; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BP_TimerCallback %d", data); GraphicService::GetInstance()->PostGraphicEvent( std::bind(BP_TimerCallbackProc, data)); } @@ -156,8 +247,9 @@ void BPModel::BP_StopTimer(void) { "osTimerDelete failed, ret = %lx!!", ret); } g_timer = nullptr; - Time = 30; + Time = BP_CHECK_TIME_MAX; } + } } // namespace OHOS -- 2.17.1