mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 00:58:36 -07:00
Revert "Revert "Feature: Custom user set charging cap (#265)""
This reverts commit 31f624d662.
This commit is contained in:
@@ -45,6 +45,17 @@ static void xtreme_app_scene_misc_butthurt_timer_changed(VariableItem* item) {
|
|||||||
app->require_reboot = true;
|
app->require_reboot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHARGE_CAP_INTV 5
|
||||||
|
static void xtreme_app_scene_misc_charge_cap_changed(VariableItem* item) {
|
||||||
|
XtremeApp* app = variable_item_get_context(item);
|
||||||
|
char cap_str[6];
|
||||||
|
uint32_t value = (variable_item_get_current_value_index(item) + 1) * CHARGE_CAP_INTV;
|
||||||
|
snprintf(cap_str, 6, "%lu%%", value);
|
||||||
|
variable_item_set_current_value_text(item, cap_str);
|
||||||
|
XTREME_SETTINGS()->charge_cap = value;
|
||||||
|
app->save_settings = true;
|
||||||
|
}
|
||||||
|
|
||||||
static void xtreme_app_scene_misc_lcd_color_changed(VariableItem* item) {
|
static void xtreme_app_scene_misc_lcd_color_changed(VariableItem* item) {
|
||||||
XtremeApp* app = variable_item_get_context(item);
|
XtremeApp* app = variable_item_get_context(item);
|
||||||
uint8_t index = variable_item_get_current_value_index(item);
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
@@ -96,6 +107,18 @@ void xtreme_app_scene_misc_on_enter(void* context) {
|
|||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, butthurt_timer_names[value_index]);
|
variable_item_set_current_value_text(item, butthurt_timer_names[value_index]);
|
||||||
|
|
||||||
|
char cap_str[6];
|
||||||
|
value_index = xtreme_settings->charge_cap / CHARGE_CAP_INTV;
|
||||||
|
snprintf(cap_str, 6, "%lu%%", (uint32_t)value_index * CHARGE_CAP_INTV);
|
||||||
|
item = variable_item_list_add(
|
||||||
|
var_item_list,
|
||||||
|
"Charge Cap",
|
||||||
|
100 / CHARGE_CAP_INTV,
|
||||||
|
xtreme_app_scene_misc_charge_cap_changed,
|
||||||
|
app);
|
||||||
|
variable_item_set_current_value_index(item, value_index - 1);
|
||||||
|
variable_item_set_current_value_text(item, cap_str);
|
||||||
|
|
||||||
item = variable_item_list_add(var_item_list, "RGB Backlight", 1, NULL, app);
|
item = variable_item_list_add(var_item_list, "RGB Backlight", 1, NULL, app);
|
||||||
variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF");
|
variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF");
|
||||||
|
|
||||||
|
|||||||
@@ -472,6 +472,20 @@ static void power_check_battery_level_change(Power* power) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void power_check_charge_cap(Power* power) {
|
||||||
|
if(power->info.charge >= XTREME_SETTINGS()->charge_cap) {
|
||||||
|
if(!power->info.is_charge_capped) { // Suppress charging if charge reaches custom cap
|
||||||
|
power->info.is_charge_capped = true;
|
||||||
|
furi_hal_power_suppress_charge_enter();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(power->info.is_charge_capped) { // Start charging again if charge below custom cap
|
||||||
|
power->info.is_charge_capped = false;
|
||||||
|
furi_hal_power_suppress_charge_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void power_trigger_ui_update(Power* power) {
|
void power_trigger_ui_update(Power* power) {
|
||||||
view_port_update(power->battery_view_port);
|
view_port_update(power->battery_view_port);
|
||||||
}
|
}
|
||||||
@@ -491,6 +505,7 @@ int32_t power_srv(void* p) {
|
|||||||
}
|
}
|
||||||
power_auto_shutdown_arm(power);
|
power_auto_shutdown_arm(power);
|
||||||
power_update_info(power);
|
power_update_info(power);
|
||||||
|
power->info.is_charge_capped = false; // default false
|
||||||
furi_record_create(RECORD_POWER, power);
|
furi_record_create(RECORD_POWER, power);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
@@ -506,6 +521,9 @@ int32_t power_srv(void* p) {
|
|||||||
// Check and notify about battery level change
|
// Check and notify about battery level change
|
||||||
power_check_battery_level_change(power);
|
power_check_battery_level_change(power);
|
||||||
|
|
||||||
|
// Check charge cap, compare with user setting and suppress/unsuppress charging
|
||||||
|
power_check_charge_cap(power);
|
||||||
|
|
||||||
// Update battery view port
|
// Update battery view port
|
||||||
if(need_refresh) {
|
if(need_refresh) {
|
||||||
view_port_update(power->battery_view_port);
|
view_port_update(power->battery_view_port);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bool gauge_is_ok;
|
bool gauge_is_ok;
|
||||||
bool is_charging;
|
bool is_charging;
|
||||||
|
bool is_charge_capped;
|
||||||
|
|
||||||
float current_charger;
|
float current_charger;
|
||||||
float current_gauge;
|
float current_gauge;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ XtremeSettings xtreme_settings = {
|
|||||||
.bad_bt = false, // USB
|
.bad_bt = false, // USB
|
||||||
.bad_bt_remember = false, // OFF
|
.bad_bt_remember = false, // OFF
|
||||||
.butthurt_timer = 21600, // 6 H
|
.butthurt_timer = 21600, // 6 H
|
||||||
|
.charge_cap = 100, // 100%
|
||||||
.rgb_backlight = false, // OFF
|
.rgb_backlight = false, // OFF
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,6 +91,8 @@ void XTREME_SETTINGS_LOAD() {
|
|||||||
flipper_format_rewind(file);
|
flipper_format_rewind(file);
|
||||||
flipper_format_read_int32(file, "butthurt_timer", &x->butthurt_timer, 1);
|
flipper_format_read_int32(file, "butthurt_timer", &x->butthurt_timer, 1);
|
||||||
flipper_format_rewind(file);
|
flipper_format_rewind(file);
|
||||||
|
flipper_format_read_uint32(file, "charge_cap", &x->charge_cap, 1);
|
||||||
|
flipper_format_rewind(file);
|
||||||
flipper_format_read_bool(file, "rgb_backlight", &x->rgb_backlight, 1);
|
flipper_format_read_bool(file, "rgb_backlight", &x->rgb_backlight, 1);
|
||||||
}
|
}
|
||||||
flipper_format_free(file);
|
flipper_format_free(file);
|
||||||
@@ -126,6 +129,7 @@ void XTREME_SETTINGS_SAVE() {
|
|||||||
flipper_format_write_bool(file, "bad_bt", &x->bad_bt, 1);
|
flipper_format_write_bool(file, "bad_bt", &x->bad_bt, 1);
|
||||||
flipper_format_write_bool(file, "bad_bt_remember", &x->bad_bt_remember, 1);
|
flipper_format_write_bool(file, "bad_bt_remember", &x->bad_bt_remember, 1);
|
||||||
flipper_format_write_int32(file, "butthurt_timer", &x->butthurt_timer, 1);
|
flipper_format_write_int32(file, "butthurt_timer", &x->butthurt_timer, 1);
|
||||||
|
flipper_format_write_uint32(file, "charge_cap", &x->charge_cap, 1);
|
||||||
flipper_format_write_bool(file, "rgb_backlight", &x->rgb_backlight, 1);
|
flipper_format_write_bool(file, "rgb_backlight", &x->rgb_backlight, 1);
|
||||||
}
|
}
|
||||||
flipper_format_free(file);
|
flipper_format_free(file);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ typedef struct {
|
|||||||
bool bad_bt;
|
bool bad_bt;
|
||||||
bool bad_bt_remember;
|
bool bad_bt_remember;
|
||||||
int32_t butthurt_timer;
|
int32_t butthurt_timer;
|
||||||
|
uint32_t charge_cap;
|
||||||
bool rgb_backlight;
|
bool rgb_backlight;
|
||||||
} XtremeSettings;
|
} XtremeSettings;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user