-#define QUANTITY_FIELDS \
- QF(info, design_capacity, "mWh") \
- QF(info, last_full_capacity, "mWh") \
- QF(state, present_rate, "mW") \
- QF(state, remaining_capacity, "mWh") \
- QF(alarm, alarm, "mWh")
-
-#define QF(f,l,u) static unsigned long thisbat_##f##_##l;
- QUANTITY_FIELDS
-#undef QF
-
-static unsigned long thisbat_alarm_present, thisbat_info_present;
-static unsigned long thisbat_state_present, thisbat_state_charging_state;
-
-#define VAL_NOTFOUND (~0UL)
-
-static const batinfo_field fields[]= {
-#define E(f,l) #f, #l, &thisbat_##f##_##l, 0
-#define QF(f,l,u) { #f, #l, &thisbat_##f##_##l, u },
- { E(alarm, present), { "no", "yes" } },
- { E(info, present), { "no", "yes" } },
- { E(state,present), { "no", "yes" } },
- { E(state,charging_state), { "discharging", "charging", "charged" } },
- QUANTITY_FIELDS /* take care re charging_state values order - */
- { 0 } /* if you must change it, search for CHGST_... */
-#undef E
-#undef QF
+#define BAT_QTYS(_) \
+ _(design_capacity, ENERGY, CHARGE, FULL_DESIGN ) \
+ _(last_full_capacity, ENERGY, CHARGE, FULL ) \
+ _(remaining_capacity, ENERGY, CHARGE, NOW ) \
+ _(present_rate, POWER, CURRENT, NOW )
+ /* ENERGY [mWh]; POWER [mW]; CHARGE [uAh]; CURRENT [uA] */
+
+#define UEVENT_QTY_CHARGE(f,lle,llc,lr) \
+ _(f##_energy, BATTERY, lle##_##lr ) \
+ _(f##_charge, BATTERY, llc##_##lr )
+
+#define UEVENT_QUANTITY_FIELDS(_) \
+ BAT_QTYS(UEVENT_QTY_CHARGE) \
+ _(present, BATTERY, PRESENT ) /* boolean */ \
+ _(online, MAINS, ONLINE ) /* boolean */
+
+#define UEVENT_ENUM_FIELDS(_) \
+ _(state, BATTERY, STATUS, "Discharging","Charging","Full","Unknown" ) \
+ _(type, BOTH, TYPE, "Mains", "Battery" )
+
+#define CHGST_DISCHARGING 0 /* Reflects order in _(state,...) above */
+#define CHGST_CHARGING 1 /* Also, much code assumes exactly */
+#define CHGST_CHARGED 2 /* these three possible states. */
+#define CHGST_UNKNOWN 3 /* these three possible states. */
+#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 SEPARATE_QUANTITY_FIELDS(_) \
+ _(alarm, BATTERY, "alarm", "0", "1")
+
+#define ALL_FIELDS(_) \
+ UEVENT_QUANTITY_FIELDS(_) \
+ UEVENT_ENUM_FIELDS(_) \
+ SEPARATE_QUANTITY_FIELDS(_)
+
+#define ALL_QUANTITY_FIELDS(_) \
+ UEVENT_QUANTITY_FIELDS(_) \
+ SEPARATE_QUANTITY_FIELDS(_)
+
+#define ALL_VARS(_) \
+ ALL_FIELDS(_) \
+ BAT_QTYS(_)
+
+#define F_VAR(f,...) \
+static value this_##f;
+ALL_VARS(F_VAR)
+
+#define Q_FLD(f,t,l) { "POWER_SUPPLY_" #l, &this_##f },
+#define E_FLD(f,t,l,vl...) { "POWER_SUPPLY_" #l, &this_##f, { vl } },
+
+static const batinfo_field uevent_fields[]= {
+ UEVENT_QUANTITY_FIELDS(Q_FLD)
+ UEVENT_ENUM_FIELDS(E_FLD)
+ { 0 }