add thisw

This commit is contained in:
Daniël Koek 2024-03-29 13:42:20 +00:00
parent 262a6be989
commit 6fed4d268f
2 changed files with 26 additions and 16 deletions

View file

@ -4,6 +4,16 @@ namespace ebyte_lora {
static const uint8_t SWITCH_PUSH = 0x55;
static const uint8_t SWITCH_INFO = 0x66;
static const uint8_t PROGRAM_CONF = 0xC1;
void EbyteLoraComponent::update() {
if (get_mode_() != NORMAL) {
if (this->config.command == 0) {
ESP_LOGD(TAG, "Config not set yet!");
}
ESP_LOGD(TAG, "Mode was not set right");
set_mode_(NORMAL);
}
send_switch_info_();
}
void EbyteLoraComponent::setup() {
this->pin_aux_->setup();
this->pin_m0_->setup();
@ -15,25 +25,24 @@ void EbyteLoraComponent::get_current_config_() {
set_mode_(CONFIGURATION);
uint8_t data[3] = {PROGRAM_CONF, 0x00, 0x08};
this->write_array(data, sizeof(data));
RegisterConfig buffer;
if (!this->available()) {
return;
}
if (read_array((uint8_t *) &buffer, sizeof(buffer))) {
if (read_array((uint8_t *) &this->config, sizeof(this->config))) {
ESP_LOGD(TAG, "Found config");
ESP_LOGD(TAG, buffer.addh_description_().c_str());
ESP_LOGD(TAG, buffer.addl_description_().c_str());
ESP_LOGD(TAG, buffer.reg_0.air_data_rate_description_().c_str());
ESP_LOGD(TAG, buffer.reg_0.uart_baud_description_().c_str());
ESP_LOGD(TAG, buffer.reg_0.parity_description_().c_str());
ESP_LOGD(TAG, buffer.reg_1.rssi_noise_description_().c_str());
ESP_LOGD(TAG, buffer.reg_1.sub_packet_description_().c_str());
ESP_LOGD(TAG, buffer.reg_1.transmission_power_description_().c_str());
ESP_LOGD(TAG, buffer.channel_description_().c_str());
ESP_LOGD(TAG, buffer.reg_3.enable_lbt_description_().c_str());
ESP_LOGD(TAG, buffer.reg_3.wor_period_description_().c_str());
ESP_LOGD(TAG, buffer.reg_3.enable_rssi_description_().c_str());
ESP_LOGD(TAG, buffer.reg_3.transmission_type_description_().c_str());
ESP_LOGD(TAG, this->config.addh_description_().c_str());
ESP_LOGD(TAG, this->config.addl_description_().c_str());
ESP_LOGD(TAG, this->config.reg_0.air_data_rate_description_().c_str());
ESP_LOGD(TAG, this->config.reg_0.uart_baud_description_().c_str());
ESP_LOGD(TAG, this->config.reg_0.parity_description_().c_str());
ESP_LOGD(TAG, this->config.reg_1.rssi_noise_description_().c_str());
ESP_LOGD(TAG, this->config.reg_1.sub_packet_description_().c_str());
ESP_LOGD(TAG, this->config.reg_1.transmission_power_description_().c_str());
ESP_LOGD(TAG, this->config.channel_description_().c_str());
ESP_LOGD(TAG, this->config.reg_3.enable_lbt_description_().c_str());
ESP_LOGD(TAG, this->config.reg_3.wor_period_description_().c_str());
ESP_LOGD(TAG, this->config.reg_3.enable_rssi_description_().c_str());
ESP_LOGD(TAG, this->config.reg_3.transmission_type_description_().c_str());
set_mode_(NORMAL);
} else {
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");

View file

@ -24,7 +24,7 @@ class EbyteLoraSwitch;
class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
public:
void setup() override;
void update() override { send_switch_info_(); }
void update() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; }
void loop() override;
void dump_config() override;
@ -55,6 +55,7 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
uint32_t starting_to_check_;
uint32_t time_out_after_;
std::string raw_message_;
RegisterConfig config;
sensor::Sensor *rssi_sensor_{nullptr};
GPIOPin *pin_aux_;
GPIOPin *pin_m0_;