Skip to content

Commit

Permalink
Added total sleep minutes to SessionData
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberneel committed Dec 17, 2024
1 parent 7d1cfae commit 1892a90
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/infinisleep/InfiniSleepController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace Pinetime {
uint8_t startTimeMinutes = 0;
uint8_t endTimeHours = 0;
uint8_t endTimeMinutes = 0;

uint16_t totalSleepMinutes = 0;
};
}

Expand Down Expand Up @@ -182,10 +184,23 @@ namespace Pinetime {
if (isEnabled) {
prevSessionData.endTimeHours = GetCurrentHour();
prevSessionData.endTimeMinutes = GetCurrentMinute();

// Calculate total sleep time
uint16_t startTotalMinutes = prevSessionData.startTimeHours * 60 + prevSessionData.startTimeMinutes;
uint16_t endTotalMinutes = GetCurrentHour() * 60 + GetCurrentMinute();

// If end time is before start time, add 24 hours to end time (handle crossing midnight)
if (endTotalMinutes < startTotalMinutes) {
endTotalMinutes += 24 * 60;
}

prevSessionData.totalSleepMinutes = endTotalMinutes - startTotalMinutes;

SavePrevSessionData();
DisableTracker();
} else {
// ClearDataCSV(TRACKER_DATA_FILE_NAME);
prevSessionData.totalSleepMinutes = 0;
prevSessionData.endTimeHours = 255;
prevSessionData.endTimeMinutes = 255;
prevSessionData.startTimeHours = GetCurrentHour();
Expand Down

0 comments on commit 1892a90

Please sign in to comment.