new
This commit is contained in:
parent
44bf85a800
commit
c1c0d33358
38
src/uptime.cpp
Normal file
38
src/uptime.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
#include "uptime.h"
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Uptime::Uptime() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Uptime::exec() {
|
||||||
|
static unsigned long lastMillis = 0;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long currentMillis = millis();
|
||||||
|
if (currentMillis >= (lastMillis + 1000)) {
|
||||||
|
m_seconds += ((currentMillis - lastMillis) / 1000);
|
||||||
|
if (m_seconds >= 60) {
|
||||||
|
m_seconds -= 60;
|
||||||
|
m_minutes++;
|
||||||
|
if (m_minutes >= 60) {
|
||||||
|
m_minutes -= 60;
|
||||||
|
m_hours++;
|
||||||
|
if (m_hours >= 24) {
|
||||||
|
m_hours -= 24;
|
||||||
|
m_days++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastMillis = currentMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/uptime.h
Normal file
27
src/uptime.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef UPTIME_H_
|
||||||
|
#define UPTIME_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class Uptime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Uptime {
|
||||||
|
public:
|
||||||
|
Uptime();
|
||||||
|
void exec();
|
||||||
|
uint8_t getSeconds() { return m_seconds; };
|
||||||
|
uint8_t getMinutes() { return m_minutes; };
|
||||||
|
uint8_t getHours() { return m_hours; };
|
||||||
|
uint16_t getDays() { return m_days; };
|
||||||
|
private:
|
||||||
|
uint8_t m_seconds;
|
||||||
|
uint8_t m_minutes;
|
||||||
|
uint8_t m_hours;
|
||||||
|
uint16_t m_days;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* TEST_H_ */
|
Loading…
x
Reference in New Issue
Block a user