This commit is contained in:
Daniël Koek 2024-02-20 16:30:03 +00:00
parent b5912c7d6e
commit 895a90bdc8
4 changed files with 37 additions and 55 deletions

View file

@ -160,5 +160,21 @@ void Lora::loop() {
raw_message_ = buffer.substr(0, buffer.length() - 1);
}
// pin stuff
static const char *const TAGPin = "lora.pin";
void LoraGPIOPin::setup() { pin_mode(flags_); }
void LoraGPIOPin::pin_mode(gpio::Flags flags) {
if (flags != gpio::FLAG_OUTPUT) {
ESP_LOGD(TAGPin, "Output only supported");
}
}
bool LoraGPIOPin::digital_read() { return false; }
void LoraGPIOPin::digital_write(bool value) { this->parent_->digital_write(this->pin_, value != this->inverted_); }
std::string LoraGPIOPin::dump_summary() const {
char buffer[32];
snprintf(buffer, sizeof(buffer), "%u via Lora", pin_);
return buffer;
}
} // namespace lora
} // namespace esphome

View file

@ -65,5 +65,26 @@ class Lora : public PollingComponent, public uart::UARTDevice {
GPIOPin *pin_m1{nullptr};
};
// pin stuff
class LoraGPIOPin : public GPIOPin {
public:
void setup() override;
void pin_mode(gpio::Flags flags) override;
bool digital_read() override;
void digital_write(bool value) override;
std::string dump_summary() const override;
void set_parent(Lora *parent) { parent_ = parent; }
void set_pin(uint8_t pin) { pin_ = pin; }
void set_inverted(bool inverted) { inverted_ = inverted; }
void set_flags(gpio::Flags flags) { flags_ = flags; }
protected:
Lora *parent_;
uint8_t pin_;
bool inverted_;
gpio::Flags flags_;
};
} // namespace lora
} // namespace esphome

View file

@ -1,22 +0,0 @@
#include "lora_pin.h"
#include "esphome/core/log.h"
namespace esphome {
namespace lora {
static const char *const TAGPin = "lora.pin";
void LoraGPIOPin::setup() { pin_mode(flags_); }
void LoraGPIOPin::pin_mode(gpio::Flags flags) {
if (flags != gpio::FLAG_OUTPUT) {
ESP_LOGD(TAGPin, "Output only supported");
}
}
bool LoraGPIOPin::digital_read() { return false; }
void LoraGPIOPin::digital_write(bool value) { this->parent_->digital_write(this->pin_, value != this->inverted_); }
std::string LoraGPIOPin::dump_summary() const {
char buffer[32];
snprintf(buffer, sizeof(buffer), "%u via Lora", pin_);
return buffer;
}
} // namespace lora
} // namespace esphome

View file

@ -1,33 +0,0 @@
#pragma once
#include "esphome/core/component.h"
#include "./lora.h"
#include <cinttypes>
#include <vector>
namespace esphome {
namespace lora {
class LoraGPIOPin : public GPIOPin {
public:
void setup() override;
void pin_mode(gpio::Flags flags) override;
bool digital_read() override;
void digital_write(bool value) override;
std::string dump_summary() const override;
void set_parent(Lora *parent) { parent_ = parent; }
void set_pin(uint8_t pin) { pin_ = pin; }
void set_inverted(bool inverted) { inverted_ = inverted; }
void set_flags(gpio::Flags flags) { flags_ = flags; }
protected:
Lora *parent_;
uint8_t pin_;
bool inverted_;
gpio::Flags flags_;
};
} // namespace lora
} // namespace esphome