更新cywee算法,修改gsensor为中断模式,优化久坐提醒,优化next day触发机制。 199/1 199/head 202/target/1
authorpenglei <1624952103@qq.com>
Thu, 30 May 2024 07:34:14 +0000 (15:34 +0800)
committerpenglei <1624952103@qq.com>
Thu, 30 May 2024 07:34:14 +0000 (15:34 +0800)
16 files changed:
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/include/AlarmClockTimerConfig.h
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h
code/sdk/drivers/peripheral/cywee/CMakeLists.txt
code/sdk/drivers/peripheral/cywee/Inc/CWM_EventStructure.h
code/sdk/drivers/peripheral/cywee/Inc/OsApi.h
code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h
code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a [deleted file]
code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a [deleted file]
code/sdk/drivers/peripheral/cywee/service/cywee_service.c
code/sdk/drivers/peripheral/cywee/src/config.h [new file with mode: 0644]
code/sdk/drivers/peripheral/cywee/src/main.c
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/cywee/src/test_api.c

index 28adda2..c799928 100644 (file)
@@ -116,9 +116,10 @@ void AlarmScan(void *arg)
 \r
     if (g_alarmCtrB.state == ALARM_STATUS_RUNNING) {\r
         if ((g_alarmCtrB.callback != NULL) &&\r
-            (g_alarmCtrB.info.week == curTime.tm_wday) &&\r
+            //(g_alarmCtrB.info.week == curTime.tm_wday) &&\r
             (g_alarmCtrB.info.hour == curTime.tm_hour) &&\r
-            (g_alarmCtrB.info.minute == curTime.tm_min)) {\r
+            (g_alarmCtrB.info.minute == curTime.tm_min) &&\r
+            (g_alarmCtrB.info.second == curTime.tm_sec)) {\r
             g_alarmCtrB.callback();\r
             g_alarmCtrB.state = ALARM_STATUS_CREATED;\r
         }\r
@@ -180,6 +181,7 @@ int32_t SetAlarm(AlarmType type, uint8_t week, uint8_t hour, uint8_t minute)
         g_alarmCtrB.info.week = week;\r
         g_alarmCtrB.info.hour = hour;\r
         g_alarmCtrB.info.minute = minute;\r
+        g_alarmCtrB.info.second = 1;\r
     } else {\r
         return ERRCODE_FAIL;\r
     }\r
index 8bd10ae..640f12d 100644 (file)
@@ -881,7 +881,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
     switch (cywee_Inactivity_Info->output_number)
     {
         case INACTIVITY_MODE_SEDENTARY_OUTPUT:
-            if(cywee_Inactivity_Info->sedentary_status == 3)
+            if(cywee_Inactivity_Info->sedentary_status == 1)
             {
                 NotificationManager::GetInstance()->ShowNotify(showSedentaryReminderNotify, (uint16_t)topic, true);
                 // if(SedentaryReminderViewEventListener::GetInstance().IsReminderTime() == true)
index 121d8d1..3ed74a4 100755 (executable)
@@ -161,7 +161,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = {
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },    // S_AGPIO_L9 dsp uart   TP35
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },    // S_AGPIO_L10 dsp uart   TP36
 #endif
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },    // S_AGPIO_L11 G_INT1
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },    // S_AGPIO_L11 G_INT1
 
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },    // S_AGPIO_L12 i2c data HX3507_SDIO
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L13 i2c CLK HX3507_SCLK
@@ -291,7 +291,7 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = {
 
 #ifdef ENABLE_CYWEE
     /**G sensor G_INT1 S_AGPIO_L11 G_INT2 S_AGPIO_L19   采用timer 时这些中断要屏蔽*/
-    //{   S_AGPIO_L11, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, cywee_int_callback },
+    {   S_AGPIO_L11, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, cywee_int_callback },
     //{   S_AGPIO_L19, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE, cywee_int_callback },
 #endif   
     /**S_AGPIO_R1 GPO alipay默认resetpin*/
index 8501dbf..05b6d83 100644 (file)
@@ -49,7 +49,7 @@ set(MAIN_COMPONENT
 
 if("SUPPORT_AT_CYWEE" IN_LIST DEFINES)
     find_library(LIB_PATH_CWM_LIB_DML Lib/CWM_LIB_DML_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR})
-    find_library(LIB_PATH_CWM_LIB Lib/CWM_LIB_clang_riscv.p3.a ${CMAKE_CURRENT_SOURCE_DIR})
+    find_library(LIB_PATH_CWM_LIB Lib/CWM_LIB_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR})
     target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_CWM_LIB_DML} ${LIB_PATH_CWM_LIB} PRIVATE -Wl,--whole-archive)
 endif()
 
