2008-09-23 06:21:28 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - BatteryMeter.c
|
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
2008-09-23 06:21:28 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).
|
2008-09-23 06:21:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BatteryMeter.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2015-01-23 05:08:21 +00:00
|
|
|
#include "Battery.h"
|
2008-09-23 06:21:28 +00:00
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "CRT.h"
|
2015-08-19 16:43:20 +00:00
|
|
|
#include "StringUtils.h"
|
2015-02-20 16:52:10 +00:00
|
|
|
#include "Platform.h"
|
2008-09-23 06:21:28 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-04-27 21:48:09 +00:00
|
|
|
/*{
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Meter.h"
|
2009-04-27 21:48:09 +00:00
|
|
|
|
|
|
|
typedef enum ACPresence_ {
|
|
|
|
AC_ABSENT,
|
|
|
|
AC_PRESENT,
|
|
|
|
AC_ERROR
|
|
|
|
} ACPresence;
|
|
|
|
}*/
|
|
|
|
|
2008-09-23 06:21:28 +00:00
|
|
|
int BatteryMeter_attributes[] = {
|
|
|
|
BATTERY
|
|
|
|
};
|
|
|
|
|
2016-05-04 05:39:26 +00:00
|
|
|
static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) {
|
2014-11-27 23:02:52 +00:00
|
|
|
ACPresence isOnAC;
|
|
|
|
double percent;
|
|
|
|
|
2015-01-23 05:08:21 +00:00
|
|
|
Battery_getData(&percent, &isOnAC);
|
2014-11-27 23:02:52 +00:00
|
|
|
|
|
|
|
if (percent == -1) {
|
|
|
|
this->values[0] = 0;
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, "n/a");
|
2014-11-27 23:02:52 +00:00
|
|
|
return;
|
2009-04-27 21:48:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-23 06:21:28 +00:00
|
|
|
this->values[0] = percent;
|
|
|
|
|
2010-02-25 01:43:18 +00:00
|
|
|
const char *onAcText, *onBatteryText, *unknownText;
|
2009-04-27 21:48:09 +00:00
|
|
|
|
|
|
|
unknownText = "%.1f%%";
|
2008-09-23 06:21:28 +00:00
|
|
|
if (this->mode == TEXT_METERMODE) {
|
|
|
|
onAcText = "%.1f%% (Running on A/C)";
|
|
|
|
onBatteryText = "%.1f%% (Running on battery)";
|
|
|
|
} else {
|
|
|
|
onAcText = "%.1f%%(A/C)";
|
|
|
|
onBatteryText = "%.1f%%(bat)";
|
|
|
|
}
|
|
|
|
|
2014-11-27 23:02:52 +00:00
|
|
|
if (isOnAC == AC_PRESENT) {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, onAcText, percent);
|
2014-11-27 23:02:52 +00:00
|
|
|
} else if (isOnAC == AC_ABSENT) {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, onBatteryText, percent);
|
2008-09-23 06:21:28 +00:00
|
|
|
} else {
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, unknownText, percent);
|
2008-09-23 06:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
MeterClass BatteryMeter_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete
|
|
|
|
},
|
2016-05-04 05:39:26 +00:00
|
|
|
.updateValues = BatteryMeter_updateValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2016-03-11 02:54:34 +00:00
|
|
|
.maxItems = 1,
|
2008-09-23 06:21:28 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = BatteryMeter_attributes,
|
|
|
|
.name = "Battery",
|
|
|
|
.uiName = "Battery",
|
|
|
|
.caption = "Battery: "
|
|
|
|
};
|