chiark / gitweb /
xbatmon-simple: Parse (but do not process) TYPE=USB
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 15 Jul 2025 13:22:50 +0000 (14:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 15 Jul 2025 15:40:33 +0000 (16:40 +0100)
We prefer the general ACAD entry, which subsumes the more specific USB
entries.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cprogs/xbatmon-simple.c

index 8fe9b0690761ed154c607c6144d00d9340876888..3ce1d5726b3e6b32b690b126209e8d473b9b2eb1 100644 (file)
@@ -123,7 +123,7 @@ typedef struct batinfo_field {
 
 #define UEVENT_ENUM_FIELDS(_)                                          \
   _(state,   BATTERY,  STATUS,  "Discharging","Charging","Full","Unknown" ) \
-  _(type,    BOTH,     TYPE,    "Mains",       "Battery"              )
+  _(type,    BOTH,     TYPE,    "Mains",       "Battery",  "USB" )
 
 #define CHGST_DISCHARGING 0 /* Reflects order in _(state,...) above     */
 #define CHGST_CHARGING    1 /* Also, much code assumes exactly          */
@@ -132,8 +132,9 @@ typedef struct batinfo_field {
 #define CHGST_ERROR       8 /* Except that this one is an extra bit.    */
 
 #define TYPE_MAINS        0 /* Reflects order in _(type,...) above        */
-#define TYPE_BATTERY      1 /* Also, much code assumes exactly these two  */
-#define TYPE_BOTH       100 /* Except this is a magic invalid value.      */
+#define TYPE_BATTERY      1 /* We want exactly one of MAINS & BATTERY     */
+#define TYPE_USB          2 /* These get ignored.                         */
+#define TYPE_BOTH       100 /* This is a magic invalid value.             */
 
 #define SEPARATE_QUANTITY_FIELDS(_)            \
   /* See commit ec6f5f0be800bc5f2a27046833dba04e0c67ffac for
@@ -396,6 +397,9 @@ ALL_ACCUMULATE_FIELDS(Q_ZERO)
     r= readbattery();
     tidybattery();
 
+    if (this_type >= TYPE_USB)
+      continue;
+
     if (r) {
     bad:
       charging_mask |= (1u << CHGST_ERROR);