index 611cbb1..f875e94 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __CWM_EVENT_STRUCTURE_H__
 #define __CWM_EVENT_STRUCTURE_H__
 #include <stdint.h>
+#include <stdlib.h>
 /**
   * @brief  CyweeMotion task handle event structure. 
   */
index 4ae3003..49b35b1 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __OS_API_H__
 #define __OS_API_H__
-#include <stdint.h>
+
 /**
   * @brief  System/OS/Peripheral API structure.
   */
@@ -25,19 +25,7 @@ typedef struct{
     int (*spiRead)(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
     int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
 } OsAPI, *pOsAPI;
-#if USE_P813
-typedef struct{
-    int (*dbgOutput)(const char*);
-    uint64_t (*GetTimeNs)(void);
-    void (*uSleep)(uint32_t);
-    int (*i2cRead)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
-    int (*i2cWrite)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
-    void *(*malloc)(int size);
-    void (*free)(void* ptr);
-    int (*spiRead)(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
-    int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
-} os_api;
-#else
+
 typedef OsAPI os_api;
-#endif
+
 #endif /* __OS_API_H__ */
index bf3cc31..50c3087 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef __CWM_LIB_H__
 #define __CWM_LIB_H__
-#include <stdint.h>
-#include "OsApi.h"
+
 #include "CWM_EventStructure.h"
+#include "OsApi.h"
 #include "CWM_CustomDataStruct.h"
 
 /**
 #define SCL_SWIM_CONFIG         13
 #define SCL_BIKING_CONFIG       14
 #define SCL_ACTIVITY_PAUSE      15
-/**
- * int[0] = 1
-int[1] = up_range (抬手反應範圍)(default: 5)
-(0: default, 3: 範圍大, 4, 5, 6: 範圍小)
-int[2] = down_range (放手反應範圍)(default: 5)
-(0: default, 3: 範圍大, 4, 5, 6: 範圍小)
-int[3] = sensitivity (反應速度)(default: 5)
-(0: default, 3: 反應速度快, 4, 5, 6: 反應速度慢)
-int[4] = horizontal_range (亮屏手肘傾斜範圍)(default: 5)
-(0: default, 1: 範圍大, 2, 3, 4, 5, 6, 7, 8, 9: 範圍小)
-*/
 #define SCL_HAND_UPDOWN_CONFIG  16
 #define SCL_CHIP_VENDOR_CONFIG  17
 #define SCL_SLEEP_CONFIG        18
@@ -54,11 +43,14 @@ int[4] = horizontal_range (亮屏手肘傾斜範圍)(default: 5)
 #define SCL_ACT_INFO_CONFIG     30
 #define SCL_REQ_ACTIVITY_EXIT   31
 #define SCL_ACT_PAI_INFO        33
+#define SCL_HAND_WRIST_CONFIG   34
 #define SCL_ACT_INTSY_INFO      35
 #define SCL_DUMP_WI_INFO        36
 #define SCL_ACT_ZONE_TIME       37
 #define SCL_ACT_TRAINING_INFO   38
+#define SCL_HAND_SHAKE_CONFIG   39
 #define SCL_WATCH_INTF_RESET    40
+#define SCL_HAND_RUB_CONFIG     41
 #define SCL_PEDO_CONFIG2        42
 #define SCL_HG_INTF_CONFIG      43
 #define SCL_ACT_AUTO_PAUSE_CFG  44
diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a
new file mode 100644 (file)
index 0000000..a74ed86
Binary files /dev/null and b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a differ
diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a
deleted file mode 100644 (file)
index c42a47d..0000000
Binary files a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a and /dev/null differ
diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a
deleted file mode 100644 (file)
index afbcedc..0000000
Binary files a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a and /dev/null differ
index e007f1a..4059dab 100644 (file)
@@ -273,9 +273,9 @@ static void cywee_service_check_task(void const *arg)
             break;
 
             case CYWEE_SERVICE_CMD_START_CHECK:
-                cywee_service_running_stat = true;
+                //cywee_service_running_stat = true;
                 cywee_main_dml();
-                cywee_service_timer_start_check(CYWEE_CHECK_MS);
+                //cywee_service_timer_start_check(CYWEE_CHECK_MS);
             break;
 
             case CYWEE_SERVICE_CMD_STOP_CHECK:
diff --git a/code/sdk/drivers/peripheral/cywee/src/config.h b/code/sdk/drivers/peripheral/cywee/src/config.h
new file mode 100644 (file)
index 0000000..fd0a010
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __CWM_SAMPLE_PROJ_CONFIG_H__
+#define __CWM_SAMPLE_PROJ_CONFIG_H__
+
+//#define RUN_TEST_API_PROCESS
+
+//#define PRINTF_FROM_UART
+
+//#define CHECK_LOG_TOOL
+
+//#define SIGNAL_SIMULATE_PROCESS
+//#define INPUT_DATA_WITH_FIFO_MODE
+
+#endif //__CWM_SAMPLE_PROJ_CONFIG_H__
index d2528c4..77f99ae 100644 (file)
-#include <stdio.h>
+/*********************/
+/*** Include Files ***/
+/*********************/
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
-#include <stdarg.h>
 #include "cwm_lib.h"
+#include "config.h"
+#include "simulate_signal.h"
 
-int CWM_OS_dbgOutput(const char * format) {
-    printf("%s", format);
-    return 0;
-}
+/*********************/
+/*** Macro Defines ***/
+/*********************/
 
-int CWM_OS_dbgPrintf(const char * format,...) {
-    va_list argList;
-    int size = 0;
-    static char tBuffer[256];
 
-    va_start(argList, format);
-    size = vsnprintf(tBuffer, sizeof(tBuffer), format, argList);
-    va_end(argList);
-
-    //strcat(tBuffer, "\n");
-    CWM_OS_dbgOutput(tBuffer);
-    return size;
-}
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+static const char* REQ_SENS_NAME[] = {"acc", "gyro", "mag", "baro", "temp", "hr", "gnss", "ob", "oc", "accany"};
+static int m_req_sensor_state = 0;
 
-uint64_t CWM_OS_GetTimeNs(void) {
-    uint64_t timeNow_us;
+/************************/
+/*** Function Defines ***/
+/************************/
 
-    timeNow_us = 0;
+extern void board_init(void);
+extern void CWM_OS_uSleep(uint32_t time);
+extern uint64_t CWM_OS_GetTimeNs(void);
+extern void* CWM_OS_malloc(int size);
+extern void CWM_OS_free(void *ptr);
+extern int CWM_OS_dbgOutput(const char * format);
+extern int CWM_OS_dbgOutput_checkLog(const char * format);
+extern int CWM_OS_dbgPrintf(const char * format,...);
+extern void test_api(void);
 
-    return timeNow_us * 1000;
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+int getReqSensor(int index) {
+    if (m_req_sensor_state & (1<<index))
+        return 1;
+    return 0;
 }
-
+/**
+  * @brief  Sensor listen callback, when you register sensor listen,
+  *            when sensor data is ready, sensor manager will call this function to send pSensorEVT_t.
+  * @param  handle  sensor register handle, if not setup this handle don't care.
+  * @sensorEVT  Sensor data event.
+  * @retval None
+  */
 void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
     switch (sensorEVT->sensorType) {
-        case 0:
-            CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",
+        case IDX_REQUEST_SENSOR:
+            if (sensorEVT->fData[2] != 0)
+                m_req_sensor_state |= (1<<(int)sensorEVT->fData[1]);
+            else
+                m_req_sensor_state &= ~(1<<(int)sensorEVT->fData[1]);
+
+            CWM_OS_dbgPrintf("req_sensor input_sensor: %s(%.1f), switch: %.1f\n",\
+                REQ_SENS_NAME[(int)sensorEVT->fData[1]], sensorEVT->fData[1], sensorEVT->fData[2]);
+            CWM_OS_dbgPrintf("input_sensor now: acc=%d gyro=%d mag=%d baro=%d temp=%d hr=%d gnss=%d ob=%d oc=%d accany=%d\n",\
+                getReqSensor(0), getReqSensor(1), getReqSensor(2), getReqSensor(3), getReqSensor(4),\
+                getReqSensor(5), getReqSensor(6), getReqSensor(7), getReqSensor(8), getReqSensor(9));
+        break;
+
+        case IDX_ACCEL:
+            CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f\n", "accel",
                                                        sensorEVT->fData[0],
                                                        sensorEVT->fData[1],
-                                                       sensorEVT->fData[2]
-                                                        );
-            break;
+                                                       sensorEVT->fData[2]);
+        break;
 
-        case 1:
-            CWM_OS_dbgPrintf("gyro: x=%.3f, y=%.3f, z=%.3f\n",
+        case IDX_ALGO_ACTIVITY_OUTPUT:
+            CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f\n", "activity output",
                                                        sensorEVT->fData[0],
                                                        sensorEVT->fData[1],
-                                                       sensorEVT->fData[2]
-                                                        );
-            break;
+                                                       sensorEVT->fData[2],
+                                                       sensorEVT->fData[3],
+                                                       sensorEVT->fData[4],
+                                                       sensorEVT->fData[5],
+                                                       sensorEVT->fData[6],
+                                                       sensorEVT->fData[7],
+                                                       sensorEVT->fData[8],
+                                                       sensorEVT->fData[9],
+                                                       sensorEVT->fData[10],
+                                                       sensorEVT->fData[11],
+                                                       sensorEVT->fData[12],
+                                                       sensorEVT->fData[13],
+                                                       sensorEVT->fData[14],
+                                                       sensorEVT->fData[15]);
+        break;
 
         default:
-            CWM_OS_dbgPrintf("IDX[%d]: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", sensorEVT->sensorType,
+            CWM_OS_dbgPrintf("%d: %.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f, "\
+                                  "%.4f, %.4f, %.4f, %.4f", sensorEVT->sensorType,
                                                        sensorEVT->fData[0],
                                                        sensorEVT->fData[1],
                                                        sensorEVT->fData[2],
@@ -58,33 +105,140 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
                                                        sensorEVT->fData[4],
                                                        sensorEVT->fData[5],
                                                        sensorEVT->fData[6],
-                                                       sensorEVT->fData[7]
-                                                        );
+                                                       sensorEVT->fData[7],
+                                                       sensorEVT->fData[8],
+                                                       sensorEVT->fData[9],
+                                                       sensorEVT->fData[10],
+                                                       sensorEVT->fData[11],
+                                                       sensorEVT->fData[12],
+                                                       sensorEVT->fData[13],
+                                                       sensorEVT->fData[14],
+                                                       sensorEVT->fData[15]);
+        break;
+    }
+}
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+#define SIGNAL_SIMULATE_FIFO_COUNT 10
+
+static void sample_fifo_input_data(time_axis_data *taxis) {
+    int i;
+    float acc[3];
+    CWM_CustomSensorInput_Fifo_Start(CUSTOM_ACC,
+                                     simulate_fake_get_time_ns(),
+                                     20 * 1000000);
+
+    for (i=0; i<SIGNAL_SIMULATE_FIFO_COUNT; i++) {
+        if (simulate_time_axis(taxis, acc) != 0) {
+            CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+            return;
+        }
+        CustomSensorData data;
+        memset(&data, 0, sizeof(data));
+        data.sensorType = CUSTOM_ACC;
+        memcpy(data.fData, acc, sizeof(float) *3);
+        CWM_CustomSensorInput(&data);
+    }
+    CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+}
+
+static void sample_polling_input_data(time_axis_data *taxis) {
+    float acc[3];
+    if (simulate_time_axis(taxis, acc) != 0) {
+        return;
     }
+    CustomSensorData data;
+    memset(&data, 0, sizeof(data));
+    data.sensorType = CUSTOM_ACC;
+    memcpy(data.fData, acc, sizeof(float) *3);
+    CWM_CustomSensorInput(&data);
+}
+
+void sample_data_input() {
+    time_axis_data taxis;
+    memset(&taxis, 0, sizeof(time_axis_data));
+
+    simulate_action actions[] = {
+        { simulate_pedo_moving_step, 200, 66, 0, NULL },
+        { simulate_pedo_moving_step, 1000, 150, 0, NULL },
+        { simulate_pedo_moving_time, 300, 66, 0, NULL },
+        { simulate_no_move_time, 3600 * 2, 0, 0, NULL },
+        { simulate_pedo_moving_step, 100, 66, 0, NULL },
+        { NULL, 0, 0, 0, NULL },
+    };
+
+    taxis.actions = actions;
+
+
+#ifdef INPUT_DATA_WITH_FIFO_MODE
+    sample_fifo_input_data(&taxis);
+#else
+    sample_polling_input_data(&taxis);
+#endif
 }
