battery.h 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "src/config.h"
  4. #ifndef BATTERY_H
  5. #define BATTERY_H
  6. //Battery states
  7. typedef enum{
  8. STATE_EMPTY= 0x01,
  9. STATE_BATTERY_DETECTED= 0x02,
  10. STATE_WAITING_FOR_LIMITS= 0x03,
  11. STATE_MEASUREMENT_IN_PROGRESS= 0x04,
  12. STATE_MEASUREMENT_DONE= 0x04,
  13. STATE_OVERHEATING= 0x05,
  14. } BatteryState;
  15. typedef struct{
  16. uint16_t voltage;
  17. int16_t current;
  18. uint16_t temperature;
  19. }BatteryMeasurement;
  20. typedef struct __attribute((packed))__{
  21. uint16_t min_voltage;
  22. uint16_t max_voltage;
  23. uint8_t cut_off_current;
  24. uint16_t capacitance;
  25. uint8_t charge_fraction;
  26. } BatteryLimits;
  27. typedef struct{
  28. uint8_t slot_id;
  29. int16_t charge_discharge;
  30. BatteryState battery_state;
  31. BatteryMeasurement battery_measurement;
  32. BatteryLimits battery_limits;
  33. bool batteryLimitRecieved;
  34. } BatteryInfo;
  35. extern BatteryInfo battery_data[NUM_SLOTS];
  36. void Battery_Init();
  37. void Battery_ReadState(uint8_t slot_id);
  38. #endif