From 25ab690fa95375bb0cc24f7756e5abdad1fb8df7 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 26 Sep 2020 19:30:21 +0200 Subject: [PATCH] Recalculate next day immediately after sunset --- main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 9864a4a..48ce9e0 100644 --- a/main.c +++ b/main.c @@ -243,7 +243,10 @@ static void set_temperature(struct context *ctx) { static void recalc_stops(struct context *ctx, time_t now) { time_t day = now - (now % 86400); - if (day < ctx->stop_time) { + time_t true_end = ctx->stop_time + ctx->duration; + if (now > true_end) { + day += 86400; + } else if (day < true_end) { return; } @@ -278,9 +281,6 @@ start: } ctx->state = ANIMATING_TO_LOW; ctx->animation_start = ctx->stop_time; - if (ctx->animation_start > now) { - ctx->animation_start -= 86400; - } // fallthrough case ANIMATING_TO_LOW: if (now <= ctx->animation_start + ctx->duration) { @@ -298,9 +298,6 @@ start: } ctx->state = ANIMATING_TO_HIGH; ctx->animation_start = ctx->start_time; - if (ctx->animation_start > now) { - ctx->animation_start -= 86400; - } // fallthrough case ANIMATING_TO_HIGH: if (now <= ctx->animation_start + ctx->duration) {