chiark
/
gitweb
/
~ian
/
chiark-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ec6f5f0
)
new alarm workings
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Wed, 6 Jun 2012 00:20:11 +0000
(
01:20
+0100)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Wed, 6 Jun 2012 00:20:18 +0000
(
01:20
+0100)
cprogs/xacpi-simple.c
patch
|
blob
|
history
diff --git
a/cprogs/xacpi-simple.c
b/cprogs/xacpi-simple.c
index bbdcecb7bfa723f8d29e796439ab0352ed913e71..9d67c37bbbe7ba69b1e287853645afb05bc7f112 100644
(file)
--- a/
cprogs/xacpi-simple.c
+++ b/
cprogs/xacpi-simple.c
@@
-1,7
+1,3
@@
-/* todo
- old way of doing alarm
-*/
-
/*
* display outputs, per line:
*
/*
* display outputs, per line:
*
@@
-66,7
+62,7
@@
#define TIMEOUT_ONERROR 3333 /* milliseconds */
static const char program_name[]= "xacpi-simple";
#define TIMEOUT_ONERROR 3333 /* milliseconds */
static const char program_name[]= "xacpi-simple";
-static int debug;
+static int debug
, alarmlevel
;
/*---------- general utility stuff and declarations ----------*/
/*---------- general utility stuff and declarations ----------*/
@@
-135,7
+131,8
@@
typedef struct batinfo_field {
#define TYPE_BOTH 100 /* Except this is a magic invalid value. */
#define SEPARATE_QUANTITY_FIELDS(_) \
#define TYPE_BOTH 100 /* Except this is a magic invalid value. */
#define SEPARATE_QUANTITY_FIELDS(_) \
- _(alarm, BATTERY, "alarm", "0", "1")
+ /* See commit ec6f5f0be800bc5f2a27046833dba04e0c67ffac for
+ the code needed to use this */
#define ALL_DIRECT_VARS(_) \
#define ALL_DIRECT_VARS(_) \
@@
-354,7
+351,7
@@
ALL_NEEDED_FIELDS(V_NEEDED)
/* These next three variables are the results of the charging state */
static unsigned charging_mask; /* 1u<<CHGST_* | ... */
static double nondegraded_norm, fill_norm, ratepersec_norm;
/* These next three variables are the results of the charging state */
static unsigned charging_mask; /* 1u<<CHGST_* | ... */
static double nondegraded_norm, fill_norm, ratepersec_norm;
-static int alarm
_level; /* 0=ok, 1=low */
+static int alarm
ed;
#define Q_VAR(f,t,...) \
static double total_##f;
#define Q_VAR(f,t,...) \
static double total_##f;
@@
-366,6
+363,7
@@
static void acquiredata(void) {
int r;
charging_mask= 0;
int r;
charging_mask= 0;
+ alarmed = 0;
#define Q_ZERO(f,t,...) \
total_##f= 0;
#define Q_ZERO(f,t,...) \
total_##f= 0;
@@
-435,6
+433,16
@@
ALL_PLAIN_ACCUMULATE_FIELDS(Q_ACCUMULATE_PLAIN)
printf(" %-30s = %20.6f\n", #f, total_##f);
BAT_QTYS(T_PRINT,,,)
ALL_PLAIN_ACCUMULATE_FIELDS(T_PRINT)
printf(" %-30s = %20.6f\n", #f, total_##f);
BAT_QTYS(T_PRINT,,,)
ALL_PLAIN_ACCUMULATE_FIELDS(T_PRINT)
+ }
+
+ if ((charging_mask & (1u<<CHGST_DISCHARGING)) &&
+ !total_online/*mains*/) {
+ double time_remaining =
+ -total_remaining_capacity * 3600.0 / total_present_rate;
+ if (debug) printf(" %-30s = %20.6f\n", "time remaining", time_remaining);
+ if (time_remaining < alarmlevel)
+ alarmed = 1;
+ }
if (total_design_capacity < 0.5)
total_design_capacity= 1.0;
if (total_design_capacity < 0.5)
total_design_capacity= 1.0;
@@
-444,8
+452,6
@@
ALL_PLAIN_ACCUMULATE_FIELDS(T_PRINT)
if (total_design_capacity < total_last_full_capacity)
total_design_capacity= total_last_full_capacity;
if (total_design_capacity < total_last_full_capacity)
total_design_capacity= total_last_full_capacity;
- alarm_level= total_alarm && (charging_mask & 1u << CHGST_DISCHARGING);
-
nondegraded_norm= total_last_full_capacity / total_design_capacity;
fill_norm= total_remaining_capacity / total_design_capacity;
ratepersec_norm= total_present_rate
nondegraded_norm= total_last_full_capacity / total_design_capacity;
fill_norm= total_remaining_capacity / total_design_capacity;
ratepersec_norm= total_present_rate
@@
-489,6
+495,7
@@
static const char defaultresources[]=
#define S(s) ((char*)(s))
static const XrmOptionDescRec optiontable[]= {
{ S("-debug"), S("*debug"), XrmoptionIsArg },
#define S(s) ((char*)(s))
static const XrmOptionDescRec optiontable[]= {
{ S("-debug"), S("*debug"), XrmoptionIsArg },
+ { S("-warningTime"), S("*warningTime"), XrmoptionSepArg },
{ S("-display"), S("*display"), XrmoptionSepArg },
{ S("-geometry"), S("*geometry"), XrmoptionSepArg },
#define GC(g)
{ S("-display"), S("*display"), XrmoptionSepArg },
{ S("-geometry"), S("*geometry"), XrmoptionSepArg },
#define GC(g)
@@
-539,6
+546,9
@@
static void parseargs(int argc, char **argv) {
debug= !!getresource("debug");
debug= !!getresource("debug");
+ const char *alarmlevel_string= getresource("alarmLevel");
+ alarmlevel = alarmlevel_string ? atoi(alarmlevel_string) : 300;
+
disp= XOpenDisplay(getresource("display"));
if (!disp) fail("could not open display");
disp= XOpenDisplay(getresource("display"));
if (!disp) fail("could not open display");
@@
-625,7
+635,7
@@
static void show(void) {
charging_mask & (1u<<CHGST_CHARGING)
? pix_green : pix_blue);
charging_mask & (1u<<CHGST_CHARGING)
? pix_green : pix_blue);
- setforeground(&gc_empty, alarm
_level
? pix_red : pix_black);
+ setforeground(&gc_empty, alarm
ed
? pix_red : pix_black);
for (i=0, first_beyond=1; i<height; i++) {
elap= !i ? 0 :
for (i=0, first_beyond=1; i<height; i++) {
elap= !i ? 0 :