gsensortest
authorhcj <1224667075@qq.com>
Wed, 27 Mar 2024 07:48:15 +0000 (15:48 +0800)
committerhcj <1224667075@qq.com>
Wed, 27 Mar 2024 07:48:15 +0000 (15:48 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h
code/sdk/application/wearable/fd230app/nativeui/producttest/include/testView.h
code/sdk/application/wearable/fd230app/nativeui/producttest/include/testgsenson.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp
code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h
code/sdk/drivers/peripheral/cywee/src/main_dml.c

index 15bd4d2..9277b45 100644 (file)
@@ -494,6 +494,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testmakephone.cpp  
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testcat1.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testhrsenson.cpp 
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testgsenson.cpp
+    #${CMAKE_CURRENT_SOURCE_DIR} /service/acc_service.c
 )
 if("SUPPORT_ALIPAY_SEC" IN_LIST DEFINES)
 set(SOURCES   
index 6f462af..5c1c01d 100644 (file)
@@ -33,6 +33,7 @@ namespace OHOS
         BUTTON,\r
         MAKEPHONE,\r
         HRSENSON,\r
+        GSENSON,\r
         TEST_1,\r
 \r
         MAX_TESTVIEWID,\r
index f1ba437..112907a 100644 (file)
@@ -23,6 +23,7 @@
 #include "producttest/include/testmakephone.h"\r
 #include "producttest/include/testcat1.h" \r
 #include "producttest/include/testhrsenson.h" \r
+#include "producttest/include/testgsenson.h"\r
 namespace OHOS\r
 {\r
     \r
@@ -79,6 +80,7 @@ namespace OHOS
         bool ChangeMPTESTView(int16_t thisView);\r
         bool ChangeHRTESTView(int16_t thisView);\r
         bool ChangeCAT1TESTView(int16_t thisView);\r
+        bool ChangeGTESTView(int16_t thisView);\r
 \r
         bool ClickFunc(int16_t interface);\r
         void ChangeView(int16_t hideView, int16_t showView);\r
@@ -109,7 +111,9 @@ namespace OHOS
         testMagicView *test_MG_view{nullptr};\r
         testhrsenson1View *test_hr_view{nullptr};\r
         testmakephoneView *test_MP_view{nullptr};\r
-        \r
+\r
+        testgsensonView *test_G_view{nullptr};\r
+\r
         UILabelButtonExt *button[10]={NULL};\r
         bool initViewStatus{false};\r
     };\r
diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testgsenson.h b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testgsenson.h
new file mode 100644 (file)
index 0000000..fd5018f
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef TEST_GSONSON_VIEW_H
+#define TEST_GSONSON_VIEW_H
+
+#include "BaseView.h"
+#include "View.h"
+#include "components/ui_scroll_view.h"
+#include "components/ui_label.h"
+#include "components/ui_image_view.h"
+#include "producttest/include/testmagnetic.h"
+#include "CompassModel.h"
+#include "components/ui_label_button_ext.h"
+//#include "cmsis_os.h"
+#include <iostream>
+
+namespace OHOS
+{
+    class testgsensonView
+    {
+
+    public:
+
+        struct LabelConfig
+        {
+            int16_t left;
+            int16_t top;
+            int16_t width;
+            int16_t height;
+            int16_t fontSize;      // 字体大小
+            int16_t lineHeigh;     // 行高
+            char *text;      // 文本
+            uint8_t lineBreakMode; // 断行模式。
+        };
+
+        testgsensonView();
+        virtual ~testgsensonView();
+        static testgsensonView *GetInstance(void);
+
+        UIScrollView *testGSENSONInitIView(void);
+        void ClearAll(void);
+        void set_data();
+    private:
+        bool testGsonsonScrollViewcrollViewinit(void);
+        UILabel *InitLabel(LabelConfig &labelConfig);
+        UIScrollView *testGsonsonScrollView{nullptr};
+        bool initViewStatus{false};
+        UILabel *title{nullptr}; // “关于”
+        UILabel *x{nullptr};           // “手表名称”
+        UILabel *y{nullptr};
+        UILabel *z{nullptr}; //  "固件版本"
+
+        UILabelButtonExt* labelButton_next = nullptr;
+    };
+}
+#endif
\ No newline at end of file
index f730e39..533e48d 100644 (file)
@@ -47,7 +47,8 @@ namespace OHOS
         {CAT1,"cat1button", "buttonbutton_next",true},\r
         {BUTTON,"buttonbutton", "makephonebutton_next",true},\r
         {MAKEPHONE,"makephonebutton", "hrsensonbutton_next",true},\r
-        {HRSENSON,"hrsensonbutton", "xxxxxxxxxx",true},\r
+        {HRSENSON,"hrsensonbutton", "gsensonbutton_next",true},\r
+        {GSENSON,"gsensonbutton","xxxx" ,true},\r
         };\r
         // {FACTORYRESETVIEW,"FactoryResetButton",true},\r
         // {SYSTEMLUPGRADE,"systemupgread",true},\r
