mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
more stuff
This commit is contained in:
parent
94e98b47f5
commit
fd58f9002e
2 changed files with 40 additions and 5 deletions
|
@ -7,8 +7,8 @@ void Lora::update() {
|
||||||
if (this->pin_aux_->digital_read()) {
|
if (this->pin_aux_->digital_read()) {
|
||||||
this->starting_to_check_ = 0;
|
this->starting_to_check_ = 0;
|
||||||
this->time_out_after_ = 0;
|
this->time_out_after_ = 0;
|
||||||
} else {
|
|
||||||
ESP_LOGD(TAG, "Aux pin is High! Can send again!");
|
ESP_LOGD(TAG, "Aux pin is High! Can send again!");
|
||||||
|
} else {
|
||||||
// it has taken too long to complete, error out!
|
// it has taken too long to complete, error out!
|
||||||
if ((millis() - this->starting_to_check_) > this->time_out_after_) {
|
if ((millis() - this->starting_to_check_) > this->time_out_after_) {
|
||||||
ESP_LOGD(TAG, "Timeout error! Resetting timers");
|
ESP_LOGD(TAG, "Timeout error! Resetting timers");
|
||||||
|
@ -16,6 +16,7 @@ void Lora::update() {
|
||||||
this->time_out_after_ = 0;
|
this->time_out_after_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get_mode_();
|
||||||
if (!this->update_needed_)
|
if (!this->update_needed_)
|
||||||
return;
|
return;
|
||||||
if (this->rssi_sensor_ != nullptr)
|
if (this->rssi_sensor_ != nullptr)
|
||||||
|
@ -50,6 +51,32 @@ void Lora::setup() {
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Setup success");
|
ESP_LOGD(TAG, "Setup success");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModeType Lora::get_mode_() {
|
||||||
|
if (!Lora::can_send_message_()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ModeType internalMode;
|
||||||
|
bool pin1 = this->pin_m0_->digital_read();
|
||||||
|
bool pin2 = this->pin_m1_->digital_read();
|
||||||
|
if (!pin1 && !pin2) {
|
||||||
|
internalMode = MODE_0_NORMAL;
|
||||||
|
}
|
||||||
|
if (pin1 && !pin2) {
|
||||||
|
internalMode = MODE_1_WOR_TRANSMITTER;
|
||||||
|
}
|
||||||
|
if (!pin1 && pin2) {
|
||||||
|
internalMode = MODE_2_WOR_RECEIVER;
|
||||||
|
}
|
||||||
|
if (pin1 && pin2) {
|
||||||
|
internalMode = MODE_3_CONFIGURATION;
|
||||||
|
}
|
||||||
|
if (internalMode != this->mode_) {
|
||||||
|
ESP_LOGD(TAG, "Modes are not equal, calling the set function!! , checked: %u, expected: %u", internalMode,
|
||||||
|
this->mode_);
|
||||||
|
set_mode_(internalMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
void Lora::set_mode_(ModeType mode) {
|
void Lora::set_mode_(ModeType mode) {
|
||||||
if (!Lora::can_send_message_()) {
|
if (!Lora::can_send_message_()) {
|
||||||
return;
|
return;
|
||||||
|
@ -81,6 +108,9 @@ void Lora::set_mode_(ModeType mode) {
|
||||||
this->pin_m1_->digital_write(true);
|
this->pin_m1_->digital_write(true);
|
||||||
ESP_LOGD(TAG, "MODE SLEEP CONFIG!");
|
ESP_LOGD(TAG, "MODE SLEEP CONFIG!");
|
||||||
break;
|
break;
|
||||||
|
case MODE_INIT:
|
||||||
|
ESP_LOGD(TAG, "Don't call this!");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait until aux pin goes back low
|
// wait until aux pin goes back low
|
||||||
|
@ -91,9 +121,12 @@ void Lora::set_mode_(ModeType mode) {
|
||||||
bool Lora::can_send_message_() {
|
bool Lora::can_send_message_() {
|
||||||
if (this->pin_aux_->digital_read()) {
|
if (this->pin_aux_->digital_read()) {
|
||||||
// If it is high then all good and settings have been saved
|
// If it is high then all good and settings have been saved
|
||||||
this->starting_to_check_ = 0;
|
if (this->starting_to_check_ != 0) {
|
||||||
this->time_out_after_ = 0;
|
this->starting_to_check_ = 0;
|
||||||
ESP_LOGD(TAG, "Aux pin is High! Can send again!");
|
}
|
||||||
|
if (this->time_out_after_ != 0) {
|
||||||
|
this->time_out_after_ = 0;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,6 +24,7 @@ enum ModeType {
|
||||||
MODE_3_CONFIGURATION = 3,
|
MODE_3_CONFIGURATION = 3,
|
||||||
MODE_3_PROGRAM = 3,
|
MODE_3_PROGRAM = 3,
|
||||||
MODE_3_SLEEP = 3,
|
MODE_3_SLEEP = 3,
|
||||||
|
MODE_INIT = 0xFF
|
||||||
};
|
};
|
||||||
class Lora : public PollingComponent, public uart::UARTDevice {
|
class Lora : public PollingComponent, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
|
@ -46,9 +47,10 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
||||||
void set_pin_m1(GPIOPin *s) { pin_m1_ = s; }
|
void set_pin_m1(GPIOPin *s) { pin_m1_ = s; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModeType mode_ = MODE_0_NORMAL;
|
ModeType mode_ = MODE_INIT;
|
||||||
// set WOR mode
|
// set WOR mode
|
||||||
void set_mode_(ModeType mode);
|
void set_mode_(ModeType 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);
|
||||||
bool can_send_message_();
|
bool can_send_message_();
|
||||||
|
|
Loading…
Reference in a new issue