添加buzzer tof als测试程序
authorzwj <645281962@qq.com>
Wed, 5 Jul 2023 06:42:38 +0000 (14:42 +0800)
committerzwj <645281962@qq.com>
Wed, 5 Jul 2023 06:42:38 +0000 (14:42 +0800)
als/CMakeLists.txt
als/test/als_test.c [new file with mode: 0644]
als/test/als_test.txt [changed mode: 0755->0644]
buzzer/CMakeLists.txt
buzzer/test/buzzer_test.c [new file with mode: 0755]
buzzer/test/buzzer_test.txt [changed mode: 0755->0644]
tof/CMakeLists.txt
tof/test/tof_test.c [new file with mode: 0644]
tof/test/tof_test.txt [changed mode: 0755->0644]

index 15e9accd84b886cdbf80cafdc5165508ce4c1dd6..01f0040c6b5b20fda47a1c7a9410fd33db8b26de 100644 (file)
@@ -22,5 +22,17 @@ add_library( ${PROJECT_NAME} STATIC  ${SRCS} )
 #install( TARGETS ${PROJECT_NAME} LIBRARY DESTINATION /app/lib )
 #install( TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION /app/lib )
 
-install(FILES ${PROJECT_SOURCE_DIR}/test/als_test DESTINATION /app/test/ )
+#install(FILES ${PROJECT_SOURCE_DIR}/test/als_test DESTINATION /app/test/ )
 install(FILES ${PROJECT_SOURCE_DIR}/test/als_test.txt  DESTINATION /app/test/ )
+
+add_executable( als_test  test/als_test.c )
+target_link_libraries(
+       als_test
+       PUBLIC
+       mg_als
+       mg_log
+       log4c
+       pthread
+)
+
+install( TARGETS als_test RUNTIME DESTINATION /app/test )
\ No newline at end of file
diff --git a/als/test/als_test.c b/als/test/als_test.c
new file mode 100644 (file)
index 0000000..1bcc933
--- /dev/null
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <zlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "als.h"
+
+//als测试程序
+static mg_als_t* als = NULL;
+
+int main(int argc , char* argv[])
+{
+    int i;
+    als_info_t* als_info;
+    als = mg_als_open();
+    if( als == NULL ){
+        printf( "open als failed \n");
+        return -1;
+    }
+    if(argc == 1){
+        mg_als_cfg(als,1000,400);
+    }
+    else if(argc == 3){
+        mg_als_cfg(als,atoi(argv[1]),atoi(argv[2]));
+    }
+
+    while(1){
+        als_info = mg_als_read(als);
+        if(als_info != NULL){
+            if(als_info->status == BRIGHT){
+                printf("1、亮 = %d  ad_value = %d\n",als_info->status,als_info->ad_value);
+            }
+            else if(als_info->status == DARK){
+                printf("2、灭 status = %d  ad_value = %d\n",als_info->status,als_info->ad_value);
+            }
+            printf("set als high  = %d\n",als_info->threshold_high);
+            printf("set als low = %d\n",als_info->threshold_low);
+            usleep(100*1000);
+        }
+    }
+    mg_als_close(als);
+    als_info = NULL;
+    return 0;
+}
+
old mode 100755 (executable)
new mode 100644 (file)
index 18cc6b8..ae736f5
@@ -8,4 +8,4 @@
        1-采用默认阈值
                ./als_test_app 
        2-重新设置阈值(上限阈值:500  下限阈值:200) 
-               ./als_test_app 500 200
+               ./als_test_app 500 200
\ No newline at end of file
index 8ea122dbf1918c68461243e3e3d0f0a13d01798f..ec1499a5db6a1055c56c80c61f42a1244ed1db97 100644 (file)
@@ -22,5 +22,18 @@ add_library( ${PROJECT_NAME} STATIC  ${SRCS} )
 #install( TARGETS ${PROJECT_NAME} LIBRARY DESTINATION /app/lib )
 #install( TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION /app/lib )
 
-install(FILES ${PROJECT_SOURCE_DIR}/test/buzzer_test DESTINATION /app/test/ )
+#install(FILES ${PROJECT_SOURCE_DIR}/test/buzzer_test DESTINATION /app/test/ )
 install(FILES ${PROJECT_SOURCE_DIR}/test/buzzer_test.txt  DESTINATION /app/test/ )
