AP_BoardConfig: added BRD_SAFETYOPTION parameter

allow control of safety button behaviour
This commit is contained in:
Andrew Tridgell 2018-04-14 06:34:49 +10:00
parent ef2f2d7e1c
commit 3abd7ea051
2 changed files with 49 additions and 0 deletions

View File

@ -67,7 +67,14 @@
# endif
#endif
#if AP_FEATURE_SAFETY_BUTTON
#ifndef BOARD_SAFETY_OPTION_DEFAULT
#define BOARD_SAFETY_OPTION_DEFAULT (BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF|BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON)
#endif
#endif
extern const AP_HAL::HAL& hal;
AP_BoardConfig *AP_BoardConfig::instance;
// table of user settable parameters
const AP_Param::GroupInfo AP_BoardConfig::var_info[] = {
@ -171,6 +178,15 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = {
// ID number 11 reserved for AP_Radio (pending PR)
#if AP_FEATURE_SAFETY_BUTTON
// @Param: SAFETYOPTION
// @DisplayName: Options for safety button behavior
// @Description: This controls the activation of the safety button. It allows you to control if the safety button can be used for safety enable and/or disable, and whether the button is only active when disarmed
// @Bitmask: 0:ActiveForSafetyEnable,1:ActiveForSafetyDisable,2:ActiveWhenDisarmed
// @User: Standard
AP_GROUPINFO("SAFETYOPTION", 13, AP_BoardConfig, px4.safety_option, BOARD_SAFETY_OPTION_DEFAULT),
#endif
AP_GROUPEND
};

View File

@ -7,14 +7,31 @@
extern "C" typedef int (*main_fn_t)(int argc, char **);
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#define AP_FEATURE_SAFETY_BUTTON 1
#else
#define AP_FEATURE_SAFETY_BUTTON 0
#endif
class AP_BoardConfig {
public:
// constructor
AP_BoardConfig(void)
{
instance = this;
AP_Param::setup_object_defaults(this, var_info);
};
/* Do not allow copies */
AP_BoardConfig(const AP_BoardConfig &other) = delete;
AP_BoardConfig &operator=(const AP_BoardConfig&) = delete;
// singleton support
static AP_BoardConfig *get_instance(void) {
return instance;
}
void init(void);
void init_safety(void);
@ -67,13 +84,29 @@ public:
}
#endif
#if AP_FEATURE_SAFETY_BUTTON
enum board_safety_button_option {
BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF=1,
BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON=2,
BOARD_SAFETY_OPTION_BUTTON_ACTIVE_ARMED=4,
};
// return safety button options. Bits are in enum board_safety_button_option
uint16_t get_safety_button_options(void) {
return uint16_t(px4.safety_option.get());
}
#endif
private:
static AP_BoardConfig *instance;
AP_Int16 vehicleSerialNumber;
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
struct {
AP_Int8 pwm_count;
AP_Int8 safety_enable;
AP_Int16 safety_option;
AP_Int32 ignore_safety_channels;
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
AP_Int8 ser1_rtscts;