mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 00:17:39 +00:00
Learn ic fix (#2253)
* WIP * Fixed merge * Added test code * WIP * Clean up * add reset learned params * ui fix * ui fix2 * Updated func * Fixed english * WIP * WIP testing * Added new debug app * Got new app for debug * Got new app for debug * Got one full page showing * Got app working with all reg * Got app working with all reg * Got full hex showing * Fixed dp * Fixed dp * Moved entities * Enabled apps again * SHow battery debug if ic * WIP * Refactored further * WIP * Refactor and clean up * Refactor and clean up * fix warning, add tte/ttf, add cycles counter. * wip * morse tx to ext app * fix morse crash * fix ui * Updated wording * WIP * WIP * Updated to display hours and minutes --------- Co-authored-by: HTotoo <ttotoo@gmail.com>
This commit is contained in:
@@ -23,16 +23,16 @@ bool BatteryManagement::calcOverride = false;
|
||||
void BatteryManagement::detect() {
|
||||
// try to detect supported modules
|
||||
detected_ = BATT_NONE;
|
||||
if (battery_max17055.detect()) {
|
||||
battery_max17055.init();
|
||||
detected_ = BATT_MAX17055;
|
||||
return;
|
||||
}
|
||||
if (battery_ads1110.detect()) {
|
||||
battery_ads1110.init();
|
||||
detected_ = BATT_ADS1110;
|
||||
return;
|
||||
}
|
||||
if (battery_max17055.detect()) {
|
||||
// battery_max17055.init(); //detect will call this on each "re detect"
|
||||
detected_ = BATT_MAX17055;
|
||||
return;
|
||||
}
|
||||
|
||||
// add new supported module detect + init here
|
||||
|
||||
@@ -51,6 +51,13 @@ void BatteryManagement::init(bool override) {
|
||||
create_thread();
|
||||
}
|
||||
|
||||
bool BatteryManagement::reset_learned() {
|
||||
if (detected_ == BATT_MAX17055) {
|
||||
return battery_max17055.reset_learned();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// set if the default percentage calculation should be overrided by voltage based one
|
||||
void BatteryManagement::set_calc_override(bool override) {
|
||||
calcOverride = override;
|
||||
@@ -90,6 +97,26 @@ void BatteryManagement::getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPerc
|
||||
(void)current;
|
||||
}
|
||||
|
||||
uint16_t BatteryManagement::get_cycles() {
|
||||
if (detected_ == BATT_MAX17055) {
|
||||
return (uint16_t)battery_max17055.getValue("Cycles");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float BatteryManagement::get_tte() {
|
||||
if (detected_ == BATT_MAX17055) {
|
||||
return battery_max17055.getValue("TTE");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
float BatteryManagement::get_ttf() {
|
||||
if (detected_ == BATT_MAX17055) {
|
||||
return battery_max17055.getValue("TTF");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t BatteryManagement::read_register(const uint8_t reg) {
|
||||
if (detected_ == BATT_MAX17055) {
|
||||
return battery_max17055.read_register(reg);
|
||||
|
@@ -44,6 +44,8 @@ class BatteryManagement {
|
||||
BATT_VALID_VOLTAGE = 1,
|
||||
BATT_VALID_CURRENT = 2,
|
||||
BATT_VALID_PERCENT = 4,
|
||||
BATT_VALID_CYCLES = 8,
|
||||
BATT_VALID_TTEF = 16,
|
||||
};
|
||||
static void init(bool override = false);
|
||||
static void detect();
|
||||
@@ -56,6 +58,10 @@ class BatteryManagement {
|
||||
static bool write_register(const uint8_t reg, const uint16_t value);
|
||||
static void set_calc_override(bool override);
|
||||
static uint8_t calc_percent_voltage(uint16_t); // calculates battery percentage from the voltage
|
||||
static bool reset_learned(); // resets the ic's learned parameters
|
||||
static uint16_t get_cycles();
|
||||
static float get_tte();
|
||||
static float get_ttf();
|
||||
|
||||
private:
|
||||
static void create_thread();
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -83,7 +83,7 @@
|
||||
|
||||
// Define Termination Current
|
||||
#ifndef __MAX17055_Termination_Current__
|
||||
#define __MAX17055_Termination_Current__ 0.1 // Termination Current
|
||||
#define __MAX17055_Termination_Current__ 200 // Termination Current
|
||||
#endif
|
||||
|
||||
// Define Minimum Temperature
|
||||
@@ -253,49 +253,63 @@ namespace max17055 {
|
||||
|
||||
using address_t = uint8_t;
|
||||
|
||||
struct RegisterEntry {
|
||||
const char* name;
|
||||
uint8_t address;
|
||||
const char* type;
|
||||
float scalar;
|
||||
bool is_signed;
|
||||
const char* unit;
|
||||
bool abbr_units;
|
||||
int resolution;
|
||||
bool is_user;
|
||||
bool is_save_restore;
|
||||
bool is_nv;
|
||||
uint16_t por_data;
|
||||
bool is_read_only;
|
||||
};
|
||||
|
||||
class MAX17055 {
|
||||
public:
|
||||
constexpr MAX17055(I2C& bus, const I2C::address_t bus_address)
|
||||
: bus(bus), bus_address(bus_address), detected_(false) {}
|
||||
|
||||
static const RegisterEntry entries[];
|
||||
static constexpr size_t entries_count = 144;
|
||||
|
||||
uint16_t read_register(const uint8_t reg);
|
||||
bool write_register(const uint8_t reg, const uint16_t value);
|
||||
|
||||
void init();
|
||||
bool detect();
|
||||
bool isDetected() const { return detected_; }
|
||||
|
||||
uint16_t readVoltage();
|
||||
uint8_t readPercentage();
|
||||
void getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercentage, uint16_t& voltage, int32_t& current);
|
||||
bool reset_learned();
|
||||
|
||||
uint16_t instantVoltage(void);
|
||||
uint16_t averageVoltage(void);
|
||||
uint16_t emptyVoltage(void);
|
||||
uint16_t recoveryVoltage(void);
|
||||
float getValue(const char* entityName);
|
||||
uint16_t averageMVoltage(void);
|
||||
int32_t instantCurrent(void);
|
||||
int32_t averageCurrent(void);
|
||||
uint16_t stateOfCharge(void);
|
||||
uint16_t averageStateOfCharge(void);
|
||||
uint16_t instantCapacity(void);
|
||||
uint16_t designCapacity(void);
|
||||
uint16_t fullCapacity(void);
|
||||
uint16_t icTemperature(void);
|
||||
uint16_t timeToEmpty(void);
|
||||
uint16_t timeToFull(void);
|
||||
uint16_t batteryAge(void);
|
||||
uint16_t chargeCycle(void);
|
||||
bool statusControl(const uint8_t _Status);
|
||||
void statusClear(void);
|
||||
uint16_t chargeTerminationCurrent(void);
|
||||
uint16_t read_register(const uint8_t reg);
|
||||
bool write_register(const uint8_t reg, const uint16_t value);
|
||||
|
||||
private:
|
||||
I2C& bus;
|
||||
const I2C::address_t bus_address;
|
||||
bool detected_ = false;
|
||||
|
||||
bool readRegister(uint8_t reg, uint16_t& value);
|
||||
bool readMultipleRegister(uint8_t reg, uint8_t* data, uint8_t length, bool endTransmission);
|
||||
bool writeMultipleRegister(uint8_t reg, const uint8_t* data, uint8_t length);
|
||||
const RegisterEntry* findEntry(const char* name) const;
|
||||
|
||||
bool needsInitialization();
|
||||
void partialInit();
|
||||
|
||||
bool statusControl(const uint8_t _Status);
|
||||
bool statusClear();
|
||||
|
||||
bool full_reset_and_init();
|
||||
bool soft_reset();
|
||||
bool clear_por();
|
||||
bool initialize_custom_parameters();
|
||||
bool load_custom_parameters();
|
||||
|
||||
bool setEmptyVoltage(uint16_t _Empty_Voltage);
|
||||
bool setRecoveryVoltage(uint16_t _Recovery_Voltage);
|
||||
|
@@ -953,18 +953,15 @@ bool ui_hide_sd_card() {
|
||||
bool ui_hide_fake_brightness() {
|
||||
return data->ui_config2.hide_fake_brightness;
|
||||
}
|
||||
|
||||
bool ui_hide_numeric_battery() {
|
||||
return data->ui_config2.hide_numeric_battery;
|
||||
}
|
||||
bool ui_hide_battery_icon() {
|
||||
return data->ui_config2.hide_battery_icon;
|
||||
}
|
||||
|
||||
uint8_t ui_theme_id() {
|
||||
return data->ui_config2.theme_id;
|
||||
}
|
||||
|
||||
bool ui_override_batt_calc() {
|
||||
return data->ui_config2.override_batt_calc;
|
||||
}
|
||||
|
Reference in New Issue
Block a user