mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-14 03:22:12 +01:00
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:
parent
370b8f1a23
commit
d3acf6bb5f
4 changed files with 13 additions and 7 deletions
|
|
@ -1468,7 +1468,7 @@ void SomfyShadeController::sendFrame(somfy_frame_t &frame, uint8_t repeat) {
|
||||||
|
|
||||||
byte frm[10];
|
byte frm[10];
|
||||||
frame.encodeFrame(frm);
|
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
|
// Transform the repeat bytes
|
||||||
switch(frame.cmd) {
|
switch(frame.cmd) {
|
||||||
case somfy_commands::StepUp:
|
case somfy_commands::StepUp:
|
||||||
|
|
@ -1483,7 +1483,7 @@ void SomfyShadeController::sendFrame(somfy_frame_t &frame, uint8_t repeat) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for(uint8_t i = 0; i < repeat; i++) {
|
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();
|
this->transceiver.endTransmit();
|
||||||
}
|
}
|
||||||
|
|
@ -1622,7 +1622,7 @@ bool somfy_rx_queue_t::pop(somfy_rx_t *rx) {
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
if(!this->config.enabled) return;
|
||||||
uint32_t pin = 1 << this->config.TXPin;
|
uint32_t pin = 1 << this->config.TXPin;
|
||||||
if (sync == 2 || sync == 12) { // Only with the first frame.
|
if (sync == 2 || sync == 12) { // Only with the first frame.
|
||||||
|
|
@ -1647,7 +1647,7 @@ void Transceiver::sendFrame(byte *frame, uint8_t sync) {
|
||||||
delayMicroseconds(SYMBOL);
|
delayMicroseconds(SYMBOL);
|
||||||
// Data: bits are sent one by one, starting with the MSB.
|
// Data: bits are sent one by one, starting with the MSB.
|
||||||
// TODO: Handle the 80-bit send protocol
|
// 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) {
|
if (((frame[i / 8] >> (7 - (i % 8))) & 1) == 1) {
|
||||||
REG_WRITE(GPIO_OUT_W1TC_REG, pin);
|
REG_WRITE(GPIO_OUT_W1TC_REG, pin);
|
||||||
delayMicroseconds(SYMBOL);
|
delayMicroseconds(SYMBOL);
|
||||||
|
|
|
||||||
2
Somfy.h
2
Somfy.h
|
|
@ -267,7 +267,7 @@ class Transceiver {
|
||||||
void enableReceive();
|
void enableReceive();
|
||||||
void disableReceive();
|
void disableReceive();
|
||||||
somfy_frame_t& lastFrame();
|
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 beginTransmit();
|
||||||
void endTransmit();
|
void endTransmit();
|
||||||
void emitFrame(somfy_frame_t *frame, somfy_rx_t *rx = nullptr);
|
void emitFrame(somfy_frame_t *frame, somfy_rx_t *rx = nullptr);
|
||||||
|
|
|
||||||
Binary file not shown.
10
Web.cpp
10
Web.cpp
|
|
@ -118,12 +118,14 @@ void Web::begin() {
|
||||||
HTTPMethod method = apiServer.method();
|
HTTPMethod method = apiServer.method();
|
||||||
uint8_t shadeId = 255;
|
uint8_t shadeId = 255;
|
||||||
uint8_t target = 255;
|
uint8_t target = 255;
|
||||||
|
uint8_t repeat = 1;
|
||||||
somfy_commands command = somfy_commands::My;
|
somfy_commands command = somfy_commands::My;
|
||||||
if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) {
|
if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) {
|
||||||
if (apiServer.hasArg("shadeId")) {
|
if (apiServer.hasArg("shadeId")) {
|
||||||
shadeId = atoi(apiServer.arg("shadeId").c_str());
|
shadeId = atoi(apiServer.arg("shadeId").c_str());
|
||||||
if (apiServer.hasArg("command")) command = translateSomfyCommand(apiServer.arg("command"));
|
if (apiServer.hasArg("command")) command = translateSomfyCommand(apiServer.arg("command"));
|
||||||
else if(apiServer.hasArg("target")) target = atoi(apiServer.arg("target").c_str());
|
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")) {
|
else if (apiServer.hasArg("plain")) {
|
||||||
Serial.println("Sending Shade Command");
|
Serial.println("Sending Shade Command");
|
||||||
|
|
@ -154,6 +156,7 @@ void Web::begin() {
|
||||||
else if(obj.containsKey("target")) {
|
else if(obj.containsKey("target")) {
|
||||||
target = obj["target"].as<uint8_t>();
|
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.\"}"));
|
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)
|
if(target >= 0 && target <= 100)
|
||||||
shade->moveToTarget(target);
|
shade->moveToTarget(target);
|
||||||
else
|
else
|
||||||
shade->sendCommand(command);
|
shade->sendCommand(command, repeat);
|
||||||
DynamicJsonDocument sdoc(256);
|
DynamicJsonDocument sdoc(256);
|
||||||
JsonObject sobj = sdoc.to<JsonObject>();
|
JsonObject sobj = sdoc.to<JsonObject>();
|
||||||
shade->toJSON(sobj);
|
shade->toJSON(sobj);
|
||||||
|
|
@ -702,12 +705,14 @@ void Web::begin() {
|
||||||
HTTPMethod method = server.method();
|
HTTPMethod method = server.method();
|
||||||
uint8_t shadeId = 255;
|
uint8_t shadeId = 255;
|
||||||
uint8_t target = 255;
|
uint8_t target = 255;
|
||||||
|
uint8_t repeat = 1;
|
||||||
somfy_commands command = somfy_commands::My;
|
somfy_commands command = somfy_commands::My;
|
||||||
if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) {
|
if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) {
|
||||||
if (server.hasArg("shadeId")) {
|
if (server.hasArg("shadeId")) {
|
||||||
shadeId = atoi(server.arg("shadeId").c_str());
|
shadeId = atoi(server.arg("shadeId").c_str());
|
||||||
if (server.hasArg("command")) command = translateSomfyCommand(server.arg("command"));
|
if (server.hasArg("command")) command = translateSomfyCommand(server.arg("command"));
|
||||||
else if(server.hasArg("target")) target = atoi(server.arg("target").c_str());
|
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")) {
|
else if (server.hasArg("plain")) {
|
||||||
Serial.println("Sending Shade Command");
|
Serial.println("Sending Shade Command");
|
||||||
|
|
@ -738,6 +743,7 @@ void Web::begin() {
|
||||||
else if(obj.containsKey("target")) {
|
else if(obj.containsKey("target")) {
|
||||||
target = obj["target"].as<uint8_t>();
|
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.\"}"));
|
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)
|
if(target >= 0 && target <= 100)
|
||||||
shade->moveToTarget(target);
|
shade->moveToTarget(target);
|
||||||
else
|
else
|
||||||
shade->sendCommand(command);
|
shade->sendCommand(command, repeat);
|
||||||
DynamicJsonDocument sdoc(512);
|
DynamicJsonDocument sdoc(512);
|
||||||
JsonObject sobj = sdoc.to<JsonObject>();
|
JsonObject sobj = sdoc.to<JsonObject>();
|
||||||
shade->toJSON(sobj);
|
shade->toJSON(sobj);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue