mirror of
https://github.com/esphome/esphome.git
synced 2025-01-12 23:53:19 +01:00
add power_pin (requires some improvement)
This commit is contained in:
parent
c3b70e278a
commit
87312d445d
3 changed files with 10 additions and 4 deletions
|
@ -49,6 +49,7 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.GenerateID(): cv.declare_id(ModemComponent),
|
||||
cv.Required(CONF_TYPE): cv.enum(MODEM_TYPES, upper=True),
|
||||
cv.Required(CONF_RESET_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Optional(CONF_POWER_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Required(CONF_RX_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Optional(CONF_APN, default="internet"): cv.string,
|
||||
|
@ -71,6 +72,12 @@ async def to_code(config):
|
|||
await cg.register_component(var, config)
|
||||
cg.add(var.set_type(config[CONF_TYPE]))
|
||||
cg.add(var.set_reset_pin(config[CONF_RESET_PIN]))
|
||||
|
||||
# cg.add(var.set_power_pin(config[CONF_POWER_PIN]))
|
||||
if power_pin := config.get(CONF_POWER_PIN, None):
|
||||
pin = await cg.gpio_pin_expression(power_pin)
|
||||
cg.add(var.set_power_pin(pin))
|
||||
|
||||
cg.add(var.set_tx_pin(config[CONF_TX_PIN]))
|
||||
cg.add(var.set_rx_pin(config[CONF_RX_PIN]))
|
||||
cg.add(var.set_apn(config[CONF_APN]))
|
||||
|
|
|
@ -252,7 +252,7 @@ void ModemComponent::start_connect_() {
|
|||
|
||||
bool ModemComponent::is_connected() { return this->state_ == ModemComponentState::CONNECTED; }
|
||||
|
||||
void ModemComponent::set_power_pin(int power_pin) { this->power_pin_ = power_pin; }
|
||||
void ModemComponent::set_power_pin(std::unique_ptr<GPIOPin> power_pin) { this->power_pin_ = &power_pin; }
|
||||
void ModemComponent::set_type(ModemType type) { this->type_ = type; }
|
||||
void ModemComponent::set_reset_pin(int reset_pin) { this->reset_pin_ = reset_pin; }
|
||||
void ModemComponent::set_apn(const std::string &apn) { this->apn_ = apn; }
|
||||
|
|
|
@ -40,8 +40,7 @@ class ModemComponent : public Component {
|
|||
float get_setup_priority() const override;
|
||||
bool can_proceed() override;
|
||||
bool is_connected();
|
||||
|
||||
void set_power_pin(int power_pin);
|
||||
void set_power_pin(std::unique_ptr<GPIOPin> power_pin);
|
||||
void set_type(ModemType type);
|
||||
void set_reset_pin(int reset_pin);
|
||||
void set_apn(const std::string &apn);
|
||||
|
@ -69,8 +68,8 @@ class ModemComponent : public Component {
|
|||
std::shared_ptr<esp_modem::DTE> dte{nullptr};
|
||||
std::unique_ptr<esp_modem::DCE> dce{nullptr};
|
||||
ModemType type_{MODEM_TYPE_UNKNOWN};
|
||||
int power_pin_{-1};
|
||||
int reset_pin_{-1};
|
||||
std::unique_ptr<GPIOPin> power_pin_{nullptr};
|
||||
int tx_pin_{-1};
|
||||
int rx_pin_{-1};
|
||||
std::string apn_{""};
|
||||
|
|
Loading…
Reference in a new issue