Skip to content

Commit

Permalink
Merge pull request #52 from pimlie/fix-sleep-def
Browse files Browse the repository at this point in the history
fix: check correct ifdef macro & only increment dow for sunday
  • Loading branch information
lanrat authored Aug 28, 2024
2 parents b2eb18f + c0493d0 commit 7ae44e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void runActivities(void *params)

Serial.printf("[ACTIVITY] starting activity: %d\n", activityNext);
bool doQuickSleep = activityNext == GuestWifi || activityNext == Info;
#ifdef sleepSchedule
#ifdef CONFIG_CPP
TimeInfo time = {
.dow = getDayOfWeek(true),
.hour = getHour(),
Expand Down
18 changes: 10 additions & 8 deletions src/config_example.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// NOTE: THIS FILE IS ONLY NEEDED WHEN CONFIGURING A CUSTOM SLEEP
// SCHEDULE.
// IF USING A SINGLE/STATIC SLEEP DURATION THEN THIS FILE CAN BE OMITTED
// #include "config.h"
// Note:
// This file is only needed when configuring a custom sleep schedule.
// If using a single/static sleep duration then this file can be omitted
/* REMOVE THIS LINE TO ENABLE THE SLEEP SCHEDULE
#include "config.h"
#define CONFIG_CPP
// How long to sleep between image refreshes
// - there is no validation of any kind, make sure your slots are continuous
// - falls back to TIME_TO_SLEEP_MIN if your slots are not continuous
// - a schedule slot is configured per day, i.e. cronjob style
// - dow = DayOfWeek, starts at 1 = Monday to 7 = Sunday
// SleepScheduleSlot sleepSchedule[] = {
/* EXAMPLE BLOCKS
// EXAMPLE BLOCKS
{ // On each workday from 00:00 to 08:30 sleep for 1 hour
.start_dow = 1,
.start_hour = 0,
Expand Down Expand Up @@ -55,7 +57,7 @@
.end_minute = 0,
.sleep_in_seconds = 300,
},
*/
// };
};
//const size_t sleepScheduleSize = sizeof(sleepSchedule) / sizeof(sleepSchedule[0]);
const size_t sleepScheduleSize = sizeof(sleepSchedule) / sizeof(sleepSchedule[0]);
/**/
8 changes: 7 additions & 1 deletion src/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ int getDayOfWeek(bool weekStartsOnMonday) {
// return -1 as long as rtc is not set
return -1;
}
return rtc.getDayofWeek() + (weekStartsOnMonday ? 1 : 0);

int dow = rtc.getDayofWeek();
if (dow == 0) {
return dow + 1;
} else {
return dow;
}
}

int getHour() {
Expand Down

0 comments on commit 7ae44e5

Please sign in to comment.