This commit is contained in:
Wolfgang Hottgenroth
2014-05-14 19:37:04 +02:00
commit ca8ed709b8
22 changed files with 1468 additions and 0 deletions

48
uptime.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <WString.h>
#include "uptime.h"
#include <Streaming.h>
UptimeCmd::UptimeCmd(Uptime *uptime) : m_uptime(uptime) {
}
String UptimeCmd::exec(String params) {
return m_uptime->getDays() + String(" ") +
m_uptime->getHours() + String(":") + m_uptime->getMinutes() + String(":") + m_uptime->getSeconds();
}
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;
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;
Serial << m_days << ", " << m_hours << ":" << m_minutes << ":" << m_seconds << endl;
}
}