+#endif
+
+int main(void)
+{
+    OsAPI device_func =
+    {
+        .malloc       = CWM_OS_malloc,
+        .free         = CWM_OS_free,
+        .GetTimeNs    = CWM_OS_GetTimeNs,
+        .dbgOutput    = CWM_OS_dbgOutput,
+    };
+
+#ifdef CHECK_LOG_TOOL
+    device_func.dbgOutput = CWM_OS_dbgOutput_checkLog;
+#endif
 
-int main(int argc, char* argv[]) {
-    int ret, loopIndex;
     SettingControl_t scl;
 
+    board_init();
+
+#ifdef BUILD_IAR
+    CWM_OS_dbgPrintf("Use IAR\n");
+#elif defined(BUILD_KEIL)
+    CWM_OS_dbgPrintf("Use KEIL\n");
+#endif
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+    device_func.GetTimeNs = simulate_fake_get_time_ns;
+#   ifdef INPUT_DATA_WITH_FIFO_MODE
+       CWM_CustomSensorInput_Fifo_Init(SIGNAL_SIMULATE_FIFO_COUNT);
+#   endif
+#endif
+
+#ifdef RUN_TEST_API_PROCESS
+    test_api();
+    return 0;
+#endif
+
     //get lib version information
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
     CWM_SettingControl(SCL_GET_LIB_INFO, &scl);
     CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]);
 
