Skip to content

Commit

Permalink
Fix rollover issue, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Dec 4, 2020
1 parent 14ad266 commit 63456a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ lib_deps =
monitor_filters =
esp8266_exception_decoder
; log2file
build_type = release
build_type = debug

[env:d1_mini]
board_build.filesystem = littlefs
Expand Down
34 changes: 13 additions & 21 deletions src/uptime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ const int uptimeHours(bool refr)
getNow(); // Make sure we are current
if (refr)
{
// Refresh values
unsigned long m = uptimeNow;
// Subtract millis value for any full days
m = m - (uptimeDays() * DAY_MILLIS);
// Refresh values:
// Subtract millis value for any full days via modulo
// Calculate full hours from remainder
hours = (int)floor(m / HOUR_MILLIS);
hours = (int)floor((uptimeNow % DAY_MILLIS) / HOUR_MILLIS);
}
return hours;
}
Expand All @@ -85,12 +83,10 @@ const int uptimeMinutes(bool refr)
getNow(); // Make sure we are current
if (refr)
{
// Refresh values
unsigned long m = uptimeNow;
// Subtract millis value for any full hours
m = m - (uptimeHours() * HOUR_MILLIS);
// Refresh values:
// Subtract millis value for any full hours via modulo
// Calculate full minutes from remainder
minutes = (int)floor(m / MIN_MILLIS);
minutes = (int)floor((uptimeNow % HOUR_MILLIS) / MIN_MILLIS);
}
return minutes;
}
Expand All @@ -100,12 +96,10 @@ const int uptimeSeconds(bool refr)
getNow(); // Make sure we are current
if (refr)
{
// Refresh values
unsigned long m = uptimeNow;
// Subtract millis value for any full minutes
m = m - (uptimeMinutes() * MIN_MILLIS);
// Refresh values:
// Subtract millis value for any full minutes via modulo
// Calculate full seconds from remainder
seconds = (int)floor(m / SEC_MILLIS);
seconds = (int)floor((uptimeNow % MIN_MILLIS) / SEC_MILLIS);
}
return seconds;
}
Expand All @@ -115,12 +109,10 @@ const int uptimeMillis(bool refr)
getNow(); // Make sure we are current
if (refr)
{
// Refresh values
unsigned long m = uptimeNow;
// Subtract millis value for any full seconds
m = m - (uptimeSeconds() * SEC_MILLIS);
// mills value is remainder
mills = m;
// Refresh values:
// Subtract millis value for any full seconds via modulo
// Return remainder millis
mills = (int)floor((uptimeNow % SEC_MILLIS));
}
return mills;
}
1 change: 1 addition & 0 deletions src/uptime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SOFTWARE. */
#ifndef _UPTIME_H
#define _UPTIME_H

#include <ArduinoLog.h> // DEBUG
#include <Arduino.h>

#define UPTIME_REFRESH 1
Expand Down

0 comments on commit 63456a0

Please sign in to comment.