refactor: move sun and wind automation into ShadeSensors

The sun and wind timers were spread over processFrame, checkMovement and
processInternalCommand. ShadeSensors now holds them and decides when the
weather extends or retracts a shade, when turning the sun flag on moves
it, and when wind blocks a remote Down. Each caller still sets the targets
itself, so no shade moves differently yet.

The timers are now 32-bit like millis(). As 64-bit values holding a 32-bit
millis() they fired at once after the rollover every 49.7 days. The debug
logs of each timer go: they were compiled out at CORE_DEBUG_LEVEL 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-13 21:12:34 +02:00
parent 0eb0e63631
commit 8276c1c3cd
6 changed files with 319 additions and 129 deletions

View file

@ -11,22 +11,13 @@
#define SOMFY_MAX_ROOMS 16
#define SOMFY_MAX_REPEATERS 7
#define SECS_TO_MILLIS(x) ((x) * 1000)
#define MINS_TO_MILLIS(x) SECS_TO_MILLIS((x) * 60)
#define SOMFY_SUN_TIMEOUT MINS_TO_MILLIS(2)
#define SOMFY_NO_SUN_TIMEOUT MINS_TO_MILLIS(20)
#define SOMFY_WIND_TIMEOUT SECS_TO_MILLIS(2)
#define SOMFY_NO_WIND_TIMEOUT MINS_TO_MILLIS(12)
#define SOMFY_NO_WIND_REMOTE_TIMEOUT SECS_TO_MILLIS(30)
#include "SomfyFrame.h"
#include "TxBuffer.h"
#include "RadioScheduler.h"
#include "ShadeTypes.h"
#include "ShadeMotion.h"
#include "ShadeSensors.h"
#include "Transceiver.h"
enum class somfy_flags_t : byte {
@ -127,15 +118,7 @@ class SomfyShade : public SomfyRemote {
uint8_t shadeId = 255;
uint64_t moveStart = 0;
uint64_t tiltStart = 0;
uint64_t noSunStart = 0;
uint64_t sunStart = 0;
uint64_t windStart = 0;
uint64_t windLast = 0;
uint64_t noWindStart = 0;
bool noSunDone = true;
bool sunDone = true;
bool windDone = true;
bool noWindDone = true;
ShadeSensors sensors;
float startPos = 0.0f;
float startTiltPos = 0.0f;
bool settingMyPos = false;