Added Invert Commands checkbox for motors

This commit is contained in:
Robert Strouse 2023-06-15 15:12:54 -07:00
parent 107c0357d1
commit b6a82e2e45
7 changed files with 50 additions and 11 deletions

View file

@ -6,9 +6,9 @@
extern Preferences pref;
#define SHADE_HDR_VER 8
#define SHADE_HDR_VER 9
#define SHADE_HDR_SIZE 16
#define SHADE_REC_SIZE 236
#define SHADE_REC_SIZE 242
bool ConfigFile::begin(const char* filename, bool readOnly) {
this->file = LittleFS.open(filename, readOnly ? "r" : "w");
@ -329,6 +329,9 @@ bool ShadeConfigFile::loadFile(SomfyShadeController *s, const char *filename) {
}
shade->target = floor(shade->currentPos);
shade->tiltTarget = floor(shade->currentTiltPos);
if(this->header.version >= 9) {
shade->inverted = this->readBool(false);
}
}
pref.end();
if(opened) {
@ -365,7 +368,7 @@ bool ShadeConfigFile::writeShadeRecord(SomfyShade *shade) {
this->writeFloat(shade->myPos, 5);
this->writeFloat(shade->myTiltPos, 5);
this->writeFloat(shade->currentPos, 5);
this->writeFloat(shade->currentTiltPos, 5, CFG_REC_END);
this->writeFloat(shade->currentTiltPos, 5);
}
else {
// Make sure that we write cleared values when the shade is deleted.
@ -373,8 +376,9 @@ bool ShadeConfigFile::writeShadeRecord(SomfyShade *shade) {
this->writeFloat(-1.0f, 5); // MyPos
this->writeFloat(-1.0f, 5); // MyTiltPos
this->writeFloat(0.0f, 5); // currentPos
this->writeFloat(0.0f, 5, CFG_REC_END); // currentTiltPos
this->writeFloat(0.0f, 5); // currentTiltPos
}
this->writeBool(shade->inverted, CFG_REC_END);
return true;
}
bool ShadeConfigFile::exists() { return LittleFS.exists("/shades.cfg"); }

View file

@ -1058,7 +1058,7 @@ void SomfyShade::processWaitingFrame() {
}
if(this->lastFrame.processed) return;
if(this->lastFrame.await > 0 && (millis() > this->lastFrame.await)) {
switch(this->lastFrame.cmd) {
switch(this->transformCommand(this->lastFrame.cmd)) {
case somfy_commands::StepUp:
this->lastFrame.processed = true;
// Simply move the shade up by 1%.
@ -1162,9 +1162,10 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
// If the command is coming from a remote then we are aborting all these positioning operations.
if(!internal) this->settingMyPos = this->settingPos = this->settingTiltPos = false;
somfy_commands cmd = this->transformCommand(frame.cmd);
// At this point we are not processing the combo buttons
// will need to see what the shade does when you press both.
switch(frame.cmd) {
switch(cmd) {
case somfy_commands::Sensor:
{
const uint8_t prevFlags = this->flags;
@ -1644,6 +1645,7 @@ bool SomfyShade::fromJSON(JsonObject &obj) {
this->shadeType = static_cast<shade_types>(obj["shadeType"].as<uint8_t>());
}
}
if(obj.containsKey("inverted")) this->inverted = obj["inverted"].as<bool>();
if(obj.containsKey("tiltType")) {
if(obj["tiltType"].is<const char *>()) {
if(strncmp(obj["tiltType"].as<const char *>(), "none", 4) == 0)
@ -1703,6 +1705,7 @@ bool SomfyShade::toJSON(JsonObject &obj) {
obj["bitLength"] = this->bitLength;
obj["proto"] = static_cast<uint8_t>(this->proto);
obj["flags"] = this->flags;
obj["inverted"] = this->inverted;
SomfyRemote::toJSON(obj);
JsonArray arr = obj.createNestedArray("linkedRemotes");
for(uint8_t i = 0; i < SOMFY_MAX_LINKED_REMOTES; i++) {
@ -1859,11 +1862,32 @@ SomfyShade *SomfyShadeController::addShade() {
}
return shade;
}
somfy_commands SomfyRemote::transformCommand(somfy_commands cmd) {
if(this->inverted) {
switch(cmd) {
case somfy_commands::Up:
return somfy_commands::Down;
case somfy_commands::MyUp:
return somfy_commands::MyDown;
case somfy_commands::Down:
return somfy_commands::Up;
case somfy_commands::MyDown:
return somfy_commands::MyUp;
case somfy_commands::StepUp:
return somfy_commands::StepDown;
case somfy_commands::StepDown:
return somfy_commands::StepUp;
default:
break;
}
}
return cmd;
}
void SomfyRemote::sendCommand(somfy_commands cmd, uint8_t repeat) {
somfy_frame_t frame;
frame.rollingCode = this->getNextRollingCode();
frame.remoteAddress = this->getRemoteAddress();
frame.cmd = cmd;
frame.cmd = this->transformCommand(cmd);
frame.repeats = repeat;
frame.bitLength = this->bitLength;
// Match the encKey to the rolling code. These keys range from 160 to 175.

View file

@ -167,6 +167,8 @@ class SomfyRemote {
uint32_t m_remoteAddress = 0;
public:
radio_proto proto = radio_proto::RTS;
bool inverted = false;
uint8_t flags = 0;
uint8_t bitLength = 0;
char *getRemotePrefId() {return m_remotePrefId;}
virtual bool toJSON(JsonObject &obj);
@ -176,6 +178,7 @@ class SomfyRemote {
virtual uint16_t setRollingCode(uint16_t code);
uint16_t lastRollingCode = 0;
virtual void sendCommand(somfy_commands cmd, uint8_t repeat = 1);
somfy_commands transformCommand(somfy_commands cmd);
};
class SomfyLinkedRemote : public SomfyRemote {
public:
@ -204,7 +207,6 @@ class SomfyShade : public SomfyRemote {
public:
shade_types shadeType = shade_types::roller;
tilt_types tiltType = tilt_types::none;
uint8_t flags = 0;
void load();
somfy_tx_queue_t txQueue;
somfy_frame_t lastFrame;

Binary file not shown.

Binary file not shown.

View file

@ -295,8 +295,14 @@
</span>
</label>
</div>
</div>
<div id="divInverted" style="margin-top:-10px;">
<div class="field-group">
<input id="cbInverted" name="inverted" type="checkbox" style="" />
<label for="cbInverted" style="display:block;font-size:1em;margin-top:0px;margin-left:7px;display:inline-block;">Invert Commands</label>
</div>
</div>
<div class="button-container" style="text-align:center;">
<button id="btnPairShade" type="button" onclick="somfy.pairShade(parseInt(document.getElementById('spanShadeId').innerText, 10));" style="display:inline-block;width:47%;">
Pair Shade

View file

@ -1486,6 +1486,7 @@ class Somfy {
document.getElementById('selShadeProto').value = shade.proto || 0;
document.getElementById('slidStepSize').value = shade.stepSize || 100;
document.getElementById('spanStepSize').innerHTML = shade.stepSize.fmt('#,##0');
document.getElementById('cbInverted').value = shade.inverted || false;
}
});
}
@ -1519,6 +1520,7 @@ class Somfy {
document.getElementById('spanStepSize').innerHTML = shade.stepSize.fmt('#,##0');
document.getElementById('fldTiltTime').value = shade.tiltTime;
document.getElementById('selTiltType').value = shade.tiltType;
document.getElementById('cbInverted').checked = shade.inverted;
this.onShadeTypeChanged(document.getElementById('selShadeType'));
let ico = document.getElementById('icoShade');
switch (shade.shadeType) {
@ -1576,7 +1578,8 @@ class Somfy {
tiltTime: parseInt(document.getElementById('fldTiltTime').value, 10),
bitLength: parseInt(document.getElementById('selShadeBitLength').value, 10) || 56,
proto: parseInt(document.getElementById('selShadeProto').value, 10) || 0,
stepSize: parseInt(document.getElementById('slidStepSize').value, 10) || 100
stepSize: parseInt(document.getElementById('slidStepSize').value, 10) || 100,
inverted: document.getElementById('cbInverted').checked
};
if (obj.shadeType === 1) {
obj.tiltType = parseInt(document.getElementById('selTiltType').value, 10);