mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
parent
e11c28cf30
commit
ae6724b359
@ -82,15 +82,8 @@ bool MAX17055::detect() {
|
|||||||
|
|
||||||
// Get Data from IC
|
// Get Data from IC
|
||||||
if (readMultipleRegister(0x00, _MAX17055_Data, 2, false)) {
|
if (readMultipleRegister(0x00, _MAX17055_Data, 2, false)) {
|
||||||
if (_MAX17055_Data[0] != 0x02) {
|
detected_ = true;
|
||||||
// validate result, since i2c gives a bit of power to the ic, and sometimes it sets the init value.
|
return true;
|
||||||
// this will return false when the ic is in init state (0x0002), but on the next iteration it'll give the good value
|
|
||||||
if (detected_ == false) {
|
|
||||||
detected_ = true;
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
detected_ = false;
|
detected_ = false;
|
||||||
return false;
|
return false;
|
||||||
@ -162,9 +155,15 @@ bool MAX17055::writeMultipleRegister(uint8_t reg, const uint8_t* data, uint8_t l
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MAX17055::getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercentage, uint16_t& voltage, int32_t& current) {
|
void MAX17055::getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercentage, uint16_t& voltage, int32_t& current) {
|
||||||
detect(); // need to detect again, since user can disconnect the ic anytime, and that could send garbage causing flickering data.
|
|
||||||
if (detected_) {
|
if (detected_) {
|
||||||
|
uint16_t status = 0;
|
||||||
|
// Read Status Register
|
||||||
|
readMultipleRegister(0x00, (uint8_t*)&status, 2, false);
|
||||||
voltage = averageVoltage();
|
voltage = averageVoltage();
|
||||||
|
if ((status == 0 && voltage == 0) || (status == 0x0002 && voltage == 3600) || (status == 0x0002 && voltage == 0)) {
|
||||||
|
valid_mask = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
batteryPercentage = stateOfCharge();
|
batteryPercentage = stateOfCharge();
|
||||||
current = instantCurrent();
|
current = instantCurrent();
|
||||||
valid_mask = 3; // BATT_VALID_VOLTAGE + CURRENT
|
valid_mask = 3; // BATT_VALID_VOLTAGE + CURRENT
|
||||||
|
Loading…
Reference in New Issue
Block a user