diff --git a/Somfy.cpp b/Somfy.cpp index 3e2b552..1ecba4a 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -779,7 +779,12 @@ bool SomfyGroup::hasShadeId(uint8_t shadeId) { } return false; } -bool SomfyShade::isAtTarget() { return this->currentPos == this->target && this->currentTiltPos == this->tiltTarget; } +bool SomfyShade::isAtTarget() { + float epsilon = .00001; + if(this->tiltType == tilt_types::tiltonly) return fabs(this->currentTiltPos - this->tiltTarget) < epsilon; + else if(this->tiltType == tilt_types::none) return fabs(this->currentPos - this->target) < epsilon; + return fabs(this->currentPos - this->target) < epsilon && fabs(this->currentTiltPos - this->tiltTarget) < epsilon; +} bool SomfyRemote::hasSunSensor() { return (this->flags & static_cast(somfy_flags_t::SunSensor)) > 0;} bool SomfyRemote::hasLight() { return (this->flags & static_cast(somfy_flags_t::Light)) > 0; } void SomfyRemote::setSunSensor(bool bHasSensor ) { bHasSensor ? this->flags |= static_cast(somfy_flags_t::SunSensor) : this->flags &= ~(static_cast(somfy_flags_t::SunSensor)); } @@ -928,7 +933,7 @@ void SomfyShade::checkMovement() { // moving. If this is only a tilt action then the regular tilt action should operate fine. int8_t currDir = this->direction; int8_t currTiltDir = this->tiltDirection; - this->p_direction(floor(this->currentPos) == floor(this->target) ? 0 : floor(this->currentPos) > floor(this->target) ? -1 : 1); + this->p_direction(this->currentPos == this->target ? 0 : this->currentPos > this->target ? -1 : 1); bool tilt_first = this->tiltType == tilt_types::integrated && ((this->direction == -1 && this->currentTiltPos != 0.0f) || (this->direction == 1 && this->currentTiltPos != 100.0f)); this->p_tiltDirection(this->currentTiltPos == this->tiltTarget ? 0 : this->currentTiltPos > this->tiltTarget ? -1 : 1); @@ -1020,6 +1025,7 @@ void SomfyShade::checkMovement() { } if(this->currentPos >= this->target) { this->p_currentPos(this->target); + //if(this->settingMyPos) Serial.printf("IsAtTarget: %d %f=%f\n", this->isAtTarget(), this->currentPos, this->target); // If we need to stop the shade do this before we indicate that we are // not moving otherwise the my function will kick in. if(this->settingPos) { @@ -1069,6 +1075,8 @@ void SomfyShade::checkMovement() { } if(this->currentPos <= this->target) { this->p_currentPos(this->target); + //if(this->settingMyPos) Serial.printf("IsAtTarget: %d %f=%f\n", this->isAtTarget(), this->currentPos, this->target); + // If we need to stop the shade do this before we indicate that we are // not moving otherwise the my function will kick in. if(this->settingPos) { @@ -1625,6 +1633,7 @@ float SomfyShade::p_tiltTarget(float target) { float SomfyShade::p_myPos(float pos) { float old = this->myPos; if(old != pos) { + //if(this->transformPosition(pos) == 0) Serial.println("MyPos = %.2f", pos); this->myPos = pos; if(this->transformPosition(old) != this->transformPosition(pos)) this->publish("mypos", this->transformPosition(this->myPos)); @@ -1716,7 +1725,10 @@ void SomfyGroup::emitState(uint8_t num, const char *evt) { else sockEmit.sendToClient(num, &e); this->publish(); } -int8_t SomfyShade::transformPosition(float fpos) { return static_cast(this->flipPosition && fpos >= 0.00f ? floor(100.0f - fpos) : floor(fpos)); } +int8_t SomfyShade::transformPosition(float fpos) { + if(fpos < 0) return -1; + return static_cast(this->flipPosition && fpos >= 0.00f ? floor(100.0f - fpos) : floor(fpos)); +} bool SomfyShade::isIdle() { return this->direction == 0 && this->tiltDirection == 0; } void SomfyShade::processWaitingFrame() { if(this->shadeId == 255) { @@ -2039,8 +2051,8 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) { if(this->lastFrame.processed) return; this->lastFrame.processed = true; if(!this->isIdle()) this->p_target(this->currentPos); - else if(this->currentPos == 100.0f) this->p_target(0); - else if(this->currentPos == 0.0f) this->p_target(100); + else if(this->currentPos == 100.0f) this->p_target(0.0f); + else if(this->currentPos == 0.0f) this->p_target(100.0f); else this->p_target(this->lastMovement == -1 ? 100 : 0); this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress); return; @@ -2129,6 +2141,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) { else if(this->currentPos == 100.0f) this->p_target(0); else if(this->currentPos == 0.0f) this->p_target(100); else this->p_target(this->lastMovement == -1 ? 100 : 0); + this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress); break; default: dir = 0; @@ -2157,7 +2170,6 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) { this->p_target(0.0f); } else if(this->tiltType == tilt_types::tiltonly) { - this->p_myPos(100.0f); this->p_target(100.0f); this->p_currentPos(100.0f); this->p_tiltTarget(0.0f); @@ -2176,7 +2188,6 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) { this->p_target(100.0f); } else if(this->tiltType == tilt_types::tiltonly) { - this->p_myPos(100.0f); this->p_target(100.0f); this->p_currentPos(100.0f); this->p_tiltTarget(100.0f); @@ -2195,9 +2206,7 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) { } else { if(this->tiltType == tilt_types::tiltonly) { - this->p_myPos(100.0f); this->p_target(100.0f); - this->p_currentPos(100.0f); } else this->p_target(this->currentPos); this->p_tiltTarget(this->currentTiltPos); @@ -2311,7 +2320,7 @@ 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::tiltonly) { - this->p_myPos(100.0f); + this->p_myPos(-1.0f); if(tilt != floor(this->currentTiltPos)) { this->settingMyPos = true; if(tilt == floor(this->myTiltPos)) @@ -2406,7 +2415,7 @@ void SomfyShade::moveToMyPosition() { if(!this->isIdle()) return; if(this->tiltType == tilt_types::tiltonly) { this->p_currentPos(100.0f); - this->p_myPos(100.0f); + this->p_myPos(-1.0f); } if(this->currentPos == this->myPos) { if(this->tiltType != tilt_types::none) { @@ -2565,7 +2574,7 @@ void SomfyShade::moveToTarget(float pos, float tilt) { } if(this->tiltType == tilt_types::tiltonly) { this->p_target(100.0f); - this->p_myPos(100.0f); + this->p_myPos(-1.0f); this->p_currentPos(100.0f); pos = 100; if(tilt < this->currentTiltPos) cmd = somfy_commands::Up; diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index de1ecbc..8bdda7e 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/SomfyController.littlefs.bin b/SomfyController.littlefs.bin index ae66710..9e0a9ef 100644 Binary files a/SomfyController.littlefs.bin and b/SomfyController.littlefs.bin differ diff --git a/data/index.html b/data/index.html index c404479..c2e5a2e 100644 --- a/data/index.html +++ b/data/index.html @@ -3,11 +3,11 @@ - - - + + + - +
diff --git a/data/index.js b/data/index.js index 41fb138..c06a962 100644 --- a/data/index.js +++ b/data/index.js @@ -1252,7 +1252,7 @@ var security = new Security(); class General { initialized = false; - appVersion = 'v2.2.0'; + appVersion = 'v2.2.1b'; reloadApp = false; init() { if (this.initialized) return; @@ -2098,7 +2098,7 @@ class Somfy { } for (let i = 0; i < shades.length; i++) { let shade = shades[i]; - divCfg += `
`; + divCfg += `
`; divCfg += `
`; //divCfg += ``; divCfg += `${shade.name}`; @@ -2106,7 +2106,7 @@ class Somfy { divCfg += `
`; divCfg += '
'; - divCtl += `
`; divCtl += `${shade.name}`; - if (shade.tiltType === 3) - divCtl += `${shade.myTiltPos > 0 ? shade.myTiltPos + '%' : '---'}` - else if (shade.shadeType !== 5 && shade.shadeType !== 9) { - divCtl += `${shade.myPos > 0 ? shade.myPos + '%' : '---'}`; - if (shade.myTiltPos > 0 && shade.tiltType !== 3) divCtl += `${shade.myTiltPos > 0 ? shade.myTiltPos + '%' : '---'}`; - } + divCtl += `${shade.myPos === -1 ? '---' : shade.myPos + '%'}${shade.myTiltPos === -1 ? '---' : shade.myTiltPos + '%'}`; divCtl += '
'; divCtl += `
`; divCtl += `
`; @@ -2701,9 +2696,9 @@ class Somfy { divs[i].setAttribute('data-tiltposition', state.tiltPosition); divs[i].setAttribute('data-tilttarget', state.tiltTarget); } - let span = divs[i].querySelector('#spanMyPos'); + let span = divs[i].querySelector('span.my-pos'); if (span) span.innerHTML = typeof state.myPos !== 'undefined' && state.myPos >= 0 ? `${state.myPos}%` : '---'; - span = divs[i].querySelector('#spanMyTiltPos'); + span = divs[i].querySelector('span.my-pos-tilt'); if (span) span.innerHTML = typeof state.myTiltPos !== 'undefined' && state.myTiltPos >= 0 ? `${state.myTiltPos}%` : '---'; } } diff --git a/data/widgets.css b/data/widgets.css index ebeeec6..5af05eb 100644 --- a/data/widgets.css +++ b/data/widgets.css @@ -148,6 +148,27 @@ .shadectl-buttons:not([data-shadetype="5"]):not([data-shadetype="9"]) > .button-outline[data-cmd="toggle"] { display: none; } +.somfyShadeCtl[data-shadetype="5"] .shadectl-mypos, +.somfyShadeCtl[data-shadetype="9"] .shadectl-mypos, +.somfyShadeCtl[data-tilt="3"] .shadectl-mypos .my-pos, +.somfyShadeCtl:not([data-shadetype="1"]) .shadectl-mypos .my-pos-tilt { + display: none; +} +.somfyShadeCtl:not([data-shadetype="1"][data-tilt="3"]) .shadectl-mypos label.my-pos:after { + content: "My:" +} +.somfyShadeCtl[data-shadetype="1"][data-tilt="3"] .shadectl-mypos label.my-pos { + display:none; +} +.somfyShadeCtl[data-shadetype="1"][data-tilt="3"] .shadectl-mypos label.my-pos-tilt:after { + content:"My Tilt:"; +} +.somfyShadeCtl:not([data-shadetype="1"][data-tilt="3"]) .shadectl-mypos label.my-pos-tilt:after { + content:"Tilt:"; +} +.somfyShadeCtl .shadectl-mypos span.my-pos { + margin-right:14px; +} #somfyShade #divGPIOControl { display: none; } @@ -204,3 +225,4 @@ .shade-draggable.over { border-top: solid 2px var(--shade-color, '#00bcd4'); } +