diff --git a/Somfy.cpp b/Somfy.cpp index ceb54d3..6778f74 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -1468,7 +1468,7 @@ void SomfyShadeController::sendFrame(somfy_frame_t &frame, uint8_t repeat) { byte frm[10]; frame.encodeFrame(frm); - this->transceiver.sendFrame(frm, frame.bitLength == 56 ? 2 : 12); + this->transceiver.sendFrame(frm, frame.bitLength == 56 ? 2 : 12, frame.bitLength); // Transform the repeat bytes switch(frame.cmd) { case somfy_commands::StepUp: @@ -1483,7 +1483,7 @@ void SomfyShadeController::sendFrame(somfy_frame_t &frame, uint8_t repeat) { break; } for(uint8_t i = 0; i < repeat; i++) { - this->transceiver.sendFrame(frm, frame.bitLength == 56 ? 7 : 6); + this->transceiver.sendFrame(frm, frame.bitLength == 56 ? 7 : 6, frame.bitLength); } this->transceiver.endTransmit(); } @@ -1622,7 +1622,7 @@ bool somfy_rx_queue_t::pop(somfy_rx_t *rx) { } return false; } -void Transceiver::sendFrame(byte *frame, uint8_t sync) { +void Transceiver::sendFrame(byte *frame, uint8_t sync, uint8_t bitLength) { if(!this->config.enabled) return; uint32_t pin = 1 << this->config.TXPin; if (sync == 2 || sync == 12) { // Only with the first frame. @@ -1647,7 +1647,7 @@ void Transceiver::sendFrame(byte *frame, uint8_t sync) { delayMicroseconds(SYMBOL); // Data: bits are sent one by one, starting with the MSB. // TODO: Handle the 80-bit send protocol - for (byte i = 0; i < bit_length; i++) { + for (byte i = 0; i < bitLength; i++) { if (((frame[i / 8] >> (7 - (i % 8))) & 1) == 1) { REG_WRITE(GPIO_OUT_W1TC_REG, pin); delayMicroseconds(SYMBOL); diff --git a/Somfy.h b/Somfy.h index 49cf7fa..5a85298 100644 --- a/Somfy.h +++ b/Somfy.h @@ -267,7 +267,7 @@ class Transceiver { void enableReceive(); void disableReceive(); somfy_frame_t& lastFrame(); - void sendFrame(byte *frame, uint8_t sync); + void sendFrame(byte *frame, uint8_t sync, uint8_t bitLength = 56); void beginTransmit(); void endTransmit(); void emitFrame(somfy_frame_t *frame, somfy_rx_t *rx = nullptr); diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 556d5f8..ecab614 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/Web.cpp b/Web.cpp index db402f0..51befde 100644 --- a/Web.cpp +++ b/Web.cpp @@ -118,12 +118,14 @@ void Web::begin() { HTTPMethod method = apiServer.method(); uint8_t shadeId = 255; uint8_t target = 255; + uint8_t repeat = 1; somfy_commands command = somfy_commands::My; if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) { if (apiServer.hasArg("shadeId")) { shadeId = atoi(apiServer.arg("shadeId").c_str()); if (apiServer.hasArg("command")) command = translateSomfyCommand(apiServer.arg("command")); else if(apiServer.hasArg("target")) target = atoi(apiServer.arg("target").c_str()); + if(apiServer.hasArg("repeat")) repeat = atoi(apiServer.arg("repeat").c_str()); } else if (apiServer.hasArg("plain")) { Serial.println("Sending Shade Command"); @@ -154,6 +156,7 @@ void Web::begin() { else if(obj.containsKey("target")) { target = obj["target"].as(); } + if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); } } else apiServer.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); @@ -166,7 +169,7 @@ void Web::begin() { if(target >= 0 && target <= 100) shade->moveToTarget(target); else - shade->sendCommand(command); + shade->sendCommand(command, repeat); DynamicJsonDocument sdoc(256); JsonObject sobj = sdoc.to(); shade->toJSON(sobj); @@ -702,12 +705,14 @@ void Web::begin() { HTTPMethod method = server.method(); uint8_t shadeId = 255; uint8_t target = 255; + uint8_t repeat = 1; somfy_commands command = somfy_commands::My; if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) { if (server.hasArg("shadeId")) { shadeId = atoi(server.arg("shadeId").c_str()); if (server.hasArg("command")) command = translateSomfyCommand(server.arg("command")); else if(server.hasArg("target")) target = atoi(server.arg("target").c_str()); + if(server.hasArg("repeat")) repeat = atoi(server.arg("repeat").c_str()); } else if (server.hasArg("plain")) { Serial.println("Sending Shade Command"); @@ -738,6 +743,7 @@ void Web::begin() { else if(obj.containsKey("target")) { target = obj["target"].as(); } + if(obj.containsKey("repeat")) repeat = obj["repeat"].as(); } } else server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"No shade object supplied.\"}")); @@ -750,7 +756,7 @@ void Web::begin() { if(target >= 0 && target <= 100) shade->moveToTarget(target); else - shade->sendCommand(command); + shade->sendCommand(command, repeat); DynamicJsonDocument sdoc(512); JsonObject sobj = sdoc.to(); shade->toJSON(sobj);