AP_Relay: Add singleton

This commit is contained in:
Michael du Breuil 2019-04-22 16:12:56 -07:00 committed by Andrew Tridgell
parent 1b48ce57f0
commit 062bca6361
2 changed files with 12 additions and 0 deletions

View File

@ -98,12 +98,20 @@ const AP_Param::GroupInfo AP_Relay::var_info[] = {
AP_GROUPEND
};
AP_Relay *AP_Relay::singleton;
extern const AP_HAL::HAL& hal;
AP_Relay::AP_Relay(void)
{
AP_Param::setup_object_defaults(this, var_info);
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
if (singleton != nullptr) {
AP_HAL::panic("AP_Relay must be singleton");
}
#endif
singleton = this;
}

View File

@ -38,9 +38,13 @@ public:
// toggle the relay status
void toggle(uint8_t relay);
static AP_Relay *get_singleton(void) {return singleton; }
static const struct AP_Param::GroupInfo var_info[];
private:
static AP_Relay *singleton;
AP_Int8 _pin[AP_RELAY_NUM_RELAYS];
AP_Int8 _default;
};