From 0d3b86ec54e2de8f022ce88c495155287eb99a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Koek?= Date: Wed, 31 Jan 2024 18:24:45 +0000 Subject: [PATCH] and clean even more --- .../ebyte_lora_e220/ebyte_lora_e220.cpp | 43 +++++++++++++++++++ .../ebyte_lora_e220/ebyte_lora_e220.h | 19 +------- .../components/ebyte_lora_e220/lora_e220.cpp | 7 --- 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp diff --git a/esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp b/esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp new file mode 100644 index 0000000000..0c9ff3f356 --- /dev/null +++ b/esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp @@ -0,0 +1,43 @@ +#pragma once +#include +#include +#include "esphome/core/component.h" +#include "esphome/components/sensor/sensor.h" +#include "esphome/components/text_sensor/text_sensor.h" +#include "esphome/core/helpers.h" +#include "esphome/components/uart/uart.h" +#include "esphome/core/log.h" +#include "lora_e220.h" +#include "ebyte_lora_e220.h" + +namespace esphome { +namespace ebyte_lora_e220 { + +static const char *const TAG = "ebyte_lora_e220"; + +void EbyteLoraE220::dump_config() { + ESP_LOGCONFIG(TAG, "Ebyte Lora E220"); + LOG_PIN(" Aux pin: ", this->pin_aux); + LOG_PIN(" M0 Pin: ", this->pin_m0); + LOG_PIN(" M1 Pin: ", this->pin_m1); +}; +void EbyteLoraE220::update() { + // This will be called by App.loop() + + if (e220ttl.available() > 1) { + // read the String message + lora_e220::ResponseContainer rc = e220ttl.receiveMessageRSSI(); + // Is something goes wrong print error + if (rc.status.code != 1) { + this->status_text_sensor->publish_state(rc.status.getResponseDescription()); + } else { + // Print the data received + this->status_text_sensor->publish_state(rc.status.getResponseDescription()); + this->message_text_sensor->publish_state(rc.data); + this->rssi_sensor->publish_state(rc.rssi); + } + } +} + +} // namespace ebyte_lora_e220 +} // namespace esphome diff --git a/esphome/components/ebyte_lora_e220/ebyte_lora_e220.h b/esphome/components/ebyte_lora_e220/ebyte_lora_e220.h index 58ad0a1046..ccc27f4b15 100644 --- a/esphome/components/ebyte_lora_e220/ebyte_lora_e220.h +++ b/esphome/components/ebyte_lora_e220/ebyte_lora_e220.h @@ -23,23 +23,8 @@ class EbyteLoraE220 : public PollingComponent, public uart::UARTDevice { void set_pin_aux(GPIOPin *s) { pin_aux = s; } void set_pin_m0(GPIOPin *s) { pin_m0 = s; } void set_pin_m1(GPIOPin *s) { pin_m1 = s; } - void update() override { - // This will be called by App.loop() - - if (e220ttl.available() > 1) { - // read the String message - lora_e220::ResponseContainer rc = e220ttl.receiveMessageRSSI(); - // Is something goes wrong print error - if (rc.status.code != 1) { - this->status_text_sensor->publish_state(rc.status.getResponseDescription()); - } else { - // Print the data received - this->status_text_sensor->publish_state(rc.status.getResponseDescription()); - this->message_text_sensor->publish_state(rc.data); - this->rssi_sensor->publish_state(rc.rssi); - } - } - } + void dump_config() override; + void update() override; protected: std::vector buffer_; diff --git a/esphome/components/ebyte_lora_e220/lora_e220.cpp b/esphome/components/ebyte_lora_e220/lora_e220.cpp index 296b9da119..a78a613764 100644 --- a/esphome/components/ebyte_lora_e220/lora_e220.cpp +++ b/esphome/components/ebyte_lora_e220/lora_e220.cpp @@ -11,13 +11,6 @@ LoRa_E220::LoRa_E220(esphome::uart::UARTDevice *serial, GPIOPin *auxPin, GPIOPin this->m1Pin = m1Pin; } bool LoRa_E220::begin() { - ESP_LOGD(TAG, "AUX ---> "); - LOG_PIN(TAG, this->auxPin); - ESP_LOGD(TAG, "M0 ---> "); - LOG_PIN(TAG, this->m0Pin); - ESP_LOGD(TAG, "M1 ---> "); - LOG_PIN(TAG, this->m1Pin); - if (this->auxPin != nullptr) { this->m0Pin->pin_mode(gpio::FLAG_INPUT); ESP_LOGD(TAG, "Init AUX pin!");