2014-02-23 23:42:22 +01:00
|
|
|
|
2014-02-23 21:12:13 +01:00
|
|
|
#include <WString.h>
|
|
|
|
#include "uptime.h"
|
|
|
|
|
|
|
|
|
2014-02-23 23:42:22 +01:00
|
|
|
|
|
|
|
|
2014-02-23 21:12:13 +01:00
|
|
|
UptimeCmd::UptimeCmd(Uptime *uptime) : m_uptime(uptime) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String UptimeCmd::exec(String params) {
|
2014-02-23 23:42:22 +01:00
|
|
|
String res = m_uptime->getDays() + String(" ") +
|
2014-02-23 21:12:13 +01:00
|
|
|
m_uptime->getHours() + String(":") + m_uptime->getMinutes() + String(":") + m_uptime->getSeconds();
|
2014-02-23 23:42:22 +01:00
|
|
|
return res;
|
2014-02-23 21:12:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Uptime::Uptime() : m_uptimeCmd(this), m_seconds(0), m_minutes(0), m_hours(0), m_days(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Uptime::begin(CmdServer *cmdServer) {
|
|
|
|
m_uptimeCmd.registerYourself(cmdServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Uptime::exec() {
|
|
|
|
static unsigned long lastMillis = 0;
|
|
|
|
|
2014-02-23 23:42:22 +01:00
|
|
|
|
2014-02-23 21:12:13 +01:00
|
|
|
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;
|
|
|
|
}
|
2014-02-23 23:42:22 +01:00
|
|
|
|
2014-02-23 21:12:13 +01:00
|
|
|
}
|