Merge pull request #16914 from cybermaus/Deduplicate-and-fix-%timerN%

Deduplicate and fix %timer n%
This commit is contained in:
Theo Arends 2022-10-29 14:21:41 +02:00 committed by GitHub
commit 2c114d3243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 17 deletions

View File

@ -253,10 +253,10 @@ uint16_t TimerGetTimeOfDay(uint8_t index)
int16_t xtime = xtimer.time;
#ifdef USE_SUNRISE
if (xtimer.mode) {
if (xtime >= 12*60) xtime = 12*60 - xtime;
xtime += (int16_t)SunMinutes(xtimer.mode-1);
if (xtime < 0) xtime += 24*60;
if (xtime >= 24*60) xtime -= 24*60;
ApplyTimerOffsets(&xtimer);
xtime = xtimer.time;
if (xtime==2047 && xtimer.mode==1) xtime *= -1; // Sun always has already rises
if (xtime==2046 && xtimer.mode==2) xtime *= -1; // Sun always has already set
}
#endif
return xtime;

View File

@ -1458,19 +1458,7 @@ bool findNextVariableValue(char * &pVarname, float &value)
} else if (sVarName.startsWith(F("TIMER"))) {
uint32_t index = sVarName.substring(5).toInt();
if (index > 0 && index <= MAX_TIMERS) {
value = Settings->timer[index -1].time;
#if defined(USE_SUNRISE)
// Correct %timerN% values for sunrise/sunset timers
if ((1 == Settings->timer[index -1].mode) || (2 == Settings->timer[index -1].mode)) {
// in this context, time variable itself is merely an offset, with <720 being negative
value += -720 + SunMinutes(Settings->timer[index -1].mode -1);
if (2 == Settings->timer[index -1].mode) {
// To aid rule comparative statements, sunset past midnight (high lattitudes) is expressed past 24h00
// So sunset at 00h45 is at 24h45
if (value < 360) { value += 1440; }
}
}
#endif // USE_SUNRISE
value = TimerGetTimeOfDay(index -1);
}
#if defined(USE_SUNRISE)
} else if (sVarName.equals(F("SUNRISE"))) {