Clock: some improvements

This commit is contained in:
gid9798 2023-05-23 22:47:15 +03:00
parent c82ed71b6f
commit 1d5a4240b9
7 changed files with 105 additions and 15 deletions

View file

@ -8,6 +8,7 @@
#include <furi_hal.h> #include <furi_hal.h>
#include <cli/cli.h> #include <cli/cli.h>
#include <cli/cli_vcp.h> #include <cli/cli_vcp.h>
#include <locale/locale.h>
#include "animations/animation_manager.h" #include "animations/animation_manager.h"
#include "desktop/scenes/desktop_scene.h" #include "desktop/scenes/desktop_scene.h"
@ -48,6 +49,21 @@ static void desktop_dummy_mode_icon_draw_callback(Canvas* canvas, void* context)
canvas_draw_icon(canvas, 0, 0, &I_GameMode_11x8); canvas_draw_icon(canvas, 0, 0, &I_GameMode_11x8);
} }
static void desktop_togle_clock_view(Desktop* desktop, bool is_enabled) {
furi_assert(desktop);
// clock type upd after 1 minute
desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h);
if(is_enabled) { // && !furi_timer_is_running(desktop->update_clock_timer)) {
furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000));
} else if(!is_enabled) { //&& furi_timer_is_running(desktop->update_clock_timer)) {
furi_timer_stop(desktop->update_clock_timer);
}
view_port_enabled_set(desktop->clock_viewport, is_enabled);
}
static uint8_t desktop_clock_get_num_w(uint8_t num) { static uint8_t desktop_clock_get_num_w(uint8_t num) {
if(num == 1) { if(num == 1) {
return 3; return 3;
@ -81,7 +97,8 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
desktop_clock_get_num_w(d[3]) + //c4 desktop_clock_get_num_w(d[3]) + //c4
2 + 4; // ":" + 4 separators 2 + 4; // ":" + 4 separators
view_port_set_width(desktop->clock_viewport, new_w - 1); // further away from the battery charge indicator, if the smallest minute is 1
view_port_set_width(desktop->clock_viewport, new_w - !(d[0] == 1));
uint8_t x = new_w; uint8_t x = new_w;
@ -123,6 +140,9 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
// TODO: Implement a message mechanism for loading settings and (optionally) // TODO: Implement a message mechanism for loading settings and (optionally)
// locking and unlocking // locking and unlocking
DESKTOP_SETTINGS_LOAD(&desktop->settings); DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_togle_clock_view(desktop, desktop->settings.display_clock);
desktop_auto_lock_arm(desktop); desktop_auto_lock_arm(desktop);
return true; return true;
case DesktopGlobalAutoLock: case DesktopGlobalAutoLock:
@ -192,15 +212,25 @@ static void desktop_update_clock_timer_callback(void* context) {
furi_assert(context); furi_assert(context);
Desktop* desktop = context; Desktop* desktop = context;
FuriHalRtcDateTime curr_dt; if(gui_get_count_of_enabled_view_port_in_layer(desktop->gui, GuiLayerStatusBarLeft) < 6) {
furi_hal_rtc_get_datetime(&curr_dt); FuriHalRtcDateTime curr_dt;
if(desktop->minute != curr_dt.minute) { furi_hal_rtc_get_datetime(&curr_dt);
desktop->hour = curr_dt.hour;
desktop->minute = curr_dt.minute;
view_port_update(desktop->clock_viewport);
}
// view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAutoLock); if(desktop->minute != curr_dt.minute) {
if(desktop->clock_type) {
desktop->hour = curr_dt.hour;
} else {
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
}
desktop->minute = curr_dt.minute;
view_port_update(desktop->clock_viewport);
}
view_port_enabled_set(desktop->clock_viewport, true);
} else {
view_port_enabled_set(desktop->clock_viewport, false);
}
} }
void desktop_lock(Desktop* desktop) { void desktop_lock(Desktop* desktop) {
@ -353,7 +383,7 @@ Desktop* desktop_alloc() {
desktop->clock_viewport = view_port_alloc(); desktop->clock_viewport = view_port_alloc();
view_port_set_width(desktop->clock_viewport, 25); view_port_set_width(desktop->clock_viewport, 25);
view_port_draw_callback_set(desktop->clock_viewport, desktop_clock_draw_callback, desktop); view_port_draw_callback_set(desktop->clock_viewport, desktop_clock_draw_callback, desktop);
view_port_enabled_set(desktop->clock_viewport, true); view_port_enabled_set(desktop->clock_viewport, false);
gui_add_view_port(desktop->gui, desktop->clock_viewport, GuiLayerStatusBarRight); gui_add_view_port(desktop->gui, desktop->clock_viewport, GuiLayerStatusBarRight);
// Stealth mode icon // Stealth mode icon
@ -391,11 +421,14 @@ Desktop* desktop_alloc() {
FuriHalRtcDateTime curr_dt; FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt); furi_hal_rtc_get_datetime(&curr_dt);
desktop->hour = curr_dt.hour; if(desktop->clock_type) {
desktop->hour = curr_dt.hour;
} else {
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
}
desktop->minute = curr_dt.minute; desktop->minute = curr_dt.minute;
furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000));
furi_record_create(RECORD_DESKTOP, desktop); furi_record_create(RECORD_DESKTOP, desktop);
return desktop; return desktop;
@ -489,6 +522,9 @@ int32_t desktop_srv(void* p) {
} }
view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode); view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode);
desktop_togle_clock_view(desktop, desktop->settings.display_clock);
desktop_main_set_dummy_mode_state(desktop->main_view, desktop->settings.dummy_mode); desktop_main_set_dummy_mode_state(desktop->main_view, desktop->settings.dummy_mode);
animation_manager_set_dummy_mode_state( animation_manager_set_dummy_mode_state(
desktop->animation_manager, desktop->settings.dummy_mode); desktop->animation_manager, desktop->settings.dummy_mode);

