mirror of
https://github.com/esphome/esphome.git
synced 2025-10-26 12:43:48 +00:00
[gpio] Optimize switch interlock with FixedVector (#11448)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -67,7 +67,7 @@ void GPIOSwitch::write_state(bool state) {
|
|||||||
this->pin_->digital_write(state);
|
this->pin_->digital_write(state);
|
||||||
this->publish_state(state);
|
this->publish_state(state);
|
||||||
}
|
}
|
||||||
void GPIOSwitch::set_interlock(const std::vector<Switch *> &interlock) { this->interlock_ = interlock; }
|
void GPIOSwitch::set_interlock(const std::initializer_list<Switch *> &interlock) { this->interlock_ = interlock; }
|
||||||
|
|
||||||
} // namespace gpio
|
} // namespace gpio
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/components/switch/switch.h"
|
#include "esphome/components/switch/switch.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace gpio {
|
namespace gpio {
|
||||||
|
|
||||||
@@ -19,14 +18,14 @@ class GPIOSwitch : public switch_::Switch, public Component {
|
|||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_interlock(const std::vector<Switch *> &interlock);
|
void set_interlock(const std::initializer_list<Switch *> &interlock);
|
||||||
void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
|
void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_state(bool state) override;
|
void write_state(bool state) override;
|
||||||
|
|
||||||
GPIOPin *pin_;
|
GPIOPin *pin_;
|
||||||
std::vector<Switch *> interlock_;
|
FixedVector<Switch *> interlock_;
|
||||||
uint32_t interlock_wait_time_{0};
|
uint32_t interlock_wait_time_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user