-#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(_, _ec, EC_, PC_) \
+ _(design_capacity##_ec, BATTERY, EC_##FULL_DESIGN ) \
+ _(last_full_capacity##_ec, BATTERY, EC_##FULL ) \
+ _(remaining_capacity##_ec, BATTERY, EC_##NOW ) \
+ _(present_rate##_ec, BATTERY, PC_##NOW )
+ /* ENERGY [mWh]; POWER [mW]; CHARGE [uAh]; CURRENT [uA] */
+
+#define UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \
+ _(present, BATTERY, PRESENT /* bool */ ) \
+ _(online, MAINS, ONLINE /* bool */ )
+
+#define UEVENT_FUNKY_QUANTITY_FIELDS(_) \
+ BAT_QTYS(_,_energy,ENERGY_,POWER_) \
+ BAT_QTYS(_,_charge,CHARGE_,CURRENT_)
+
+#define UEVENT_OPTIONAL_QUANTITY_FIELDS(_) \
+ _(voltage, BATTERY, VOLTAGE_NOW /* uV */ )
+
+#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(_) \
+ /* See commit ec6f5f0be800bc5f2a27046833dba04e0c67ffac for
+ the code needed to use this */
+
+
+#define ALL_DIRECT_VARS(_) \
+ UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \
+ UEVENT_FUNKY_QUANTITY_FIELDS(_) \
+ UEVENT_OPTIONAL_QUANTITY_FIELDS(_) \
+ UEVENT_ENUM_FIELDS(_) \
+ SEPARATE_QUANTITY_FIELDS(_)
+
+#define ALL_VARS(_) \
+ ALL_DIRECT_VARS(_) \
+ BAT_QTYS(_,,,)
+
+#define ALL_NEEDED_FIELDS(_) \
+ UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \
+ UEVENT_ENUM_FIELDS(_) \
+ SEPARATE_QUANTITY_FIELDS(_)
+
+#define ALL_PLAIN_ACCUMULATE_FIELDS(_) \
+ UEVENT_ESSENTIAL_QUANTITY_FIELDS(_) \
+ SEPARATE_QUANTITY_FIELDS(_)
+
+#define ALL_ACCUMULATE_FIELDS(_) \
+ ALL_PLAIN_ACCUMULATE_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_ESSENTIAL_QUANTITY_FIELDS(Q_FLD)
+ UEVENT_FUNKY_QUANTITY_FIELDS(Q_FLD)
+ UEVENT_OPTIONAL_QUANTITY_FIELDS(Q_FLD)
+ UEVENT_ENUM_FIELDS(E_FLD)
+ { 0 }