From ea4fc0908c2be2306d2698ee8324da88974f5b73 Mon Sep 17 00:00:00 2001 From: Alexandr Pyslar <34306652+CCChelios@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:47:24 +0000 Subject: [PATCH] add timings --- esphome/components/modem/modem_component.cpp | 30 ++++++++++++-------- esphome/components/modem/modem_component.h | 3 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/esphome/components/modem/modem_component.cpp b/esphome/components/modem/modem_component.cpp index 97845d2470..848ce5e61c 100644 --- a/esphome/components/modem/modem_component.cpp +++ b/esphome/components/modem/modem_component.cpp @@ -17,6 +17,8 @@ uint32_t time_info_print = 0; uint32_t time_hard_reset_modem = 0; uint32_t time_check_rssi = 0; +uint32_t time_push_pwrkey = 0; +uint32_t time_turn_on_modem = 0; #define TIME_TO_NEXT_HARD_RESET 30000 #define TIME_TO_START_MODEM 9000 @@ -58,8 +60,7 @@ void ModemComponent::setup() { this->turn_on_modem(); this->use_pwrkey(); - //esp_modem_hard_reset(); - + // esp_modem_hard_reset(); if (esp_reset_reason() != ESP_RST_DEEPSLEEP) { // Delay here to allow power to stabilise before Modem is initialized. @@ -123,11 +124,18 @@ void ModemComponent::loop() { } } break; + case ModemComponentState::RESETTING: + break; + case ModemComponentState::TURNING_ON: + + break; + case ModemComponentState::TURNING_OFF: + break; case ModemComponentState::CONNECTING: break; case ModemComponentState::CONNECTED: if (time_info_print < now) { - //ESP_LOGI(TAG, "voltage %dV.", get_modem_voltage() / 1000); + // ESP_LOGI(TAG, "voltage %dV.", get_modem_voltage() / 1000); if (esp_netif_is_netif_up(this->modem_netif_)) { ESP_LOGD(TAG, "esp_netif_is_netif_UP"); } else { @@ -139,42 +147,40 @@ void ModemComponent::loop() { } } -bool ModemComponent::turn_on_modem(){ +bool ModemComponent::turn_on_modem() { if (this->power_pin_) { this->power_pin_->digital_write(true); + time_turn_on_modem = millis(); vTaskDelay(pdMS_TO_TICKS(1900)); // NOLINT ESP_LOGD(TAG, "modem is on"); return true; - } - else { + } else { ESP_LOGD(TAG, "failed to turn on modem because power_pin_ is not initialized"); return false; } // wait no more than 1.9 sec for signs of life to appear } -bool ModemComponent::turn_off_modem(){ +bool ModemComponent::turn_off_modem() { if (this->power_pin_) { this->power_pin_->digital_write(true); vTaskDelay(pdMS_TO_TICKS(1900)); // NOLINT ESP_LOGD(TAG, "modem is off"); return true; - } - else { + } else { ESP_LOGD(TAG, "failed to turn off modem because power_pin_ is not initialized"); return false; } // wait no more than 1.9 sec for signs of life to appear } -bool ModemComponent::use_pwrkey(){ +bool ModemComponent::use_pwrkey() { if (this->pwrkey_pin_) { ESP_LOGD(TAG, "pwrkey used"); this->pwrkey_pin_->digital_write(false); vTaskDelay(pdMS_TO_TICKS(1050)); // NOLINT this->pwrkey_pin_->digital_write(true); - } - else { + } else { ESP_LOGD(TAG, "failed to press button because pwrkey_pin_ is not initialized"); } return true; diff --git a/esphome/components/modem/modem_component.h b/esphome/components/modem/modem_component.h index bb16558228..cf98eb4c33 100644 --- a/esphome/components/modem/modem_component.h +++ b/esphome/components/modem/modem_component.h @@ -26,6 +26,9 @@ enum ModemType { enum class ModemComponentState { STOPPED, + RESETTING, + TURNING_ON, + TURNING_OFF, CONNECTING, CONNECTED, };