From: zwj <645281962@qq.com> Date: Wed, 5 Jul 2023 06:42:38 +0000 (+0800) Subject: 添加buzzer tof als测试程序 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=8dfb3d6036df90f6e9d06df89e27f99aa1897959;p=yn%2Falarmmonitor.git 添加buzzer tof als测试程序 --- diff --git a/als/CMakeLists.txt b/als/CMakeLists.txt index 15e9acc..01f0040 100644 --- a/als/CMakeLists.txt +++ b/als/CMakeLists.txt @@ -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 index 0000000..1bcc933 --- /dev/null +++ b/als/test/als_test.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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; +} + diff --git a/als/test/als_test.txt b/als/test/als_test.txt old mode 100755 new mode 100644 index 18cc6b8..ae736f5 --- a/als/test/als_test.txt +++ b/als/test/als_test.txt @@ -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 diff --git a/buzzer/CMakeLists.txt b/buzzer/CMakeLists.txt index 8ea122d..ec1499a 100644 --- a/buzzer/CMakeLists.txt +++ b/buzzer/CMakeLists.txt @@ -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 index 0000000..4f84d6d --- /dev/null +++ b/buzzer/test/buzzer_test.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 diff --git a/buzzer/test/buzzer_test.txt b/buzzer/test/buzzer_test.txt old mode 100755 new mode 100644 index c8f8c05..becc173 --- a/buzzer/test/buzzer_test.txt +++ b/buzzer/test/buzzer_test.txt @@ -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 diff --git a/tof/CMakeLists.txt b/tof/CMakeLists.txt index a77ce71..72263d3 100644 --- a/tof/CMakeLists.txt +++ b/tof/CMakeLists.txt @@ -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 index 0000000..b886da1 --- /dev/null +++ b/tof/test/tof_test.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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; +} diff --git a/tof/test/tof_test.txt b/tof/test/tof_test.txt old mode 100755 new mode 100644 index 37f4f5d..e3367b1 --- a/tof/test/tof_test.txt +++ b/tof/test/tof_test.txt @@ -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