2006-03-04 18:16:49 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - UptimeMeter.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2021-09-22 09:33:00 +00:00
|
|
|
Released under the GNU GPLv2+, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UptimeMeter.h"
|
2020-09-19 18:22:34 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "CRT.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Object.h"
|
2020-09-19 18:22:34 +00:00
|
|
|
#include "Platform.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2020-09-28 10:23:07 +00:00
|
|
|
static const int UptimeMeter_attributes[] = {
|
2006-06-06 20:41:01 +00:00
|
|
|
UPTIME
|
|
|
|
};
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2020-10-06 11:13:16 +00:00
|
|
|
static void UptimeMeter_updateValues(Meter* this) {
|
2014-11-27 21:41:14 +00:00
|
|
|
int totalseconds = Platform_getUptime();
|
2021-06-13 09:17:24 +00:00
|
|
|
if (totalseconds <= 0) {
|
2020-10-06 11:13:16 +00:00
|
|
|
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "(unknown)");
|
2014-11-27 21:41:14 +00:00
|
|
|
return;
|
2011-09-08 02:54:02 +00:00
|
|
|
}
|
2006-04-10 20:40:38 +00:00
|
|
|
int seconds = totalseconds % 60;
|
2020-10-31 22:28:02 +00:00
|
|
|
int minutes = (totalseconds / 60) % 60;
|
|
|
|
int hours = (totalseconds / 3600) % 24;
|
|
|
|
int days = (totalseconds / 86400);
|
2006-04-10 20:40:38 +00:00
|
|
|
this->values[0] = days;
|
|
|
|
if (days > this->total) {
|
|
|
|
this->total = days;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2017-07-27 19:07:50 +00:00
|
|
|
char daysbuf[32];
|
2006-04-10 20:40:38 +00:00
|
|
|
if (days > 100) {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
|
2006-04-10 20:40:38 +00:00
|
|
|
} else if (days > 1) {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
|
2006-04-10 20:40:38 +00:00
|
|
|
} else if (days == 1) {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(daysbuf, sizeof(daysbuf), "1 day, ");
|
2006-04-10 20:40:38 +00:00
|
|
|
} else {
|
|
|
|
daysbuf[0] = '\0';
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2020-10-06 11:13:16 +00:00
|
|
|
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const MeterClass UptimeMeter_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete
|
|
|
|
},
|
2016-05-04 05:39:26 +00:00
|
|
|
.updateValues = UptimeMeter_updateValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2016-03-11 02:54:34 +00:00
|
|
|
.maxItems = 1,
|
2008-03-09 08:58:38 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = UptimeMeter_attributes,
|
|
|
|
.name = "Uptime",
|
|
|
|
.uiName = "Uptime",
|
|
|
|
.caption = "Uptime: "
|
|
|
|
};
|