+
+add_executable( buzzer_test  test/buzzer_test.c )
+target_link_libraries(
+       buzzer_test
+       PUBLIC
+       mg_buzzer
+       mg_log
+       log4c
+       rt
+       pthread
+)
+
+install( TARGETS buzzer_test RUNTIME DESTINATION /app/test )
diff --git a/buzzer/test/buzzer_test.c b/buzzer/test/buzzer_test.c
new file mode 100755 (executable)
index 0000000..4f84d6d
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <zlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "buzzer.h"
+
+
+static mg_buzzer_t* buzzer = NULL;
+
+
+int main(int argc, char *argv[])
+{
+       int32_t duty_cycle,timer_ms;
+       float period, c;
+       int a ,b, e;
+       if(argc == 1)
+       {
+               period     = 200;
+               duty_cycle = 50;
+               timer_ms   = 1000;
+       }
+       else if(argc == 4)
+       {
+               period     = atof(argv[1]);
+               duty_cycle = atoi(argv[2]);
+               timer_ms   = atoi(argv[3]);
+       }
+
+       if(period > 10000)
+               period = 10000;
+        
+       buzzer = mg_buzzer_open();
+       if( buzzer == NULL ){
+               printf( "open buzzer failed \n");
+               return -1;
+       }
+        
+       mg_buzzer_start(buzzer, period ,duty_cycle , timer_ms);
+       mg_buzzer_get(buzzer,&c,&a,&b,&e);
+       printf( "1-------main get hz = %f du = %d time = %dms  enable = %d\r\n",c,a,b,e);
+       sleep(10);
+       mg_buzzer_close(buzzer);
+       return 0;
+}
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index c8f8c05..becc173
@@ -2,8 +2,14 @@
        adb push buzzer_test_app /app/
        chmod a+x buzzer_test_app
 
-#测试程序只会运行10s,10s之后就会退出
+#测试程序只会运行10s,10s之后就会退出;
+#频率范围:1-10000HZ   占空比范围:0-100
 
 #使用示例:
-       200:频率hz  50:占空比%   1000:播放时间ms
-       ./buzzer_test_app 200 50 1000
+       1-采用默认参数运行
+               (默认参数: 频率:200HZ 占空比:50% 播放时间:1000ms)
+               ./buzzer_test_app
+
+       2-重新传入参数    
+               100:频率HZ  40:占空比%   1000:播放时间ms
+               ./buzzer_test_app 100 40 1000
\ No newline at end of file
index a77ce7160574b75007a950af22bc9fb718e8ef24..72263d3b55b198f93f7dc1f9f1288ff0e461f319 100644 (file)
@@ -17,5 +17,15 @@ add_library( ${PROJECT_NAME} STATIC  ${SRCS} )
 #install( TARGETS ${PROJECT_NAME} LIBRARY DESTINATION /app/lib )
 #install( TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION /app/lib )
 
-install(FILES ${PROJECT_SOURCE_DIR}/test/tof_test DESTINATION /app/test/ )
+#install(FILES ${PROJECT_SOURCE_DIR}/test/tof_test DESTINATION /app/test/ )
 install(FILES ${PROJECT_SOURCE_DIR}/test/tof_test.txt  DESTINATION /app/test/ )
+
+add_executable( tof_test  test/tof_test.c )
+target_link_libraries(
+       tof_test
+       PUBLIC
+       mg_tof
+       pthread
+)
+
+install( TARGETS tof_test RUNTIME DESTINATION /app/test )
diff --git a/tof/test/tof_test.c b/tof/test/tof_test.c
new file mode 100644 (file)
index 0000000..b886da1
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <zlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "tof.h"
+
+mg_tof_t* main_ctl;
+
+void cb_test(tof_info_t* info)
+{
+       if(info->status == TOF_ANYBODY)
+               printf("== 在 %d mm处有人存在 ==\n",info->distance);
+       else if(info->status == TOF_NOBODY)
+               printf("== 在测量距离 %d mm内无人 ==\n",main_ctl->default_range);
+       else
+               printf("== 在 %d mm处存在障碍物 ==\n",info->distance);
+}
+
+int main()
+{
+       main_ctl = mg_tof_open(1000);
+       mg_tof_event_register(main_ctl,cb_test);
+
+       sleep(90);
+       printf("===== 测量距离已修改为 1500 mm =====\n");
+       Distance_parameter_correction(main_ctl,1500);
+       
+
+       while(1)
+       {
+               sleep(120);
+               break;
+       }
+       printf("===== TOF已关闭 =====\n");
+       mg_tof_close(main_ctl);
+       return 0;
+}
old mode 100755 (executable)
new mode 100644 (file)
index 37f4f5d..e3367b1
@@ -1,7 +1,4 @@
 #将tof中间件测试程序push进板子
-
-       adb push TOF_test /app
-        chmod 777 tof_test
        ./tof_test
 
-#运行后90s会将测量距离修改为1500mm,修改距离120s后会关闭整个测试程序。
+#运行后90s会将测量距离修改为1500mm,修改距离120s后会关闭整个测试程序。
\ No newline at end of file