Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
BatteryController.cpp
Go to the documentation of this file.
1
18
19#include "BatteryController.hpp"
20#include "I2CController.hpp"
21
23#define REG_CALIBRATION 0x05
25#define REG_BUSVOLTAGE 0x02
28#define REG_SHUNTVOLTAGE 0x01
29
39 : m_i2cController(i2cController ? i2cController : new I2CController("/dev/i2c-1", 0x41))
40 , m_ownI2CController(i2cController == nullptr)
41{
43}
44
57
64
69
77
79{
80 uint16_t raw = m_i2cController->readRegister(REG_BUSVOLTAGE);
81 return ((raw >> 3) * 0.004); // Convert to volts
82}
83
92{
93 int16_t raw = static_cast<int16_t>(m_i2cController->readRegister(REG_SHUNTVOLTAGE));
94 return raw * 0.01; // Convert to volts
95}
96
104 float busVoltage = getBusVoltage_V();
105 float shuntVoltage = getShuntVoltage_V();
106 float loadVoltage = busVoltage + shuntVoltage;
107
108 // Calculate percentage
109 float percentage = (loadVoltage - 6.0F) / 2.4f * 100.0F;
110 if (percentage > 100.0F)
111 percentage = 100.0F;
112 if (percentage < 0.0F)
113 percentage = 0.0F;
114 return percentage;
115}
#define REG_SHUNTVOLTAGE
#define REG_CALIBRATION
#define REG_BUSVOLTAGE
Definition of the BatteryController class.
Definition of the I2CController class.
void setCalibration32V2A()
Set the calibration for 32V and 2A.
~BatteryController() override
Destroy the BatteryController object.
BatteryController(II2CController *i2cController=nullptr)
Construct a new BatteryController object.
float getBusVoltage_V()
Get the bus voltage in volts.
float getShuntVoltage_V()
Get the shunt voltage in volts.
float getBatteryPercentage() override
Get the battery percentage.
II2CController * m_i2cController
Class that controls I2C devices.
Interface for controlling I2C devices.