feat: 增加蜂鸣器和灯条接口

This commit is contained in:
bmy
2024-06-02 18:24:01 +08:00
parent 07a32a247e
commit 5f6c342b86
3 changed files with 71 additions and 11 deletions

View File

@@ -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);
}