-    os_api api = {0};
-    api.dbgOutput    = CWM_OS_dbgOutput;
-    //api.GetTimeNs    = CWM_OS_GetTimeNs;
-
-    CWM_LibPreInit(&api);
+    CWM_LibPreInit(&device_func);
 
-    //set mcu_chip information, must call this before CWM_LibPostInit()
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
-    scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect
+    scl.iData[1] = 0;
+    scl.iData[2] = 0;
+    scl.iData[3] = 0;
     CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl);
 
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 0;
+    //CWM_SettingControl(SCL_LIB_DEBUG, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 25;
+    CWM_SettingControl(SCL_ALGO_PROC_CONFIG, &scl);
+
     CWM_LibPostInit(CWM_AP_SensorListen);
 
     //get chip information
@@ -103,48 +257,56 @@ int main(int argc, char* argv[]) {
     CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]);
     CWM_OS_dbgPrintf("secFileId = %08X\n", scl.iData[7]);
 
+#if 0
+    //turn on input log
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[3] = 1;
+    scl.iData[4] = 5;
+    CWM_SettingControl(SCL_LOG, &scl);
+#endif
+
+    //initial request_sensor to receive hardware_sensor on/off event
+    CWM_Sensor_Enable(IDX_REQUEST_SENSOR);
+
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
-    scl.iData[3] = 3;
-    scl.iData[4] = 15 + 64;
-    //scl.iData[6] = 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384;
-    //CWM_SettingControl(SCL_LOG, &scl);
-
-    CWM_Sensor_Enable(0); //IDX_ACCEL
-    CWM_Sensor_Enable(1); //IDX_GYRO
-
-/*
-    CWM_Sensor_Disable(0);
-    CWM_Sensor_Disable(1);
-*/
-
-    for (loopIndex = 0; loopIndex < 101; loopIndex ++) {
-        int dt_us;
-
-        dt_us = 20000;
-
-        CustomSensorData csd;
-
-        memset(&csd, 0, sizeof(CustomSensorData));
-        csd.sensorType = CUSTOM_ACC;
-        csd.fData[0] = 0;
-        csd.fData[1] = 0;
-        csd.fData[2] = 9.80665;
-        CWM_CustomSensorInput(&csd);
-
-        memset(&csd, 0, sizeof(CustomSensorData));
-        csd.sensorType = CUSTOM_GYRO;
-        csd.fData[0] = 0;
-        csd.fData[1] = 0;
-        csd.fData[2] = -3.1415926;
-        CWM_CustomSensorInput(&csd);
-
-        ret = CWM_process2(dt_us);
-        if (ret < 0) {
-            CWM_OS_dbgPrintf("FATAL ERROR! ret=%d\n", ret);
+    CWM_SettingControl(SCL_REQ_ACTIVITY_EXIT, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 1001;
+    CWM_SettingControl(SCL_SET_ACTIVITY_MODE, &scl);
+
+    memset(&scl, 0, sizeof(scl));
+    scl.iData[0] = 1;
+    scl.iData[1] = 2021;
+    scl.iData[2] = 10;
+    scl.iData[3] = 8;
+    scl.iData[4] = 12;
+    scl.iData[5] = 0;
+    CWM_SettingControl(SCL_DATE_TIME, &scl);
+
+
+    //CWM_Sensor_Enable(IDX_ACCEL);
+    CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT);
+
+    while (1)
+    {
+        int64_t next_duration = CWM_GetNextActionDuration_ns();
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+        sample_data_input();
+        next_duration = 0;
+#endif
+
+        if (next_duration > 0) {
+            /* Do Low power process here
+            */
+
+            CWM_OS_uSleep(next_duration / 1000);
         }
-    }
 
-    return 0;
+        CWM_process();
+    }
 }