index b489a32..6388cd1 100644 (file)
@@ -30,6 +30,7 @@ namespace OHOS
         {BUTTON,"buttonbutton","button" ,&testView::ChangKEYTESTView},\r
         {MAKEPHONE,"makephonebutton","makephone" ,&testView::ChangeMPTESTView},\r
         {HRSENSON,"hrsensonbutton","hrsenson" ,&testView::ChangeHRTESTView},\r
+        {GSENSON,"gsensonbutton","gsenson" ,&testView::ChangeGTESTView},\r
         // {FACTORYRESETVIEW,"FactoryResetButton","恢复出厂", &testView::ChangeSystemAboutView},\r
         // {SYSTEMLUPGRADE,"systemupgread","系统升级",&testView::ChangeSystemAboutView},\r
         // {TEST,"testButton","测试模式", &testView::ChangeSystemAboutView},\r
@@ -450,6 +451,24 @@ namespace OHOS
         return true;\r
     }\r
 \r
+    \r
+    bool testView::ChangeGTESTView(int16_t thisView)\r
+    {\r
+        if (SystemScrollView[thisView] == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSystemAboutView");\r
+            test_G_view = new testgsensonView();\r
+            if (test_G_view == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: new scrollView[%d] fail", thisView);\r
+                return false;\r
+            }\r
+            SystemScrollView[thisView] = test_G_view->testGSENSONInitIView();\r
+            RootView::GetInstance()->Add(SystemScrollView[thisView]);\r
+        }\r
+        return true;\r
+    }\r
+\r
     UIScrollView *testView::GetSystemScrollView(int ViewId)\r
     {\r
         if (SystemScrollView[ViewId] == nullptr)\r
diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp
new file mode 100644 (file)
index 0000000..9d93740
--- /dev/null
@@ -0,0 +1,229 @@
+#include "wearable_log.h"
+#include "custom_utils.h"
+#include "producttest/include/testPresenter.h"
+#include "producttest/include/testgsenson.h"
+#include "mag_service.h"
+#include "cmsis_os2.h"
+#include "cywee_hal.h" 
+//#include "acc_service.h"
+namespace OHOS
+{
+
+    // static void get_gsonsen_xyz(gsenson_t *t)
+    // {
+    //     // if(osal_mutex_trylock(&mutex_gsenson_queue)==0)
+    //     // {
+    //     //     CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n");
+    //     //     return;
+    //     // }
+    //     lis2doc_read_data_single(&t->x,&t->y,&t->z);
+    //     //osal_mutex_trylock(&mutex_gsenson_queue);
+    //     // t->x=gxyz_t.x;
+    //     // t->y=gxyz_t.y;
+    //     // t->z=gxyz_t.z;
+    //     //osal_mutex_unlock(&mutex_gsenson_queue);
+    // //    int ret= osal_msg_queue_read_copy(gsenson_queue, t, sizeof(gsenson_t),OSAL_MSGQ_NO_WAIT);
+    // //    if(ret!=0)
+    // //    {
+    // //         CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n");
+    // //    }
+    // }
+
+    static testgsensonView *g_pSystemAboutTheWatchView{nullptr};
+
+    testgsensonView::testgsensonView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::SystemAboutTheWatchView");
+        g_pSystemAboutTheWatchView = this;
+    }
+
+    testgsensonView::~testgsensonView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::~SystemAboutTheWatchView");
+        ClearAll();
+        g_pSystemAboutTheWatchView = nullptr;
+    }
+
+    testgsensonView *testgsensonView::GetInstance()
+    {
+
+        return g_pSystemAboutTheWatchView;
+    }
+    static osTimerId_t  Gsenson_TEST_timer=NULL;
+    void testgsensonView::ClearAll()
+    {
+        if(testGsonsonScrollView)
+        {
+            testGsonsonScrollView->RemoveAll();
+
+            if (Gsenson_TEST_timer != NULL) {
+                osTimerDelete(Gsenson_TEST_timer);
+                Gsenson_TEST_timer = NULL;
+                return ;
+            }
+
+            if(title!=NULL)
+            {
+                delete title;
+                title=nullptr;
+            }
+            if(x!=NULL)
+            {
+                delete x;
+                x=nullptr;
+            }
+            if(labelButton_next)
+            {
+                delete labelButton_next;
+                labelButton_next=nullptr;
+            }
+            delete testGsonsonScrollView;
+            testGsonsonScrollView=nullptr;
+        }
+    }
+
+    static void  mgdataTimerCallBack(int data)
+    {
+         testgsensonView::GetInstance()->set_data();
+    }
+    static uint8_t MG_TEST_FALG=0;
+    void testgsensonView ::set_data(void)
+    {
+        
+        MG_TEST_FALG++;
+        gsenson_t t;
+        get_gsonsen_xyz(&t);
+        char buf[124]={0};
+        sprintf(buf,"X:%d\nY:%d\nZ:%d",t.x,t.y,t.z);
+        x->SetText(buf);
+        RootView::GetInstance()->Invalidate();
+
+        // if(MG_TEST_FALG>10)
+        // CompassModel::GetInstance()->CloseCompassSensor();
+    }
+
+    UILabel *testgsensonView::InitLabel(LabelConfig &labelConfig)
+    {
+        UILabel *label = new UILabel();
+        if (label == nullptr)
+        {
+            return nullptr;
+        }
+        label->SetPosition(labelConfig.left, labelConfig.top, labelConfig.width, labelConfig.height); // 位置大小
+        label->SetStyle(STYLE_TEXT_FONT, labelConfig.fontSize);                                       // 字体大小
+        label->SetStyle(STYLE_LINE_HEIGHT, labelConfig.lineHeigh);                                    // 字体行高
+        label->SetText(labelConfig.text);                                                             // 内容
+        label->SetLineBreakMode(labelConfig.lineBreakMode);                                           // 断行模式。
+        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
+        label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelConfig.fontSize);
+        return label;
+    }
+
+   
+   
+    bool testgsensonView::testGsonsonScrollViewcrollViewinit(void)
+    {
+        uint32_t tick;
+        osStatus_t retTimer;
+
+       // CompassModel::GetInstance()->OpenCompassSensor();
+
+        testGsonsonScrollView = new UIScrollView();
+        if (testGsonsonScrollView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::testGsonsonScrollView new fail!");
+            return false;
+        }
+        testGsonsonScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        testGsonsonScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        testGsonsonScrollView->SetStyle(STYLE_BORDER_RADIUS, 1294);
+
+        testGsonsonScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        MG_TEST_FALG=0;
+        
+        Gsenson_TEST_timer = osTimerNew((osTimerFunc_t)mgdataTimerCallBack, osTimerPeriodic, NULL, NULL);
+            tick =1000;// osMs2Tick(1000);
+            retTimer = osTimerStart(Gsenson_TEST_timer, tick);
+            if (retTimer != osOK && Gsenson_TEST_timer != NULL) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+                osTimerDelete(Gsenson_TEST_timer);
+                Gsenson_TEST_timer = NULL;
+                return false;
+            }
+
+        testGsonsonScrollView->SetScrollBlankSize(0);
+        testGsonsonScrollView->SetReboundSize(0);
+        testGsonsonScrollView->SetDirection(1);
+        //UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(SystemPresenter::GetInstance());
+        // if (draglistener == nullptr)
+        // {
+        //     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::draglistener can not be nullptr!");
+        //     return false;
+        // }
+       // testGsonsonScrollView->SetOnDragListener(draglistener);
+
+        LabelConfig Config = {
+            .left = 203,
+            .top = 52,
+            .width = 60,
+            .height = 35,
+            .fontSize = 30,
+            .lineHeigh = 35,
+            .text = "GSENSON",
+            .lineBreakMode = UILabel::LINE_BREAK_ADAPT,
+        };
+        title = InitLabel(Config);
+        if (title == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!");
+            return false;
+        }
+        testGsonsonScrollView->Add(title);
+        /* -------------------------------------------------------------------------- */
+        uint16_t angle_value= (int16_t)mag_service_get_fAzimuth();
+        gsenson_t t;
+        //get_gsonsen_xyz(&t);
+        char buf[124]={0};
+        sprintf(buf,"X:%f\nY:%f\nZ:%f",t.x,t.y,t.z);
+        Config = {
+            .left = 173,
+            .top = 160,
+            .width = 120,
+            .height = 35,
+            .fontSize = 40,
+            .lineHeigh = 35,
+            .text = buf,
+            .lineBreakMode = UILabel::LINE_BREAK_ADAPT,
+        };
+        
+        x = InitLabel(Config);
+        if (x == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::WatchNameTitle new fail!");
+            return false;
+        }
+        testGsonsonScrollView->Add(x);
+        /* -------------------------------------------------------------------------- */
+       
+        labelButton_next= testAboutView::GetInstance()->init_button_next(167,378,"luminanceButton_next");
+        testGsonsonScrollView->Add(labelButton_next);
+
+
+        testGsonsonScrollView->SetTouchable(true);
+        testGsonsonScrollView->SetDraggable(false);
+
+
+
+
+        return true;
+    }
+
+    UIScrollView *testgsensonView::testGSENSONInitIView()
+    {
+        if (!testGsonsonScrollViewcrollViewinit())
+        {
+            return nullptr;
+        }
+        return testGsonsonScrollView;
+    }
+}
\ No newline at end of file
index 9793468..c62c3cd 100644 (file)
@@ -32,6 +32,7 @@ extern void* CWM_OS_malloc(int size);
 extern void CWM_OS_free(void *ptr);
 extern void CWM_OS_saveData(uint8_t* data, uint32_t len);
 extern void CWM_OS_restoreData(uint8_t* data, uint32_t len);