View file

@ -75,8 +75,9 @@ struct Desktop {
uint8_t hour; uint8_t hour;
uint8_t minute; uint8_t minute;
bool clock_type : 1; // true - 24h false - 12h
bool in_transition; bool in_transition : 1;
}; };
Desktop* desktop_alloc(); Desktop* desktop_alloc();

View file

@ -63,4 +63,5 @@ typedef struct {
uint32_t auto_lock_delay_ms; uint32_t auto_lock_delay_ms;
uint8_t displayBatteryPercentage; uint8_t displayBatteryPercentage;
uint8_t dummy_mode; uint8_t dummy_mode;
uint8_t display_clock;
} DesktopSettings; } DesktopSettings;

View file

@ -17,6 +17,23 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {
return NULL; return NULL;
} }
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer) {
furi_assert(gui);
furi_check(layer < GuiLayerMAX);
uint8_t ret = 0;
ViewPortArray_it_t it;
ViewPortArray_it_last(it, gui->layers[layer]);
while(!ViewPortArray_end_p(it)) {
ViewPort* view_port = *ViewPortArray_ref(it);
if(view_port_is_enabled(view_port)) {
ret++;
}
ViewPortArray_previous(it);
}
return ret;
}
void gui_update(Gui* gui) { void gui_update(Gui* gui) {
furi_assert(gui); furi_assert(gui);
if(!gui->direct_draw) furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW); if(!gui->direct_draw) furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW);

View file

