mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-14 02:04:31 -05:00
83b65ba6ce
* message on dev list change * dc detect * added sht3x sensor. * separete environment data from light * max17055 moved to i2c dev * sht fix, goterror detection fix * fix ext sensor app display for a lot of devices. * added bh1750 driver * autoscan on main view * added devlist mutex * better timing * fix h2 sw8 on poweron by usb
30 lines
1.1 KiB
C++
30 lines
1.1 KiB
C++
#include "battery.hpp"
|
|
#include "portapack.hpp"
|
|
#include "i2cdevmanager.hpp"
|
|
namespace battery {
|
|
|
|
bool BatteryManagement::calcOverride = false;
|
|
|
|
// set if the default percentage calculation should be overrided by voltage based one
|
|
void BatteryManagement::set_calc_override(bool override) {
|
|
calcOverride = override;
|
|
}
|
|
|
|
// Helper function to checkif there is ANY battery management ic present.
|
|
bool BatteryManagement::isDetected() {
|
|
auto dev = i2cdev::I2CDevManager::get_dev_by_model(I2CDEVMDL_MAX17055);
|
|
if (dev) return true;
|
|
dev = i2cdev::I2CDevManager::get_dev_by_model(I2CDEVMDL_ADS1110);
|
|
if (dev) return true;
|
|
return false;
|
|
}
|
|
|
|
uint8_t BatteryManagement::calc_percent_voltage(uint16_t voltage) {
|
|
// Calculate the remaining battery percentage
|
|
uint8_t batteryPercentage = (float)(voltage - BATTERY_MIN_VOLTAGE) / (float)(BATTERY_MAX_VOLTAGE - BATTERY_MIN_VOLTAGE) * 100.0;
|
|
// Limit the values to the valid range
|
|
batteryPercentage = (batteryPercentage > 100) ? 100 : batteryPercentage;
|
|
return batteryPercentage;
|
|
}
|
|
|
|
} // namespace battery
|