1.接通心率和血氧到UI,2.增加切换表盘功能,点击表盘中心,可以切换。
authorCaisking <3449750381@qq.com>
Tue, 27 Feb 2024 08:29:03 +0000 (16:29 +0800)
committerCaisking <3449750381@qq.com>
Tue, 27 Feb 2024 08:29:03 +0000 (16:29 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/dialupdate/include/DialUpdateModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/dialupdate/include/DialUpdatePresenter.h
code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdatePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelHeartRate.cpp
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dials/KUMI.bin
code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp

index cac577e..337692e 100644 (file)
@@ -314,6 +314,7 @@ set(SOURCES
 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateView.cpp   
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdatePresenter.cpp   
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateModel.cpp   
 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phoneservice/src/PhoneService.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phoneservice/src/PhoneAudio.cpp
diff --git a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/include/DialUpdateModel.h b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/include/DialUpdateModel.h
new file mode 100644 (file)
index 0000000..1b662df
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef DIALUPDATE_MODEL_H
+#define DIALUPDATE_MODEL_H
+
+#include <string>
+
+namespace OHOS
+{
+    class DialUpdateModel
+    {
+    public:
+        static DialUpdateModel *GetInstance();
+
+        std::string GetDialConfigPath();
+        void UpdateDialConfigPath(const std::string &newPath);
+
+    private:
+        DialUpdateModel();
+        DialUpdateModel(const DialUpdateModel &);
+        DialUpdateModel &operator=(const DialUpdateModel &);
+        virtual ~DialUpdateModel();
+
+        std::string dialConfigPath = "user/res/dials/dog.bin";; // Member variable to store the dial configuration path
+    };
+}
+
+#endif
index d75e1f4..c4c0454 100644 (file)
 #include "Presenter.h"
 #include "DialViewGroup.h"
 #include "dialupdate/include/DialUpdateView.h"
-
+#include "dialupdate/include/DialUpdateModel.h"
 namespace OHOS
 {
     class DialUpdateView;
-
+    class DialupdateModel;
     class DialUpdatePresenter : public Presenter<DialUpdateView>,
                                 public UIView::OnClickListener,
                                 public UIView::OnDragListener
@@ -37,6 +37,7 @@ namespace OHOS
     private:
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
+        DialUpdateModel *g_pdialupdatemodel;
     };
 } // namespace OHOS
 
diff --git a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp
new file mode 100644 (file)
index 0000000..23fab3a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
+ * Description: DialUpdateModel.cpp
+ * Author:
+ * Create: 2021-11-23
+ */
+
+#include "dialupdate/include/DialUpdateModel.h"
+
+namespace OHOS
+{
+    DialUpdateModel::DialUpdateModel() {}
+
+    DialUpdateModel::~DialUpdateModel() {}
+
+    DialUpdateModel *DialUpdateModel::GetInstance()
+    {
+        static DialUpdateModel instance;
+        return &instance;
+    }
+    std::string DialUpdateModel::GetDialConfigPath()
+    {
+        return dialConfigPath;
+    }
+    void DialUpdateModel::UpdateDialConfigPath(const std::string &newPath)
+    {
+        dialConfigPath = newPath;
+    }
+}
index ba7f814..92f60ca 100644 (file)
@@ -2,7 +2,7 @@
 #include "NativeAbility.h"
 #include "DialViewGroup.h"
 #include "dialupdate/include/DialUpdatePresenter.h"
-
+#include "wearable_log.h"
 namespace OHOS
 {
 
@@ -11,6 +11,7 @@ namespace OHOS
 
     DialUpdatePresenter::DialUpdatePresenter()
     {
+        g_pdialupdatemodel = DialUpdateModel::GetInstance();
         g_pDialUpdatePresenter = this;
     }
 
@@ -62,11 +63,18 @@ namespace OHOS
 
     bool DialUpdatePresenter::OnClick(UIView &view, const ClickEvent &event)
     {
+        std::string filepath;
         if (strcmp(view.GetViewId(), "button_choose") == 0)
         {
-            // std::string filePath = RES_PATH "/dials/KUMI.bin";
-            // dialGroup_->SetDial(filePath);
-             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+            filepath = "user/res/dials/KUMI.bin";
+            // 检查是否需要更新表盘路径
+            std::string currentPath = g_pdialupdatemodel->GetDialConfigPath();
+            if (currentPath != filepath)
+            {
+                g_pdialupdatemodel->UpdateDialConfigPath(filepath);
+            }
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filepath:%s || currentPath:%s ", filepath.c_str(), currentPath.c_str());
+            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
         }
         if (strcmp(view.GetViewId(), "flowerbudbutton") == 0)
         {
index d5cbad4..0cc1c08 100644 (file)
@@ -7,6 +7,7 @@
 #include "wearable_log.h"
 #include "MainViewSample.h"
 #include "graphic_service.h"
+#include "dialupdate/include/DialUpdateModel.h"
 
 namespace OHOS
 {
@@ -331,16 +332,17 @@ namespace OHOS
     {
 #if USE_OFFLINE_DIAL
         mainClockView = new DialViewGroup();
+        #if 0
         std::string filePath = dynamic_cast<MainPresenterSample *>(presenter_)->GetDialPath();
         if (filePath.size() == 0)
         {
             filePath = RES_PATH "/dials/dog.bin";
-
-#if 0
-            const std::string *dialPathPtr = new std::string("example_path"); // 创建指向const std::string的指针
-            DialModelPath::GetInstance()->UpdatePath(dialPathPtr);                            // 调用UpdatePath函数并传递参数
-            delete dialPathPtr; // 释放内存
-#endif
+        }
+        #endif
+        std::string filePath = DialUpdateModel::GetInstance()->GetDialConfigPath();
+        if (filePath.size() == 0)
+        {
+            filePath = RES_PATH "/dials/KUMI.bin";
         }
         mainClockView->SetDial(filePath);
 #else
index f4a337e..c738b4d 100644 (file)
@@ -7,22 +7,26 @@
 
 #include "RegisterDialModel.h"
 #include "DialModelHeartRate.h"
+#include "wearable_log.h"
 
 REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_HEART_RATE, OHOS::DialModelHeartRate::GetInstance());
 
-namespace OHOS {
-bool DialModelHeartRate::GetDialFloatData(DialDataType& type, float& out)
+namespace OHOS
 {
-    (void)type;
-    out = heartRate_;
-    return true;
-}
+    bool DialModelHeartRate::GetDialFloatData(DialDataType &type, float &out)
+    {
+        (void)type;
+        out = heartRate_;
+        return true;
+    }
 
-void DialModelHeartRate::UpdateHeartRate(int16_t heartRate)
-{
-    heartRate_ = static_cast<float>(heartRate);
-    if (onChangeListener_ != nullptr) {
-        onChangeListener_->OnDialFloatDataUpdate(DialDataType::DATA_TYPE_HEART_RATE, heartRate_);
+    void DialModelHeartRate::UpdateHeartRate(int16_t heartRate)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateHeartRate = %d", heartRate);
+        heartRate_ = static_cast<float>(heartRate);
+        if (onChangeListener_ != nullptr)
+        {
+            onChangeListener_->OnDialFloatDataUpdate(DialDataType::DATA_TYPE_HEART_RATE, heartRate_);
+        }
     }
 }
-}
index 6667c63..3125dbb 100755 (executable)
@@ -17,6 +17,7 @@
 #include "AlarmClockModel.h"
 #include "AlarmPopUpPresenter.h"
 #include "DialModelCharge.h"
+#include "DialModelHeartRate.h"
 #include "CallerLogModel.h"
 #include "notification_manager.h"
 #include "NativeAbility.h"
@@ -46,6 +47,10 @@ const PriorityMapper g_pri_mapper[] = {
     {TOPIC_EVENT_HFP_WATCH_ACTIVE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_WATCH_TO_PHONE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE},
+#ifdef SUPPORT_SPO2_NOTIFICATION
+    {TOPIC_EVENT_SPO2_UPDATE, PRIORITY_TWO},
+    {TOPIC_EVENT_HEARTRATE_UPDATA, PRIORITY_TWO},
+#endif
 };
 
 static bool CheckPriority(const Topic topic)
@@ -79,6 +84,11 @@ void MsgCenterSubscribe()
     MsgCenterSubscribeTopic(TOPIC_EVENT_CHARGE_PLUG);
     MsgCenterSubscribeTopic(TOPIC_EVENT_CHARGE_UNPLUG);
 #endif
+#ifdef SUPPORT_SPO2_NOTIFICATION_TEST
+    MsgCenterSubscribeTopic(TOPIC_EVENT_SPO2_UPDATE);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_WEARSTATE_UPDATE);
+#endif
 }
 
 static OHOS::UIViewGroup* showAlarmNotify(void)
@@ -173,7 +183,44 @@ void MsgCenterNotifyHfpWatchProc(const Topic topic, Request* req)
         NotificationManager::GetInstance()->ShowNotify(showCallingNotify, (uint16_t)topic, true);
     }
 }
+#ifdef SUPPORT_SPO2_NOTIFICATION_TEST
+
 
+void MsgCenterNotifySPO2hProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+    if (topic == TOPIC_EVENT_SPO2_UPDATE && req != nullptr && req->data != nullptr)
+    {
+        u_int8_t sp02 = *((u_int8_t*)(req->data)); // 进行类型转换
+        DialModelHeartRate::GetInstance()->UpdateHeartRate(sp02);
+    }
+}
+void MsgCenterNotifyWearStateProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+    if ( topic == TOPIC_EVENT_WEARSTATE_UPDATE)
+    {
+        // req->msgId 
+    }
+}
+void MsgCenterNotifyHeartRateProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+    if ( topic == TOPIC_EVENT_HEARTRATE_UPDATA)
+    {
+        #if 0
+        // req->msgId 
+        if (OHOS::DialModelHeartRate::GetInstance()!=NULL)
+        {
+            OHOS::DialModelHeartRate::GetInstance()->UpdateHeartRate();
+        }
+        #endif
+    }
+}
+#endif
 /* 订阅事件通知逻辑可定制 */
 static msg_center_notify_table_t g_msg_center_notify_table[] = {
     {TOPIC_EVENT_ALARM_RING,         MsgCenterNotifyAlarmProc},
@@ -188,6 +235,11 @@ static msg_center_notify_table_t g_msg_center_notify_table[] = {
     {TOPIC_EVENT_CHARGE_PLUG,        MsgCenterNotifyChargePlugProc},
     {TOPIC_EVENT_CHARGE_UNPLUG,      MsgCenterNotifyChargeUnPlugProc},
 #endif
+#ifdef SUPPORT_SPO2_NOTIFICATION_TEST
+    {TOPIC_EVENT_SPO2_UPDATE,           MsgCenterNotifySPO2hProc},
+    {TOPIC_EVENT_WEARSTATE_UPDATE,      MsgCenterNotifyWearStateProc},
+    {TOPIC_EVENT_HEARTRATE_UPDATA,      MsgCenterNotifyHeartRateProc},
+#endif
 };
 
 static msg_center_notify_table_t *MsgCenterGetNotifyTblCb(uint8_t idx)
index ad3fc16..b775322 100644 (file)
Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dials/KUMI.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dials/KUMI.bin differ
index 7176797..891b0ab 100644 (file)
@@ -113,20 +113,22 @@ void CustomEventPublish(uint16_t topic, uint8_t *data , uint32_t size)
 errcode_t update_spo2_event_notify(uint8_t spo2)
 {
    
-    CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,(uint8_t*)&spo2,sizeof(spo2));
+    CustomEventPublish(TOPIC_EVENT_SPO2_UPDATE,(uint8_t*)&spo2,sizeof(spo2));
     return 0;
 }
 errcode_t update_spo2_event_sendmsg_toUI(uint8_t spo2)
 {
-
     /**通过UI事件发送Notify*/
     GraphicService::GetInstance()->PostGraphicEvent(std::bind(update_spo2_event_notify, spo2));
     return ERRCODE_SUCC;
 }
 
 #include "hx3695_hal.h"
