mirror of
https://github.com/esphome/esphome.git
synced 2024-12-28 08:21:44 +01:00
add delays
This commit is contained in:
parent
752fdeff90
commit
f13609783b
2 changed files with 12 additions and 21 deletions
|
@ -94,31 +94,22 @@ bool Lora::set_mode_(ModeType mode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Lora::wait_complete_response_(uint32_t timeout, uint32_t wait_no_aux) {
|
bool Lora::wait_complete_response_(uint32_t timeout) {
|
||||||
uint32_t t = millis();
|
uint32_t start_millis = millis();
|
||||||
|
|
||||||
// make darn sure millis() is not about to reach max data type limit and start over
|
// make darn sure millis() is not about to reach max data type limit and start over
|
||||||
if ((t + timeout) == 0) {
|
if ((start_millis + timeout) == 0) {
|
||||||
t = 0;
|
start_millis = 0;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Checking if response was complete");
|
ESP_LOGD(TAG, "Checking if response was complete");
|
||||||
// if AUX pin was supplied and look for HIGH state
|
// loop till not high, or the timeout is reached
|
||||||
// note you can omit using AUX if no pins are available, but you will have to use delay() to let module finish
|
while (!this->pin_aux_->digital_read()) {
|
||||||
if (this->pin_aux_ != nullptr) {
|
if ((millis() - start_millis) > timeout) {
|
||||||
while (!this->pin_aux_->digital_read()) {
|
ESP_LOGD(TAG, "Timeout error!");
|
||||||
if ((millis() - t) > timeout) {
|
return false;
|
||||||
ESP_LOGD(TAG, "Timeout error!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "AUX HIGH!");
|
delay(50);
|
||||||
} else {
|
|
||||||
// if you can't use aux pin, use 4K7 pullup with Arduino
|
|
||||||
// you may need to adjust this value if transmissions fail
|
|
||||||
delay(wait_no_aux);
|
|
||||||
ESP_LOGD(TAG, "Wait no AUX pin!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
return true;
|
return true;
|
||||||
|
@ -139,7 +130,7 @@ bool Lora::send_pin_info_(uint8_t pin, bool value) {
|
||||||
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]);
|
||||||
this->write_array(data, sizeof(data));
|
this->write_array(data, sizeof(data));
|
||||||
bool return_value = this->wait_complete_response_(5000, 5000);
|
bool return_value = this->wait_complete_response_(5000);
|
||||||
this->flush();
|
this->flush();
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
||||||
// set WOR mode
|
// set WOR mode
|
||||||
bool set_mode_(ModeType mode);
|
bool set_mode_(ModeType mode);
|
||||||
// checks the aux port to see if it is done setting
|
// checks the aux port to see if it is done setting
|
||||||
bool wait_complete_response_(uint32_t timeout = 1000, uint32_t wait_no_aux = 100);
|
bool wait_complete_response_(uint32_t timeout = 1000);
|
||||||
bool send_pin_info_(uint8_t pin, bool value);
|
bool send_pin_info_(uint8_t pin, bool value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue