mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 19:12:10 +01:00
v2.0.0 Release Candidate
Added functions for emitting the last command for a motor.
This commit is contained in:
parent
cfd3bdc4a1
commit
42947690a2
7 changed files with 50 additions and 12 deletions
43
Somfy.cpp
43
Somfy.cpp
|
|
@ -1208,6 +1208,23 @@ void SomfyShade::emitState(uint8_t num, const char *evt) {
|
|||
}
|
||||
}
|
||||
}
|
||||
void SomfyShade::emitCommand(somfy_commands cmd, const char *source, uint32_t sourceAddress, const char *evt) { this->emitCommand(255, cmd, source, sourceAddress, evt); }
|
||||
void SomfyShade::emitCommand(uint8_t num, somfy_commands cmd, const char *source, uint32_t sourceAddress, const char *evt) {
|
||||
ClientSocketEvent e(evt);
|
||||
char buf[30];
|
||||
snprintf(buf, sizeof(buf), "{\"shadeId\":%d", this->shadeId);
|
||||
e.appendMessage(buf);
|
||||
snprintf(buf, sizeof(buf), ",\"remoteAddress\":%d", this->getRemoteAddress());
|
||||
e.appendMessage(buf);
|
||||
snprintf(buf, sizeof(buf), ",\"cmd\":\"%s\"", translateSomfyCommand(cmd));
|
||||
e.appendMessage(buf);
|
||||
snprintf(buf, sizeof(buf), ",\"source\":\"%s\"", source);
|
||||
e.appendMessage(buf);
|
||||
snprintf(buf, sizeof(buf), ",\"sourceAddress\":%d}", sourceAddress);
|
||||
e.appendMessage(buf);
|
||||
if(num >= 255) sockEmit.sendToClients(&e);
|
||||
else sockEmit.sendToClient(num, &e);
|
||||
}
|
||||
void SomfyGroup::emitState(const char *evt) { this->emitState(255, evt); }
|
||||
void SomfyGroup::emitState(uint8_t num, const char *evt) {
|
||||
ClientSocketEvent e(evt);
|
||||
|
|
@ -1250,13 +1267,15 @@ void SomfyShade::processWaitingFrame() {
|
|||
}
|
||||
if(this->lastFrame.processed) return;
|
||||
if(this->lastFrame.await > 0 && (millis() > this->lastFrame.await)) {
|
||||
switch(this->transformCommand(this->lastFrame.cmd)) {
|
||||
somfy_commands cmd = this->transformCommand(this->lastFrame.cmd);
|
||||
switch(cmd) {
|
||||
case somfy_commands::StepUp:
|
||||
this->lastFrame.processed = true;
|
||||
// Simply move the shade up by 1%.
|
||||
if(this->currentPos > 0) {
|
||||
this->target = floor(this->currentPos) - 1;
|
||||
this->setMovement(-1);
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
break;
|
||||
case somfy_commands::StepDown:
|
||||
|
|
@ -1265,6 +1284,7 @@ void SomfyShade::processWaitingFrame() {
|
|||
if(this->currentPos < 100) {
|
||||
this->target = floor(this->currentPos) + 1;
|
||||
this->setMovement(1);
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
break;
|
||||
case somfy_commands::Down:
|
||||
|
|
@ -1281,14 +1301,19 @@ void SomfyShade::processWaitingFrame() {
|
|||
Serial.print(" after ");
|
||||
Serial.print(this->lastFrame.repeats);
|
||||
Serial.println(" repeats");
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
else {
|
||||
int8_t dir = this->lastFrame.cmd == somfy_commands::Up ? -1 : 1;
|
||||
this->target = dir > 0 ? 100 : 0;
|
||||
this->setMovement(dir);
|
||||
this->lastFrame.processed = true;
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
if(this->lastFrame.repeats > TILT_REPEATS + 2) {
|
||||
this->lastFrame.processed = true;
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
if(this->lastFrame.repeats > TILT_REPEATS + 2) this->lastFrame.processed = true;
|
||||
}
|
||||
break;
|
||||
case somfy_commands::My:
|
||||
|
|
@ -1311,6 +1336,7 @@ void SomfyShade::processWaitingFrame() {
|
|||
if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->tiltTarget = this->myTiltPos;
|
||||
this->setMovement(0);
|
||||
this->lastFrame.processed = true;
|
||||
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
|
||||
}
|
||||
else {
|
||||
this->target = this->currentPos;
|
||||
|
|
@ -1472,6 +1498,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
// If from a remote we will simply be going up.
|
||||
if(!internal) this->target = this->tiltTarget = 0.0f;
|
||||
this->lastFrame.processed = true;
|
||||
this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress);
|
||||
}
|
||||
break;
|
||||
case somfy_commands::Down:
|
||||
|
|
@ -1488,6 +1515,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
if(this->tiltType != tilt_types::none) this->tiltTarget = 100.0f;
|
||||
}
|
||||
}
|
||||
this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress);
|
||||
}
|
||||
break;
|
||||
case somfy_commands::My:
|
||||
|
|
@ -1499,10 +1527,9 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
}
|
||||
else {
|
||||
this->lastFrame.processed = true;
|
||||
if(!internal) {
|
||||
if(this->myTiltPos >= 0.0f && this->myTiltPos >= 100.0f) this->tiltTarget = this->myTiltPos;
|
||||
if(this->myPos >= 0.0f && this->myPos <= 100.0f) this->target = this->myPos;
|
||||
}
|
||||
this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -1513,7 +1540,6 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case somfy_commands::MyUp:
|
||||
case somfy_commands::StepUp:
|
||||
this->lastFrame.processed = true;
|
||||
if(this->lastFrame.repeats != 0) return;
|
||||
|
|
@ -1530,7 +1556,6 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
this->target = max(0.0f, this->currentPos - (100.0f/(static_cast<float>(this->upTime/static_cast<float>(this->stepSize)))));
|
||||
}
|
||||
break;
|
||||
case somfy_commands::MyDown:
|
||||
case somfy_commands::StepDown:
|
||||
this->lastFrame.processed = true;
|
||||
if(this->lastFrame.repeats != 0) return;
|
||||
|
|
@ -1546,6 +1571,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
if(this->downTime == 0 || this->stepSize == 0) return;
|
||||
this->target = min(100.0f, this->currentPos + (100.0f/(static_cast<float>(this->downTime/static_cast<float>(this->stepSize)))));
|
||||
}
|
||||
this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress);
|
||||
break;
|
||||
default:
|
||||
dir = 0;
|
||||
|
|
@ -1806,7 +1832,10 @@ void SomfyGroup::sendCommand(somfy_commands cmd, uint8_t repeat) {
|
|||
for(uint8_t i = 0; i < SOMFY_MAX_GROUPED_SHADES; i++) {
|
||||
if(this->linkedShades[i] != 0) {
|
||||
SomfyShade * shade = somfy.getShadeById(this->linkedShades[i]);
|
||||
if(shade) shade->processInternalCommand(cmd, repeat);
|
||||
if(shade) {
|
||||
shade->processInternalCommand(cmd, repeat);
|
||||
shade->emitCommand(cmd, "group", this->getRemoteAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
2
Somfy.h
2
Somfy.h
|
|
@ -258,6 +258,8 @@ class SomfyShade : public SomfyRemote {
|
|||
bool unlinkRemote(uint32_t remoteAddress);
|
||||
void emitState(const char *evt = "shadeState");
|
||||
void emitState(uint8_t num, const char *evt = "shadeState");
|
||||
void emitCommand(somfy_commands cmd, const char *source, uint32_t sourceAddress, const char *evt = "shadeCommand");
|
||||
void emitCommand(uint8_t num, somfy_commands cmd, const char *source, uint32_t sourceAddress, const char *evt = "shadeCommand");
|
||||
void setMyPosition(int8_t pos, int8_t tilt = -1);
|
||||
void moveToMyPosition();
|
||||
void processWaitingFrame();
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
4
Web.cpp
4
Web.cpp
|
|
@ -225,6 +225,10 @@ void Web::handleLoginContext(WebServer &server) {
|
|||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["type"] = static_cast<uint8_t>(settings.Security.type);
|
||||
obj["permissions"] = settings.Security.permissions;
|
||||
obj["serverId"] = settings.serverId;
|
||||
obj["version"] = settings.fwVersion;
|
||||
obj["model"] = "ESPSomfyRTS";
|
||||
obj["hostname"] = settings.hostname;
|
||||
serializeJson(doc, g_content);
|
||||
server.send(200, _encoding_json, g_content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -484,9 +484,8 @@
|
|||
</select>
|
||||
</div>
|
||||
<div class="field-group" style="display:inline-block;width:77px;">
|
||||
<label for="selRadioType">Radio</label>
|
||||
<label for="selRadioType">Bit Length</label>
|
||||
<select id="selRadioType" name="radioType" data-bind="transceiver.config.type" data-datatype="int" style="width:77px;">
|
||||
<option value="none" selected>None</option>
|
||||
<option value="56">56-BIT</option>
|
||||
<option value="80">80-BIT</option>
|
||||
</select>
|
||||
|
|
@ -495,7 +494,8 @@
|
|||
<input id="cbEnableRadio" name="enableRadio" type="checkbox" data-bind="transceiver.config.enabled" style="display:inline-block;" />
|
||||
<label for="cbEnableRadio" style="display:inline-block;cursor:pointer;">Enable Radio</label>
|
||||
</div>
|
||||
<div class="field-group1" style="margin-top:-20px;white-space:nowrap">
|
||||
<div class="field-group" style="margin-top:-18px;"><label style="font-size:12px;">(default when adding new motors)</label></div>
|
||||
<div class="field-group1" style="white-space:nowrap">
|
||||
<div class="field-group radioPins">
|
||||
<select id="selTransSCKPin" name="transSCK" data-bind="transceiver.config.SCKPin" data-datatype="int"></select>
|
||||
<label for="selTransSCKPin">SCLK</label>
|
||||
|
|
|
|||
|
|
@ -470,6 +470,9 @@ async function initSockets() {
|
|||
case 'shadeState':
|
||||
somfy.procShadeState(msg);
|
||||
break;
|
||||
case 'shadeCommand':
|
||||
console.log(msg);
|
||||
break;
|
||||
case 'shadeRemoved':
|
||||
break;
|
||||
case 'shadeAdded':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue