battery.h 986 B

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