fix
This commit is contained in:
parent
a6125240b0
commit
1c09148ea1
|
@ -13,8 +13,6 @@
|
|||
|
||||
#include "ratgdo.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
@ -92,10 +90,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
class RATGDOComponent : public uart::UARTDevice, public Component {
|
||||
public:
|
||||
|
||||
void setup() override
|
||||
void RATGDOComponent::setup()
|
||||
{
|
||||
this->pref_ = global_preferences->make_preference<int>(734874333U);
|
||||
if (!this->pref_.load(&this->rollingCodeCounter)) {
|
||||
|
@ -142,7 +137,7 @@ namespace ratgdo {
|
|||
// reboot/sync to the opener on startup
|
||||
}
|
||||
|
||||
void loop() override
|
||||
void RATGDOComponent::loop()
|
||||
{
|
||||
ESP_LOGD(TAG, "loop rollingCodeCounter: %d", this->rollingCodeCounter);
|
||||
obstructionLoop();
|
||||
|
@ -152,7 +147,7 @@ namespace ratgdo {
|
|||
// ESP_LOGD(TAG, "Door State: %s", this->doorState.c_str());
|
||||
}
|
||||
|
||||
void readRollingCode(uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction)
|
||||
void RATGDOComponent::readRollingCode(uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction)
|
||||
{
|
||||
uint32_t rolling = 0;
|
||||
uint64_t fixed = 0;
|
||||
|
@ -186,7 +181,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void getRollingCode(const char* command)
|
||||
void RATGDOComponent::getRollingCode(const char* command)
|
||||
{
|
||||
|
||||
uint64_t id = 0x539;
|
||||
|
@ -240,7 +235,7 @@ namespace ratgdo {
|
|||
return;
|
||||
}
|
||||
|
||||
void printRollingCode()
|
||||
void RATGDOComponent::printRollingCode()
|
||||
{
|
||||
for (int i = 0; i < CODE_LENGTH; i++) {
|
||||
if (this->txRollingCode[i] <= 0x0f)
|
||||
|
@ -250,7 +245,7 @@ namespace ratgdo {
|
|||
}
|
||||
|
||||
// handle changes to the dry contact state
|
||||
void dryContactLoop()
|
||||
void RATGDOComponent::dryContactLoop()
|
||||
{
|
||||
if (this->store_.dryContactDoorOpen) {
|
||||
ESP_LOGD(TAG, "Dry Contact: open the door");
|
||||
|
@ -272,7 +267,8 @@ namespace ratgdo {
|
|||
}
|
||||
|
||||
/*************************** OBSTRUCTION DETECTION ***************************/
|
||||
void obstructionLoop()
|
||||
|
||||
void RATGDOComponent::obstructionLoop()
|
||||
{
|
||||
long currentMillis = millis();
|
||||
static unsigned long lastMillis = 0;
|
||||
|
@ -306,7 +302,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void gdoStateLoop()
|
||||
void RATGDOComponent::gdoStateLoop()
|
||||
{
|
||||
if (!this->swSerial.available()) {
|
||||
// ESP_LOGD(TAG, "No data available input:%d output:%d", this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin());
|
||||
|
@ -352,7 +348,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void statusUpdateLoop()
|
||||
void RATGDOComponent::statusUpdateLoop()
|
||||
{
|
||||
// initialize to unknown
|
||||
static uint8_t previousDoorState = 0;
|
||||
|
@ -380,29 +376,29 @@ namespace ratgdo {
|
|||
previousObstructionState = this->store_.obstructionState;
|
||||
}
|
||||
|
||||
void sendDoorStatus()
|
||||
void RATGDOComponent::sendDoorStatus()
|
||||
{
|
||||
ESP_LOGD(TAG, "Door state %d", this->store_.doorState);
|
||||
this->status_door_pin_->digital_write(this->store_.doorState == 1);
|
||||
}
|
||||
|
||||
void sendLightStatus()
|
||||
void RATGDOComponent::sendLightStatus()
|
||||
{
|
||||
ESP_LOGD(TAG, "Light state %d", this->store_.lightState);
|
||||
}
|
||||
|
||||
void sendLockStatus()
|
||||
void RATGDOComponent::sendLockStatus()
|
||||
{
|
||||
ESP_LOGD(TAG, "Lock state %d", this->store_.lockState);
|
||||
}
|
||||
|
||||
void sendMotionStatus()
|
||||
void RATGDOComponent::sendMotionStatus()
|
||||
{
|
||||
ESP_LOGD(TAG, "Motion state %d", this->store_.motionState);
|
||||
this->store_.motionState = 0; // reset motion state
|
||||
}
|
||||
|
||||
void sendObstructionStatus()
|
||||
void RATGDOComponent::sendObstructionStatus()
|
||||
{
|
||||
ESP_LOGD(TAG, "Obstruction state %d", this->store_.obstructionState);
|
||||
this->status_obst_pin_->digital_write(this->store_.obstructionState == 0);
|
||||
|
@ -417,7 +413,7 @@ namespace ratgdo {
|
|||
* The opener requires a specific duration low/high pulse before it will accept
|
||||
* a message
|
||||
*/
|
||||
void transmit(const unsigned char* payload)
|
||||
void RATGDOComponent::transmit(const unsigned char* payload)
|
||||
{
|
||||
this->output_gdo_pin_->digital_write(true); // pull the line high for 1305 micros so the
|
||||
// door opener responds to the message
|
||||
|
@ -428,7 +424,7 @@ namespace ratgdo {
|
|||
this->swSerial.write(payload, CODE_LENGTH);
|
||||
}
|
||||
|
||||
void sync()
|
||||
void RATGDOComponent::sync()
|
||||
{
|
||||
getRollingCode("reboot1");
|
||||
transmit(this->txRollingCode);
|
||||
|
@ -457,7 +453,7 @@ namespace ratgdo {
|
|||
this->pref_.save(&this->rollingCodeCounter);
|
||||
}
|
||||
|
||||
void openDoor()
|
||||
void RATGDOComponent::openDoor()
|
||||
{
|
||||
if (this->doorStates[this->store_.doorState] == "open" || doorStates[this->store_.doorState] == "opening") {
|
||||
ESP_LOGD(TAG, "The door is already %s", this->doorStates[this->store_.doorState]);
|
||||
|
@ -466,7 +462,7 @@ namespace ratgdo {
|
|||
toggleDoor();
|
||||
}
|
||||
|
||||
void closeDoor()
|
||||
void RATGDOComponent::closeDoor()
|
||||
{
|
||||
if (this->doorStates[this->store_.doorState] == "closed" || doorStates[this->store_.doorState] == "closing") {
|
||||
ESP_LOGD(TAG, "The door is already %s", this->doorStates[this->store_.doorState]);
|
||||
|
@ -475,7 +471,7 @@ namespace ratgdo {
|
|||
toggleDoor();
|
||||
}
|
||||
|
||||
void stopDoor()
|
||||
void RATGDOComponent::stopDoor()
|
||||
{
|
||||
if (this->doorStates[this->store_.doorState] == "opening" || doorStates[this->store_.doorState] == "closing") {
|
||||
toggleDoor();
|
||||
|
@ -484,7 +480,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void toggleDoor()
|
||||
void RATGDOComponent::toggleDoor()
|
||||
{
|
||||
getRollingCode("door1");
|
||||
transmit(this->txRollingCode);
|
||||
|
@ -494,7 +490,7 @@ namespace ratgdo {
|
|||
this->pref_.save(&this->rollingCodeCounter);
|
||||
}
|
||||
|
||||
void lightOn()
|
||||
void RATGDOComponent::lightOn()
|
||||
{
|
||||
if (this->lightStates[this->store_.lightState] == "on") {
|
||||
ESP_LOGD(TAG, "already on");
|
||||
|
@ -503,7 +499,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void lightOff()
|
||||
void RATGDOComponent::lightOff()
|
||||
{
|
||||
if (this->lightStates[this->store_.lightState] == "off") {
|
||||
ESP_LOGD(TAG, "already off");
|
||||
|
@ -512,13 +508,13 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void toggleLight()
|
||||
void RATGDOComponent::toggleLight()
|
||||
{
|
||||
sendCommand("light");
|
||||
}
|
||||
|
||||
// Lock functions
|
||||
void lock()
|
||||
void RATGDOComponent::lock()
|
||||
{
|
||||
if (this->lockStates[this->store_.lockState] == "locked") {
|
||||
ESP_LOGD(TAG, "already locked");
|
||||
|
@ -527,7 +523,7 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void unlock()
|
||||
void RATGDOComponent::unlock()
|
||||
{
|
||||
if (this->lockStates[this->store_.lockState] == "unlocked") {
|
||||
ESP_LOGD(TAG, "already unlocked");
|
||||
|
@ -536,17 +532,17 @@ namespace ratgdo {
|
|||
}
|
||||
}
|
||||
|
||||
void toggleLock()
|
||||
void RATGDOComponent::toggleLock()
|
||||
{
|
||||
sendCommand("lock");
|
||||
}
|
||||
|
||||
void sendCommand(const char* command)
|
||||
void RATGDOComponent::sendCommand(const char* command)
|
||||
{
|
||||
getRollingCode(command);
|
||||
transmit(this->txRollingCode);
|
||||
this->pref_.save(&this->rollingCodeCounter);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
************************************/
|
||||
|
||||
#pragma once
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
|
||||
#include "SoftwareSerial.h"
|
||||
extern "C" {
|
||||
|
@ -29,7 +28,6 @@ extern "C" {
|
|||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
||||
|
||||
struct RATGDOStore {
|
||||
ISRInternalGPIOPin input_obst;
|
||||
|
||||
|
|
Loading…
Reference in New Issue