#include #include "uptime.h" #include 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; } }