Browse Source

relay: use helper type alias for the provider

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
acf299582b
2 changed files with 11 additions and 6 deletions
  1. +9
    -5
      code/espurna/relay.cpp
  2. +2
    -1
      code/espurna/relay.h

+ 9
- 5
code/espurna/relay.cpp View File

@ -211,6 +211,10 @@ public:
// Struct defaults to empty relay configuration, as we allow switches to exist without real GPIOs
relay_t() = default;
relay_t(RelayProviderBasePtr&& provider_) :
provider(provider_.release())
{}
relay_t(RelayProviderBase* provider_) :
provider(provider_)
{}
@ -1758,11 +1762,11 @@ std::unique_ptr<GpioProvider> _relayGpioProvider(unsigned char index, RelayType
);
}
std::unique_ptr<RelayProviderBase> _relaySetupProvider(unsigned char index) {
RelayProviderBasePtr _relaySetupProvider(unsigned char index) {
auto provider = getSetting({"relayProv", index}, _relayProvider(index));
auto type = getSetting({"relayType", index}, _relayType(index));
std::unique_ptr<RelayProviderBase> result;
RelayProviderBasePtr result;
switch (provider) {
case RelayProvider::Dummy:
@ -1799,7 +1803,7 @@ void _relaySetupAdhoc() {
if (!impl->setup()) {
break;
}
_relays.emplace_back(impl.release());
_relays.emplace_back(std::move(impl));
}
}
@ -1835,10 +1839,10 @@ void relaySetup() {
}
bool relayAdd(std::unique_ptr<RelayProviderBase>&& provider) {
bool relayAdd(RelayProviderBasePtr&& provider) {
if (provider && provider->setup()) {
static bool scheduled { false };
_relays.emplace_back(provider.release());
_relays.emplace_back(std::move(provider));
if (!scheduled) {
schedule_function([]() {
_relayConfigure();


+ 2
- 1
code/espurna/relay.h View File

@ -93,8 +93,9 @@ void relaySync(unsigned char id);
void relaySave(bool persist);
using RelayStatusCallback = void(*)(unsigned char id, bool status);
using RelayProviderBasePtr = std::unique_ptr<RelayProviderBase>;
bool relayAdd(std::unique_ptr<RelayProviderBase>&& provider);
bool relayAdd(RelayProviderBasePtr&& provider);
void relaySetStatusNotify(RelayStatusCallback);
void relaySetStatusChange(RelayStatusCallback);


Loading…
Cancel
Save