fix
This commit is contained in:
parent
e1fda67378
commit
8d2b6823fd
|
@ -87,55 +87,6 @@ namespace ratgdo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire on RISING edge of RPM1
|
|
||||||
void IRAM_ATTR HOT RATGDOStore::isrRPM1(RATGDOStore *arg) {
|
|
||||||
arg->rpm1Pulsed = true;
|
|
||||||
ESP_LOGD(TAG, "isrRPM1 rpm1Pulsed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire on RISING edge of RPM2
|
|
||||||
// When RPM1 HIGH on RPM2 rising edge, door closing:
|
|
||||||
// RPM1: __|--|___
|
|
||||||
// RPM2: ___|--|__
|
|
||||||
|
|
||||||
// When RPM1 LOW on RPM2 rising edge, door opening:
|
|
||||||
// RPM1: ___|--|__
|
|
||||||
// RPM2: __|--|___
|
|
||||||
void IRAM_ATTR HOT RATGDOStore::isrRPM2(RATGDOStore *arg)
|
|
||||||
{
|
|
||||||
unsigned long currentMillis = millis();
|
|
||||||
|
|
||||||
// The encoder updates faster than the ESP wants to process, so by sampling
|
|
||||||
// every 5ms we get a more reliable curve The counter is behind the actual
|
|
||||||
// pulse counter, but it doesn't matter since we only need a reliable linear
|
|
||||||
// counter to determine the door direction
|
|
||||||
if (currentMillis - arg->lastPulse < 5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In rare situations, the rotary encoder can be parked so that RPM2
|
|
||||||
// continuously fires this ISR. This causes the door counter to change value
|
|
||||||
// even though the door isn't moving To solve this, check to see if RPM1
|
|
||||||
// pulsed. If not, do nothing. If yes, reset the pulsed flag
|
|
||||||
if (arg->rpm1Pulsed) {
|
|
||||||
arg->rpm1Pulsed = false;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg->lastPulse = currentMillis;
|
|
||||||
|
|
||||||
// If the RPM1 state is different from the RPM2 state, then the door is
|
|
||||||
// opening
|
|
||||||
if (arg->input_rpm1.digital_read()) {
|
|
||||||
ESP_LOGD(TAG, "isrRPM2 RPM1 HIGH");
|
|
||||||
arg->doorPositionCounter--;
|
|
||||||
} else {
|
|
||||||
ESP_LOGD(TAG, "isrRPM2 RPM1 LOW");
|
|
||||||
arg->doorPositionCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR HOT RATGDOStore::isrObstruction(RATGDOStore *arg)
|
void IRAM_ATTR HOT RATGDOStore::isrObstruction(RATGDOStore *arg)
|
||||||
{
|
{
|
||||||
if (arg->input_obst.digital_read()) {
|
if (arg->input_obst.digital_read()) {
|
||||||
|
@ -535,28 +486,6 @@ namespace ratgdo {
|
||||||
this->status_obst_pin_->digital_write(this->store_.obstructionState == 0);
|
this->status_obst_pin_->digital_write(this->store_.obstructionState == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::obstructionDetected()
|
|
||||||
{
|
|
||||||
static unsigned long lastInterruptTime = 0;
|
|
||||||
unsigned long interruptTime = millis();
|
|
||||||
// Anything less than 100ms is a bounce and is ignored
|
|
||||||
if (interruptTime - lastInterruptTime > 250) {
|
|
||||||
this->store_.doorIsObstructed = true;
|
|
||||||
this->status_obst_pin_->digital_write(true);
|
|
||||||
ESP_LOGD(TAG, "Obstruction Detected");
|
|
||||||
}
|
|
||||||
lastInterruptTime = interruptTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RATGDOComponent::obstructionCleared()
|
|
||||||
{
|
|
||||||
if (this->store_.doorIsObstructed) {
|
|
||||||
this->store_.doorIsObstructed = false;
|
|
||||||
this->status_obst_pin_->digital_write(false);
|
|
||||||
ESP_LOGD(TAG, "Obstruction Cleared");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************* DOOR COMMUNICATION *************************/
|
/************************* DOOR COMMUNICATION *************************/
|
||||||
/*
|
/*
|
||||||
* Transmit a message to the door opener over uart1
|
* Transmit a message to the door opener over uart1
|
||||||
|
|
|
@ -50,7 +50,12 @@ namespace ratgdo {
|
||||||
int obstructionLowCount = 0; // count obstruction low pulses
|
int obstructionLowCount = 0; // count obstruction low pulses
|
||||||
long lastObstructionHigh = 0; // count time between high pulses from the obst ISR
|
long lastObstructionHigh = 0; // count time between high pulses from the obst ISR
|
||||||
|
|
||||||
bool doorIsObstructed { false };
|
uint8_t obstructionState = 2;
|
||||||
|
uint8_t motionState = 0;
|
||||||
|
uint8_t lockState = 2;
|
||||||
|
uint8_t lightState = 2;
|
||||||
|
uint8_t doorState = 0;
|
||||||
|
|
||||||
bool dryContactDoorOpen { false };
|
bool dryContactDoorOpen { false };
|
||||||
bool dryContactDoorClose { false };
|
bool dryContactDoorClose { false };
|
||||||
bool dryContactToggleLight { false };
|
bool dryContactToggleLight { false };
|
||||||
|
@ -73,8 +78,11 @@ namespace ratgdo {
|
||||||
SoftwareSerial swSerial;
|
SoftwareSerial swSerial;
|
||||||
uint8_t txRollingCode[CODE_LENGTH];
|
uint8_t txRollingCode[CODE_LENGTH];
|
||||||
uint8_t rxRollingCode[CODE_LENGTH];
|
uint8_t rxRollingCode[CODE_LENGTH];
|
||||||
String doorState = "unknown"; // will be
|
String doorStates[6] = {"unknown","open","closed","stopped","opening","closing"};
|
||||||
// [online|offline|opening|open|closing|closed|obstructed|clear|reed_open|reed_closed]
|
String lightStates[3] = {"off","on","unknown"};
|
||||||
|
String lockStates[3] = {"unlocked","locked","unknown"};
|
||||||
|
String motionStates[2] = {"clear","detected"};
|
||||||
|
String obstructionStates[3] = {"obstructed","clear","unknown"};
|
||||||
|
|
||||||
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; };
|
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; };
|
||||||
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
|
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
|
||||||
|
|
Loading…
Reference in New Issue