mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-22 23:49:05 +00:00
Fix battery display bug, and the flash time (#3232)
* battfix * por again, but nicer
This commit is contained in:
@@ -192,7 +192,10 @@ void I2cDev_MAX17055::update() {
|
||||
bool battChanged = false;
|
||||
|
||||
getBatteryInfo(validity, batteryPercentage, voltage, current, battChanged);
|
||||
|
||||
if (validity == 0) {
|
||||
// no valid data, don't send message
|
||||
return;
|
||||
}
|
||||
// send local message
|
||||
BatteryStateMessage msg{validity, batteryPercentage, current >= 25, voltage, battChanged};
|
||||
EventDispatcher::send_message(msg);
|
||||
@@ -225,6 +228,7 @@ bool I2cDev_MAX17055::init(uint8_t addr_) {
|
||||
bool return_status = true;
|
||||
if (needsInitialization()) {
|
||||
// First-time or POR initialization
|
||||
was_por = true;
|
||||
return_status = full_reset_and_init();
|
||||
}
|
||||
chThdSleepMilliseconds(300); // wait for adc to fully wake up!
|
||||
@@ -252,10 +256,9 @@ bool I2cDev_MAX17055::full_reset_and_init() {
|
||||
if (!load_custom_parameters()) {
|
||||
return false;
|
||||
}
|
||||
/*if (!clear_por()) {
|
||||
if (!clear_por()) {
|
||||
return false;
|
||||
}*/
|
||||
// don't clear it, we'll need to know the state
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -390,17 +393,25 @@ void I2cDev_MAX17055::getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercen
|
||||
valid_mask = 0;
|
||||
return;
|
||||
}
|
||||
if (status == 0xFFFF) {
|
||||
valid_mask = 0;
|
||||
return;
|
||||
}
|
||||
bool requires_reset = false;
|
||||
|
||||
if (((status & 0xFF) >> 1) & 0x01) { // POR FLAG
|
||||
requires_reset = true;
|
||||
was_por = true;
|
||||
}
|
||||
// Execute the reset if either flag was tripped
|
||||
if (requires_reset) {
|
||||
reInit(); // todo maybe don't do it automatically, just signal. but for now it is safer to do it.
|
||||
// battMayChanged = true && portapack::persistent_memory::battery_replaceable(); // only signal a change if the battery is replaceable. othervise do it silently
|
||||
// We don't want to signal this for now. the Voltage drop during power up messes this up a bit.
|
||||
reInit(); // reinit the ic. that takes time, so we'll return
|
||||
valid_mask = 0;
|
||||
return;
|
||||
}
|
||||
#ifdef MAX17055_REPORT_POR_FLAG
|
||||
battMayChanged = was_por && portapack::persistent_memory::battery_replaceable(); // only signal a change if the battery is replaceable. othervise do it silently
|
||||
#endif
|
||||
|
||||
batteryPercentage = stateOfCharge();
|
||||
current = instantCurrent();
|
||||
|
||||
Reference in New Issue
Block a user