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