battery.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef BACKEND_BATTERY_H_
  2. #define BACKEND_BATTERY_H_
  3. #include "timer.h"
  4. #include "api.h"
  5. #include "probe.h"
  6. struct battery {
  7. const char *name;
  8. /* Returns 1 if on AC; 0 if not. */
  9. int (*on_ac)(struct battery *b);
  10. /* Enable/disable charging. Returns 0 on success or negative error code. */
  11. int (*charger_enable)(struct battery *b, int enable);
  12. /* Returns 1 if charging the battery; 0 if not */
  13. int (*charging)(struct battery *b);
  14. /* Returns the minimum battery level constant value */
  15. int (*min_level)(struct battery *b);
  16. /* Returns the maximum battery level constant value */
  17. int (*max_level)(struct battery *b);
  18. /* Get the battery charge level value */
  19. int (*charge_level)(struct battery *b);
  20. /* Returns the battery capacity in mAh. 0 if no battery present.
  21. * Negative if unknown */
  22. int (*capacity_mAh)(struct battery *b);
  23. /* Returns the measured battery current in mA.
  24. * This is charge current if charging and drain current if draining.
  25. * Negative value is returned on error */
  26. int (*current_mA)(struct battery *b);
  27. /* Returns the battery temperature in K. Negative is not supported. */
  28. int (*temperature_K)(struct battery *b);
  29. void (*destroy)(struct battery *b);
  30. int (*update)(struct battery *b);
  31. unsigned int poll_interval;
  32. /* Internal */
  33. struct sleeptimer timer;
  34. int emergency_handled;
  35. };
  36. void battery_init(struct battery *b, const char *name);
  37. struct battery * battery_probe(void);
  38. void battery_destroy(struct battery *b);
  39. int battery_fill_pt_message_stat(struct battery *b, struct pt_message *msg);
  40. int battery_notify_state_change(struct battery *b);
  41. DECLARE_PROBES(battery);
  42. #define BATTERY_PROBE(_name, _func) DEFINE_PROBE(battery, _name, _func)
  43. #endif /* BACKEND_BATTERY_H_ */