From 5f6c342b86c3ad2a45cc75697f6763756e70d47b Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Sun, 2 Jun 2024 18:24:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=9C=82=E9=B8=A3?= =?UTF-8?q?=E5=99=A8=E5=92=8C=E7=81=AF=E6=9D=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- by_cmd.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- by_cmd.h | 3 +++ test.c | 32 ++++++++++++++++++++++---------- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/by_cmd.c b/by_cmd.c index 62790cd..18c0c18 100644 --- a/by_cmd.c +++ b/by_cmd.c @@ -21,6 +21,7 @@ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; int by_cmd_init(void) { + log_set_level(LOG_INFO); log_debug("by_cmd init"); return (by_frame_init()); } @@ -61,6 +62,7 @@ int by_cmd_reg_listerning(uint8_t cmd, int timeout) // log_debug("received done! using %fSEC", (float)timeout_cnt * 0.00005); listerning_cmd = 0; received_flag = 0; + log_info("get callback done"); return 0; } usleep(10); @@ -69,7 +71,7 @@ int by_cmd_reg_listerning(uint8_t cmd, int timeout) listerning_cmd = 0; received_flag = 0; - log_warn("get cmd time out"); + log_warn("get callback time out"); return -1; } @@ -434,4 +436,47 @@ int by_cmd_recv_ranging_data(float *distance) } else { return -1; } +} + +/** + * @brief 发送灯指令 + * + * @param status 0-关闭 其他 - 开启 + * @return int + */ +int by_cmd_send_light(uint8_t status) +{ + LOCKAPI(); + log_info("set light %s", (status ? "on" : "off")); + int ret = 0; + uint8_t buff[4] = {0}; + + buff[0] = status; + + by_frame_send(0x61, buff, 4); + ret = by_cmd_reg_listerning(0x61, 1000); + UNLOCKAPI(); + return (ret); +} + +/** + * @brief 发送蜂鸣器指令 + * + * @param status 0-关闭 其他 - 开启 + * @return int + */ +int by_cmd_send_beep(uint8_t status) +{ + LOCKAPI(); + log_info("set beep %s", (status ? "on" : "off")); + + int ret = 0; + uint8_t buff[4] = {0}; + + buff[0] = status; + + by_frame_send(0x62, buff, 4); + ret = by_cmd_reg_listerning(0x62, 1000); + UNLOCKAPI(); + return (ret); } \ No newline at end of file diff --git a/by_cmd.h b/by_cmd.h index 2284e98..d865996 100644 --- a/by_cmd.h +++ b/by_cmd.h @@ -33,4 +33,7 @@ int by_cmd_send_angle_storage(float angle); int by_cmd_send_ranging_start(void); int by_cmd_recv_ranging_data(float *distance); +int by_cmd_send_light(uint8_t status); +int by_cmd_send_beep(uint8_t status); + #endif diff --git a/test.c b/test.c index b5d1ea0..cf1cd8e 100644 --- a/test.c +++ b/test.c @@ -22,17 +22,29 @@ int main(int argc, char **argv) return -1; } - by_cmd_send_distance_x(12, 100); - by_cmd_send_angle_camera(20.0); - by_cmd_send_position_axis_z(0x11, 100); - by_cmd_send_distance_axis_z(10, 20); - by_cmd_send_distance_axis_x(4, 100); - by_cmd_send_position_axis_x(4, 0); - by_cmd_send_angle_claw_arm(34); - by_cmd_send_angle_claw_arm(220); - by_cmd_send_angle_claw(27); + // by_cmd_send_distance_x(12, 100); + // by_cmd_send_angle_camera(20.0); + // by_cmd_send_position_axis_z(0x11, 100); + // by_cmd_send_distance_axis_z(15, 20); + // by_cmd_send_distance_axis_x(4, 100); + // by_cmd_send_position_axis_x(4, 0); + // by_cmd_send_angle_claw_arm(34); + // by_cmd_send_angle_claw_arm(220); + // by_cmd_send_angle_claw(27); + // sleep(1); + // by_cmd_send_distance_axis_x(4, -60); + by_cmd_send_light(1); + by_cmd_send_beep(1); + sleep(0.5); + by_cmd_send_light(0); + by_cmd_send_beep(0); + sleep(1); + by_cmd_send_light(1); + by_cmd_send_beep(1); + sleep(0.5); + by_cmd_send_light(0); + by_cmd_send_beep(0); sleep(1); - by_cmd_send_distance_axis_x(4, -60); return 0; }