+
 /********************CYWEE LIB*************************/
 
 #define   SPORT_ACTIVE_MODE_NORMAL             1001               // 一般模式(生活模式)        normal(base)    1001
@@ -112,6 +113,15 @@ typedef struct
     int sub_mode_number;// int[2] = sub_mode_number (預設: 0) 
 }set_activity_mode_t;
 
+typedef struct {
+    uint16_t x;
+    uint16_t y;
+    uint16_t z;
+    // uint16_t x_1;
+    // uint16_t y_1;
+    // uint16_t z_1;
+} gsenson_t;
+
 #if  1
 
 /**
@@ -417,6 +427,9 @@ typedef struct
     int mag_axis_setting;// int[2] = mag_axis setting    (0: default, 1-24: axis_mode)
 }input_sensor_config_t;
 
+
+extern void get_gsonsen_xyz(gsenson_t *t);
+
 #pragma pack()
 
 
index 3804615..017442c 100644 (file)
 #include "power_display_service.h"
 #include "ppg_service.h"
 #include "broadcast_feature.h"
+#include "cmsis_os2.h"
+#include "osal_msgqueue.h"
+#include "osal_mutex.h" 
 #define AP_ENABLE_DML_SDO_LISTEN
 
+int16_t gsensor_x[24] = {0};
+int16_t gsensor_y[24] = {0};
+int16_t gsensor_z[24] = {0};
+#define GSENSON_MSG_COUNT   16
 
+osal_mutex mutex_gsenson_queue;
+static unsigned long gsenson_queue;
+
+void uapi_GSENSON_create_queue(void)
+{
+    if (osal_msg_queue_create("battery_queue", GSENSON_MSG_COUNT, &gsenson_queue,
+                              0, sizeof(gsenson_t)) != ERRCODE_SUCC) {
+        //PRINT("[battery][service] app create mail fail\n");   
+    }
+
+    osal_mutex_init(&mutex_gsenson_queue);
+}
+
+static gsenson_t gxyz_t;
+static uint8_t gsenson_falg=0;
+void get_gsonsen_xyz(gsenson_t *t)
+{
+    if(osal_mutex_trylock(&mutex_gsenson_queue)==0)
+    {
+        CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n");
+        return;
+    }
+    t->x=gxyz_t.x;
+    t->y=gxyz_t.y;
+    t->z=gxyz_t.z;
+    CWM_OS_dbgPrintf("get_gsonsen_%d,%d,%d\n",t->x, t->y,t->z);
+    osal_mutex_unlock(&mutex_gsenson_queue);
+}
 
 void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
     switch (sensorEVT->sensorType) {
         case IDX_ACCEL:
-        #if 0
-            CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",
-                                                       sensorEVT->fData[0],
-                                                       sensorEVT->fData[1],
-                                                       sensorEVT->fData[2]
-                                                        );
+        #if 1  
+            // CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",
+            //                                            sensorEVT->fData[0],
+            //                                            sensorEVT->fData[1],
+            //                                            sensorEVT->fData[2]
+            //                                             );
+            if(osal_msg_queue_is_full(gsenson_queue))
+            {
+              
+                gsenson_t t;
+                int ret=osal_msg_queue_read_copy(gsenson_queue, &t, sizeof(gsenson_t),OSAL_MSGQ_NO_WAIT);
+                if(osal_mutex_trylock(&mutex_gsenson_queue)==0)
+                {
+                    CWM_OS_dbgPrintf("get_gsonsen_xxxxxxxx_fail\n");
+                    break;
+                }
+                gxyz_t.x=t.x;
+                gxyz_t.y=t.y;
+                gxyz_t.z=t.z;
+                osal_mutex_unlock(&mutex_gsenson_queue);
+
+                if(ret!=0)
+                {
+                    CWM_OS_dbgPrintf("osal_msg_queue_read_copyz_fail\n");
+                }
+                t.x=sensorEVT->fData[0]*1024;
+                t.y=sensorEVT->fData[1]*1024;
+                t.z=sensorEVT->fData[2]*1024;
+                ret=osal_msg_queue_write_copy(gsenson_queue, &t, sizeof(gsenson_t),OSAL_MSGQ_NO_WAIT);
+                if(ret!=0)
+                {
+                    CWM_OS_dbgPrintf("osal_msg_queue_write_copy_fail\n");
+                }
+
+
+            }    
+            else 
+            {
+                gsenson_t t;
+                t.x=sensorEVT->fData[0];
+                t.y=sensorEVT->fData[1];
+                t.z=sensorEVT->fData[2];
+                int ret= osal_msg_queue_write_copy(gsenson_queue, &t, sizeof(gsenson_t),OSAL_MSGQ_NO_WAIT);
+                if(ret!=0)
+                {
+                    CWM_OS_dbgPrintf("osal_msg_queue_write_copy_fail\n");
+                }
+
+           
+            }
+           
+
         #endif
             break;