-/* todo
- old way of doing alarm
-*/
-
/*
* display outputs, per line:
*
- * Remaining: | Empty: | Degraded:
- * blue | black | dimgrey discharging
- * green | black | dimgrey charging
- * cyan | black | dimgrey charged
- * grey | black | dimgrey charging&discharching!
- * darkcyan | black | dimgrey none of the above
- * blue | red | dimgrey discharging - low!
- * green | red | dimgrey charging - low
- * cyan | red | dimgrey charged - low [1]
- * grey | red | dimgrey charging&discharching, low [1]
+ * Remaining: | Empty: | Degraded:
+ * blue | black | dimgrey discharging
+ * green | black | dimgrey charging
+ * cyan | black | dimgrey charged
+ * grey | black | dimgrey charging&discharching!
+ * lightgrey | black | dimgrey none of the above
+ * blue | red | dimgrey discharging - low!
+ * green | red | dimgrey charging - low
+ * cyan | red | dimgrey charged - low [1]
+ * grey | red | dimgrey charging&discharching, low [1]
* ... darkgreen ... no batteries present
* ... yellow ... error
*
#define TIMEOUT_ONERROR 3333 /* milliseconds */
static const char program_name[]= "xacpi-simple";
-static int debug;
+static int debug, alarmlevel;
/*---------- general utility stuff and declarations ----------*/
#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_PLAIN_ACCUMULATE_FIELDS(_) \
UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \
- UEVENT_ENUM_FIELDS(_) \
SEPARATE_QUANTITY_FIELDS(_)
#define ALL_ACCUMULATE_FIELDS(_) \
/* 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 alarmed;
#define Q_VAR(f,t,...) \
static double total_##f;
int r;
charging_mask= 0;
+ alarmed = 0;
+
+ if (debug) printf("\n");
#define Q_ZERO(f,t,...) \
total_##f= 0;
}
closedir(di);
- printf("TOTAL:\n");
+ if (debug) {
+ printf("TOTAL:\n");
+ printf(" %-30s = %#20x\n", "mask", charging_mask);
#define T_PRINT(f,...) \
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 < 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
C(blue, discharging) \
C(green, charging) \
C(cyan, charged) \
- C(darkcyan, notcharging) \
+ C(lightgrey, notcharging) \
C(grey, confusing) \
C(black, normal) \
C(red, low) \
#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)
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");
setforeground(&gc_remain,
!(charging_mask & CHGMASK_CHG_DIS) ?
(~charging_mask & (1u << CHGST_CHARGED) ?
- pix_darkcyan : pix_cyan) :
+ pix_lightgrey : pix_cyan) :
!(~charging_mask & CHGMASK_CHG_DIS) ? pix_grey :
charging_mask & (1u<<CHGST_CHARGING)
? pix_green : pix_blue);
- setforeground(&gc_empty, alarm_level ? pix_red : pix_black);
+ setforeground(&gc_empty, alarmed ? pix_red : pix_black);
for (i=0, first_beyond=1; i<height; i++) {
elap= !i ? 0 :