mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-27 10:13:57 -04:00
AP_Notify: make the buzzer pin configurable on all boards
this allows any board to setup a buzzer pin on any available GPIO. Previously the pin if set in hwdef.dat was not configurable
This commit is contained in:
parent
c5ff9ac23f
commit
bee44b03b0
@ -123,6 +123,15 @@ AP_Notify *AP_Notify::_singleton;
|
|||||||
#define NOTIFY_LED_LEN_DEFAULT 1
|
#define NOTIFY_LED_LEN_DEFAULT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAL_BUZZER_PIN
|
||||||
|
#define HAL_BUZZER_PIN -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAL_BUZZER_ON
|
||||||
|
#define HAL_BUZZER_ON 1
|
||||||
|
#define HAL_BUZZER_OFF 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// table of user settable parameters
|
// table of user settable parameters
|
||||||
const AP_Param::GroupInfo AP_Notify::var_info[] = {
|
const AP_Param::GroupInfo AP_Notify::var_info[] = {
|
||||||
|
|
||||||
@ -165,14 +174,12 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = {
|
|||||||
AP_GROUPINFO("OREO_THEME", 4, AP_Notify, _oreo_theme, 0),
|
AP_GROUPINFO("OREO_THEME", 4, AP_Notify, _oreo_theme, 0),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(HAL_BUZZER_PIN)
|
|
||||||
// @Param: BUZZ_PIN
|
// @Param: BUZZ_PIN
|
||||||
// @DisplayName: Buzzer pin
|
// @DisplayName: Buzzer pin
|
||||||
// @Description: Enables to connect active buzzer to arbitrary pin. Requires 3-pin buzzer or additional MOSFET!
|
// @Description: Enables to connect active buzzer to arbitrary pin. Requires 3-pin buzzer or additional MOSFET!
|
||||||
// @Values: 0:Disabled
|
// @Values: 0:Disabled
|
||||||
// @User: Advanced
|
// @User: Advanced
|
||||||
AP_GROUPINFO("BUZZ_PIN", 5, AP_Notify, _buzzer_pin, 0),
|
AP_GROUPINFO("BUZZ_PIN", 5, AP_Notify, _buzzer_pin, HAL_BUZZER_PIN),
|
||||||
#endif
|
|
||||||
|
|
||||||
// @Param: LED_TYPES
|
// @Param: LED_TYPES
|
||||||
// @DisplayName: LED Driver Types
|
// @DisplayName: LED Driver Types
|
||||||
@ -181,14 +188,12 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = {
|
|||||||
// @User: Advanced
|
// @User: Advanced
|
||||||
AP_GROUPINFO("LED_TYPES", 6, AP_Notify, _led_type, BUILD_DEFAULT_LED_TYPE),
|
AP_GROUPINFO("LED_TYPES", 6, AP_Notify, _led_type, BUILD_DEFAULT_LED_TYPE),
|
||||||
|
|
||||||
#if !defined(HAL_BUZZER_PIN)
|
|
||||||
// @Param: BUZZ_ON_LVL
|
// @Param: BUZZ_ON_LVL
|
||||||
// @DisplayName: Buzzer-on pin logic level
|
// @DisplayName: Buzzer-on pin logic level
|
||||||
// @Description: Specifies pin level that indicates buzzer should play
|
// @Description: Specifies pin level that indicates buzzer should play
|
||||||
// @Values: 0:LowIsOn,1:HighIsOn
|
// @Values: 0:LowIsOn,1:HighIsOn
|
||||||
// @User: Advanced
|
// @User: Advanced
|
||||||
AP_GROUPINFO("BUZZ_ON_LVL", 7, AP_Notify, _buzzer_level, 1),
|
AP_GROUPINFO("BUZZ_ON_LVL", 7, AP_Notify, _buzzer_level, HAL_BUZZER_ON),
|
||||||
#endif
|
|
||||||
|
|
||||||
// @Param: BUZZ_VOLUME
|
// @Param: BUZZ_VOLUME
|
||||||
// @DisplayName: Buzzer volume
|
// @DisplayName: Buzzer volume
|
||||||
|
@ -21,32 +21,18 @@
|
|||||||
|
|
||||||
#include "AP_Notify.h"
|
#include "AP_Notify.h"
|
||||||
|
|
||||||
#ifndef HAL_BUZZER_ON
|
|
||||||
#if !defined(HAL_BUZZER_PIN)
|
|
||||||
#define HAL_BUZZER_ON (pNotify->get_buzz_level())
|
|
||||||
#define HAL_BUZZER_OFF (!pNotify->get_buzz_level())
|
|
||||||
#else
|
|
||||||
#define HAL_BUZZER_ON 1
|
|
||||||
#define HAL_BUZZER_OFF 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern const AP_HAL::HAL& hal;
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
|
||||||
bool Buzzer::init()
|
bool Buzzer::init()
|
||||||
{
|
{
|
||||||
if (pNotify->buzzer_enabled() == false) {
|
if (pNotify->buzzer_enabled() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#if defined(HAL_BUZZER_PIN)
|
|
||||||
_pin = HAL_BUZZER_PIN;
|
|
||||||
#else
|
|
||||||
_pin = pNotify->get_buzz_pin();
|
_pin = pNotify->get_buzz_pin();
|
||||||
#endif
|
if (_pin <= 0) {
|
||||||
if(!_pin) return false;
|
// no buzzer
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// setup the pin and ensure it's off
|
// setup the pin and ensure it's off
|
||||||
hal.gpio->pinMode(_pin, HAL_GPIO_OUTPUT);
|
hal.gpio->pinMode(_pin, HAL_GPIO_OUTPUT);
|
||||||
@ -147,7 +133,8 @@ void Buzzer::on(bool turn_on)
|
|||||||
_flags.on = turn_on;
|
_flags.on = turn_on;
|
||||||
|
|
||||||
// pull pin high or low
|
// pull pin high or low
|
||||||
hal.gpio->write(_pin, _flags.on? HAL_BUZZER_ON : HAL_BUZZER_OFF);
|
const uint8_t buzz_on = pNotify->get_buzz_level();
|
||||||
|
hal.gpio->write(_pin, _flags.on? buzz_on : !buzz_on);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// play_pattern - plays the defined buzzer pattern
|
/// play_pattern - plays the defined buzzer pattern
|
||||||
|
Loading…
Reference in New Issue
Block a user