mirror of
https://github.com/esphome/esphome.git
synced 2024-12-29 00:41:44 +01:00
and clean even more
This commit is contained in:
parent
a2438b7386
commit
0d3b86ec54
3 changed files with 45 additions and 24 deletions
43
esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp
Normal file
43
esphome/components/ebyte_lora_e220/ebyte_lora_e220.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#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
|
|
@ -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<uint8_t> buffer_;
|
||||
|
|
|
@ -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!");
|
||||
|
|
Loading…
Reference in a new issue