Update ebyte_lora_e220.cpp

This commit is contained in:
Daniël Koek 2024-02-01 16:30:23 +00:00
parent fce151a128
commit 372169dbf2

View file

@ -23,7 +23,10 @@ void EbyteLoraE220::setup() {
} }
bool status = setMode(MODE_0_NORMAL); bool status = setMode(MODE_0_NORMAL);
ESP_LOGD(TAG, "setup success %s", status); if (status)
ESP_LOGD(TAG, "Setup success");
else
ESP_LOGD(TAG, "Something went wrong");
} }
bool EbyteLoraE220::setMode(MODE_TYPE mode) { bool EbyteLoraE220::setMode(MODE_TYPE mode) {
// data sheet claims module needs some extra time after mode setting (2ms) // data sheet claims module needs some extra time after mode setting (2ms)
@ -72,12 +75,12 @@ bool EbyteLoraE220::setMode(MODE_TYPE mode) {
if (result) { if (result) {
this->mode = mode; this->mode = mode;
ESP_LOGD(TAG, "Mode set");
return true;
} else { } else {
ESP_LOGD(TAG, "No success"); ESP_LOGD(TAG, "No success setting mode");
return false; return false;
} }
return true;
} }
bool EbyteLoraE220::waitCompleteResponse(unsigned long timeout, unsigned int waitNoAux) { bool EbyteLoraE220::waitCompleteResponse(unsigned long timeout, unsigned int waitNoAux) {
unsigned long t = millis(); unsigned long t = millis();
@ -106,7 +109,6 @@ bool EbyteLoraE220::waitCompleteResponse(unsigned long timeout, unsigned int wai
// per data sheet control after aux goes high is 2ms so delay for at least that long) // per data sheet control after aux goes high is 2ms so delay for at least that long)
delay(20); delay(20);
ESP_LOGD(TAG, "Complete!");
return true; return true;
} }
void EbyteLoraE220::dump_config() { void EbyteLoraE220::dump_config() {
@ -117,20 +119,23 @@ void EbyteLoraE220::dump_config() {
}; };
void EbyteLoraE220::loop() { void EbyteLoraE220::loop() {
// This will be called by App.loop() // This will be called by App.loop()
ESP_LOGD(TAG, "Checking if uart is available");
if (this->available() > 1) { if (!available()) {
return;
}
std::string buffer; std::string buffer;
uint8_t data;
while (this->available() > 0) { ESP_LOGD(TAG, "Starting to read message");
if (this->read_byte(&data)) { while (available()) {
buffer += (char) data; uint8_t c;
if (this->read_byte(&c)) {
buffer += (char) c;
} }
} }
ESP_LOGD(TAG, "%s", buffer); ESP_LOGD(TAG, "%s", buffer);
this->message_text_sensor->publish_state(buffer.substr(0, buffer.length() - 1)); this->message_text_sensor->publish_state(buffer.substr(0, buffer.length() - 1));
this->rssi_sensor->publish_state(atoi(buffer.substr(buffer.length() - 1, 1).c_str())); this->rssi_sensor->publish_state(atoi(buffer.substr(buffer.length() - 1, 1).c_str()));
} }
}
} // namespace ebyte_lora_e220 } // namespace ebyte_lora_e220
} // namespace esphome } // namespace esphome