mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
refactor: carry out shade requests from one module behind a LoopQueue
HTTP routes and MQTT commands now both build a shade request and submit it to the LoopQueue, which loop() drains into ShadeRequests. ShadeRequests finds the shade or group, turns client positions into stored ones, checks ranges and fills in default repeats, and reaches the shades through the ShadeOps seam: SomfyShadeOps on the device, a recording fake in the native tests. MqttCommands turns a .../set topic into a shade request. Behaviour that changes: - MQTT tiltTarget, mypos, myTiltPos and tiltPosition, and /setPositions, now honour flipPosition like the other routes. - MQTT mypos keeps the favorite tilt (was set to 0) and myTiltPos keeps the favorite lift. - repeat 0 on /shadeCommand means no repeats, as it did for groups; a JSON repeat over 127 is capped instead of wrapping to the default. - Position corrections go through the setters, so MQTT publishes them. - MQTT commands wait while the radio is full instead of being refused. - The queue is drained every loop() pass and no longer from inside a GitHub firmware download. WebCommand.h is replaced by LoopQueue.h and ShadeRequests.h. 45 new native tests, 271 in all. Flash: esp32devdbg +976 bytes, esp32dev +1,380 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5fd5feda28
commit
395cb2d1c7
20 changed files with 1354 additions and 569 deletions
70
src/SomfyShadeOps.cpp
Normal file
70
src/SomfyShadeOps.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include "SomfyShadeOps.h"
|
||||
#include "Somfy.h"
|
||||
|
||||
extern SomfyShadeController somfy;
|
||||
|
||||
// ShadeRequests only calls these for a shade or group it has just found.
|
||||
bool SomfyShadeOps::findShade(uint8_t shadeId, shade_info_t &info) {
|
||||
SomfyShade *shade = somfy.getShadeById(shadeId);
|
||||
if(!shade) return false;
|
||||
info.flipPosition = shade->flipPosition;
|
||||
info.shadeType = shade->shadeType;
|
||||
info.tiltType = shade->tiltType;
|
||||
info.repeats = shade->repeats;
|
||||
info.bitLength = shade->bitLength;
|
||||
info.currentPos = shade->currentPos;
|
||||
info.myPos = shade->myPos;
|
||||
info.myTiltPos = shade->myTiltPos;
|
||||
return true;
|
||||
}
|
||||
bool SomfyShadeOps::findGroup(uint8_t groupId, uint8_t &repeats) {
|
||||
SomfyGroup *group = somfy.getGroupById(groupId);
|
||||
if(!group) return false;
|
||||
repeats = group->repeats;
|
||||
return true;
|
||||
}
|
||||
bool SomfyShadeOps::moveToTarget(uint8_t shadeId, float pos) { return somfy.getShadeById(shadeId)->moveToTarget(pos); }
|
||||
bool SomfyShadeOps::moveToTiltTarget(uint8_t shadeId, float tilt) { return somfy.getShadeById(shadeId)->moveToTiltTarget(tilt); }
|
||||
bool SomfyShadeOps::sendCommand(uint8_t shadeId, somfy_commands cmd, uint8_t repeat, uint8_t stepSize) {
|
||||
return somfy.getShadeById(shadeId)->sendCommand(cmd, repeat, stepSize);
|
||||
}
|
||||
bool SomfyShadeOps::sendTiltCommand(uint8_t shadeId, somfy_commands cmd) { return somfy.getShadeById(shadeId)->sendTiltCommand(cmd); }
|
||||
bool SomfyShadeOps::isLastCommand(uint8_t shadeId, somfy_commands cmd) { return somfy.getShadeById(shadeId)->isLastCommand(cmd); }
|
||||
bool SomfyShadeOps::repeatFrame(uint8_t shadeId, uint8_t repeat) { return somfy.getShadeById(shadeId)->repeatFrame(repeat); }
|
||||
bool SomfyShadeOps::sendSensorCommand(uint8_t shadeId, int8_t windy, int8_t sunny, uint8_t repeat) {
|
||||
SomfyShade *shade = somfy.getShadeById(shadeId);
|
||||
const bool sent = shade->sendSensorCommand(windy, sunny, repeat);
|
||||
shade->emitState();
|
||||
return sent;
|
||||
}
|
||||
bool SomfyShadeOps::setMyPosition(uint8_t shadeId, int8_t pos, int8_t tilt) { return somfy.getShadeById(shadeId)->setMyPosition(pos, tilt); }
|
||||
void SomfyShadeOps::setPositions(uint8_t shadeId, float pos, float tilt) {
|
||||
SomfyShade *shade = somfy.getShadeById(shadeId);
|
||||
// Through the setters, so MQTT hears about it too.
|
||||
if(pos >= 0.0f) {
|
||||
shade->p_target(pos);
|
||||
shade->p_currentPos(pos);
|
||||
}
|
||||
if(tilt >= 0.0f) {
|
||||
shade->p_tiltTarget(tilt);
|
||||
shade->p_currentTiltPos(tilt);
|
||||
}
|
||||
shade->emitState();
|
||||
}
|
||||
void SomfyShadeOps::setUnpaired(uint8_t shadeId) {
|
||||
SomfyShade *shade = somfy.getShadeById(shadeId);
|
||||
shade->paired = false;
|
||||
shade->save();
|
||||
}
|
||||
void SomfyShadeOps::setRollingCode(uint8_t shadeId, uint16_t code) { somfy.getShadeById(shadeId)->setRollingCode(code); }
|
||||
bool SomfyShadeOps::sendGroupCommand(uint8_t groupId, somfy_commands cmd, uint8_t repeat, uint8_t stepSize) {
|
||||
return somfy.getGroupById(groupId)->sendCommand(cmd, repeat, stepSize);
|
||||
}
|
||||
bool SomfyShadeOps::isLastGroupCommand(uint8_t groupId, somfy_commands cmd) { return somfy.getGroupById(groupId)->isLastCommand(cmd); }
|
||||
bool SomfyShadeOps::repeatGroupFrame(uint8_t groupId, uint8_t repeat) { return somfy.getGroupById(groupId)->repeatFrame(repeat); }
|
||||
bool SomfyShadeOps::sendGroupSensorCommand(uint8_t groupId, int8_t windy, int8_t sunny, uint8_t repeat) {
|
||||
SomfyGroup *group = somfy.getGroupById(groupId);
|
||||
const bool sent = group->sendSensorCommand(windy, sunny, repeat);
|
||||
group->emitState();
|
||||
return sent;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue