mirror of
https://github.com/ratspeak/ratdeck.git
synced 2026-08-22 02:29:56 +00:00
adjusted power levels according to real discharge process, fixing some setting related issues
This commit is contained in:
@@ -61,8 +61,8 @@ struct UserSettings {
|
||||
// Battery
|
||||
uint8_t batteryDisplay = 0; // 0 = percent, 1 = bar
|
||||
uint8_t batteryModel = 0; // 0=lipo, 1=linear
|
||||
float chargeThresholdV = 4.1f; // Battery voltage threshold for indication "is charging"
|
||||
float fullBatteryV = 3.8f; // Battery voltage if 100% charged
|
||||
float chargeThresholdV = 4.0f; // Battery voltage threshold for indication "is charging"
|
||||
float fullBatteryV = 3.9f; // Battery voltage if 100% charged
|
||||
|
||||
// Keyboard
|
||||
uint8_t keyboardBrightness = 100; // Percentage 0-100 (0 = off)
|
||||
|
||||
+28
-27
@@ -1,6 +1,8 @@
|
||||
#include "Power.h"
|
||||
#include "hal/Display.h"
|
||||
#include "hal/Keyboard.h"
|
||||
#include "storage/SDStore.h"
|
||||
|
||||
|
||||
// Forward declarations — display & keyboard instances provided externally
|
||||
extern Display display;
|
||||
@@ -10,36 +12,31 @@ extern Keyboard keyboard;
|
||||
// interpolated chart from https://www.researchgate.net/figure/Li-ion-battery-discharge-voltage-curve_fig5_363575973
|
||||
// the manual chart reading entries are read from chart, while the others are interpolated
|
||||
namespace {
|
||||
struct VoltPct { float v; int pct; };
|
||||
static const VoltPct LIPO_CURVE[] = {
|
||||
{4.20f, 100}, // manual chart reading
|
||||
{4.00f, 95},
|
||||
{3.80f, 90}, // manual chart reading
|
||||
{3.78f, 85},
|
||||
{3.75f, 80}, // manual chart reading
|
||||
{3.74f, 75},
|
||||
{3.73f, 70},
|
||||
{3.71f, 65},
|
||||
{3.70f, 60}, // manual chart reading
|
||||
{3.69f, 55},
|
||||
{3.68f, 50},
|
||||
{3.66f, 45},
|
||||
{3.65f, 40}, // manual chart reading
|
||||
{3.64f, 35},
|
||||
{3.63f, 30},
|
||||
{3.61f, 25},
|
||||
{3.60f, 20}, // manual chart reading
|
||||
{3.55f, 15},
|
||||
{3.50f, 10}, // manual chart reading
|
||||
{3.25f, 5}, // manual chart reading
|
||||
{3.00f, 0}, // manual chart reading
|
||||
};
|
||||
constexpr int LIPO_CURVE_N = sizeof(LIPO_CURVE) / sizeof(LIPO_CURVE[0]);
|
||||
|
||||
struct VoltPoint { float v; int pct; };
|
||||
static constexpr VoltPoint LIPO_CURVE[] = {
|
||||
{3.90f, 100},
|
||||
{3.80f, 90},
|
||||
{3.72f, 80},
|
||||
{3.65f, 70},
|
||||
{3.59f, 60},
|
||||
{3.53f, 50},
|
||||
{3.48f, 40},
|
||||
{3.44f, 30},
|
||||
{3.40f, 20},
|
||||
{3.36f, 15},
|
||||
{3.30f, 10},
|
||||
{3.15f, 5},
|
||||
{3.00f, 0},
|
||||
};
|
||||
constexpr int LIPO_CURVE_N = sizeof(LIPO_CURVE) / sizeof(LIPO_CURVE[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Power::enablePeripherals() {
|
||||
// CRITICAL: GPIO 10 must be HIGH to enable all T-Deck Plus peripherals
|
||||
pinMode(BOARD_POWER_PIN, OUTPUT);
|
||||
@@ -68,10 +65,14 @@ float Power::batteryVoltage() const {
|
||||
int Power::batteryPercent() const {
|
||||
float v = batteryVoltage();
|
||||
|
||||
// Charging: voltage exceeds the discharge curve's top (3.9V = full).
|
||||
// A discharging cell never gets there, so treat this as full.
|
||||
if (isCharging())
|
||||
return 100;
|
||||
|
||||
// Compensate for load-induced voltage drop when running on battery.
|
||||
// Calculates an offset and adds it to real voltage for to be able using default LiPo lookup table
|
||||
if (!isCharging())
|
||||
v += (4.2f - _fullBatteryV);
|
||||
v += (3.9f - _fullBatteryV);
|
||||
|
||||
// Clamp to valid curve range.
|
||||
v = constrain(v, 3.0f, 4.2f);
|
||||
|
||||
+2
-2
@@ -69,6 +69,6 @@ private:
|
||||
|
||||
// Battery
|
||||
uint8_t _batteryModel = 0;
|
||||
float _chargeThreshold = 4.1f;
|
||||
float _fullBatteryV = 3.8f;
|
||||
float _chargeThreshold = 4.0f;
|
||||
float _fullBatteryV = 3.9f;
|
||||
};
|
||||
|
||||
@@ -1482,6 +1482,10 @@ void setup() {
|
||||
|
||||
// Step 26: Battery init
|
||||
ui.lvStatusBar().setBatteryDisplay(userConfig.settings().batteryDisplay);
|
||||
powerMgr.setBatteryModel(userConfig.settings().batteryModel);
|
||||
powerMgr.setChargeThreshold(userConfig.settings().chargeThresholdV);
|
||||
powerMgr.setFullBatteryVoltage(userConfig.settings().fullBatteryV);
|
||||
|
||||
|
||||
|
||||
// Boot complete — transition to Home screen
|
||||
|
||||
@@ -260,13 +260,12 @@ void LvStatusBar::refreshBattery() {
|
||||
uint32_t indicatorCol;
|
||||
if (_isCharging) {
|
||||
indicatorCol = Theme::SUCCESS;
|
||||
/*
|
||||
// Future stuff, we can enable it, as soon as battery levels are working correctly
|
||||
} else if (_battPct >= 0 && _battPct <= 15) {
|
||||
|
||||
} else if (_battPct >= 0 && _battPct <= 10) {
|
||||
indicatorCol = Theme::ERROR_CLR;
|
||||
} else if (_battPct >= 0 && _battPct <= 30) {
|
||||
} else if (_battPct >= 0 && _battPct <= 20) {
|
||||
indicatorCol = Theme::WARNING_CLR;
|
||||
*/
|
||||
|
||||
} else {
|
||||
indicatorCol = 0xFFFFFF;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user