2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
2021-09-20 11:47:51 +02:00
|
|
|
#include "esphome/core/hal.h"
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace power_supply {
|
|
|
|
|
|
|
|
class PowerSupply : public Component {
|
|
|
|
public:
|
2019-04-22 21:56:30 +02:00
|
|
|
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
|
|
|
void set_enable_time(uint32_t enable_time) { enable_time_ = enable_time; }
|
|
|
|
void set_keep_on_time(uint32_t keep_on_time) { keep_on_time_ = keep_on_time; }
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
/// Is this power supply currently on?
|
|
|
|
bool is_enabled() const;
|
|
|
|
|
|
|
|
/// Request high power mode. Use unrequest_high_power() to remove this request.
|
|
|
|
void request_high_power();
|
|
|
|
|
|
|
|
/// Un-request high power mode.
|
|
|
|
void unrequest_high_power();
|
|
|
|
|
|
|
|
// ========== INTERNAL METHODS ==========
|
|
|
|
// (In most use cases you won't need these)
|
|
|
|
/// Register callbacks.
|
|
|
|
void setup() override;
|
|
|
|
void dump_config() override;
|
|
|
|
/// Hardware setup priority (+1).
|
|
|
|
float get_setup_priority() const override;
|
|
|
|
|
|
|
|
void on_shutdown() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GPIOPin *pin_;
|
|
|
|
bool enabled_{false};
|
|
|
|
uint32_t enable_time_;
|
|
|
|
uint32_t keep_on_time_;
|
|
|
|
int16_t active_requests_{0}; // use signed integer to make catching negative requests easier.
|
|
|
|
};
|
|
|
|
|
2019-05-12 23:04:36 +02:00
|
|
|
class PowerSupplyRequester {
|
|
|
|
public:
|
|
|
|
void set_parent(PowerSupply *parent) { parent_ = parent; }
|
|
|
|
void request() {
|
|
|
|
if (!this->requested_ && this->parent_ != nullptr) {
|
|
|
|
this->parent_->request_high_power();
|
|
|
|
this->requested_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void unrequest() {
|
|
|
|
if (this->requested_ && this->parent_ != nullptr) {
|
|
|
|
this->parent_->unrequest_high_power();
|
|
|
|
this->requested_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PowerSupply *parent_{nullptr};
|
|
|
|
bool requested_{false};
|
|
|
|
};
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
} // namespace power_supply
|
|
|
|
} // namespace esphome
|