#include #include #include "src/config.h" #ifndef BATTERY_H #define BATTERY_H //Battery states read by Pi typedef enum{ STATE_EMPTY= 0x01, STATE_BATTERY_DETECTED= 0x02, STATE_WAITING_FOR_LIMITS= 0x03, STATE_MEASUREMENT_IN_PROGRESS= 0x04, STATE_MEASUREMENT_DONE= 0x04, STATE_OVERHEATING= 0x05, } BatteryState; //Battery Discharge Safety Check typedef enum __attribute((packed))__{ SLOT_STATE_OK= 0x00, SLOT_STATE_SOV= 0x01, SLOT_ERR_HOV= (0x02 | 0x80), SLOT_ERR_OVERTEMPERATURE= (0x03 | 0x80), // first bit indicates complete error // Control error states SLOT_WARN_LOWER_DAC_NOT_POSSIBLE=0x10, SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE=0x11, SLOT_WARN_DAC_INVALID_VALUE=0x12, SLOT_WARN_LOWER_PWM_NOT_POSSIBLE=0x13, SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE=0x14, // I2C Slave Error states SLOT_ERR_NO_DAC = (0x20 | 0x80), SLOT_ERR_NO_ADC1 = (0x21 | 0x80), SLOT_ERR_NO_ADC2 = (0x22 | 0x80), SLOT_ERR_NO_ADC3 = (0x23 | 0x80), SLOT_ERR_NO_ADC4 = (0x24 | 0x80), SLOT_ERR_CONFIGBYTE = (0x25 | 0x80), SLOT_ERR_DAC_WRITE_FAILED= (0x26 | 0x80) } SlotState; typedef struct __attribute__((packed)){ uint16_t voltage; int16_t current; uint16_t temperature; SlotState slot_state; }BatteryMeasurement; typedef struct __attribute__((packed)){ uint16_t min_voltage; uint16_t max_voltage; uint8_t cut_off_current; uint16_t capacitance; uint8_t charge_fraction; } BatteryLimits; typedef struct{ uint8_t slot_id; int16_t charge_discharge; BatteryState battery_state; BatteryMeasurement battery_measurement; BatteryLimits battery_limits; bool batteryLimitRecieved; } BatteryInfo; extern BatteryInfo battery_data[NUM_SLOTS]; void Battery_Init(); void Battery_ReadState(uint8_t slot_id); #endif