AP_ServoRelayEvents: add singleton

This commit is contained in:
Peter Barker 2018-04-14 14:16:06 +10:00 committed by Randy Mackay
parent 9aa685a6d8
commit 544ac03ca6
2 changed files with 25 additions and 6 deletions

View File

@ -133,3 +133,15 @@ void AP_ServoRelayEvents::update_events(void)
repeat ^= 1;
}
}
// singleton instance
AP_ServoRelayEvents *AP_ServoRelayEvents::_singleton;
namespace AP {
AP_ServoRelayEvents *servorelayevents()
{
return AP_ServoRelayEvents::get_singleton();
}
}

View File

@ -13,20 +13,20 @@ class AP_ServoRelayEvents {
public:
AP_ServoRelayEvents(AP_Relay &_relay)
: relay(_relay)
, mask(0)
, type(EVENT_TYPE_RELAY)
, start_time_ms(0)
, delay_ms(0)
, repeat(0)
, channel(0)
, servo_value(0)
{
_singleton = this;
}
/* Do not allow copies */
AP_ServoRelayEvents(const AP_ServoRelayEvents &other) = delete;
AP_ServoRelayEvents &operator=(const AP_ServoRelayEvents&) = delete;
// get singleton instance
static AP_ServoRelayEvents *get_singleton() {
return _singleton;
}
// set allowed servo channel mask
void set_channel_mask(uint16_t _mask) { mask = _mask; }
@ -37,6 +37,9 @@ public:
void update_events(void);
private:
static AP_ServoRelayEvents *_singleton;
AP_Relay &relay;
uint16_t mask;
@ -63,3 +66,7 @@ private:
// PWM for servos
uint16_t servo_value;
};
namespace AP {
AP_ServoRelayEvents *servorelayevents();
};