feat: 增加蜂鸣器和灯条接口
This commit is contained in:
47
by_cmd.c
47
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;
|
||||
}
|
||||
@@ -435,3 +437,46 @@ int by_cmd_recv_ranging_data(float *distance)
|
||||
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);
|
||||
}
|
||||
3
by_cmd.h
3
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
|
||||
|
||||
32
test.c
32
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user