From c2396e8542481a9de40d72f7915ce65a639e9edd Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 28 May 2023 04:14:39 +0100 Subject: [PATCH] About go nappy nap + much fw info --- .../animations/views/bubble_animation_view.c | 2 +- .../views/one_shot_animation_view.c | 2 +- applications/settings/about/about.c | 242 +++--------------- applications/settings/about/about.h | 5 + .../power_settings_app/power_settings_app.c | 23 +- .../power_settings_app/power_settings_app.h | 1 + .../power_settings_scene_battery_info.c | 1 + .../power_settings_app/views/battery_info.c | 63 ++++- .../power_settings_app/views/battery_info.h | 6 +- 9 files changed, 116 insertions(+), 229 deletions(-) create mode 100644 applications/settings/about/about.h diff --git a/applications/services/desktop/animations/views/bubble_animation_view.c b/applications/services/desktop/animations/views/bubble_animation_view.c index 3cef74a81..e59ca0c98 100644 --- a/applications/services/desktop/animations/views/bubble_animation_view.c +++ b/applications/services/desktop/animations/views/bubble_animation_view.c @@ -136,7 +136,7 @@ static bool bubble_animation_input_callback(InputEvent* event, void* context) { } } else if(event->type == InputTypeLong) { Loader* loader = furi_record_open(RECORD_LOADER); - loader_start(loader, "About", "batt"); + loader_start(loader, "Power", "about_battery"); furi_record_close(RECORD_LOADER); } } diff --git a/applications/services/desktop/animations/views/one_shot_animation_view.c b/applications/services/desktop/animations/views/one_shot_animation_view.c index d12c4ccbe..d11d35b17 100644 --- a/applications/services/desktop/animations/views/one_shot_animation_view.c +++ b/applications/services/desktop/animations/views/one_shot_animation_view.c @@ -73,7 +73,7 @@ static bool one_shot_view_input(InputEvent* event, void* context) { } } else if(event->type == InputTypeLong) { Loader* loader = furi_record_open(RECORD_LOADER); - loader_start(loader, "About", "batt"); + loader_start(loader, "Power", "about_battery"); furi_record_close(RECORD_LOADER); } } diff --git a/applications/settings/about/about.c b/applications/settings/about/about.c index 2d38d930a..3fc31b1d6 100644 --- a/applications/settings/about/about.c +++ b/applications/settings/about/about.c @@ -9,8 +9,6 @@ #include #include -int screen_index; - typedef DialogMessageButton (*AboutDialogScreen)(DialogsApp* dialogs, DialogMessage* message); static DialogMessageButton product_screen(DialogsApp* dialogs, DialogMessage* message) { @@ -140,26 +138,18 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* furi_hal_info_get_api_version(&api_major, &api_minor); furi_string_cat_printf( buffer, - "%s [%s]\n%s%s [%d.%d] %s\n[%d] %s", + "%s %s\n%s F%d %d.%d %s\nhttps://flipper-xtre.me/", version_get_version(ver), version_get_builddate(ver), - version_get_dirty_flag(ver) ? "[!] " : "", version_get_githash(ver), + version_get_target(ver), api_major, api_minor, - c2_ver ? c2_ver->StackTypeString : "", - version_get_target(ver), - version_get_gitbranch(ver)); + c2_ver ? c2_ver->StackTypeString : ""); } dialog_message_set_header(message, "Firmware Info:", 0, 0, AlignLeft, AlignTop); - dialog_message_set_text( - message, - "XFW - Xtreme Firmware\nGithub.com/ClaraCrazy/Flipper-Xtreme", - 0, - 13, - AlignLeft, - AlignTop); + dialog_message_set_text(message, furi_string_get_cstr(buffer), 0, 13, AlignLeft, AlignTop); result = dialog_message_show(dialogs, message); dialog_message_set_text(message, NULL, 0, 0, AlignLeft, AlignTop); dialog_message_set_header(message, NULL, 0, 0, AlignLeft, AlignTop); @@ -168,157 +158,6 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* return result; } -#include -#include -#include - -#define LOW_CHARGE_THRESHOLD (10) -#define HIGH_DRAIN_CURRENT_THRESHOLD (-100) - -static void draw_stat(Canvas* canvas, int x, int y, const Icon* icon, char* val) { - canvas_draw_frame(canvas, x - 7, y + 7, 30, 13); - canvas_draw_icon(canvas, x, y, icon); - canvas_set_color(canvas, ColorWhite); - canvas_draw_box(canvas, x - 4, y + 16, 24, 6); - canvas_set_color(canvas, ColorBlack); - canvas_draw_str_aligned(canvas, x + 8, y + 22, AlignCenter, AlignBottom, val); -} - -static void draw_battery(Canvas* canvas, PowerInfo* info, int x, int y) { - char header[20] = {}; - char value[20] = {}; - - int32_t current = 1000.0f * info->current_gauge; - - // Draw battery - canvas_draw_icon(canvas, x, y, &I_BatteryBody_52x28); - if(current > 0) { - canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceCharging_29x14); - } else if(current < HIGH_DRAIN_CURRENT_THRESHOLD) { - canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceConfused_29x14); - } else if(info->charge < LOW_CHARGE_THRESHOLD) { - canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNopower_29x14); - } else { - canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNormal_29x14); - } - - // Draw bubble - elements_bubble(canvas, x + 53, y + 0, 71, 28); - - // Set text - if(current > 0) { - snprintf(header, sizeof(header), "%s", "Charging at"); - snprintf( - value, - sizeof(value), - "%lu.%luV %lumA", - (uint32_t)(info->voltage_vbus), - (uint32_t)(info->voltage_vbus * 10) % 10, - current); - } else if(current < -5) { - // Often gauge reports anything in the range 1~5ma as 5ma - // That brings confusion, so we'll treat it as Napping - snprintf(header, sizeof(header), "%s", "Consumption is"); - snprintf( - value, - sizeof(value), - "%ld %s", - ABS(current), - current < HIGH_DRAIN_CURRENT_THRESHOLD ? "mA!" : "mA"); - } else if(info->voltage_vbus > 0) { - if(info->voltage_battery_charge_limit < 4.2) { - // Non-default battery charging limit, mention it - snprintf(header, sizeof(header), "Limited to"); - snprintf( - value, - sizeof(value), - "%lu.%luV", - (uint32_t)(info->voltage_battery_charge_limit), - (uint32_t)(info->voltage_battery_charge_limit * 10) % 10); - } else { - snprintf(header, sizeof(header), "Charged!"); - } - } else { - snprintf(header, sizeof(header), "Napping..."); - } - - if(!strcmp(value, "")) { - canvas_draw_str_aligned(canvas, x + 92, y + 14, AlignCenter, AlignCenter, header); - } else if(!strcmp(header, "")) { - canvas_draw_str_aligned(canvas, x + 92, y + 14, AlignCenter, AlignCenter, value); - } else { - canvas_draw_str_aligned(canvas, x + 92, y + 9, AlignCenter, AlignCenter, header); - canvas_draw_str_aligned(canvas, x + 92, y + 19, AlignCenter, AlignCenter, value); - } -} - -static void battery_info_draw_callback(Canvas* canvas, void* context) { - furi_assert(context); - PowerInfo* info = context; - - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - draw_battery(canvas, info, 0, 0); - - char batt_level[10]; - char temperature[10]; - char voltage[10]; - char health[10]; - - snprintf(batt_level, sizeof(batt_level), "%lu%%", (uint32_t)info->charge); - if(locale_get_measurement_unit() == LocaleMeasurementUnitsMetric) { - snprintf(temperature, sizeof(temperature), "%lu C", (uint32_t)info->temperature_gauge); - } else { - snprintf( - temperature, - sizeof(temperature), - "%lu F", - (uint32_t)locale_celsius_to_fahrenheit(info->temperature_gauge)); - } - snprintf( - voltage, - sizeof(voltage), - "%lu.%01lu V", - (uint32_t)info->voltage_gauge, - (uint32_t)(info->voltage_gauge * 10) % 10UL); - snprintf(health, sizeof(health), "%d%%", info->health); - - draw_stat(canvas, 8, 28, &I_Battery_16x16, batt_level); - draw_stat(canvas, 40, 28, &I_Temperature_16x16, temperature); - draw_stat(canvas, 72, 28, &I_Voltage_16x16, voltage); - draw_stat(canvas, 104, 28, &I_Health_16x16, health); - - elements_button_left(canvas, "Back"); - elements_button_right(canvas, "Next"); - char uptime[17]; - uint32_t sec = furi_get_tick() / furi_kernel_get_tick_frequency(); - snprintf(uptime, sizeof(uptime), "Up %02lu:%02lu:%02lu", sec / 3600, sec / 60 % 60, sec % 60); - canvas_draw_str_aligned(canvas, 64, 61, AlignCenter, AlignBottom, uptime); -} - -static bool battery_info_input_callback(InputEvent* event, void* context) { - FuriSemaphore* semaphore = context; - - bool consumed = false; - if(event->type == InputTypeShort) { - if(event->key == InputKeyLeft) { - screen_index--; - consumed = true; - } else if(event->key == InputKeyRight) { - screen_index++; - consumed = true; - } else if(event->key == InputKeyBack) { - screen_index = -2; - consumed = true; - } - } - - if(consumed) { - furi_semaphore_release(semaphore); - } - return consumed; -} - const AboutDialogScreen about_screens[] = { product_screen, hw_version_screen, @@ -328,77 +167,60 @@ const AboutDialogScreen about_screens[] = { compliance_screen, address_screen}; -const int about_screens_count = sizeof(about_screens) / sizeof(AboutDialogScreen); +const size_t about_screens_count = sizeof(about_screens) / sizeof(AboutDialogScreen); int32_t about_settings_app(void* p) { - bool battery_info = false; - if(p && strlen(p) && !strcmp(p, "batt")) { - battery_info = true; - } + UNUSED(p); + DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); + DialogMessage* message = dialog_message_alloc(); Gui* gui = furi_record_open(RECORD_GUI); ViewDispatcher* view_dispatcher = view_dispatcher_alloc(); - const uint32_t battery_info_index = 0; - const uint32_t empty_screen_index = 1; - - FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0); - Power* power = furi_record_open(RECORD_POWER); - View* battery_view = view_alloc(); - view_set_context(battery_view, semaphore); - view_set_input_callback(battery_view, battery_info_input_callback); - view_allocate_model(battery_view, ViewModelTypeLocking, sizeof(PowerInfo)); - view_set_draw_callback(battery_view, battery_info_draw_callback); - - DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); - DialogMessage* message = dialog_message_alloc(); EmptyScreen* empty_screen = empty_screen_alloc(); + const uint32_t empty_screen_index = 0; + + size_t screen_index = 0; DialogMessageButton screen_result; // draw empty screen to prevent menu flickering - view_dispatcher_add_view(view_dispatcher, battery_info_index, battery_view); view_dispatcher_add_view( view_dispatcher, empty_screen_index, empty_screen_get_view(empty_screen)); view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen); + view_dispatcher_switch_to_view(view_dispatcher, empty_screen_index); - screen_index = -1 + !battery_info; - while(screen_index > -2) { - if(screen_index == -1) { - if(!battery_info) { - break; - } - with_view_model( - battery_view, PowerInfo * model, { power_get_info(power, model); }, true); - view_dispatcher_switch_to_view(view_dispatcher, battery_info_index); - furi_semaphore_acquire(semaphore, 2000); + int32_t ret = 0; + while(1) { + if(screen_index >= about_screens_count - 1) { + dialog_message_set_buttons(message, "Back", NULL, NULL); } else { - view_dispatcher_switch_to_view(view_dispatcher, empty_screen_index); - if(screen_index >= about_screens_count - 1) { - dialog_message_set_buttons(message, "Back", NULL, NULL); + dialog_message_set_buttons(message, "Back", NULL, "Next"); + } + + screen_result = about_screens[screen_index](dialogs, message); + + if(screen_result == DialogMessageButtonLeft) { + if(screen_index <= 0) { + ret = 1; + break; } else { - dialog_message_set_buttons(message, "Back", NULL, "Next"); - } - screen_result = about_screens[screen_index](dialogs, message); - if(screen_result == DialogMessageButtonLeft) { screen_index--; - } else if(screen_result == DialogMessageButtonRight) { - screen_index++; - } else if(screen_result == DialogMessageButtonBack) { - screen_index = -2; } + } else if(screen_result == DialogMessageButtonRight) { + if(screen_index < about_screens_count) { + screen_index++; + } + } else if(screen_result == DialogMessageButtonBack) { + break; } } dialog_message_free(message); furi_record_close(RECORD_DIALOGS); - furi_record_close(RECORD_POWER); - furi_semaphore_free(semaphore); view_dispatcher_remove_view(view_dispatcher, empty_screen_index); - view_dispatcher_remove_view(view_dispatcher, battery_info_index); - view_free(battery_view); view_dispatcher_free(view_dispatcher); empty_screen_free(empty_screen); furi_record_close(RECORD_GUI); - return 0; + return ret; } diff --git a/applications/settings/about/about.h b/applications/settings/about/about.h new file mode 100644 index 000000000..b8c9310a3 --- /dev/null +++ b/applications/settings/about/about.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +int32_t about_settings_app(void* p); diff --git a/applications/settings/power_settings_app/power_settings_app.c b/applications/settings/power_settings_app/power_settings_app.c index 8843a31ed..1d5aafef1 100644 --- a/applications/settings/power_settings_app/power_settings_app.c +++ b/applications/settings/power_settings_app/power_settings_app.c @@ -1,4 +1,5 @@ #include "power_settings_app.h" +#include "../about/about.h" static bool power_settings_custom_event_callback(void* context, uint32_t event) { furi_assert(context); @@ -21,6 +22,8 @@ static void power_settings_tick_event_callback(void* context) { PowerSettingsApp* power_settings_app_alloc(uint32_t first_scene) { PowerSettingsApp* app = malloc(sizeof(PowerSettingsApp)); + app->about_battery = first_scene == PowerSettingsAppSceneBatteryInfo; + // Records app->gui = furi_record_open(RECORD_GUI); app->power = furi_record_open(RECORD_POWER); @@ -92,11 +95,25 @@ void power_settings_app_free(PowerSettingsApp* app) { int32_t power_settings_app(void* p) { uint32_t first_scene = PowerSettingsAppSceneStart; - if(p && strlen(p) && !strcmp(p, "off")) { - first_scene = PowerSettingsAppScenePowerOff; + if(p && strlen(p)) { + if(!strcmp(p, "off")) { + first_scene = PowerSettingsAppScenePowerOff; + } else if(!strcmp(p, "about_battery")) { + first_scene = PowerSettingsAppSceneBatteryInfo; + } } PowerSettingsApp* app = power_settings_app_alloc(first_scene); - view_dispatcher_run(app->view_dispatcher); + while(true) { + view_dispatcher_run(app->view_dispatcher); + if(app->battery_info->exit_to_about) { + app->battery_info->exit_to_about = false; + if(about_settings_app("about_battery")) { + scene_manager_next_scene(app->scene_manager, first_scene); + continue; + } + } + break; + } power_settings_app_free(app); return 0; } diff --git a/applications/settings/power_settings_app/power_settings_app.h b/applications/settings/power_settings_app/power_settings_app.h index 65f7f7ab1..830eb77f1 100644 --- a/applications/settings/power_settings_app/power_settings_app.h +++ b/applications/settings/power_settings_app/power_settings_app.h @@ -28,6 +28,7 @@ typedef struct { VariableItemList* variable_item_list; uint32_t shutdown_idle_delay_ms; FuriPubSub* settings_events; + bool about_battery; } PowerSettingsApp; typedef enum { diff --git a/applications/settings/power_settings_app/scenes/power_settings_scene_battery_info.c b/applications/settings/power_settings_app/scenes/power_settings_scene_battery_info.c index e0186a5a6..da9feca2c 100644 --- a/applications/settings/power_settings_app/scenes/power_settings_scene_battery_info.c +++ b/applications/settings/power_settings_app/scenes/power_settings_scene_battery_info.c @@ -10,6 +10,7 @@ static void power_settings_scene_battery_info_update_model(PowerSettingsApp* app .charge_voltage_limit = app->info.voltage_battery_charge_limit, .charge = app->info.charge, .health = app->info.health, + .alt = app->about_battery, }; battery_info_set_data(app->battery_info, &battery_info_data); } diff --git a/applications/settings/power_settings_app/views/battery_info.c b/applications/settings/power_settings_app/views/battery_info.c index 9ffb0d22b..bbd6680eb 100644 --- a/applications/settings/power_settings_app/views/battery_info.c +++ b/applications/settings/power_settings_app/views/battery_info.c @@ -7,10 +7,6 @@ #define LOW_CHARGE_THRESHOLD (10) #define HIGH_DRAIN_CURRENT_THRESHOLD (-100) -struct BatteryInfo { - View* view; -}; - static void draw_stat(Canvas* canvas, int x, int y, const Icon* icon, char* val) { canvas_draw_frame(canvas, x - 7, y + 7, 30, 13); canvas_draw_icon(canvas, x, y, icon); @@ -40,7 +36,7 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { } // Draw bubble - elements_bubble(canvas, 53, 0, 71, 39); + elements_bubble(canvas, 53, 0, 71, data->alt ? 28 : 39); // Set text if(current > 0) { @@ -86,9 +82,20 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { snprintf(header, sizeof(header), "Napping..."); } - canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote); - canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header); - canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value); + if(data->alt) { + if(!strcmp(value, "")) { + canvas_draw_str_aligned(canvas, x + 92, y + 14, AlignCenter, AlignCenter, header); + } else if(!strcmp(header, "")) { + canvas_draw_str_aligned(canvas, x + 92, y + 14, AlignCenter, AlignCenter, value); + } else { + canvas_draw_str_aligned(canvas, x + 92, y + 9, AlignCenter, AlignCenter, header); + canvas_draw_str_aligned(canvas, x + 92, y + 19, AlignCenter, AlignCenter, value); + } + } else { + canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote); + canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header); + canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value); + } } static void battery_info_draw_callback(Canvas* canvas, void* context) { @@ -97,7 +104,7 @@ static void battery_info_draw_callback(Canvas* canvas, void* context) { canvas_clear(canvas); canvas_set_color(canvas, ColorBlack); - draw_battery(canvas, model, 0, 5); + draw_battery(canvas, model, 0, model->alt ? 0 : 5); char batt_level[10]; char temperature[10]; @@ -122,10 +129,39 @@ static void battery_info_draw_callback(Canvas* canvas, void* context) { (uint32_t)(model->gauge_voltage * 10) % 10UL); snprintf(health, sizeof(health), "%d%%", model->health); - draw_stat(canvas, 8, 42, &I_Battery_16x16, batt_level); - draw_stat(canvas, 40, 42, &I_Temperature_16x16, temperature); - draw_stat(canvas, 72, 42, &I_Voltage_16x16, voltage); - draw_stat(canvas, 104, 42, &I_Health_16x16, health); + int h = model->alt ? 28 : 42; + draw_stat(canvas, 8, h, &I_Battery_16x16, batt_level); + draw_stat(canvas, 40, h, &I_Temperature_16x16, temperature); + draw_stat(canvas, 72, h, &I_Voltage_16x16, voltage); + draw_stat(canvas, 104, h, &I_Health_16x16, health); + + if(model->alt) { + elements_button_left(canvas, "Back"); + elements_button_right(canvas, "Next"); + char uptime[17]; + uint32_t sec = furi_get_tick() / furi_kernel_get_tick_frequency(); + snprintf( + uptime, sizeof(uptime), "Up %02lu:%02lu:%02lu", sec / 3600, sec / 60 % 60, sec % 60); + canvas_draw_str_aligned(canvas, 64, 61, AlignCenter, AlignBottom, uptime); + } +} + +static bool battery_info_input_callback(InputEvent* event, void* context) { + furi_assert(event); + furi_assert(context); + + BatteryInfo* battery_info = context; + + if(event->type == InputTypeShort) { + if(event->key == InputKeyLeft) { + event->key = InputKeyBack; + } else if(event->key == InputKeyRight) { + event->key = InputKeyBack; + battery_info->exit_to_about = true; + } + } + + return false; } BatteryInfo* battery_info_alloc() { @@ -134,6 +170,7 @@ BatteryInfo* battery_info_alloc() { view_set_context(battery_info->view, battery_info); view_allocate_model(battery_info->view, ViewModelTypeLocking, sizeof(BatteryInfoModel)); view_set_draw_callback(battery_info->view, battery_info_draw_callback); + view_set_input_callback(battery_info->view, battery_info_input_callback); return battery_info; } diff --git a/applications/settings/power_settings_app/views/battery_info.h b/applications/settings/power_settings_app/views/battery_info.h index e52d1844c..99186b585 100644 --- a/applications/settings/power_settings_app/views/battery_info.h +++ b/applications/settings/power_settings_app/views/battery_info.h @@ -2,7 +2,10 @@ #include -typedef struct BatteryInfo BatteryInfo; +typedef struct { + View* view; + bool exit_to_about; +} BatteryInfo; typedef struct { float vbus_voltage; @@ -12,6 +15,7 @@ typedef struct { float charge_voltage_limit; uint8_t charge; uint8_t health; + bool alt; } BatteryInfoModel; BatteryInfo* battery_info_alloc();