MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / toneAlarm_set_buzzer_tone

Method toneAlarm_set_buzzer_tone

libraries/AP_HAL_ChibiOS/Util.cpp:177–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175#endif
176
177void Util::toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms)
178{
179#if HAL_USE_PWM == TRUE
180 if (_toneAlarm_pwm_group.pwm_drv != nullptr) {
181 if (is_zero(frequency) || is_zero(volume)) {
182 pwmDisableChannel(_toneAlarm_pwm_group.pwm_drv, _toneAlarm_pwm_group.chan);
183 } else {
184 pwmChangePeriod(_toneAlarm_pwm_group.pwm_drv,
185 roundf(_toneAlarm_pwm_group.pwm_cfg.frequency/frequency));
186
187 pwmEnableChannel(_toneAlarm_pwm_group.pwm_drv, _toneAlarm_pwm_group.chan, roundf(volume*_toneAlarm_pwm_group.pwm_cfg.frequency/frequency)/2);
188 }
189 }
190#endif // HAL_USE_PWM
191#if HAL_DSHOT_ALARM_ENABLED
192 // don't play the motors while flying
193 if (!(_toneAlarm_types & uint8_t(AP_Notify::BuzzerType::DSHOT)) || get_soft_armed() || hal.rcout->get_dshot_esc_type() == RCOutput::DSHOT_ESC_NONE) {
194 return;
195 }
196
197 if (is_zero(frequency)) { // silence
198 hal.rcout->send_dshot_command(RCOutput::DSHOT_RESET, RCOutput::ALL_CHANNELS, duration_ms);
199 } else if (frequency < 1047) { // C
200 hal.rcout->send_dshot_command(RCOutput::DSHOT_BEEP1, RCOutput::ALL_CHANNELS, duration_ms);
201 } else if (frequency < 1175) { // D
202 hal.rcout->send_dshot_command(RCOutput::DSHOT_BEEP2, RCOutput::ALL_CHANNELS, duration_ms);
203 } else if (frequency < 1319) { // E
204 hal.rcout->send_dshot_command(RCOutput::DSHOT_BEEP3, RCOutput::ALL_CHANNELS, duration_ms);
205 } else if (frequency < 1397) { // F
206 hal.rcout->send_dshot_command(RCOutput::DSHOT_BEEP4, RCOutput::ALL_CHANNELS, duration_ms);
207 } else { // G+
208 hal.rcout->send_dshot_command(RCOutput::DSHOT_BEEP5, RCOutput::ALL_CHANNELS, duration_ms);
209 }
210#endif // HAL_DSHOT_ALARM_ENABLED
211}
212
213/*
214 set HW RTC in UTC microseconds

Callers

nothing calls this directly

Calls 3

is_zeroFunction · 0.50
get_dshot_esc_typeMethod · 0.45
send_dshot_commandMethod · 0.45

Tested by

no test coverage detected