mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
fix: move only the tilt of a tilt-only shade for sun and wind
The three places that act on the sun and wind each set different targets for a tilt-only shade: the sun timer moved its lift, the no-sun and wind timers moved tilt and lift, a group's sun flag moved its lift and only a remote's sun flag moved its tilt. They now share sensorTargets(): a tilt-only shade moves its tilt to the favorite tilt (or fully) and back to 0, and every other shade its lift, as Up and Down already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8276c1c3cd
commit
5f26340d06
5 changed files with 83 additions and 37 deletions
|
|
@ -72,6 +72,20 @@ SensorMove ShadeSensors::onSunFlag(bool sunny, bool windy) const {
|
|||
if(!sunny && this->noSunDone) return SensorMove::retract;
|
||||
return SensorMove::none;
|
||||
}
|
||||
SensorTargets sensorTargets(SensorMove move, tilt_types tilt, float myPos, float myTiltPos) {
|
||||
SensorTargets t;
|
||||
if(move == SensorMove::none) return t;
|
||||
const bool extend = move == SensorMove::extend;
|
||||
if(tilt == tilt_types::tiltonly) {
|
||||
t.setTilt = true;
|
||||
t.tilt = extend ? (myTiltPos >= 0 ? myTiltPos : 100.0f) : 0.0f;
|
||||
}
|
||||
else {
|
||||
t.setLift = true;
|
||||
t.lift = extend ? (myPos >= 0 ? myPos : 100.0f) : 0.0f;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
bool ShadeSensors::windBlocksDown(uint32_t now) const {
|
||||
return this->windLast != 0 && now - this->windLast < SOMFY_NO_WIND_REMOTE_TIMEOUT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SHADE_SENSORS_H
|
||||
#define SHADE_SENSORS_H
|
||||
#include <stdint.h>
|
||||
#include "ShadeTypes.h"
|
||||
|
||||
// Sun and wind automation for a shade with a sun sensor. Kept free of the
|
||||
// shade, radio and network so it can be unit tested on the PC
|
||||
|
|
@ -49,4 +50,14 @@ struct ShadeSensors {
|
|||
// Whether a remote Down is ignored because the sensor reported wind lately.
|
||||
bool windBlocksDown(uint32_t now) const;
|
||||
};
|
||||
// The targets a sensor move sets. A tilt-only shade only moves its tilt and
|
||||
// every other shade only its lift, as Up and Down do.
|
||||
struct SensorTargets {
|
||||
bool setLift = false;
|
||||
float lift = 0.0f;
|
||||
bool setTilt = false;
|
||||
float tilt = 0.0f;
|
||||
};
|
||||
// myPos and myTiltPos are the favorite, -1 when there is none.
|
||||
SensorTargets sensorTargets(SensorMove move, tilt_types tilt, float myPos, float myTiltPos);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -134,6 +134,8 @@ class SomfyShade : public SomfyRemote {
|
|||
// Repeats for a tilt command, more for a separate tilt motor.
|
||||
uint8_t tiltRepeats() const;
|
||||
void runToLimit(int8_t dir, bool tilt, uint32_t since);
|
||||
// Sets the targets the sun or wind sends the shade to.
|
||||
void applySensorMove(SensorMove move);
|
||||
public:
|
||||
uint8_t roomId = 0;
|
||||
int8_t sortOrder = 0;
|
||||
|
|
|
|||
|
|
@ -152,17 +152,7 @@ void SomfyShade::checkMovement() {
|
|||
case TxHoldCheck::none:
|
||||
break;
|
||||
}
|
||||
switch(this->sensors.check(sunFlag, isSunny, isWindy, (uint32_t)curTime)) {
|
||||
case SensorMove::extend:
|
||||
this->p_target(this->myPos >= 0 ? this->myPos : 100.0f);
|
||||
break;
|
||||
case SensorMove::retract:
|
||||
if(this->tiltType == tilt_types::tiltonly) this->p_tiltTarget(0.0f);
|
||||
this->p_target(0.0f);
|
||||
break;
|
||||
case SensorMove::none:
|
||||
break;
|
||||
}
|
||||
this->applySensorMove(this->sensors.check(sunFlag, isSunny, isWindy, (uint32_t)curTime));
|
||||
|
||||
if(!tilt_first && this->direction > 0) {
|
||||
this->p_currentPos(travelPosition(this->startPos, 1, (uint32_t)(curTime - this->moveStart), downTime));
|
||||
|
|
@ -609,22 +599,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
|
|||
const bool isSunny = this->flags & static_cast<uint8_t>(somfy_flags_t::Sunny);
|
||||
//this->flags |= static_cast<uint8_t>(somfy_flags_t::SunFlag);
|
||||
this->p_sunFlag(true);
|
||||
switch(this->sensors.onSunFlag(isSunny, isWindy)) {
|
||||
case SensorMove::extend:
|
||||
if(this->tiltType == tilt_types::tiltonly)
|
||||
this->p_tiltTarget(this->myTiltPos >= 0 ? this->myTiltPos : 100.0f);
|
||||
else
|
||||
this->p_target(this->myPos >= 0 ? this->myPos : 100.0f);
|
||||
break;
|
||||
case SensorMove::retract:
|
||||
if(this->tiltType == tilt_types::tiltonly)
|
||||
this->p_tiltTarget(0.0f);
|
||||
else
|
||||
this->p_target(0.0f);
|
||||
break;
|
||||
case SensorMove::none:
|
||||
break;
|
||||
}
|
||||
this->applySensorMove(this->sensors.onSunFlag(isSunny, isWindy));
|
||||
somfy.isDirty = true;
|
||||
this->emitState();
|
||||
this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress);
|
||||
|
|
@ -1007,16 +982,7 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
|
|||
const bool isSunny = this->flags & static_cast<uint8_t>(somfy_flags_t::Sunny);
|
||||
this->p_sunFlag(true);
|
||||
//this->flags |= static_cast<uint8_t>(somfy_flags_t::SunFlag);
|
||||
switch(this->sensors.onSunFlag(isSunny, isWindy)) {
|
||||
case SensorMove::extend:
|
||||
this->p_target(this->myPos >= 0 ? this->myPos : 100.0f);
|
||||
break;
|
||||
case SensorMove::retract:
|
||||
this->p_target(0.0f);
|
||||
break;
|
||||
case SensorMove::none:
|
||||
break;
|
||||
}
|
||||
this->applySensorMove(this->sensors.onSunFlag(isSunny, isWindy));
|
||||
somfy.isDirty = true;
|
||||
this->emitState();
|
||||
}
|
||||
|
|
@ -1126,6 +1092,11 @@ void SomfyShade::runToLimit(int8_t dir, bool tilt, uint32_t since) {
|
|||
// The favorite can't be set where the shade won't stop.
|
||||
this->settingMyPos = false;
|
||||
}
|
||||
void SomfyShade::applySensorMove(SensorMove move) {
|
||||
const SensorTargets t = sensorTargets(move, this->tiltType, this->myPos, this->myTiltPos);
|
||||
if(t.setLift) this->p_target(t.lift);
|
||||
if(t.setTilt) this->p_tiltTarget(t.tilt);
|
||||
}
|
||||
void SomfyShade::setMovement(int8_t dir) {
|
||||
int8_t currDir = this->direction;
|
||||
int8_t currTiltDir = this->tiltDirection;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue