ESPHome 2025.5.0
Loading...
Searching...
No Matches
power_supply.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
5
6#include <cinttypes>
7
8namespace esphome {
9namespace power_supply {
10
11class PowerSupply : public Component {
12 public:
13 void set_pin(GPIOPin *pin) { pin_ = pin; }
14 void set_enable_time(uint32_t enable_time) { enable_time_ = enable_time; }
15 void set_keep_on_time(uint32_t keep_on_time) { keep_on_time_ = keep_on_time; }
16 void set_enable_on_boot(bool enable_on_boot) { enable_on_boot_ = enable_on_boot; }
17
19 bool is_enabled() const;
20
22 void request_high_power();
23
26
27 // ========== INTERNAL METHODS ==========
28 // (In most use cases you won't need these)
30 void setup() override;
31 void dump_config() override;
33 float get_setup_priority() const override;
34
35 void on_shutdown() override;
36
37 protected:
39 bool enable_on_boot_{false};
40 uint32_t enable_time_;
41 uint32_t keep_on_time_;
42 int16_t active_requests_{0}; // use signed integer to make catching negative requests easier.
43};
44
46 public:
47 void set_parent(PowerSupply *parent) { parent_ = parent; }
48 void request() {
49 if (!this->requested_ && this->parent_ != nullptr) {
51 this->requested_ = true;
52 }
53 }
54 void unrequest() {
55 if (this->requested_ && this->parent_ != nullptr) {
57 this->requested_ = false;
58 }
59 }
60
61 protected:
63 bool requested_{false};
64};
65
66} // namespace power_supply
67} // namespace esphome
void request_high_power()
Request high power mode. Use unrequest_high_power() to remove this request.
void set_enable_time(uint32_t enable_time)
void set_enable_on_boot(bool enable_on_boot)
bool is_enabled() const
Is this power supply currently on?
void unrequest_high_power()
Un-request high power mode.
void set_keep_on_time(uint32_t keep_on_time)
void setup() override
Register callbacks.
float get_setup_priority() const override
Hardware setup priority (+1).
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7