-
index 337b9cd..ab21c9a 100644 (file)
@@ -41,11 +41,14 @@ static uint8_t hrs = 0;
 
 uint8_t hrs_mode_state = 0;
 
-int history_step = 0;
-int stepcount = 0;
+static int history_step = 0;
+static int stepcount = 0;
 
 int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据
 
+int cm__hs1__init(void);
+int cm__hs1__deinit(void);
+
 void cywee_save_data(void)
 {
     CWM_OS_saveData(&stepcount,sizeof(int));
@@ -745,7 +748,7 @@ int cywee_main_dml(void)
     //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__);
 
     //set mcu_chip information, must call this before CWM_LibPostInit()
-
+#if 0
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
     scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect
@@ -755,7 +758,7 @@ int cywee_main_dml(void)
     CWM_LibPostInit(CWM_AP_SensorListen);
     //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__);
 
-#if 0
+#else
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
     scl.iData[1] = 31010100;
@@ -818,7 +821,7 @@ int cywee_main_dml(void)
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
     scl.iData[7] = 5;  //轴向配置
-#if 1
+#if 0
     scl.iData[3] = 2;
     scl.iData[4] = 1; //1 anytime 2 fifo
     scl.iData[6] = 25; //先設定5
index bbaa85a..b4af5e4 100644 (file)
@@ -2,9 +2,6 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include "cmsis_os2.h"
-#include "errcode.h"
-#include "los_task_base.h"
 
 extern void CWM_OS_uSleep(uint32_t time);
 extern uint64_t CWM_OS_GetTimeNs(void);
@@ -45,8 +42,7 @@ __FAIL:
     return 0;
 }
 
