Add ability to send repeats via API. Tweak 80-bit timing

Add the ability to identify how many repeats you want on the API command.
Fix timing for bit output when the shade is configured for 80-bits
This commit is contained in:
Robert Strouse 2023-03-19 16:54:19 -07:00
parent 370b8f1a23
commit d3acf6bb5f
4 changed files with 13 additions and 7 deletions

View file

@ -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);

View file

@ -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);

Binary file not shown.

10
Web.cpp
View file

@ -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<uint8_t>();
}
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>();
}
}
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<JsonObject>();
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<uint8_t>();
}
if(obj.containsKey("repeat")) repeat = obj["repeat"].as<uint8_t>();
}
}
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<JsonObject>();
shade->toJSON(sobj);