mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
model power delay
This commit is contained in:
parent
5c0b7222ec
commit
1096bc264f
2 changed files with 35 additions and 8 deletions
|
@ -364,6 +364,7 @@ void ModemComponent::loop() {
|
|||
ESP_LOGE(TAG, "modem not ready after hang up");
|
||||
}
|
||||
this->set_timeout("wait_lost_ip", 60000, [this]() {
|
||||
// often reached on 7600, but not reached on 7670
|
||||
ESP_LOGW(TAG, "No lost ip event received. Forcing disconnect state");
|
||||
|
||||
this->state_ = ModemComponentState::DISCONNECTED;
|
||||
|
@ -466,11 +467,12 @@ void ModemComponent::poweron_() {
|
|||
this->power_transition_ = true;
|
||||
this->power_pin_->digital_write(false);
|
||||
// min 100 for SIM7600, but min 1200 for SIM800. min BG96: 650
|
||||
delay(1300); // NOLINT
|
||||
delay(this->modem_model_ton_[this->model_]); // NOLINT
|
||||
this->power_pin_->digital_write(true);
|
||||
// status will be on from 3s (SIM800) to 12s (SIM7600)
|
||||
ESP_LOGD(TAG, "Will check that the modem is on in 12s...");
|
||||
this->set_timeout("wait_poweron", 12000, [this]() {
|
||||
// use a timout for long wait delay
|
||||
uint32_t tonuart = this->modem_model_tonuart_[this->model_];
|
||||
ESP_LOGD(TAG, "Will check that the modem is on in %.1fs...", float(tonuart) / 1000);
|
||||
this->set_timeout("wait_poweron", tonuart, [this]() {
|
||||
Watchdog wdt(60);
|
||||
while (!this->get_power_status()) {
|
||||
delay(this->command_delay_);
|
||||
|
@ -496,12 +498,12 @@ void ModemComponent::poweroff_() {
|
|||
this->power_pin_->digital_write(true);
|
||||
delay(10);
|
||||
this->power_pin_->digital_write(false);
|
||||
delay(2700); // NOLINT
|
||||
delay(this->modem_model_toff_[this->model_]);
|
||||
this->power_pin_->digital_write(true);
|
||||
|
||||
// will have to wait at least 25s
|
||||
ESP_LOGD(TAG, "Will check that the modem is off in 25s...");
|
||||
this->set_timeout("wait_poweron", 25000, [this]() {
|
||||
uint32_t toffuart = this->modem_model_toffuart_[this->model_];
|
||||
ESP_LOGD(TAG, "Will check that the modem is off in %.1fs...", float(toffuart) / 1000);
|
||||
this->set_timeout("wait_poweron", toffuart, [this]() {
|
||||
Watchdog wdt(60);
|
||||
|
||||
while (this->get_power_status()) {
|
||||
|
|
|
@ -117,6 +117,31 @@ class ModemComponent : public Component {
|
|||
uint32_t command_delay_ = 500;
|
||||
// Will be true when power transitionning
|
||||
bool power_transition_ = false;
|
||||
// time needed for power_pin to be low for poweron
|
||||
std::unordered_map<ModemModel, uint32_t> modem_model_ton_ = {{ModemModel::BG96, 600},
|
||||
{ModemModel::SIM800, 1300},
|
||||
{ModemModel::SIM7000, 1100},
|
||||
{ModemModel::SIM7070, 1100},
|
||||
{ModemModel::SIM7600, 500}};
|
||||
// time to wait after poweron for uart to be ready
|
||||
std::unordered_map<ModemModel, uint32_t> modem_model_tonuart_ = {{ModemModel::BG96, 4900},
|
||||
{ModemModel::SIM800, 3000},
|
||||
{ModemModel::SIM7000, 4500},
|
||||
{ModemModel::SIM7070, 2500},
|
||||
{ModemModel::SIM7600, 12000}};
|
||||
// time needed for power_pin to be high for poweroff
|
||||
std::unordered_map<ModemModel, uint32_t> modem_model_toff_ = {{ModemModel::BG96, 650},
|
||||
{ModemModel::SIM800, 200},
|
||||
{ModemModel::SIM7000, 1300},
|
||||
{ModemModel::SIM7070, 1300},
|
||||
{ModemModel::SIM7600, 2800}};
|
||||
// time to wait after for poweroff for uart to be really closed
|
||||
std::unordered_map<ModemModel, uint32_t> modem_model_toffuart_ = {{ModemModel::BG96, 2000},
|
||||
{ModemModel::SIM800, 3000},
|
||||
{ModemModel::SIM7000, 1800},
|
||||
{ModemModel::SIM7070, 1800},
|
||||
{ModemModel::SIM7600, 25000}};
|
||||
|
||||
// separate handler for `on_not_responding` (we want to know when it's ended)
|
||||
Trigger<> *not_responding_cb_{nullptr};
|
||||
CallbackManager<void(ModemComponentState)> on_state_callback_;
|
||||
|
|
Loading…
Reference in a new issue