battery.h 938 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. //for testing
  6. #define NUM_SLOTS (1)
  7. #define BATTERY_THRESHOLD (50)
  8. //Battery states
  9. typedef enum{
  10. STATE_EMPTY= 0x01,
  11. STATE_BATTERY_DETECTED= 0x02,
  12. STATE_MEASUREMENT_IN_PROGRESS= 0x03,
  13. STATE_MEASUREMENT_DONE= 0x04,
  14. STATE_OVERCHARGING= 0x05
  15. } BatteryState;
  16. //Battery Structure
  17. typedef struct{
  18. uint8_t slot_id;
  19. BatteryState state;
  20. uint16_t voltage;
  21. int16_t current;
  22. uint16_t temperature;
  23. uint16_t min_voltage;
  24. uint16_t max_voltage;
  25. uint16_t cut_off_current;
  26. uint16_t capacitance;
  27. uint16_t charge_fraction;
  28. } Battery;
  29. //global battery array declaration: extending visiblity of the variable to multiple source files
  30. extern Battery batteries[NUM_SLOTS];
  31. void Battery_Init();
  32. void Battery_SafetyCheck(uint8_t slot);
  33. #endif