From 9e3f87cc259d21c138412120cae8dfe5801df9a5 Mon Sep 17 00:00:00 2001 From: sqozz Date: Mon, 12 Mar 2018 23:39:14 +0100 Subject: [PATCH] Add codes for brennenstuhl plugs --- espower.ino | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/espower.ino b/espower.ino index f047c03..f7bffae 100644 --- a/espower.ino +++ b/espower.ino @@ -33,13 +33,20 @@ typedef struct { char* id; String name; bool powered; + uint8_t type; // 0=DIP, 1=Learned + int on_code; + int off_code; } PowerSocket; PowerSocket sockets[] = { - (PowerSocket) {"00000", "10000", "A", false}, - (PowerSocket) {"00000", "01000", "B", false}, - (PowerSocket) {"00000", "00100", "C", false}, - (PowerSocket) {"00000", "00010", "D", false} + (PowerSocket) {"00000", "10000", "A", false, 0, -1, -1}, + (PowerSocket) {"00000", "01000", "B", false, 0, -1, -1}, + (PowerSocket) {"00000", "00100", "C", false, 0, -1, -1}, + (PowerSocket) {"00000", "00010", "D", false, 0, -1, -1}, + (PowerSocket) {"", "", "E", false, 1, 530800, 713872}, + (PowerSocket) {"", "", "F", false, 1, 172340, 409380}, + (PowerSocket) {"", "", "G", false, 1, 842428, 409388}, + (PowerSocket) {"", "", "H", false, 1, 713874, 530802} }; int numofsockets = sizeof(sockets)/sizeof(sockets[0]); @@ -187,12 +194,29 @@ String setSocket(int socketIdx, bool newStatus) { sockets[socketIdx] = socket; // write back to status array if (newStatus == true) { for (char i = 0; i <= 1; i++) { - mySwitch.switchOn(socket.channel, socket.id); + if (socket.type == 0) { + Serial.println("id socket"); + mySwitch.setProtocol(1); + mySwitch.switchOn(socket.channel, socket.id); + } else if (socket.type == 1) { + Serial.println("learning socket"); + mySwitch.setProtocol(5); + mySwitch.send(socket.on_code, 24); + } delay(250); } } else { for (char i = 0; i <= 1; i++) { - mySwitch.switchOff(socket.channel, socket.id); + if (socket.type == 0) { + Serial.println("id socket"); + mySwitch.setProtocol(1); + mySwitch.switchOff(socket.channel, socket.id); + } else if (socket.type == 1) { + Serial.println("learning socket"); + char* off_code = socket.id; + mySwitch.setProtocol(5); + mySwitch.send(socket.off_code, 24); + } delay(250); } }