mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +02:00
Add TM1651 simple level, turn on, turn off actions (#920)
* Add TM1651 simple level action * fixed brightness validation * Updated lib, fixed import * Added turn_on, turn_off actions * Fixed after lint
This commit is contained in:
@@ -17,13 +17,18 @@ class TM1651Display : public Component {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_level_percent(uint8_t);
|
||||
void set_level(uint8_t);
|
||||
void set_brightness(uint8_t);
|
||||
|
||||
void turn_on();
|
||||
void turn_off();
|
||||
|
||||
protected:
|
||||
TM1651 *battery_display_;
|
||||
GPIOPin *clk_pin_;
|
||||
GPIOPin *dio_pin_;
|
||||
bool is_on_ = true;
|
||||
|
||||
uint8_t brightness_;
|
||||
uint8_t level_;
|
||||
@@ -34,9 +39,20 @@ class TM1651Display : public Component {
|
||||
uint8_t calculate_brightness_(uint8_t);
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetLevelPercentAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(uint8_t, level_percent)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto level_percent = this->level_percent_.value(x...);
|
||||
this->parent_->set_level_percent(level_percent);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetLevelAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(uint8_t, level)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto level = this->level_.value(x...);
|
||||
this->parent_->set_level(level);
|
||||
@@ -46,11 +62,22 @@ template<typename... Ts> class SetLevelAction : public Action<Ts...>, public Par
|
||||
template<typename... Ts> class SetBrightnessAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(uint8_t, brightness)
|
||||
|
||||
void play(Ts... x) override {
|
||||
auto brightness = this->brightness_.value(x...);
|
||||
this->parent_->set_brightness(brightness);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts> class TurnOnAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->turn_on(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class TurnOffAction : public Action<Ts...>, public Parented<TM1651Display> {
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->turn_off(); }
|
||||
};
|
||||
|
||||
} // namespace tm1651
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user