mirror of
https://github.com/vicliu624/trail-mate.git
synced 2026-08-22 02:29:44 +00:00
Fix T-Deck battery estimate
This commit is contained in:
@@ -30,6 +30,8 @@ MemoryStats memory_stats();
|
||||
const char* firmware_version();
|
||||
void handle_low_battery(const BatteryInfo& info);
|
||||
bool supports_screen_brightness();
|
||||
bool supports_configurable_battery_gauge();
|
||||
void reload_configurable_battery_gauge();
|
||||
uint8_t screen_brightness();
|
||||
void set_screen_brightness(uint8_t level);
|
||||
void trigger_haptic();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace power
|
||||
{
|
||||
|
||||
struct BatteryEstimatorSample
|
||||
{
|
||||
uint32_t now_ms = 0;
|
||||
int pmu_percent = -1;
|
||||
int pmu_battery_mv = -1;
|
||||
int adc_battery_mv = -1;
|
||||
bool charging = false;
|
||||
bool vbus_present = false;
|
||||
};
|
||||
|
||||
enum class BatteryEstimateReason
|
||||
{
|
||||
NoSample,
|
||||
PmuPercent,
|
||||
VoltageFallback,
|
||||
ChargerStableHold,
|
||||
DetachStableHold,
|
||||
DropGuard,
|
||||
ZeroGuard,
|
||||
RateLimited,
|
||||
};
|
||||
|
||||
struct BatteryEstimate
|
||||
{
|
||||
BatteryEstimate() = default;
|
||||
BatteryEstimate(int percent_value, BatteryEstimateReason reason_value)
|
||||
: percent(percent_value), reason(reason_value)
|
||||
{
|
||||
}
|
||||
|
||||
int percent = -1;
|
||||
BatteryEstimateReason reason = BatteryEstimateReason::NoSample;
|
||||
};
|
||||
|
||||
class BatteryEstimator
|
||||
{
|
||||
public:
|
||||
BatteryEstimate update(const BatteryEstimatorSample& sample);
|
||||
int lastPercent() const { return last_percent_; }
|
||||
uint32_t lastVbusDetachMs() const { return last_vbus_detach_ms_; }
|
||||
void reset();
|
||||
|
||||
private:
|
||||
int last_percent_ = -1;
|
||||
uint32_t last_sample_ms_ = 0;
|
||||
uint32_t last_vbus_detach_ms_ = 0;
|
||||
bool has_last_power_state_ = false;
|
||||
bool last_vbus_present_ = false;
|
||||
bool last_charging_ = false;
|
||||
uint8_t zero_streak_ = 0;
|
||||
};
|
||||
|
||||
int batteryPercentFromLipoMillivolts(int mv);
|
||||
|
||||
} // namespace power
|
||||
Reference in New Issue
Block a user