fix
This commit is contained in:
parent
8d4d957618
commit
2d576b07f3
|
@ -81,7 +81,7 @@ namespace ratgdo {
|
||||||
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter);
|
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::readRollingCode(bool &isStatus, uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction, uint8_t& motor)
|
void RATGDOComponent::readRollingCode(bool& isStatus, uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction, uint8_t& motor)
|
||||||
{
|
{
|
||||||
uint32_t rolling = 0;
|
uint32_t rolling = 0;
|
||||||
uint64_t fixed = 0;
|
uint64_t fixed = 0;
|
||||||
|
@ -130,58 +130,12 @@ namespace ratgdo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::getRollingCode(Commands command)
|
void RATGDOComponent::getRollingCode(command command)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint64_t id = 0x539;
|
uint64_t id = 0x539;
|
||||||
uint64_t fixed = 0;
|
uint64_t fixed = command.fixed;
|
||||||
uint32_t data = 0;
|
uint32_t data = command.data;
|
||||||
|
|
||||||
switch (command) {
|
|
||||||
case REBOOT1:
|
|
||||||
fixed = 0x400000000;
|
|
||||||
data = 0x0000618b;
|
|
||||||
break;
|
|
||||||
case REBOOT2:
|
|
||||||
fixed = 0;
|
|
||||||
data = 0x01009080;
|
|
||||||
break;
|
|
||||||
case REBOOT3:
|
|
||||||
fixed = 0;
|
|
||||||
data = 0x0000b1a0;
|
|
||||||
break;
|
|
||||||
case REBOOT4:
|
|
||||||
fixed = 0;
|
|
||||||
data = 0x01009080;
|
|
||||||
break;
|
|
||||||
case REBOOT5:
|
|
||||||
fixed = 0x300000000;
|
|
||||||
data = 0x00008092;
|
|
||||||
break;
|
|
||||||
case REBOOT6:
|
|
||||||
fixed = 0x300000000;
|
|
||||||
data = 0x00008092;
|
|
||||||
break;
|
|
||||||
case DOOR1:
|
|
||||||
fixed = 0x200000000;
|
|
||||||
data = 0x01018280;
|
|
||||||
break;
|
|
||||||
case DOOR2:
|
|
||||||
fixed = 0x200000000;
|
|
||||||
data = 0x01009280;
|
|
||||||
break;
|
|
||||||
case LIGHT:
|
|
||||||
fixed = 0x200000000;
|
|
||||||
data = 0x00009281;
|
|
||||||
break;
|
|
||||||
case LOCK:
|
|
||||||
fixed = 0x0100000000;
|
|
||||||
data = 0x0000728c;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ESP_LOGD(TAG, "ERROR: Invalid command");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Command: %d rollingCodeCounter=%d", command, this->rollingCodeCounter);
|
ESP_LOGD(TAG, "Command: %d rollingCodeCounter=%d", command, this->rollingCodeCounter);
|
||||||
|
|
||||||
|
@ -191,7 +145,7 @@ namespace ratgdo {
|
||||||
|
|
||||||
printRollingCode();
|
printRollingCode();
|
||||||
|
|
||||||
if (command != Commands::DOOR1) { // door2 is created with same counter and should always be called after door1
|
if (command != Commands.DOOR1) { // door2 is created with same counter and should always be called after door1
|
||||||
incrementRollingCodeCounter();
|
incrementRollingCodeCounter();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -284,8 +238,8 @@ namespace ratgdo {
|
||||||
{
|
{
|
||||||
static uint32_t msgStart;
|
static uint32_t msgStart;
|
||||||
static bool reading = false;
|
static bool reading = false;
|
||||||
static uint16_t byteCount = 0;
|
static uint16_t byteCount = 0;
|
||||||
static bool isStatus = false;
|
static bool isStatus = false;
|
||||||
|
|
||||||
while (this->available()) {
|
while (this->available()) {
|
||||||
// ESP_LOGD(TAG, "No data available input:%d output:%d", this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin());
|
// ESP_LOGD(TAG, "No data available input:%d output:%d", this->input_gdo_pin_->get_pin(), this->output_gdo_pin_->get_pin());
|
||||||
|
@ -362,7 +316,7 @@ namespace ratgdo {
|
||||||
void RATGDOComponent::query()
|
void RATGDOComponent::query()
|
||||||
{
|
{
|
||||||
this->forceUpdate_ = true;
|
this->forceUpdate_ = true;
|
||||||
sendCommandAndSaveCounter(Commands::REBOOT2);
|
sendCommandAndSaveCounter(Commands.REBOOT2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::sendDoorStatus()
|
void RATGDOComponent::sendDoorStatus()
|
||||||
|
@ -430,7 +384,7 @@ namespace ratgdo {
|
||||||
* The opener requires a specific duration low/high pulse before it will accept
|
* The opener requires a specific duration low/high pulse before it will accept
|
||||||
* a message
|
* a message
|
||||||
*/
|
*/
|
||||||
void RATGDOComponent::transmit(Commands command)
|
void RATGDOComponent::transmit(command command)
|
||||||
{
|
{
|
||||||
getRollingCode(command);
|
getRollingCode(command);
|
||||||
this->output_gdo_pin_->digital_write(true); // pull the line high for 1305 micros so the
|
this->output_gdo_pin_->digital_write(true); // pull the line high for 1305 micros so the
|
||||||
|
@ -444,22 +398,22 @@ namespace ratgdo {
|
||||||
|
|
||||||
void RATGDOComponent::sync()
|
void RATGDOComponent::sync()
|
||||||
{
|
{
|
||||||
transmit(Commands::REBOOT1);
|
transmit(Commands.REBOOT1);
|
||||||
delay(65);
|
delay(65);
|
||||||
|
|
||||||
transmit(Commands::REBOOT2);
|
transmit(Commands.REBOOT2);
|
||||||
delay(65);
|
delay(65);
|
||||||
|
|
||||||
transmit(Commands::REBOOT3);
|
transmit(Commands.REBOOT3);
|
||||||
delay(65);
|
delay(65);
|
||||||
|
|
||||||
transmit(Commands::REBOOT4);
|
transmit(Commands.REBOOT4);
|
||||||
delay(65);
|
delay(65);
|
||||||
|
|
||||||
transmit(Commands::REBOOT5);
|
transmit(Commands.REBOOT5);
|
||||||
delay(65);
|
delay(65);
|
||||||
|
|
||||||
sendCommandAndSaveCounter(Commands::REBOOT6);
|
sendCommandAndSaveCounter(Commands.REBOOT6);
|
||||||
delay(65);
|
delay(65);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,9 +446,9 @@ namespace ratgdo {
|
||||||
|
|
||||||
void RATGDOComponent::toggleDoor()
|
void RATGDOComponent::toggleDoor()
|
||||||
{
|
{
|
||||||
transmit(Commands::DOOR1);
|
transmit(Commands.DOOR1);
|
||||||
delay(40);
|
delay(40);
|
||||||
sendCommandAndSaveCounter(Commands::DOOR2);
|
sendCommandAndSaveCounter(Commands.DOOR2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RATGDOComponent::isLightOn()
|
bool RATGDOComponent::isLightOn()
|
||||||
|
@ -528,7 +482,7 @@ namespace ratgdo {
|
||||||
|
|
||||||
void RATGDOComponent::toggleLight()
|
void RATGDOComponent::toggleLight()
|
||||||
{
|
{
|
||||||
sendCommandAndSaveCounter(Commands::LIGHT);
|
sendCommandAndSaveCounter(Commands.LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock functions
|
// Lock functions
|
||||||
|
@ -552,10 +506,10 @@ namespace ratgdo {
|
||||||
|
|
||||||
void RATGDOComponent::toggleLock()
|
void RATGDOComponent::toggleLock()
|
||||||
{
|
{
|
||||||
sendCommandAndSaveCounter(Commands::LOCK);
|
sendCommandAndSaveCounter(Commands.LOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RATGDOComponent::sendCommandAndSaveCounter(Commands command)
|
void RATGDOComponent::sendCommandAndSaveCounter(command command)
|
||||||
{
|
{
|
||||||
transmit(command);
|
transmit(command);
|
||||||
this->pref_.save(&this->rollingCodeCounter);
|
this->pref_.save(&this->rollingCodeCounter);
|
||||||
|
|
|
@ -33,17 +33,36 @@ namespace ratgdo {
|
||||||
// Forward declare RATGDOClient
|
// Forward declare RATGDOClient
|
||||||
class RATGDOClient;
|
class RATGDOClient;
|
||||||
|
|
||||||
enum Commands {
|
typedef struct {
|
||||||
REBOOT1,
|
uint64_t fixed;
|
||||||
REBOOT2,
|
uint32_t data;
|
||||||
REBOOT3,
|
} command;
|
||||||
REBOOT4,
|
|
||||||
REBOOT5,
|
typedef struct {
|
||||||
REBOOT6,
|
command REBOOT1;
|
||||||
DOOR1,
|
command REBOOT2;
|
||||||
DOOR2,
|
command REBOOT3;
|
||||||
LIGHT,
|
command REBOOT4;
|
||||||
LOCK,
|
command REBOOT5;
|
||||||
|
command REBOOT6;
|
||||||
|
command REBOOT4;
|
||||||
|
command DOOR1;
|
||||||
|
command DOOR2;
|
||||||
|
command LIGHT;
|
||||||
|
command LOCK;
|
||||||
|
} commands;
|
||||||
|
|
||||||
|
static const commands Command = {
|
||||||
|
.REBOOT1 = (command) { 0x400000000, 0x0000618b },
|
||||||
|
.REBOOT2 = (command) { 0, 0x01009080 },
|
||||||
|
.REBOOT3 = (command) { 0, 0x0000b1a0 },
|
||||||
|
.REBOOT4 = (command) { 0, 0x01009080 },
|
||||||
|
.REBOOT5 = (command) { 0x300000000, 0x00008092 },
|
||||||
|
.REBOOT6 = (command) { 0x300000000, 0x00008092 },
|
||||||
|
.DOOR1 = (command) { 0x200000000, 0x01018280 },
|
||||||
|
.DOOR2 = (command) { 0x200000000, 0x01009280 },
|
||||||
|
.LIGHT = (command) { 0x200000000, 0x00009281 },
|
||||||
|
.LOCK = (command) { 0x0100000000, 0x0000728c },
|
||||||
};
|
};
|
||||||
struct RATGDOStore {
|
struct RATGDOStore {
|
||||||
ISRInternalGPIOPin input_obst;
|
ISRInternalGPIOPin input_obst;
|
||||||
|
@ -121,7 +140,7 @@ namespace ratgdo {
|
||||||
void getRollingCode(Commands command);
|
void getRollingCode(Commands command);
|
||||||
void gdoStateLoop();
|
void gdoStateLoop();
|
||||||
void statusUpdateLoop();
|
void statusUpdateLoop();
|
||||||
void readRollingCode(bool &isStatus, uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction, uint8_t& motor);
|
void readRollingCode(bool& isStatus, uint8_t& door, uint8_t& light, uint8_t& lock, uint8_t& motion, uint8_t& obstruction, uint8_t& motor);
|
||||||
void incrementRollingCodeCounter();
|
void incrementRollingCodeCounter();
|
||||||
void sendRollingCodeChanged();
|
void sendRollingCodeChanged();
|
||||||
void setRollingCodeCounter(uint32_t counter);
|
void setRollingCodeCounter(uint32_t counter);
|
||||||
|
|
Loading…
Reference in New Issue