-#define QUANTITY_FIELDS \
- QF(info, design_capacity, "mWh", energy_full_design, 1e-3) \
- QF(info, last_full_capacity, "mWh", energy_full, 1e-3) \
- QF(state, present_rate, "mW", power_now, 1e-3) \
- QF(state, remaining_capacity, "mWh", energy_now, 1e-3) \
- QF(alarm, alarm, "mWh", alarm, 1e-3)
-
-#define QF(f,l,u,a,ac) 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 UEVENT_QUANTITY_FIELDS(q) \
+ q(design_capacity, CHARGE_FULL_DESIGN ) /* uAh */ \
+ q(last_full_capacity, CHARGE_FULL ) /* uAh */ \
+ q(present_rate, CURRENT_NOW ) /* uA */ \
+ q(remaining_capacity, CHARGE_NOW ) /* uAh */ \
+ q(present, PRESENT ) /* boolean */ \
+ q(online, ONLINE ) /* boolean */
+
+#define UEVENT_ENUM_FIELDS(e) \
+ e(type, TYPE, "Battery", "Mains" ) \
+ e(state, STATUS, "Discharging", "Charging", "Charged" )
+
+#define CHGST_DISCHARGING 0 /* Reflects order in e(state,...) above */
+#define CHGST_CHARGING 1 /* Also, much code assumes exadtly */
+#define CHGST_CHARGED 2 /* these three possible states. */
+#define CHGST_ERROR 8 /* Except that this one is an extra bit. */
+
+#define Q_FLD(f,l) { "POWER_SUPPLY_" #l, &thisbat_##f },
+#define E_FLD(f,l,vl...) { "POWER_SUPPLY_" #l, &thisbat_##f, { vl } },
+
+#define ALL_FIELDS(i) \
+ UEVENT_QUANTITY_FIELDS(i) \
+ UEVENT_ENUM_FIELDS(i) \
+ i(thisbat_alarm)
+
+#define F_VAR(f,...) static uint64_t thisbat_##f;
+ ALL_FIELDS(F_VAR)
+
+static const batinfo_field uevent_fields[]= {
+ UEVENT_QUANTITY_FIELDS(Q_FLD)
+ UEVENT_ENUM_FIELDS(E_FLD)
+ { 0 }
+};