mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
test: cover the radio queue rules, shade TX state, rolling codes and web command hold
Move the pieces of the radio TX path that don't need FreeRTOS or NVS out of Somfy.cpp and Web.cpp so they build in the native test env: the TX job and event types and job encoding (TxBuffer), the queue rules (TxQueuePolicy.h), a shade's pending radio jobs (ShadeTxState), the next rolling code (RollingCode.h) and the web command queue types (WebCommand.h). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6a3769406f
commit
1962778912
15 changed files with 912 additions and 186 deletions
|
|
@ -29,6 +29,7 @@ int8_t displayPosition(float pos, bool flip) {
|
|||
if(pos < 0) return -1;
|
||||
return static_cast<int8_t>(flip && pos >= 0.00f ? floor(100.0f - pos) : floor(pos));
|
||||
}
|
||||
float limitTarget(int8_t dir) { return dir > 0 ? 100.0f : 0.0f; }
|
||||
void TxHold::mark(uint32_t jobSeq, bool moving, uint32_t now) {
|
||||
if(jobSeq == 0 || this->seq != 0 || moving) return;
|
||||
this->seq = jobSeq;
|
||||
|
|
@ -39,3 +40,58 @@ bool TxHold::release(uint32_t jobSeq) {
|
|||
this->seq = 0;
|
||||
return true;
|
||||
}
|
||||
TxHoldCheck TxHold::check(bool moving, uint32_t now, uint32_t timeoutMs) {
|
||||
if(!this->held()) return TxHoldCheck::none;
|
||||
if(!moving) {
|
||||
// The command didn't set the shade moving so there is nothing to hold.
|
||||
this->clear();
|
||||
return TxHoldCheck::none;
|
||||
}
|
||||
if(!this->timedOut(now, timeoutMs)) return TxHoldCheck::holding;
|
||||
this->clear();
|
||||
return TxHoldCheck::expired;
|
||||
}
|
||||
void ShadeTxState::stopSent(uint32_t seq, uint32_t now, int8_t dir, bool tilt) {
|
||||
this->stopSeq = seq;
|
||||
this->stopAt = now;
|
||||
this->stopDir = dir;
|
||||
this->stopTilt = tilt;
|
||||
}
|
||||
void ShadeTxState::setMySent(uint32_t seq, float oldPos, float oldTiltPos) {
|
||||
this->mySeq = seq;
|
||||
this->myOldPos = oldPos;
|
||||
this->myOldTiltPos = oldTiltPos;
|
||||
}
|
||||
ShadeTxActions ShadeTxState::onEvent(const somfy_tx_event_t &evt, bool moving) {
|
||||
ShadeTxActions act;
|
||||
if(evt.seq == 0) return act;
|
||||
if(this->hold.release(evt.seq)) {
|
||||
if(evt.type == tx_event_t::started) {
|
||||
act.startMovement = true;
|
||||
act.startAt = evt.at;
|
||||
}
|
||||
else act.cancelMovement = true;
|
||||
}
|
||||
if(this->mySeq == evt.seq && evt.type != tx_event_t::started) {
|
||||
this->mySeq = 0;
|
||||
// The motor only stores the favorite when it gets the whole long press.
|
||||
if(evt.type == tx_event_t::finished) act.commitMy = true;
|
||||
else {
|
||||
act.restoreMy = true;
|
||||
act.myOldPos = this->myOldPos;
|
||||
act.myOldTiltPos = this->myOldTiltPos;
|
||||
}
|
||||
}
|
||||
if(this->stopSeq == evt.seq) {
|
||||
this->stopSeq = 0;
|
||||
// Unless something has moved the shade since, the motor never got the stop
|
||||
// and is still running.
|
||||
if(evt.type == tx_event_t::dropped && !moving) {
|
||||
act.runToLimit = true;
|
||||
act.limitDir = this->stopDir;
|
||||
act.limitTilt = this->stopTilt;
|
||||
act.limitSince = this->stopAt;
|
||||
}
|
||||
}
|
||||
return act;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue