Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/buzzer.cpp
Views: 1798
#include "AP_Periph.h"12#if defined(HAL_PERIPH_ENABLE_NOTIFY) || defined(HAL_PERIPH_ENABLE_BUZZER_WITHOUT_NOTIFY)34/*5buzzer support6*/78#include <dronecan_msgs.h>910extern const AP_HAL::HAL &hal;1112static uint32_t buzzer_start_ms;13static uint32_t buzzer_len_ms;1415/*16handle BeepCommand17*/18void AP_Periph_FW::handle_beep_command(CanardInstance* canard_instance, CanardRxTransfer* transfer)19{20uavcan_equipment_indication_BeepCommand req;21if (uavcan_equipment_indication_BeepCommand_decode(transfer, &req)) {22return;23}24static bool initialised;25if (!initialised) {26initialised = true;27hal.rcout->init();28// just one buzzer type supported:29hal.util->toneAlarm_init(uint8_t(AP_Notify::BuzzerType::BUILTIN));30}31buzzer_start_ms = AP_HAL::millis();32buzzer_len_ms = req.duration*1000;33#ifdef HAL_PERIPH_ENABLE_BUZZER_WITHOUT_NOTIFY34float volume = constrain_float(periph.g.buzz_volume*0.01f, 0, 1);35#elif defined(HAL_PERIPH_ENABLE_NOTIFY)36float volume = constrain_float(periph.notify.get_buzz_volume()*0.01f, 0, 1);37#endif38hal.util->toneAlarm_set_buzzer_tone(req.frequency, volume, uint32_t(req.duration*1000));39}4041/*42update buzzer43*/44void AP_Periph_FW::can_buzzer_update(void)45{46if (buzzer_start_ms != 0) {47uint32_t now = AP_HAL::millis();48if (now - buzzer_start_ms > buzzer_len_ms) {49hal.util->toneAlarm_set_buzzer_tone(0, 0, 0);50buzzer_start_ms = 0;51}52}53}5455#endif // (HAL_PERIPH_ENABLE_BUZZER_WITHOUT_NOTIFY) || (HAL_PERIPH_ENABLE_NOTIFY)565758