mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 03:04:12 +01:00
add more logic! exiting
This commit is contained in:
parent
39bd77242a
commit
822100ae16
2 changed files with 9 additions and 6 deletions
|
@ -5,7 +5,6 @@ namespace lora {
|
||||||
void Lora::update() {
|
void Lora::update() {
|
||||||
can_send_message_();
|
can_send_message_();
|
||||||
get_mode_();
|
get_mode_();
|
||||||
check_for_message_();
|
|
||||||
if (!this->update_needed_)
|
if (!this->update_needed_)
|
||||||
return;
|
return;
|
||||||
if (this->rssi_sensor_ != nullptr)
|
if (this->rssi_sensor_ != nullptr)
|
||||||
|
@ -147,7 +146,7 @@ void Lora::send_pin_info_(uint8_t pin, bool value) {
|
||||||
this->setup_wait_response_(5000);
|
this->setup_wait_response_(5000);
|
||||||
ESP_LOGD(TAG, "Successfully put in queue");
|
ESP_LOGD(TAG, "Successfully put in queue");
|
||||||
}
|
}
|
||||||
void Lora::check_for_message_() {
|
void Lora::loop() {
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
bool pin_data_found = false;
|
bool pin_data_found = false;
|
||||||
|
@ -160,6 +159,7 @@ void Lora::check_for_message_() {
|
||||||
buffer += (char) c;
|
buffer += (char) c;
|
||||||
// indicates that there is pin data, lets capture that
|
// indicates that there is pin data, lets capture that
|
||||||
if (c == 0xA5) {
|
if (c == 0xA5) {
|
||||||
|
ESP_LOGD(TAG, "Found pin data!");
|
||||||
pin_data_found = true;
|
pin_data_found = true;
|
||||||
}
|
}
|
||||||
if (pin_data_found)
|
if (pin_data_found)
|
||||||
|
@ -167,18 +167,22 @@ void Lora::check_for_message_() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->update_needed_ = true;
|
this->update_needed_ = true;
|
||||||
ESP_LOGD(TAG, "Got %s", buffer.c_str());
|
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
ESP_LOGD(TAG, "Found pin data!");
|
ESP_LOGD(TAG, "Found pin data!");
|
||||||
ESP_LOGD(TAG, "PIN: %u ", data[1]);
|
ESP_LOGD(TAG, "PIN: %u ", data[1]);
|
||||||
ESP_LOGD(TAG, "VALUE: %u ", data[2]);
|
ESP_LOGD(TAG, "VALUE: %u ", data[2]);
|
||||||
|
} else {
|
||||||
|
ESP_LOGD(TAG, "Got %s", buffer.c_str());
|
||||||
}
|
}
|
||||||
char *ptr;
|
char *ptr;
|
||||||
// set the rssi
|
// set the rssi
|
||||||
rssi_ = strtol(buffer.substr(buffer.length() - 1, 1).c_str(), &ptr, 2);
|
rssi_ = strtol(buffer.substr(buffer.length() - 1, 1).c_str(), &ptr, 2);
|
||||||
ESP_LOGD(TAG, "RSSI: %u ", rssi_);
|
ESP_LOGD(TAG, "RSSI: %u ", rssi_);
|
||||||
// set the raw message
|
// set the raw message
|
||||||
raw_message_ = buffer.substr(0, buffer.length() - 1);
|
if (!pin_data_found) {
|
||||||
|
raw_message_ = buffer.substr(0, buffer.length() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace lora
|
} // namespace lora
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
||||||
void setup() override;
|
void setup() override;
|
||||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
||||||
void update() override;
|
void update() override;
|
||||||
|
void loop() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
/// Helper function to write the value of a pin.
|
/// Helper function to write the value of a pin.
|
||||||
void digital_write(uint8_t pin, bool value);
|
void digital_write(uint8_t pin, bool value);
|
||||||
|
@ -45,7 +45,6 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
||||||
ModeType mode_ = MODE_INIT;
|
ModeType mode_ = MODE_INIT;
|
||||||
// set WOR mode
|
// set WOR mode
|
||||||
void set_mode_(ModeType mode);
|
void set_mode_(ModeType mode);
|
||||||
void check_for_message_();
|
|
||||||
ModeType get_mode_();
|
ModeType get_mode_();
|
||||||
// checks the aux port to see if it is done setting
|
// checks the aux port to see if it is done setting
|
||||||
void setup_wait_response_(uint32_t timeout = 1000);
|
void setup_wait_response_(uint32_t timeout = 1000);
|
||||||
|
|
Loading…
Reference in a new issue