+
 void hx3695_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen)
 {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hx3695_msg_callback");
+    FT_CUSTOM_RESULTS_t sensor_data; // 使用更通用的名称 sensor_data
     switch(msg_type)
     {
         case HX3695_MSG_TYPE_HRS_UPDATE:
@@ -134,6 +136,18 @@ void hx3695_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datale
         case HX3695_MSG_TYPE_HRV_UPDATE:
             break;
         case HX3695_MSG_TYPE_SPO2_UPDATE:
+            {
+                #if 1
+                if (msg_datalen < sizeof(FT_CUSTOM_RESULTS_t)) {
+                    // 数据长度不足以填充整个结构体
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid data length for SPO2 update");
+                    break;
+                }
+                #endif
+                memcpy(&sensor_data, msg_data, sizeof(FT_CUSTOM_RESULTS_t));
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HX3695_MSG_TYPE_SPO2_UPDATE = %d", sensor_data.lastestspo2);
+                update_spo2_event_sendmsg_toUI(sensor_data.lastestspo2);
+            }
             break;
         case HX3695_MSG_TYPE_LEAKLIGHT_UPDATE:
             break;
@@ -148,8 +162,6 @@ void hx3695_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datale
 
 void uapi_ppg_service_deinit(void)
 {
-
-
     ppg_service_running_stat = false;
 }
 
@@ -185,7 +197,7 @@ static void ppg_service_check_task(void const *arg)
     int32_t ret;
     uint32_t mail;
     uint32_t msgsize = (uint32_t)sizeof(PPG_CMD_TYPE_T);
-
+    hx3695_register_msg_callback(hx3695_msg_callback);//注册驱动回调
     while (1) {
         ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize,
                                        OSAL_MSGQ_WAIT_FOREVER);