-int test_free_1(void) 
-{
+int test_free_1(void) {
     char *pBuf1;
     char *pBuf2;
     int alloc_size;
@@ -79,8 +75,7 @@ __FAIL:
     return 0;
 }
 
-void test_GetTimeNs_0(void)
-{
+void test_GetTimeNs_0(void) {
     uint64_t timeNow;
 
     CWM_OS_dbgPrintf("[test_GetTimeNs_0] test up_time start\r\n");
@@ -94,8 +89,7 @@ void test_GetTimeNs_0(void)
     }
 }
 
-void test_GetTimeNs_1(void) 
-{
+void test_GetTimeNs_1(void) {
     uint64_t timeNow, timeLast, timeDiff;
 
     CWM_OS_dbgPrintf("[test_GetTimeNs_1] test 10 seconds start\r\n");
@@ -112,8 +106,7 @@ void test_GetTimeNs_1(void)
     }
 }
 
-void test_GetTimeNs_2(void) 
-{
+void test_GetTimeNs_2(void) {
     uint64_t timeNow, timeLast, timeDiff;
     uint64_t count;
 
@@ -137,8 +130,7 @@ void test_GetTimeNs_2(void)
     }
 }
 
-void test_GetTimeNs_3(void) 
-{
+void test_GetTimeNs_3(void) {
     uint64_t timeNow, timeLast, timeDiff;
 
     CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes start\r\n");
@@ -148,15 +140,14 @@ void test_GetTimeNs_3(void)
         timeNow = CWM_OS_GetTimeNs();
         timeDiff = timeNow - timeLast;
         //CWM_OS_dbgPrintf("timeNow=%lld\ttimeLast=%lld\ttimeDiff=%lld\n", timeNow, timeLast, timeDiff);
-        if (timeDiff >= (uint64_t)1 * 60 * 1000000000) {
+        if (timeDiff >= (uint64_t)20 * 60 * 1000000000) {
             CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes end\r\n");
             break;
         }
     }
 }
 
-void test_uSleep_1(void) 
-{
+void test_uSleep_1(void) {
 
     CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds start\r\n");
 
@@ -181,15 +172,12 @@ void test_uSleep_2(void) {
 
 void test_uSleep_3(void) {
     int i, j, k;
-    //CWM_OS_uSleep 只能到ms,所以实际上等于10000秒
+
     CWM_OS_dbgPrintf("[test_uSleep_3] test 10 seconds start\r\n");
 
     for (j = 0; j < 10; j ++) {
-        CWM_OS_dbgPrintf("j=%d\n",j);
         for (i = 0; i < 1000; i ++) {
-            if (i%10 == 0) CWM_OS_dbgPrintf("i=%d\n",i);
             for (k = 0; k < 1000; k ++) {
-                // if (k%100 == 0) CWM_OS_dbgPrintf("k=%d\n",k);
                 CWM_OS_uSleep(1);
             }
         }
@@ -199,7 +187,7 @@ void test_uSleep_3(void) {
 }
 
 #ifndef CHECK_STACK_TIME_MS
-#define CHECK_STACK_TIME_MS (uint64_t)(1 * 60 * 1000)
+#define CHECK_STACK_TIME_MS (uint64_t)(5 * 60 * 1000)
 #endif
 
 void test_stack(void) {
@@ -219,8 +207,8 @@ void test_stack(void) {
 
     while (1) {
         for (int i=0; i< sizeof(buff); i++) {
-            if ( (buff[i]&0xFF) != 0x96) {
-                CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!! buf[%d]=0x%X\r\n",i, buff[i]);
+            if (buff[i] != 0x96) {
+                CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!!\r\n");
                 CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
                 return;
             }
@@ -240,55 +228,17 @@ void test_stack(void) {
     CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
 }
 
-
-static errcode_t pcm_stream_task_body(void *data)
-{
-        
-   
-    test_malloc_1();
-    test_free_1();
+void test_api(void) {
 
     test_GetTimeNs_0(); // up_time, accumulate ts_ns from zero
     test_GetTimeNs_1(); // 10 seconds
     test_GetTimeNs_2(); // 10 seconds, accurate to 1ms
+    test_GetTimeNs_3(); // 20 minutes
+
+    test_malloc_1();
+    test_free_1();
 
     test_uSleep_1(); // 10 seconds
     test_uSleep_2(); // 10 seconds, accurate to 1ms
-
-    test_stack();
-    test_GetTimeNs_3(); // 20 minutes
     test_uSleep_3(); // 10 seconds, accurate to 1us
-
-    return ERRCODE_SUCC;
 }
-
-#define TASK_PRIORITY_PCM_STREAM    (osPriority_t)(osPriorityLow3)
-#define PCM_STREAM_MSG_STACK_SIZE   0x1C00
-static osThreadId_t g_test_thread = NULL;
-void test_api(void) {
-
-    if (g_test_thread == NULL)
-    {
-        osThreadAttr_t attr = {"cywee_test", 0, NULL, 0, NULL, PCM_STREAM_MSG_STACK_SIZE, TASK_PRIORITY_PCM_STREAM, 0, 0 };
-        g_test_thread = osThreadNew((osThreadFunc_t)pcm_stream_task_body, NULL, &attr);
-        if (g_test_thread == NULL) {
-            CWM_OS_dbgPrintf( "create cywee_test task fail!\r\n");
-        }else{
-
-        }
-    }else{
-
-
-        osThreadTerminate(g_test_thread);
-        g_test_thread = NULL;
-        CWM_OS_dbgPrintf( "create cywee_test task already running stop it !\r\n");
-
-    }
-
-    
-}
-
-
-
-
-   
\ No newline at end of file