@ -132,6 +132,8 @@ Canvas* gui_direct_draw_acquire(Gui* gui);
*/ */
void gui_direct_draw_release(Gui* gui); void gui_direct_draw_release(Gui* gui);
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -11,7 +11,8 @@
#define SCENE_EVENT_SELECT_PIN_SETUP 3 #define SCENE_EVENT_SELECT_PIN_SETUP 3
#define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 4 #define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 4
#define SCENE_EVENT_SELECT_BATTERY_DISPLAY 5 #define SCENE_EVENT_SELECT_BATTERY_DISPLAY 5
#define SCENE_EVENT_SELECT_CHANGE_NAME 6 #define SCENE_EVENT_SELECT_CLOCK_DISPLAY 6
#define SCENE_EVENT_SELECT_CHANGE_NAME 7
#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] = {
@ -29,6 +30,14 @@ 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 CLOCK_ENABLE_COUNT 2
const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = {
"OFF",
"ON",
};
const uint32_t clock_enable_value[CLOCK_ENABLE_COUNT] = {0, 1};
#define BATTERY_VIEW_COUNT 6 #define BATTERY_VIEW_COUNT 6
const char* const battery_view_count_text[BATTERY_VIEW_COUNT] = const char* const battery_view_count_text[BATTERY_VIEW_COUNT] =
@ -55,6 +64,14 @@ static void desktop_settings_scene_start_battery_view_changed(VariableItem* item
app->settings.displayBatteryPercentage = index; app->settings.displayBatteryPercentage = index;
} }
static void desktop_settings_scene_start_clock_enable_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, clock_enable_text[index]);
app->settings.display_clock = 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) {
DesktopSettingsApp* app = variable_item_get_context(item); DesktopSettingsApp* 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);
@ -106,6 +123,18 @@ void desktop_settings_scene_start_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, battery_view_count_text[value_index]); variable_item_set_current_value_text(item, battery_view_count_text[value_index]);
item = variable_item_list_add(
variable_item_list,
"Clock on desktop",
CLOCK_ENABLE_COUNT,
desktop_settings_scene_start_clock_enable_changed, //
app);
value_index =
value_index_uint32(app->settings.display_clock, clock_enable_value, CLOCK_ENABLE_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, clock_enable_text[value_index]);
variable_item_list_add(variable_item_list, "Change Flipper Name", 0, NULL, app); variable_item_list_add(variable_item_list, "Change Flipper Name", 0, NULL, app);
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList); view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
@ -142,6 +171,9 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
case SCENE_EVENT_SELECT_BATTERY_DISPLAY: case SCENE_EVENT_SELECT_BATTERY_DISPLAY:
consumed = true; consumed = true;
break; break;
case SCENE_EVENT_SELECT_CLOCK_DISPLAY:
consumed = true;
break;
case SCENE_EVENT_SELECT_CHANGE_NAME: case SCENE_EVENT_SELECT_CHANGE_NAME:
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneChangeName); scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneChangeName);
consumed = true; consumed = true;

View file

@ -1658,6 +1658,7 @@ Function,+,gui_add_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, voi
Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer" Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer"
Function,+,gui_direct_draw_acquire,Canvas*,Gui* Function,+,gui_direct_draw_acquire,Canvas*,Gui*
Function,+,gui_direct_draw_release,void,Gui* Function,+,gui_direct_draw_release,void,Gui*
Function,-,gui_get_count_of_enabled_view_port_in_layer,uint8_t,"Gui*, GuiLayer"
Function,+,gui_get_framebuffer_size,size_t,const Gui* Function,+,gui_get_framebuffer_size,size_t,const Gui*
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*" Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*" Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"

1 entry status name type params
1658 Function + gui_add_view_port void Gui*, ViewPort*, GuiLayer
1659 Function + gui_direct_draw_acquire Canvas* Gui*
1660 Function + gui_direct_draw_release void Gui*
1661 Function - gui_get_count_of_enabled_view_port_in_layer uint8_t Gui*, GuiLayer
1662 Function + gui_get_framebuffer_size size_t const Gui*
1663 Function + gui_remove_framebuffer_callback void Gui*, GuiCanvasCommitCallback, void*
1664 Function + gui_remove_view_port void Gui*, ViewPort*