mirror of
https://github.com/esphome/esphome.git
synced 2024-12-26 23:41:45 +01:00
All changed to ebyte
This commit is contained in:
parent
271444b27f
commit
40f6aa34a5
7 changed files with 52 additions and 49 deletions
|
@ -11,22 +11,25 @@ from esphome.const import (
|
|||
ENTITY_CATEGORY_NONE,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@danielkoek"]
|
||||
DEPENDENCIES = ["uart"]
|
||||
AUTO_LOAD = ["uart", "sensor", "text_sensor"]
|
||||
|
||||
lora_ns = cg.esphome_ns.namespace("lora")
|
||||
LoraComponent = lora_ns.class_("Lora", cg.PollingComponent, uart.UARTDevice)
|
||||
ebyte_lora_ns = cg.esphome_ns.namespace("ebyte_lora")
|
||||
EbyteLoraComponent = ebyte_lora_ns.class_(
|
||||
"EbyteLora", cg.PollingComponent, uart.UARTDevice
|
||||
)
|
||||
CONF_EBYTE_LORA = "ebyte_lora"
|
||||
CONF_PIN_AUX = "pin_aux"
|
||||
CONF_PIN_M0 = "pin_m0"
|
||||
CONF_PIN_M1 = "pin_m1"
|
||||
CONF_PCF8574 = "pcf8574"
|
||||
CONF_LORA_MESSAGE = "lora_message"
|
||||
CONF_LORA_RSSI = "lora_rssi"
|
||||
CONF_LORA = "lora"
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(LoraComponent),
|
||||
cv.GenerateID(): cv.declare_id(EbyteLoraComponent),
|
||||
# for communication to let us know that we can receive data
|
||||
cv.Required(CONF_PIN_AUX): pins.gpio_input_pin_schema,
|
||||
# for communication set the mode
|
|
@ -1,8 +1,8 @@
|
|||
#include "lora.h"
|
||||
#include "ebyte_lora.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lora {
|
||||
void Lora::update() {
|
||||
namespace ebyte_lora {
|
||||
void EbyteLoraComponent::update() {
|
||||
can_send_message_();
|
||||
if (!this->update_needed_)
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ void Lora::update() {
|
|||
// reset the updater
|
||||
this->update_needed_ = false;
|
||||
}
|
||||
void Lora::setup() {
|
||||
void EbyteLoraComponent::setup() {
|
||||
this->pin_aux_->setup();
|
||||
this->pin_m0_->setup();
|
||||
this->pin_m1_->setup();
|
||||
|
@ -23,9 +23,9 @@ void Lora::setup() {
|
|||
ESP_LOGD(TAG, "Setup success");
|
||||
}
|
||||
|
||||
ModeType Lora::get_mode_() {
|
||||
ModeType EbyteLoraComponent::get_mode_() {
|
||||
ModeType internalMode = MODE_INIT;
|
||||
if (!Lora::can_send_message_()) {
|
||||
if (!EbyteLoraComponent::can_send_message_()) {
|
||||
return internalMode;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ ModeType Lora::get_mode_() {
|
|||
}
|
||||
return internalMode;
|
||||
}
|
||||
void Lora::set_mode_(ModeType mode) {
|
||||
if (!Lora::can_send_message_()) {
|
||||
void EbyteLoraComponent::set_mode_(ModeType mode) {
|
||||
if (!can_send_message_()) {
|
||||
return;
|
||||
}
|
||||
if (this->pin_m0_ == nullptr && this->pin_m1_ == nullptr) {
|
||||
|
@ -95,7 +95,7 @@ void Lora::set_mode_(ModeType mode) {
|
|||
this->mode_ = mode;
|
||||
ESP_LOGD(TAG, "Mode is going to be set");
|
||||
}
|
||||
bool Lora::can_send_message_() {
|
||||
bool EbyteLoraComponent::can_send_message_() {
|
||||
// High means no more information is needed
|
||||
if (this->pin_aux_->digital_read()) {
|
||||
if (!this->starting_to_check_ == 0 && !this->time_out_after_ == 0) {
|
||||
|
@ -115,7 +115,7 @@ bool Lora::can_send_message_() {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
void Lora::setup_wait_response_(uint32_t timeout) {
|
||||
void EbyteLoraComponent::setup_wait_response_(uint32_t timeout) {
|
||||
if (this->starting_to_check_ != 0 || this->time_out_after_ != 0) {
|
||||
ESP_LOGD(TAG, "Wait response already set!! %u", timeout);
|
||||
}
|
||||
|
@ -123,15 +123,15 @@ void Lora::setup_wait_response_(uint32_t timeout) {
|
|||
this->starting_to_check_ = millis();
|
||||
this->time_out_after_ = timeout;
|
||||
}
|
||||
void Lora::dump_config() {
|
||||
void EbyteLoraComponent::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 Lora::digital_write(uint8_t pin, bool value) { this->send_pin_info_(pin, value); }
|
||||
void Lora::send_pin_info_(uint8_t pin, bool value) {
|
||||
if (!Lora::can_send_message_()) {
|
||||
void EbyteLoraComponent::digital_write(uint8_t pin, bool value) { this->send_pin_info_(pin, value); }
|
||||
void EbyteLoraComponent::send_pin_info_(uint8_t pin, bool value) {
|
||||
if (!EbyteLoraComponent::can_send_message_()) {
|
||||
return;
|
||||
}
|
||||
uint8_t data[3];
|
||||
|
@ -145,7 +145,7 @@ void Lora::send_pin_info_(uint8_t pin, bool value) {
|
|||
this->setup_wait_response_(5000);
|
||||
ESP_LOGD(TAG, "Successfully put in queue");
|
||||
}
|
||||
void Lora::loop() {
|
||||
void EbyteLoraComponent::loop() {
|
||||
std::string buffer;
|
||||
std::vector<uint8_t> data;
|
||||
if (!this->available())
|
||||
|
@ -175,5 +175,5 @@ void Lora::loop() {
|
|||
ESP_LOGD(TAG, "WEIRD");
|
||||
}
|
||||
}
|
||||
} // namespace lora
|
||||
} // namespace ebyte_lora
|
||||
} // namespace esphome
|
|
@ -10,9 +10,9 @@
|
|||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lora {
|
||||
namespace ebyte_lora {
|
||||
|
||||
static const char *const TAG = "lora";
|
||||
static const char *const TAG = "ebyte_lora";
|
||||
static const uint8_t MAX_SIZE_TX_PACKET = 200;
|
||||
// the mode the receiver is in
|
||||
enum ModeType {
|
||||
|
@ -27,7 +27,7 @@ enum ModeType {
|
|||
MODE_3_SLEEP = 3,
|
||||
MODE_INIT = 0xFF
|
||||
};
|
||||
class Lora : public PollingComponent, public uart::UARTDevice {
|
||||
class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
|
||||
public:
|
||||
void setup() override;
|
||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||
|
@ -69,5 +69,5 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
|||
pcf8574::PCF8574Component *pcf8574_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace lora
|
||||
} // namespace ebyte_lora
|
||||
} // namespace esphome
|
|
@ -1,16 +1,16 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import switch
|
||||
from .. import CONF_LORA, LoraComponent, lora_ns
|
||||
from .. import EbyteLoraComponent, CONF_EBYTE_LORA, ebyte_lora_ns
|
||||
|
||||
LoraSwitch = lora_ns.class_("LoraSwitch", switch.Switch, cg.Component)
|
||||
EbyteLoraSwitch = ebyte_lora_ns.class_("LoraSwitch", switch.Switch, cg.Component)
|
||||
|
||||
PIN_TO_SEND = "pin_to_send"
|
||||
CONFIG_SCHEMA = (
|
||||
switch.switch_schema(LoraSwitch)
|
||||
switch.switch_schema(EbyteLoraSwitch)
|
||||
.extend(
|
||||
{
|
||||
cv.Required(CONF_LORA): cv.use_id(LoraComponent),
|
||||
cv.Required(CONF_EBYTE_LORA): cv.use_id(EbyteLoraComponent),
|
||||
cv.Required(PIN_TO_SEND): cv.int_range(min=0, max=3),
|
||||
}
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ CONFIG_SCHEMA = (
|
|||
|
||||
async def to_code(config):
|
||||
var = await switch.new_switch(config)
|
||||
parent = await cg.get_variable(config[CONF_LORA])
|
||||
parent = await cg.get_variable(config[CONF_EBYTE_LORA])
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_parent(parent))
|
||||
cg.add(var.set_pin(config[PIN_TO_SEND]))
|
14
esphome/components/ebyte_lora/switch/ebyte_lora_switch.cpp
Normal file
14
esphome/components/ebyte_lora/switch/ebyte_lora_switch.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "ebyte_lora_switch.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ebyte_lora {
|
||||
static const char *const TAG_SWITCH = "ebyte_lora_switch";
|
||||
|
||||
void EbyteLoraSwitch::write_state(bool state) {
|
||||
this->parent_->digital_write(this->pin_, state);
|
||||
// finally set it
|
||||
this->publish_state(state);
|
||||
}
|
||||
void EbyteLoraSwitch::dump_config() { LOG_SWITCH(TAG_SWITCH, "Ebyte Lora Switch", this); }
|
||||
} // namespace ebyte_lora
|
||||
} // namespace esphome
|
|
@ -6,20 +6,20 @@
|
|||
#include "esphome/components/switch/switch.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "../lora.h"
|
||||
#include "../ebyte_lora.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lora {
|
||||
class LoraSwitch : public switch_::Switch, public Component {
|
||||
namespace ebyte_lora {
|
||||
class EbyteLoraSwitch : public switch_::Switch, public Component {
|
||||
public:
|
||||
void dump_config() override;
|
||||
void set_parent(Lora *parent) { parent_ = parent; }
|
||||
void set_parent(EbyteLoraComponent *parent) { parent_ = parent; }
|
||||
void set_pin(uint8_t pin) { pin_ = pin; }
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override;
|
||||
Lora *parent_;
|
||||
EbyteLoraComponent *parent_;
|
||||
uint8_t pin_;
|
||||
};
|
||||
} // namespace lora
|
||||
} // namespace ebyte_lora
|
||||
} // namespace esphome
|
|
@ -1,14 +0,0 @@
|
|||
#include "switch_lora.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace lora {
|
||||
static const char *const TAG_SWITCH = "lora.switch";
|
||||
|
||||
void LoraSwitch::write_state(bool state) {
|
||||
this->parent_->digital_write(this->pin_, state);
|
||||
// finally set it
|
||||
this->publish_state(state);
|
||||
}
|
||||
void LoraSwitch::dump_config() { LOG_SWITCH(TAG_SWITCH, "Lora Switch", this); }
|
||||
} // namespace lora
|
||||
} // namespace esphome
|
Loading…
Reference in a new issue