feat: add support for disabling the obstruction pin (#39)

This commit is contained in:
J. Nick Koston 2023-08-26 08:11:02 -05:00 committed by GitHub
parent 0c07766cab
commit a1b166e563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 15 deletions

View File

@ -45,17 +45,21 @@ namespace ratgdo {
void RATGDOComponent::setup() void RATGDOComponent::setup()
{ {
this->output_gdo_pin_->setup(); this->output_gdo_pin_->setup();
this->input_gdo_pin_->setup();
this->input_obst_pin_->setup();
this->isr_store_.input_obst = this->input_obst_pin_->to_isr();
this->output_gdo_pin_->pin_mode(gpio::FLAG_OUTPUT); this->output_gdo_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->input_gdo_pin_->setup();
this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
if (this->input_obst_pin_ == nullptr || this->input_obst_pin_->get_pin() == 0) {
// Our base.yaml is always going to set this so we check for 0
// as well to avoid a breaking change.
this->obstruction_from_status_ = true;
} else {
this->input_obst_pin_->setup();
this->isr_store_.input_obst = this->input_obst_pin_->to_isr();
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT); this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT);
this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_ANY_EDGE); this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_ANY_EDGE);
}
this->sw_serial_.begin(9600, SWSERIAL_8N1, this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin(), true); this->sw_serial_.begin(9600, SWSERIAL_8N1, this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin(), true);
ESP_LOGV(TAG, "Syncing rolling code counter after reboot..."); ESP_LOGV(TAG, "Syncing rolling code counter after reboot...");
@ -71,7 +75,9 @@ namespace ratgdo {
return; return;
} }
} }
if (!this->obstruction_from_status_) {
this->obstruction_loop(); this->obstruction_loop();
}
this->gdo_state_loop(); this->gdo_state_loop();
} }
@ -80,7 +86,11 @@ namespace ratgdo {
ESP_LOGCONFIG(TAG, "Setting up RATGDO..."); ESP_LOGCONFIG(TAG, "Setting up RATGDO...");
LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_); LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_);
LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_); LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_);
if (this->obstruction_from_status_) {
ESP_LOGCONFIG(TAG, " Input Obstruction Pin: not used, will detect from GDO status");
} else {
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_); LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
}
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", *this->rolling_code_counter); ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", *this->rolling_code_counter);
ESP_LOGCONFIG(TAG, " Remote ID: %d", this->remote_id_); ESP_LOGCONFIG(TAG, " Remote ID: %d", this->remote_id_);
} }
@ -171,7 +181,15 @@ namespace ratgdo {
this->lock_state = static_cast<LockState>(byte2 & 1); // safe because it can only be 0 or 1 this->lock_state = static_cast<LockState>(byte2 & 1); // safe because it can only be 0 or 1
this->motion_state = MotionState::CLEAR; // when the status message is read, reset motion state to 0|clear this->motion_state = MotionState::CLEAR; // when the status message is read, reset motion state to 0|clear
this->motor_state = MotorState::OFF; // when the status message is read, reset motor state to 0|off this->motor_state = MotorState::OFF; // when the status message is read, reset motor state to 0|off
// this->obstruction_state = static_cast<ObstructionState>((byte1 >> 6) & 1);
if (this->obstruction_from_status_) {
// ESP_LOGD(TAG, "Obstruction: reading from byte2, bit2, status=%d", ((byte2 >> 2) & 1) == 1);
this->obstruction_state = static_cast<ObstructionState>((byte1 >> 6) & 1);
// This isn't very fast to update, but its still better
// than nothing in the case the obstruction sensor is not
// wired up.
ESP_LOGD(TAG, "Obstruction: reading from GDO status byte1, bit6=%s", ObstructionState_to_string(*this->obstruction_state));
}
if (door_state == DoorState::CLOSED && door_state != prev_door_state) { if (door_state == DoorState::CLOSED && door_state != prev_door_state) {
this->send_command(Command::GET_OPENINGS); this->send_command(Command::GET_OPENINGS);

View File

@ -185,12 +185,14 @@ namespace ratgdo {
protected: protected:
// tx data // tx data
bool transmit_pending_ {false}; bool transmit_pending_ { false };
WirePacket tx_packet_; WirePacket tx_packet_;
RATGDOStore isr_store_ {}; RATGDOStore isr_store_ {};
SoftwareSerial sw_serial_; SoftwareSerial sw_serial_;
bool obstruction_from_status_ { false };
InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* output_gdo_pin_;
InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_gdo_pin_;
InternalGPIOPin* input_obst_pin_; InternalGPIOPin* input_obst_pin_;