|
| 1 | +#include <furi.h> |
| 2 | +#include <gui/gui.h> |
| 3 | +#include <gui/elements.h> |
| 4 | +#include <gui/view_dispatcher.h> |
| 5 | +#include <gui/modules/dialog_ex.h> |
| 6 | +#include <locale/locale.h> |
| 7 | + |
| 8 | +typedef struct { |
| 9 | + Gui* gui; |
| 10 | + ViewDispatcher* view_dispatcher; |
| 11 | + View* view; |
| 12 | +} LocaleTestApp; |
| 13 | + |
| 14 | +static void locale_test_view_draw_callback(Canvas* canvas, void* _model) { |
| 15 | + UNUSED(_model); |
| 16 | + |
| 17 | + // Prepare canvas |
| 18 | + canvas_set_color(canvas, ColorBlack); |
| 19 | + canvas_set_font(canvas, FontSecondary); |
| 20 | + |
| 21 | + FuriString* tmp_string = furi_string_alloc(); |
| 22 | + |
| 23 | + float temp = 25.3f; |
| 24 | + LocaleMeasurementUnits units = locale_get_measurement_unit(); |
| 25 | + if(units == LocaleMeasurementUnitsMetric) { |
| 26 | + furi_string_printf(tmp_string, "Temp: %5.1fC", (double)temp); |
| 27 | + } else { |
| 28 | + temp = locale_celsius_to_fahrenheit(temp); |
| 29 | + furi_string_printf(tmp_string, "Temp: %5.1fF", (double)temp); |
| 30 | + } |
| 31 | + canvas_draw_str(canvas, 0, 10, furi_string_get_cstr(tmp_string)); |
| 32 | + |
| 33 | + FuriHalRtcDateTime datetime; |
| 34 | + furi_hal_rtc_get_datetime(&datetime); |
| 35 | + |
| 36 | + locale_format_time(tmp_string, &datetime, locale_get_time_format(), false); |
| 37 | + canvas_draw_str(canvas, 0, 25, furi_string_get_cstr(tmp_string)); |
| 38 | + |
| 39 | + locale_format_date(tmp_string, &datetime, locale_get_date_format(), "/"); |
| 40 | + canvas_draw_str(canvas, 0, 40, furi_string_get_cstr(tmp_string)); |
| 41 | + |
| 42 | + furi_string_free(tmp_string); |
| 43 | +} |
| 44 | + |
| 45 | +static bool locale_test_view_input_callback(InputEvent* event, void* context) { |
| 46 | + UNUSED(event); |
| 47 | + UNUSED(context); |
| 48 | + return false; |
| 49 | +} |
| 50 | + |
| 51 | +static uint32_t locale_test_exit(void* context) { |
| 52 | + UNUSED(context); |
| 53 | + return VIEW_NONE; |
| 54 | +} |
| 55 | + |
| 56 | +static LocaleTestApp* locale_test_alloc() { |
| 57 | + LocaleTestApp* app = malloc(sizeof(LocaleTestApp)); |
| 58 | + |
| 59 | + // Gui |
| 60 | + app->gui = furi_record_open(RECORD_GUI); |
| 61 | + |
| 62 | + // View dispatcher |
| 63 | + app->view_dispatcher = view_dispatcher_alloc(); |
| 64 | + view_dispatcher_enable_queue(app->view_dispatcher); |
| 65 | + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); |
| 66 | + |
| 67 | + // Views |
| 68 | + app->view = view_alloc(); |
| 69 | + view_set_draw_callback(app->view, locale_test_view_draw_callback); |
| 70 | + view_set_input_callback(app->view, locale_test_view_input_callback); |
| 71 | + |
| 72 | + view_set_previous_callback(app->view, locale_test_exit); |
| 73 | + view_dispatcher_add_view(app->view_dispatcher, 0, app->view); |
| 74 | + view_dispatcher_switch_to_view(app->view_dispatcher, 0); |
| 75 | + |
| 76 | + return app; |
| 77 | +} |
| 78 | + |
| 79 | +static void locale_test_free(LocaleTestApp* app) { |
| 80 | + furi_assert(app); |
| 81 | + |
| 82 | + // Free views |
| 83 | + view_dispatcher_remove_view(app->view_dispatcher, 0); |
| 84 | + |
| 85 | + view_free(app->view); |
| 86 | + view_dispatcher_free(app->view_dispatcher); |
| 87 | + |
| 88 | + // Close gui record |
| 89 | + furi_record_close(RECORD_GUI); |
| 90 | + app->gui = NULL; |
| 91 | + |
| 92 | + // Free rest |
| 93 | + free(app); |
| 94 | +} |
| 95 | + |
| 96 | +int32_t locale_test_app(void* p) { |
| 97 | + UNUSED(p); |
| 98 | + LocaleTestApp* app = locale_test_alloc(); |
| 99 | + view_dispatcher_run(app->view_dispatcher); |
| 100 | + locale_test_free(app); |
| 101 | + return 0; |
| 102 | +} |
0 commit comments