battery.h 905 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef BATTERY_H
  2. #define BATTERY_H
  3. #include <stdint.h>
  4. //define macro to be used by multiple files in the program witout the variable being overwritten
  5. #define NUM_SLOTS (1)
  6. #define BATTERY_THRESHOLD (50)
  7. typedef enum{
  8. STATE_EMPTY= 0x01,
  9. STATE_BATTERY_DETECTED= 0x02,
  10. STATE_MEASUREMENT_IN_PROGRESS= 0x03,
  11. STATE_MEASUREMENT_DONE= 0x04,
  12. STATE_OVERCHARGING= 0x05
  13. } BatteryState;
  14. //Battery Structure
  15. typedef struct{
  16. uint8_t slot_id;
  17. BatteryState state;
  18. uint16_t voltage;
  19. int16_t current;
  20. uint16_t temperature;
  21. uint16_t min_voltage;
  22. uint16_t max_voltage;
  23. uint16_t cut_off_current;
  24. uint16_t capacitance;
  25. uint16_t charge_fraction;
  26. } Battery;
  27. //global battery array declaration: extending visiblity of the variable to multiple source files
  28. extern Battery batteries[NUM_SLOTS];
  29. void Battery_Init();
  30. void Battery_SafetyCheck(uint8_t slot);
  31. #endif