mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 20:49:49 +04:00
@@ -46,4 +46,5 @@ typedef struct {
|
|||||||
PinCode pin_code;
|
PinCode pin_code;
|
||||||
uint8_t is_locked;
|
uint8_t is_locked;
|
||||||
uint32_t auto_lock_delay_ms;
|
uint32_t auto_lock_delay_ms;
|
||||||
|
uint8_t displayBatteryPercentage;
|
||||||
} DesktopSettings;
|
} DesktopSettings;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define SCENE_EVENT_SELECT_FAVORITE_SECONDARY 1
|
#define SCENE_EVENT_SELECT_FAVORITE_SECONDARY 1
|
||||||
#define SCENE_EVENT_SELECT_PIN_SETUP 2
|
#define SCENE_EVENT_SELECT_PIN_SETUP 2
|
||||||
#define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 3
|
#define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 3
|
||||||
|
#define SCENE_EVENT_SELECT_BATTERY_DISPLAY 4
|
||||||
|
|
||||||
#define AUTO_LOCK_DELAY_COUNT 9
|
#define AUTO_LOCK_DELAY_COUNT 9
|
||||||
const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
||||||
@@ -25,9 +26,30 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
|
|||||||
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
|
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
|
||||||
{0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000};
|
{0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000};
|
||||||
|
|
||||||
|
#define BATTERY_VIEW_COUNT 5
|
||||||
|
|
||||||
|
const char* const battery_view_count_text[BATTERY_VIEW_COUNT] = {
|
||||||
|
"Bar",
|
||||||
|
"%",
|
||||||
|
"Inv. %",
|
||||||
|
"Retro 3",
|
||||||
|
"Retro 5",
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t displayBatteryPercentage_value[BATTERY_VIEW_COUNT] = {0, 1, 2, 3, 4};
|
||||||
|
|
||||||
static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||||
DesktopSettingsApp* app = context;
|
DesktopSettingsApp* app = context;
|
||||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void desktop_settings_scene_start_battery_view_changed(VariableItem* item) {
|
||||||
|
DesktopSettingsApp* app = variable_item_get_context(item);
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
|
||||||
|
variable_item_set_current_value_text(item, battery_view_count_text[index]);
|
||||||
|
app->settings.displayBatteryPercentage = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) {
|
static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) {
|
||||||
@@ -64,6 +86,20 @@ void desktop_settings_scene_start_on_enter(void* context) {
|
|||||||
app->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
|
app->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
|
||||||
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, auto_lock_delay_text[value_index]);
|
variable_item_set_current_value_text(item, auto_lock_delay_text[value_index]);
|
||||||
|
|
||||||
|
item = variable_item_list_add(
|
||||||
|
variable_item_list,
|
||||||
|
"Battery View",
|
||||||
|
BATTERY_VIEW_COUNT,
|
||||||
|
desktop_settings_scene_start_battery_view_changed,
|
||||||
|
app);
|
||||||
|
|
||||||
|
value_index = value_index_uint32(
|
||||||
|
app->settings.displayBatteryPercentage,
|
||||||
|
displayBatteryPercentage_value,
|
||||||
|
BATTERY_VIEW_COUNT);
|
||||||
|
variable_item_set_current_value_index(item, value_index);
|
||||||
|
variable_item_set_current_value_text(item, battery_view_count_text[value_index]);
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
|
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
|
||||||
}
|
}
|
||||||
@@ -91,6 +127,9 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
|
|||||||
case SCENE_EVENT_SELECT_AUTO_LOCK_DELAY:
|
case SCENE_EVENT_SELECT_AUTO_LOCK_DELAY:
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
case SCENE_EVENT_SELECT_BATTERY_DISPLAY:
|
||||||
|
consumed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
|
|||||||
[FontSecondary] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
|
[FontSecondary] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
|
||||||
[FontKeyboard] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
|
[FontKeyboard] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
|
||||||
[FontBigNumbers] = {.leading_default = 18, .leading_min = 16, .height = 15, .descender = 0},
|
[FontBigNumbers] = {.leading_default = 18, .leading_min = 16, .height = 15, .descender = 0},
|
||||||
|
[FontBatteryPercent] = {.leading_default = 11, .leading_min = 9, .height = 6, .descender = 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
Canvas* canvas_init() {
|
Canvas* canvas_init() {
|
||||||
@@ -132,6 +133,8 @@ void canvas_set_font(Canvas* canvas, Font font) {
|
|||||||
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mr);
|
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mr);
|
||||||
} else if(font == FontBigNumbers) {
|
} else if(font == FontBigNumbers) {
|
||||||
u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn);
|
u8g2_SetFont(&canvas->fb, u8g2_font_profont22_tn);
|
||||||
|
} else if(font == FontBatteryPercent) {
|
||||||
|
u8g2_SetFont(&canvas->fb, u8g2_font_5x7_tf); //u8g2_font_micro_tr);
|
||||||
} else {
|
} else {
|
||||||
furi_crash(NULL);
|
furi_crash(NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ typedef enum {
|
|||||||
FontSecondary,
|
FontSecondary,
|
||||||
FontKeyboard,
|
FontKeyboard,
|
||||||
FontBigNumbers,
|
FontBigNumbers,
|
||||||
|
FontBatteryPercent,
|
||||||
|
|
||||||
// Keep last for fonts number calculation
|
// Keep last for fonts number calculation
|
||||||
FontTotalNumber,
|
FontTotalNumber,
|
||||||
} Font;
|
} Font;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "power_i.h"
|
#include "power_i.h"
|
||||||
#include "views/power_off.h"
|
#include "views/power_off.h"
|
||||||
|
#include "desktop/desktop_settings/desktop_settings.h"
|
||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
@@ -14,7 +15,51 @@ void power_draw_battery_callback(Canvas* canvas, void* context) {
|
|||||||
canvas_draw_icon(canvas, 0, 0, &I_Battery_26x8);
|
canvas_draw_icon(canvas, 0, 0, &I_Battery_26x8);
|
||||||
|
|
||||||
if(power->info.gauge_is_ok) {
|
if(power->info.gauge_is_ok) {
|
||||||
canvas_draw_box(canvas, 2, 2, (power->info.charge + 4) / 5, 4);
|
|
||||||
|
char batteryPercentile[5];
|
||||||
|
snprintf(batteryPercentile, sizeof(batteryPercentile), "%d", power->info.charge);
|
||||||
|
strcat(batteryPercentile, "%");
|
||||||
|
|
||||||
|
if((power->displayBatteryPercentage == 1) && (power->state != PowerStateCharging)) { //if display battery percentage, black background white text
|
||||||
|
canvas_set_font(canvas, FontBatteryPercent);
|
||||||
|
canvas_set_color(canvas, ColorBlack);
|
||||||
|
canvas_draw_box(canvas, 1, 1, 22, 6);
|
||||||
|
canvas_set_color(canvas, ColorWhite);
|
||||||
|
canvas_draw_str_aligned(canvas, 12, 4, AlignCenter, AlignCenter, batteryPercentile);
|
||||||
|
} else if((power->displayBatteryPercentage == 2) && (power->state != PowerStateCharging)) { //if display inverted percentage, white background black text
|
||||||
|
canvas_set_font(canvas, FontBatteryPercent);
|
||||||
|
canvas_set_color(canvas, ColorBlack);
|
||||||
|
canvas_draw_str_aligned(canvas, 12, 4, AlignCenter, AlignCenter, batteryPercentile);
|
||||||
|
} else if((power->displayBatteryPercentage == 3) && (power->state != PowerStateCharging)) { //Retro style segmented display, 3 parts
|
||||||
|
if(power->info.charge > 25) {
|
||||||
|
canvas_draw_box(canvas, 2, 2, 6, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 50) {
|
||||||
|
canvas_draw_box(canvas, 9, 2, 6, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 75) {
|
||||||
|
canvas_draw_box(canvas, 16, 2, 6, 4);
|
||||||
|
}
|
||||||
|
} else if((power->displayBatteryPercentage == 4) && (power->state != PowerStateCharging)) { //Retro style segmented display, 5 parts
|
||||||
|
if(power->info.charge > 10) {
|
||||||
|
canvas_draw_box(canvas, 2, 2, 3, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 30) {
|
||||||
|
canvas_draw_box(canvas, 6, 2, 3, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 50) {
|
||||||
|
canvas_draw_box(canvas, 10, 2, 3, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 70) {
|
||||||
|
canvas_draw_box(canvas, 14, 2, 3, 4);
|
||||||
|
}
|
||||||
|
if(power->info.charge > 90) {
|
||||||
|
canvas_draw_box(canvas, 18, 2, 3, 4);
|
||||||
|
}
|
||||||
|
} else { //default bar display, added here to serve as fallback/default behaviour.
|
||||||
|
canvas_draw_box(canvas, 2, 2, (power->info.charge + 4) / 5, 4);
|
||||||
|
}
|
||||||
|
|
||||||
if(power->state == PowerStateCharging) {
|
if(power->state == PowerStateCharging) {
|
||||||
canvas_set_bitmap_mode(canvas, 1);
|
canvas_set_bitmap_mode(canvas, 1);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
@@ -206,6 +251,11 @@ int32_t power_srv(void* p) {
|
|||||||
Power* power = power_alloc();
|
Power* power = power_alloc();
|
||||||
power_update_info(power);
|
power_update_info(power);
|
||||||
furi_record_create(RECORD_POWER, power);
|
furi_record_create(RECORD_POWER, power);
|
||||||
|
|
||||||
|
DesktopSettings* settings = malloc(sizeof(DesktopSettings));
|
||||||
|
LOAD_DESKTOP_SETTINGS(settings);
|
||||||
|
power->displayBatteryPercentage = settings->displayBatteryPercentage;
|
||||||
|
free(settings);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// Update data from gauge and charger
|
// Update data from gauge and charger
|
||||||
@@ -221,7 +271,13 @@ int32_t power_srv(void* p) {
|
|||||||
power_check_battery_level_change(power);
|
power_check_battery_level_change(power);
|
||||||
|
|
||||||
// Update battery view port
|
// Update battery view port
|
||||||
if(need_refresh) view_port_update(power->battery_view_port);
|
if(need_refresh) {
|
||||||
|
DesktopSettings* settings = malloc(sizeof(DesktopSettings));
|
||||||
|
LOAD_DESKTOP_SETTINGS(settings);
|
||||||
|
power->displayBatteryPercentage = settings->displayBatteryPercentage;
|
||||||
|
free(settings);
|
||||||
|
view_port_update(power->battery_view_port);
|
||||||
|
}
|
||||||
|
|
||||||
// Check OTG status and disable it in case of fault
|
// Check OTG status and disable it in case of fault
|
||||||
if(furi_hal_power_is_otg_enabled()) {
|
if(furi_hal_power_is_otg_enabled()) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct Power {
|
|||||||
|
|
||||||
bool battery_low;
|
bool battery_low;
|
||||||
bool show_low_bat_level_message;
|
bool show_low_bat_level_message;
|
||||||
|
uint8_t displayBatteryPercentage;
|
||||||
uint8_t battery_level;
|
uint8_t battery_level;
|
||||||
uint8_t power_off_timeout;
|
uint8_t power_off_timeout;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user