Added support for Tilt Only motors. Improved RTV protocol detection.

This commit is contained in:
Robert Strouse 2023-08-13 15:30:23 -07:00
parent e7a95545b0
commit fe2f50ab9f
7 changed files with 115 additions and 32 deletions

View file

@ -3,7 +3,7 @@
#ifndef configsettings_h
#define configsettings_h
#define FW_VERSION "v2.1.2"
#define FW_VERSION "v2.1.3"
enum DeviceStatus {
DS_OK = 0,
DS_ERROR = 1,

View file

@ -125,7 +125,8 @@ void somfy_frame_t::decodeFrame(byte* frame) {
if(this->cmd == somfy_commands::StepDown)
this->cmd = (somfy_commands)((decoded[1] >> 4) | ((decoded[8] & 0x08) << 4));
if(this->cmd == somfy_commands::RTWProto) {
this->proto = radio_proto::RTW;
this->proto = this->encKey > 142 ? radio_proto::RTV : radio_proto::RTW;
switch(this->encKey) {
case 149:
case 133:
@ -338,6 +339,7 @@ void somfy_frame_t::encodeFrame(byte *frame) {
break;
case somfy_commands::Prog:
frame[0] = 156;
frame[1] = 0xFD;
break;
case somfy_commands::SunFlag:
frame[0] = 157;
@ -1684,6 +1686,10 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
else
this->target = 0.0f;
}
else if(this->tiltType == tilt_types::tiltonly) {
this->currentPos = this->target = 100.0f; // We are always 100% with this.
this->tiltTarget = 0.0f;
}
else
this->target = this->tiltTarget = 0.0f;
break;
@ -1695,6 +1701,10 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
else
this->target = 100.0f;
}
else if(this->tiltType == tilt_types::tiltonly) {
this->currentPos = this->target = 100.0f;
this->tiltTarget = 100.0f;
}
else {
this->target = 100.0f;
if(this->tiltType != tilt_types::none) this->tiltTarget = 100.0f;
@ -1703,11 +1713,13 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
break;
case somfy_commands::My:
if(this->isIdle()) {
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;
Serial.printf("Shade #%d is idle\n", this->getShadeId());
if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->tiltTarget = this->myTiltPos;
if(this->myPos >= 0.0f && this->myPos <= 100.0f && this->tiltType != tilt_types::tiltonly) this->target = this->myPos;
}
else {
this->target = this->currentPos;
if(this->tiltType == tilt_types::tiltonly) this->currentPos = this->target = 100.0f;
else this->target = this->currentPos;
this->tiltTarget = this->currentTiltPos;
}
break;
@ -1719,6 +1731,10 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
if(this->tiltTime == 0 || this->stepSize == 0) return;
this->tiltTarget = max(0.0f, this->currentTiltPos - (100.0f/(static_cast<float>(this->tiltTime/static_cast<float>(this->stepSize)))));
}
else if(this->tiltType == tilt_types::tiltonly) {
if(this->tiltTime == 0 || this->stepSize == 0 || this->currentTiltPos <= 0.0f) return;
this->tiltTarget = max(0.0f, this->currentTiltPos - (100.0f/(static_cast<float>(this->tiltTime/static_cast<float>(this->stepSize)))));
}
else if(this->currentPos > 0.0f) {
if(this->downTime == 0 || this->stepSize == 0) return;
this->target = max(0.0f, this->currentPos - (100.0f/(static_cast<float>(this->upTime/static_cast<float>(this->stepSize)))));
@ -1733,6 +1749,10 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
if(this->tiltTime == 0 || this->stepSize == 0) return;
this->tiltTarget = min(100.0f, this->currentTiltPos + (100.0f/(static_cast<float>(this->tiltTime/static_cast<float>(this->stepSize)))));
}
else if(this->tiltType == tilt_types::tiltonly) {
if(this->tiltTime == 0 || this->stepSize == 0 || this->currentTiltPos >= 100.0f) return;
this->tiltTarget = min(100.0f, this->currentTiltPos + (100.0f/(static_cast<float>(this->tiltTime/static_cast<float>(this->stepSize)))));
}
else if(this->currentPos < 100.0f) {
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)))));
@ -1809,9 +1829,39 @@ void SomfyShade::setMovement(int8_t dir) {
}
void SomfyShade::setMyPosition(int8_t pos, int8_t tilt) {
if(!this->isIdle()) return; // Don't do this if it is moving.
if(this->tiltType != tilt_types::none) {
if(this->tiltType == tilt_types::tiltonly) {
this->myPos = 100.0f;
if(tilt != floor(this->currentTiltPos)) {
this->settingMyPos = true;
if(tilt == floor(this->myTiltPos))
this->moveToMyPosition();
else
this->moveToTarget(100, tilt);
}
else if(tilt == floor(this->myTiltPos)) {
// Of so we need to clear the my position. These motors are finicky so send
// a my command to ensure we are actually at the my position then send the clear
// command. There really is no other way to do this.
if(this->currentTiltPos != this->myTiltPos) {
this->settingMyPos = true;
this->moveToMyPosition();
}
else {
SomfyRemote::sendCommand(somfy_commands::My, this->repeats);
this->settingPos = false;
this->settingMyPos = true;
}
}
else {
SomfyRemote::sendCommand(somfy_commands::My, SETMY_REPEATS);
this->myTiltPos = this->currentTiltPos;
}
this->commitMyPosition();
this->emitState();
}
else if(this->tiltType != tilt_types::none) {
if(tilt < 0) tilt = 0;
if(pos != floor(this->currentPos) || tilt != floor(currentTiltPos)) {
if(pos != floor(this->currentPos) || tilt != floor(this->currentTiltPos)) {
this->settingMyPos = true;
if(pos == floor(this->myPos) && tilt == floor(this->myTiltPos))
this->moveToMyPosition();
@ -1873,6 +1923,7 @@ void SomfyShade::setMyPosition(int8_t pos, int8_t tilt) {
}
void SomfyShade::moveToMyPosition() {
if(!this->isIdle()) return;
if(this->tiltType == tilt_types::tiltonly) this->currentPos = this->myPos = 100.0f;
if(this->currentPos == this->myPos) {
if(this->tiltType != tilt_types::none) {
if(this->currentTiltPos == this->myTiltPos) return; // Nothing to see here since we are already here.
@ -1881,6 +1932,7 @@ void SomfyShade::moveToMyPosition() {
return;
}
if(this->myPos == -1 && (this->tiltType == tilt_types::none || this->myTiltPos == -1)) return;
/*
Serial.print("Seeking my Position:");
Serial.print(this->myPos);
Serial.print("% ");
@ -1892,7 +1944,8 @@ void SomfyShade::moveToMyPosition() {
Serial.print("% using ");
Serial.print(translateSomfyCommand(somfy_commands::My));
Serial.println(this->direction);
if(this->myPos >= 0.0f && this->myPos <= 100.0f) this->target = this->myPos;
*/
if(this->tiltType != tilt_types::tiltonly && this->myPos >= 0.0f && this->myPos <= 100.0f) this->target = this->myPos;
if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->tiltTarget = this->myTiltPos;
this->settingPos = false;
SomfyRemote::sendCommand(somfy_commands::My, this->repeats);
@ -1904,12 +1957,14 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat) {
if(this->bitLength == 0) this->bitLength = somfy.transceiver.config.type;
if(cmd == somfy_commands::Up) {
SomfyRemote::sendCommand(cmd, repeat);
this->target = 0.0f;
if(this->tiltType != tilt_types::tiltonly) this->target = 0.0f;
else this->tiltTarget = 0.0f;
if(this->tiltType == tilt_types::integrated) this->tiltTarget = 0.0f;
}
else if(cmd == somfy_commands::Down) {
SomfyRemote::sendCommand(cmd, repeat);
this->target = 100.0f;
if(this->tiltType != tilt_types::tiltonly) this->target = 100.0f;
else this->tiltTarget = 100.0f;
if(this->tiltType == tilt_types::integrated) this->tiltTarget = 100.0f;
}
else if(cmd == somfy_commands::My) {
@ -1919,7 +1974,7 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat) {
}
else {
SomfyRemote::sendCommand(cmd, repeat);
this->target = this->currentPos;
if(this->tiltType != tilt_types::tiltonly) this->target = this->currentPos;
this->tiltTarget = this->currentTiltPos;
}
}
@ -1997,6 +2052,13 @@ void SomfyShade::moveToTiltTarget(float target) {
}
void SomfyShade::moveToTarget(float pos, float tilt) {
somfy_commands cmd = somfy_commands::My;
if(this->tiltType == tilt_types::tiltonly) {
this->currentPos = this->target = 100.0f;
pos = 100;
if(tilt < this->currentTiltPos) cmd = somfy_commands::Up;
else if(tilt > this->currentTiltPos) cmd = somfy_commands::Down;
}
else {
if(pos < this->currentPos)
cmd = somfy_commands::Up;
else if(pos > this->currentPos)
@ -2005,6 +2067,7 @@ void SomfyShade::moveToTarget(float pos, float tilt) {
cmd = somfy_commands::Up;
else if(tilt >= 0 && tilt > this->currentTiltPos)
cmd = somfy_commands::Down;
}
if(cmd != somfy_commands::My) {
Serial.print("Moving to ");
Serial.print(pos);

Binary file not shown.

Binary file not shown.

View file

@ -1 +1 @@
2.1.2
2.1.3

View file

@ -333,7 +333,7 @@
<input id="fldShadeName" name="shadeName" data-bind="name" type="text" length=20 placeholder="Name">
<label for="fldShadeName">Name</label>
</div>
<div style="margin-top:-10px;">
<div id="divLiftSettings" style="margin-top:-10px;">
<div class="field-group" style="display:inline-block;max-width:127px;margin-right:17px;margin-top:-10px;">
<input id="fldShadeUpTime" name="shadeUpTime" data-bind="upTime" data-datatype="int" type="number" length=5 placeholder="milliseconds" style="width:100%;text-align:right;" />
<label for="fldShadeUpTime">Up Time (ms)</label>
@ -349,6 +349,7 @@
<option value="0">None</option>
<option value="1">Tilt Motor</option>
<option value="2">Integrated</option>
<option value="3">Tilt Only</option>
</select>
<label for="selTiltType" style="cursor:pointer;">Tilt Type</label>
</div>

View file

@ -1197,7 +1197,7 @@ var security = new Security();
class General {
initialized = false;
appVersion = 'v2.1.2';
appVersion = 'v2.1.3';
reloadApp = false;
init() {
if (this.initialized) return;
@ -1971,8 +1971,12 @@ class Somfy {
divCtl += `<div class="shade-name">`;
divCtl += `<span class="shadectl-name">${shade.name}</span>`;
if (shade.tiltType === 3)
divCtl += `<span class="shadectl-mypos"><label>My Tilt: </label><span id="spanMyTiltPos">${shade.myTiltPos > 0 ? shade.myTiltPos + '%' : '---'}</span>`
else {
divCtl += `<span class="shadectl-mypos"><label>My: </label><span id="spanMyPos">${shade.myPos > 0 ? shade.myPos + '%' : '---'}</span>`;
if (shade.myTiltPos > 0) divCtl += `<label> Tilt: </label><span id="spanMyTiltPos">${shade.myTiltPos > 0 ? shade.myTiltPos + '%' : '---'}</span>`;
if (shade.myTiltPos > 0 && shade.tiltType !== 3) divCtl += `<label> Tilt: </label><span id="spanMyTiltPos">${shade.myTiltPos > 0 ? shade.myTiltPos + '%' : '---'}</span>`;
}
divCtl += '</div>';
divCtl += `<div class="shadectl-buttons">`;
@ -2148,13 +2152,15 @@ class Somfy {
let elname = shade.querySelector(`.shadectl-name`);
let shadeName = elname.innerHTML;
let html = `<div class="shade-name"><span>${shadeName}</span><div style="float:right;vertical-align:top;cursor:pointer;font-size:12px;margin-top:4px;">`;
if (myPos >= 0)
if (myPos >= 0 && tiltType !== 3)
html += `<div onclick="document.getElementById('slidShadeTarget').value = ${myPos}; document.getElementById('slidShadeTarget').dispatchEvent(new Event('change'));"><span style="display:inline-block;width:47px;">Current:</span><span>${myPos}</span><span>%</span></div>`;
if (myTiltPos >= 0 && tiltType > 0)
html += `<div onclick="document.getElementById('slidShadeTiltTarget').value = ${myTiltPos}; document.getElementById('slidShadeTarget').dispatchEvent(new Event('change'));"><span style="display:inline-block;width:47px;">Tilt:</span><span>${myTiltPos}</span><span>%</span></div>`;
html += `</div></div >`;
html += `</div></div>`;
html += `<div id="divShadeTarget">`
html += `<input id="slidShadeTarget" name="shadeTarget" type="range" min="0" max="100" step="1" oninput="document.getElementById('spanShadeTarget').innerHTML = this.value;" />`;
html += `<label for="slidShadeTarget"><span>Target Position </span><span><span id="spanShadeTarget" class="shade-target">${currPos}</span><span>%</span></span></label>`;
html += `</div>`
html += '<div id="divTiltTarget" style="display:none;">';
html += `<input id="slidShadeTiltTarget" name="shadeTiltTarget" type="range" min="0" max="100" step="1" oninput="document.getElementById('spanShadeTiltTarget').innerHTML = this.value;" />`;
html += `<label for="slidShadeTiltTarget"><span>Target Tilt </span><span><span id="spanShadeTiltTarget" class="shade-target">${currTiltPos}</span><span>%</span></span></label>`;
@ -2175,11 +2181,19 @@ class Somfy {
elTarget.value = currPos;
elTiltTarget.value = currTiltPos;
let elBtn = div.querySelector('button#btnSetMyPosition');
if (tiltType > 0) div.querySelector('div#divTiltTarget').style.display = '';
if (tiltType === 3) {
div.querySelector('div#divTiltTarget').style.display = '';
div.querySelector('div#divShadeTarget').style.display = 'none';
}
else if (tiltType > 0) div.querySelector('div#divTiltTarget').style.display = '';
let fnProcessChange = () => {
let pos = parseInt(elTarget.value, 10);
let tilt = parseInt(elTiltTarget.value, 10);
if (pos === myPos && (tiltType === 0 || tilt === myTiltPos)) {
if (tiltType === 3 && tilt === myTiltPos) {
elBtn.innerHTML = 'Clear My Position';
elBtn.style.background = 'orangered';
}
else if (pos === myPos && (tiltType === 0 || tilt === myTiltPos)) {
elBtn.innerHTML = 'Clear My Position';
elBtn.style.background = 'orangered';
}
@ -2415,6 +2429,7 @@ class Somfy {
if (ico.classList.contains('icss-window-blind')) ico.classList.remove('icss-window-blind');
if (ico.classList.contains('icss-shutter')) ico.classList.remove('icss-shutter');
if (!ico.classList.contains('icss-awning')) ico.classList.add('icss-awning');
tilt = false;
break;
case 4:
document.getElementById('divTiltSettings').style.display = 'none';
@ -2422,6 +2437,7 @@ class Somfy {
if (ico.classList.contains('icss-window-blind')) ico.classList.remove('icss-window-blind');
if (ico.classList.contains('icss-awning')) ico.classList.remove('icss-awning');
if (!ico.classList.contains('icss-shutter')) ico.classList.add('icss-shutter');
tilt = false;
break;
default:
@ -2434,6 +2450,7 @@ class Somfy {
break;
}
document.getElementById('fldTiltTime').parentElement.style.display = tilt ? 'inline-block' : 'none';
document.getElementById('divLiftSettings').style.display = tilt === 3 ? 'none' : '';
document.querySelector('#divSomfyButtons i.icss-window-tilt').style.display = tilt ? '' : 'none';
}
onShadeBitLengthChanged(el) {
@ -3220,14 +3237,16 @@ class Somfy {
console.log('Closing shade positioner');
ctls[i].remove();
}
let tiltType = parseInt(shade.getAttribute('data-tilt'), 10) || 0;
let currPos = parseInt(shade.getAttribute('data-target'), 0);
let elname = shade.querySelector(`.shadectl-name`);
let shadeName = elname.innerHTML;
let html = `<div class="shade-name">${shadeName}</div>`;
if (tiltType !== 3) {
html += `<input id="slidShadeTarget" name="shadeTarget" type="range" min="0" max="100" step="1" value="${currPos}" onchange="somfy.processShadeTarget(this, ${shadeId});" oninput="document.getElementById('spanShadeTarget').innerHTML = this.value;" />`;
html += `<label for="slidShadeTarget"><span>Target Position </span><span><span id="spanShadeTarget" class="shade-target">${currPos}</span><span>%</span></span></label>`;
if (makeBool(shade.getAttribute('data-tilt'))) {
}
if (tiltType > 0) {
let currTiltPos = parseInt(shade.getAttribute('data-tilttarget'), 10);
html += `<input id="slidShadeTiltTarget" name="shadeTarget" type="range" min="0" max="100" step="1" value="${currTiltPos}" onchange="somfy.processShadeTiltTarget(this, ${shadeId});" oninput="document.getElementById('spanShadeTiltTarget').innerHTML = this.value;" />`;
html += `<label for="slidShadeTiltTarget"><span>Target Tilt Position </span><span><span id="spanShadeTiltTarget" class="shade-tilt-target">${currTiltPos}</span><span>%</span></span></label>`;