Willy-JL 1 год назад
Родитель
Сommit
9c10f37d00
70 измененных файлов с 10394 добавлено и 11938 удалено
  1. 4 7
      flip_library/app.c
  2. 1 1
      flip_library/application.fam
  3. 142 200
      flip_library/easy_flipper.h
  4. 218 317
      flip_library/flip_library_callback.h
  5. 37 40
      flip_library/flip_library_e.h
  6. 16 31
      flip_library/flip_library_free.h
  7. 178 74
      flip_library/flip_library_i.h
  8. 20 32
      flip_library/flip_library_storage.h
  9. 190 302
      flip_library/flipper_http.h
  10. 523 604
      flip_library/jsmn.h
  11. 113 213
      flip_library/uart_text_input.h
  12. 8 11
      flip_social/app.c
  13. 142 200
      flip_social/easy_flipper.h
  14. 336 241
      flip_social/flip_social_callback.h
  15. 308 298
      flip_social/flip_social_draw.h
  16. 214 185
      flip_social/flip_social_e.h
  17. 50 59
      flip_social/flip_social_explore.h
  18. 47 69
      flip_social/flip_social_feed.h
  19. 100 147
      flip_social/flip_social_free.h
  20. 58 66
      flip_social/flip_social_friends.h
  21. 732 333
      flip_social/flip_social_i.h
  22. 140 158
      flip_social/flip_social_messages.h
  23. 113 137
      flip_social/flip_social_storage.h
  24. 269 343
      flip_social/flipper_http.h
  25. 531 614
      flip_social/jsmn.h
  26. 113 213
      flip_social/uart_text_input.h
  27. 4 7
      flip_store/app.c
  28. 142 200
      flip_store/easy_flipper.h
  29. 166 224
      flip_store/flip_store_apps.h
  30. 118 128
      flip_store/flip_store_callback.h
  31. 57 63
      flip_store/flip_store_e.h
  32. 24 47
      flip_store/flip_store_free.h
  33. 268 107
      flip_store/flip_store_i.h
  34. 72 114
      flip_store/flip_store_storage.h
  35. 256 311
      flip_store/flipper_http.h
  36. 531 614
      flip_store/jsmn.h
  37. 113 213
      flip_store/uart_text_input.h
  38. 4 7
      flip_trader/app.c
  39. 1 1
      flip_trader/application.fam
  40. 142 200
      flip_trader/easy_flipper.h
  41. 81 119
      flip_trader/flip_trader_callback.h
  42. 28 31
      flip_trader/flip_trader_e.h
  43. 11 21
      flip_trader/flip_trader_free.h
  44. 107 51
      flip_trader/flip_trader_i.h
  45. 20 32
      flip_trader/flip_trader_storage.h
  46. 251 299
      flip_trader/flipper_http.h
  47. 523 604
      flip_trader/jsmn.h
  48. 113 213
      flip_trader/uart_text_input.h
  49. 4 7
      flip_weather/app.c
  50. 1 1
      flip_weather/application.fam
  51. 142 200
      flip_weather/easy_flipper.h
  52. 87 130
      flip_weather/flip_weather_callback.h
  53. 27 30
      flip_weather/flip_weather_e.h
  54. 16 31
      flip_weather/flip_weather_free.h
  55. 104 49
      flip_weather/flip_weather_i.h
  56. 38 58
      flip_weather/flip_weather_parse.h
  57. 20 32
      flip_weather/flip_weather_storage.h
  58. 190 302
      flip_weather/flipper_http.h
  59. 531 614
      flip_weather/jsmn.h
  60. 113 213
      flip_weather/uart_text_input.h
  61. 4 7
      flip_wifi/app.c
  62. 142 200
      flip_wifi/easy_flipper.h
  63. 144 150
      flip_wifi/flip_wifi_callback.h
  64. 38 42
      flip_wifi/flip_wifi_e.h
  65. 19 37
      flip_wifi/flip_wifi_free.h
  66. 148 69
      flip_wifi/flip_wifi_i.h
  67. 101 144
      flip_wifi/flip_wifi_storage.h
  68. 254 304
      flip_wifi/flipper_http.h
  69. 523 604
      flip_wifi/jsmn.h
  70. 113 213
      flip_wifi/uart_text_input.h

+ 4 - 7
flip_library/app.c

@@ -5,21 +5,18 @@
 #include <flip_library_free.h>
 
 // Entry point for the FlipLibrary application
-int32_t flip_library_app(void *p)
-{
+int32_t flip_library_app(void* p) {
     // Suppress unused parameter warning
     UNUSED(p);
 
     // Initialize the FlipLibrary application
-    FlipLibraryApp *app = flip_library_app_alloc();
-    if (!app)
-    {
+    FlipLibraryApp* app = flip_library_app_alloc();
+    if(!app) {
         FURI_LOG_E(TAG, "Failed to allocate FlipLibraryApp");
         return -1;
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 1 - 1
flip_library/application.fam

@@ -10,5 +10,5 @@ App(
     fap_description="Dictionary, random facts, and more.",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipLibrary",
-    fap_version = "1.1",
+    fap_version="1.1",
 )

+ 142 - 200
flip_library/easy_flipper.h

@@ -26,11 +26,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -44,16 +42,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -72,39 +67,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -118,22 +106,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -150,29 +134,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -189,24 +168,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -223,29 +198,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -264,33 +234,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -303,38 +270,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -349,40 +316,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -406,63 +374,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -486,48 +443,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -543,24 +492,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -573,16 +518,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -590,4 +532,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

Разница между файлами не показана из-за своего большого размера
+ 218 - 317
flip_library/flip_library_callback.h


+ 37 - 40
flip_library/flip_library_e.h

@@ -16,30 +16,28 @@
 #define TAG "FlipLibrary"
 
 // Define the submenu items for our FlipLibrary application
-typedef enum
-{
+typedef enum {
     FlipLibrarySubmenuIndexRandomFacts, // Click to run the random facts
-    FlipLibrarySubmenuIndexDictionary,  // click to view the dictionary variable item list
-    FlipLibrarySubmenuIndexAbout,       // Click to view the about screen
-    FlipLibrarySubmenuIndexSettings,    // Click to view the WiFi settings
+    FlipLibrarySubmenuIndexDictionary, // click to view the dictionary variable item list
+    FlipLibrarySubmenuIndexAbout, // Click to view the about screen
+    FlipLibrarySubmenuIndexSettings, // Click to view the WiFi settings
     //
-    FlipLibrarySubmenuIndexRandomFactsCats,   // Click to view the random facts (cats)
-    FlipLibrarySubmenuIndexRandomFactsDogs,   // Click to view the random facts (dogs)
+    FlipLibrarySubmenuIndexRandomFactsCats, // Click to view the random facts (cats)
+    FlipLibrarySubmenuIndexRandomFactsDogs, // Click to view the random facts (dogs)
     FlipLibrarySubmenuIndexRandomFactsQuotes, // Click to view the random facts (quotes)
-    FlipLibrarySubmenuIndexRandomFactsAll,    // Click to view the random facts (all)
+    FlipLibrarySubmenuIndexRandomFactsAll, // Click to view the random facts (all)
 } FlipLibrarySubmenuIndex;
 
 // Define a single view for our FlipLibrary application
-typedef enum
-{
-    FlipLibraryViewRandomFacts = 7,        // The random facts main screen
-    FlipLibraryViewRandomFactsRun = 8,     // The random facts widget that displays the random fact
-    FlipLibraryViewSubmenuMain = 9,        // The submenu screen
-    FlipLibraryViewAbout = 10,             // The about screen
-    FlipLibraryViewSettings = 11,          // The settings screen
-    FlipLibraryViewTextInputSSID = 12,     // The text input screen (SSID)
+typedef enum {
+    FlipLibraryViewRandomFacts = 7, // The random facts main screen
+    FlipLibraryViewRandomFactsRun = 8, // The random facts widget that displays the random fact
+    FlipLibraryViewSubmenuMain = 9, // The submenu screen
+    FlipLibraryViewAbout = 10, // The about screen
+    FlipLibraryViewSettings = 11, // The settings screen
+    FlipLibraryViewTextInputSSID = 12, // The text input screen (SSID)
     FlipLibraryViewTextInputPassword = 13, // The text input screen (password)
-    FlipLibraryViewDictionary = 14,        // The dictionary submenu screen
+    FlipLibraryViewDictionary = 14, // The dictionary submenu screen
     //
     FlipLibraryViewDictionaryTextInput = 15,
     FlipLibraryViewDictionaryRun = 16,
@@ -54,35 +52,34 @@ typedef enum
 } FlipLibraryView;
 
 // Each screen will have its own view
-typedef struct
-{
-    ViewDispatcher *view_dispatcher;            // Switches between our views
-    View *view_random_facts;                    // The main screen that displays the random fact
-    View *view_dictionary;                      // The dictionary screen
-    Submenu *submenu_main;                      // The submenu for the main screen
-    Submenu *submenu_random_facts;              // The submenu for the random facts screen
-    Widget *widget;                             // The widget
-    VariableItemList *variable_item_list_wifi;  // The variable item list (WiFi settings)
-    VariableItem *variable_item_ssid;           // The variable item (SSID)
-    VariableItem *variable_item_password;       // The variable item (password)
-    UART_TextInput *uart_text_input_ssid;       // The text input for the SSID
-    UART_TextInput *uart_text_input_password;   // The text input for the password
-    UART_TextInput *uart_text_input_dictionary; // The text input for the dictionary
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    View* view_random_facts; // The main screen that displays the random fact
+    View* view_dictionary; // The dictionary screen
+    Submenu* submenu_main; // The submenu for the main screen
+    Submenu* submenu_random_facts; // The submenu for the random facts screen
+    Widget* widget; // The widget
+    VariableItemList* variable_item_list_wifi; // The variable item list (WiFi settings)
+    VariableItem* variable_item_ssid; // The variable item (SSID)
+    VariableItem* variable_item_password; // The variable item (password)
+    UART_TextInput* uart_text_input_ssid; // The text input for the SSID
+    UART_TextInput* uart_text_input_password; // The text input for the password
+    UART_TextInput* uart_text_input_dictionary; // The text input for the dictionary
     //
-    Widget *widget_random_fact; // The text box that displays the random fact
-    Widget *widget_dictionary;  // The text box that displays the dictionary
+    Widget* widget_random_fact; // The text box that displays the random fact
+    Widget* widget_dictionary; // The text box that displays the dictionary
 
-    char *uart_text_input_buffer_ssid;         // Buffer for the text input (SSID)
-    char *uart_text_input_temp_buffer_ssid;    // Temporary buffer for the text input (SSID)
+    char* uart_text_input_buffer_ssid; // Buffer for the text input (SSID)
+    char* uart_text_input_temp_buffer_ssid; // Temporary buffer for the text input (SSID)
     uint32_t uart_text_input_buffer_size_ssid; // Size of the text input buffer (SSID)
 
-    char *uart_text_input_buffer_password;         // Buffer for the text input (password)
-    char *uart_text_input_temp_buffer_password;    // Temporary buffer for the text input (password)
+    char* uart_text_input_buffer_password; // Buffer for the text input (password)
+    char* uart_text_input_temp_buffer_password; // Temporary buffer for the text input (password)
     uint32_t uart_text_input_buffer_size_password; // Size of the text input buffer (password)
 
-    char *uart_text_input_buffer_dictionary;         // Buffer for the text input (dictionary)
-    char *uart_text_input_temp_buffer_dictionary;    // Temporary buffer for the text input (dictionary)
+    char* uart_text_input_buffer_dictionary; // Buffer for the text input (dictionary)
+    char* uart_text_input_temp_buffer_dictionary; // Temporary buffer for the text input (dictionary)
     uint32_t uart_text_input_buffer_size_dictionary; // Size of the text input buffer (dictionary)
 } FlipLibraryApp;
 
-#endif // FLIP_LIBRARY_E_H
+#endif // FLIP_LIBRARY_E_H

+ 16 - 31
flip_library/flip_library_free.h

@@ -2,75 +2,62 @@
 #define FLIP_LIBRARY_FREE_H
 
 // Function to free the resources used by FlipLibraryApp
-static void flip_library_app_free(FlipLibraryApp *app)
-{
-    if (!app)
-    {
+static void flip_library_app_free(FlipLibraryApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
         return;
     }
 
     // Free View(s)
-    if (app->view_random_facts)
-    {
+    if(app->view_random_facts) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactsRun);
         view_free(app->view_random_facts);
     }
-    if (app->view_dictionary)
-    {
+    if(app->view_dictionary) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryRun);
         view_free(app->view_dictionary);
     }
 
     // Free Submenu(s)
-    if (app->submenu_main)
-    {
+    if(app->submenu_main) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSubmenuMain);
         submenu_free(app->submenu_main);
     }
-    if (app->submenu_random_facts)
-    {
+    if(app->submenu_random_facts) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFacts);
         submenu_free(app->submenu_random_facts);
     }
 
     // Free Widget(s)
-    if (app->widget)
-    {
+    if(app->widget) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewAbout);
         widget_free(app->widget);
     }
-    if (app->widget_random_fact)
-    {
+    if(app->widget_random_fact) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewRandomFactWidget);
         widget_free(app->widget_random_fact);
     }
-    if (app->widget_dictionary)
-    {
+    if(app->widget_dictionary) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryWidget);
         widget_free(app->widget_dictionary);
     }
 
     // Free Variable Item List(s)
-    if (app->variable_item_list_wifi)
-    {
+    if(app->variable_item_list_wifi) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewSettings);
         variable_item_list_free(app->variable_item_list_wifi);
     }
 
     // Free Text Input(s)
-    if (app->uart_text_input_ssid)
-    {
+    if(app->uart_text_input_ssid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputSSID);
         uart_text_input_free(app->uart_text_input_ssid);
     }
-    if (app->uart_text_input_password)
-    {
+    if(app->uart_text_input_password) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputPassword);
         uart_text_input_free(app->uart_text_input_password);
     }
-    if (app->uart_text_input_dictionary)
-    {
+    if(app->uart_text_input_dictionary) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryTextInput);
         uart_text_input_free(app->uart_text_input_dictionary);
     }
@@ -79,14 +66,12 @@ static void flip_library_app_free(FlipLibraryApp *app)
     flipper_http_deinit();
 
     // free the view dispatcher
-    if (app->view_dispatcher)
-        view_dispatcher_free(app->view_dispatcher);
+    if(app->view_dispatcher) view_dispatcher_free(app->view_dispatcher);
 
     // close the gui
     furi_record_close(RECORD_GUI);
 
-    if (app_instance)
-    {
+    if(app_instance) {
         // free the app instance
         free(app_instance);
         app_instance = NULL;
@@ -95,4 +80,4 @@ static void flip_library_app_free(FlipLibraryApp *app)
     free(app);
 }
 
-#endif // FLIP_LIBRARY_FREE_H
+#endif // FLIP_LIBRARY_FREE_H

+ 178 - 74
flip_library/flip_library_i.h

@@ -2,14 +2,12 @@
 #define FLIP_LIBRARY_I_H
 
 // Function to allocate resources for the FlipLibraryApp
-static FlipLibraryApp *flip_library_app_alloc()
-{
-    FlipLibraryApp *app = (FlipLibraryApp *)malloc(sizeof(FlipLibraryApp));
+static FlipLibraryApp* flip_library_app_alloc() {
+    FlipLibraryApp* app = (FlipLibraryApp*)malloc(sizeof(FlipLibraryApp));
 
-    Gui *gui = furi_record_open(RECORD_GUI);
+    Gui* gui = furi_record_open(RECORD_GUI);
 
-    if (!flipper_http_init(flipper_http_rx_callback, app))
-    {
+    if(!flipper_http_init(flipper_http_rx_callback, app)) {
         FURI_LOG_E(TAG, "Failed to initialize flipper http");
         return NULL;
     }
@@ -18,124 +16,230 @@ static FlipLibraryApp *flip_library_app_alloc()
     app->uart_text_input_buffer_size_ssid = 64;
     app->uart_text_input_buffer_size_password = 64;
     app->uart_text_input_buffer_size_dictionary = 64;
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_dictionary, app->uart_text_input_buffer_size_dictionary))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_dictionary, app->uart_text_input_buffer_size_dictionary)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_dictionary, app->uart_text_input_buffer_size_dictionary))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_dictionary,
+           app->uart_text_input_buffer_size_dictionary)) {
         return NULL;
     }
 
     // Allocate ViewDispatcher
-    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
-    {
+    if(!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app)) {
         return NULL;
     }
 
     // Main view
-    if (!easy_flipper_set_view(&app->view_random_facts, FlipLibraryViewRandomFactsRun, view_draw_callback_random_facts, NULL, callback_to_random_facts, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_random_facts,
+           FlipLibraryViewRandomFactsRun,
+           view_draw_callback_random_facts,
+           NULL,
+           callback_to_random_facts,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_view(&app->view_dictionary, FlipLibraryViewDictionaryRun, view_draw_callback_dictionary_run, NULL, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_dictionary,
+           FlipLibraryViewDictionaryRun,
+           view_draw_callback_dictionary_run,
+           NULL,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Widget
-    if (!easy_flipper_set_widget(&app->widget, FlipLibraryViewAbout, "FlipLibrary v1.2\n-----\nDictionary, random facts, and\nmore.\n-----\nwww.github.com/jblanked", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget,
+           FlipLibraryViewAbout,
+           "FlipLibrary v1.2\n-----\nDictionary, random facts, and\nmore.\n-----\nwww.github.com/jblanked",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_widget(&app->widget_random_fact, FlipLibraryViewRandomFactWidget, "Error, try again.", callback_to_random_facts, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget_random_fact,
+           FlipLibraryViewRandomFactWidget,
+           "Error, try again.",
+           callback_to_random_facts,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_widget(&app->widget_dictionary, FlipLibraryViewDictionaryWidget, "Error, try again.", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget_dictionary,
+           FlipLibraryViewDictionaryWidget,
+           "Error, try again.",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
 
     // Text Input
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_ssid, FlipLibraryViewTextInputSSID, "Enter SSID", app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid, text_updated_ssid, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_password, FlipLibraryViewTextInputPassword, "Enter Password", app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password, text_updated_password, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_dictionary, FlipLibraryViewDictionaryTextInput, "Enter a word", app->uart_text_input_temp_buffer_dictionary, app->uart_text_input_buffer_size_dictionary, text_updated_dictionary, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_ssid,
+           FlipLibraryViewTextInputSSID,
+           "Enter SSID",
+           app->uart_text_input_temp_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           text_updated_ssid,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_password,
+           FlipLibraryViewTextInputPassword,
+           "Enter Password",
+           app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password,
+           text_updated_password,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_dictionary,
+           FlipLibraryViewDictionaryTextInput,
+           "Enter a word",
+           app->uart_text_input_temp_buffer_dictionary,
+           app->uart_text_input_buffer_size_dictionary,
+           text_updated_dictionary,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Variable Item List
-    if (!easy_flipper_set_variable_item_list(&app->variable_item_list_wifi, FlipLibraryViewSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_variable_item_list(
+           &app->variable_item_list_wifi,
+           FlipLibraryViewSettings,
+           settings_item_selected,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
-    app->variable_item_ssid = variable_item_list_add(app->variable_item_list_wifi, "SSID", 0, NULL, NULL);
-    app->variable_item_password = variable_item_list_add(app->variable_item_list_wifi, "Password", 0, NULL, NULL);
+    app->variable_item_ssid =
+        variable_item_list_add(app->variable_item_list_wifi, "SSID", 0, NULL, NULL);
+    app->variable_item_password =
+        variable_item_list_add(app->variable_item_list_wifi, "Password", 0, NULL, NULL);
     variable_item_set_current_value_text(app->variable_item_ssid, "");
     variable_item_set_current_value_text(app->variable_item_password, "");
 
     // Submenu
-    if (!easy_flipper_set_submenu(&app->submenu_main, FlipLibraryViewSubmenuMain, "FlipLibrary v1.2", callback_exit_app, &app->view_dispatcher))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_submenu(&app->submenu_random_facts, FlipLibraryViewRandomFacts, "Random Facts", callback_to_submenu, &app->view_dispatcher))
-    {
-        return NULL;
-    }
-
-    submenu_add_item(app->submenu_main, "Random Fact", FlipLibrarySubmenuIndexRandomFacts, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "Dictionary", FlipLibrarySubmenuIndexDictionary, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "About", FlipLibrarySubmenuIndexAbout, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "WiFi", FlipLibrarySubmenuIndexSettings, callback_submenu_choices, app);
+    if(!easy_flipper_set_submenu(
+           &app->submenu_main,
+           FlipLibraryViewSubmenuMain,
+           "FlipLibrary v1.2",
+           callback_exit_app,
+           &app->view_dispatcher)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_submenu(
+           &app->submenu_random_facts,
+           FlipLibraryViewRandomFacts,
+           "Random Facts",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
+        return NULL;
+    }
+
+    submenu_add_item(
+        app->submenu_main,
+        "Random Fact",
+        FlipLibrarySubmenuIndexRandomFacts,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_main,
+        "Dictionary",
+        FlipLibrarySubmenuIndexDictionary,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_main, "About", FlipLibrarySubmenuIndexAbout, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_main, "WiFi", FlipLibrarySubmenuIndexSettings, callback_submenu_choices, app);
     //
-    submenu_add_item(app->submenu_random_facts, "Cats", FlipLibrarySubmenuIndexRandomFactsCats, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_random_facts, "Dogs", FlipLibrarySubmenuIndexRandomFactsDogs, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_random_facts, "Quotes", FlipLibrarySubmenuIndexRandomFactsQuotes, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_random_facts, "Random", FlipLibrarySubmenuIndexRandomFactsAll, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_random_facts,
+        "Cats",
+        FlipLibrarySubmenuIndexRandomFactsCats,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_random_facts,
+        "Dogs",
+        FlipLibrarySubmenuIndexRandomFactsDogs,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_random_facts,
+        "Quotes",
+        FlipLibrarySubmenuIndexRandomFactsQuotes,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_random_facts,
+        "Random",
+        FlipLibrarySubmenuIndexRandomFactsAll,
+        callback_submenu_choices,
+        app);
 
     // load settings
-    if (load_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(load_settings(
+           app->uart_text_input_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           app->uart_text_input_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         // Update variable items
-        if (app->variable_item_ssid)
-            variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+        if(app->variable_item_ssid)
+            variable_item_set_current_value_text(
+                app->variable_item_ssid, app->uart_text_input_buffer_ssid);
         // dont show password
 
         // Copy items into their temp buffers with safety checks
-        if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
-        {
-            strncpy(app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid - 1);
-            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
+        if(app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid) {
+            strncpy(
+                app->uart_text_input_temp_buffer_ssid,
+                app->uart_text_input_buffer_ssid,
+                app->uart_text_input_buffer_size_ssid - 1);
+            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] =
+                '\0';
         }
-        if (app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password)
-        {
-            strncpy(app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password - 1);
-            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
+        if(app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password) {
+            strncpy(
+                app->uart_text_input_temp_buffer_password,
+                app->uart_text_input_buffer_password,
+                app->uart_text_input_buffer_size_password - 1);
+            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] =
+                '\0';
         }
     }
 
@@ -148,4 +252,4 @@ static FlipLibraryApp *flip_library_app_alloc()
     return app;
 }
 
-#endif // FLIP_LIBRARY_I_H
+#endif // FLIP_LIBRARY_I_H

+ 20 - 32
flip_library/flip_library_storage.h

@@ -6,22 +6,19 @@
 
 #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_library/settings.bin"
 
-static void save_settings(
-    const char *ssid,
-    const char *password)
-{
+static void save_settings(const char* ssid, const char* password) {
     // Create the directory for saving settings
     char directory_path[256];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_library");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_library");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -30,17 +27,15 @@ static void save_settings(
 
     // Save the ssid length and data
     size_t ssid_length = strlen(ssid) + 1; // Include null terminator
-    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to write SSID");
     }
 
     // Save the password length and data
     size_t password_length = strlen(password) + 1; // Include null terminator
-    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, password, password_length) != password_length)
-    {
+    if(storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to write password");
     }
 
@@ -49,17 +44,11 @@ static void save_settings(
     furi_record_close(RECORD_STORAGE);
 }
 
-static bool load_settings(
-    char *ssid,
-    size_t ssid_size,
-    char *password,
-    size_t password_size)
-{
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
+static bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
 
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -68,9 +57,8 @@ static bool load_settings(
 
     // Load the ssid
     size_t ssid_length;
-    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
-        storage_file_read(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       ssid_length > ssid_size || storage_file_read(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to read SSID");
         storage_file_close(file);
         storage_file_free(file);
@@ -81,9 +69,9 @@ static bool load_settings(
 
     // Load the password
     size_t password_length;
-    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
-        storage_file_read(file, password, password_length) != password_length)
-    {
+    if(storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_length > password_size ||
+       storage_file_read(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to read password");
         storage_file_close(file);
         storage_file_free(file);
@@ -99,4 +87,4 @@ static bool load_settings(
     return true;
 }
 
-#endif // FLIP_LIBRARY_STORAGE_H
+#endif // FLIP_LIBRARY_STORAGE_H

Разница между файлами не показана из-за своего большого размера
+ 190 - 302
flip_library/flipper_http.h


+ 523 - 604
flip_library/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
+            }
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -538,313 +493,277 @@ extern "C"
 #include <furi.h>
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_library/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

+ 8 - 11
flip_social/app.c

@@ -1,7 +1,7 @@
 // app.c
-#include <jsmn.h>                // Include cJSON
-#include <uart_text_input.h>     // Include the text input widget
-#include <flip_social_e.h>       // Include the FlipSocialApp structure
+#include <jsmn.h> // Include cJSON
+#include <uart_text_input.h> // Include the text input widget
+#include <flip_social_e.h> // Include the FlipSocialApp structure
 #include <flip_social_storage.h> // Include the storage functions
 #include "flip_social_draw.h"
 #include "flip_social_feed.h"
@@ -9,8 +9,8 @@
 #include "flip_social_friends.h"
 #include "flip_social_messages.h"
 #include <flip_social_callback.h> // Include the callback functions
-#include <flip_social_i.h>        // Include the initialization functions
-#include <flip_social_free.h>     // Include the cleanup functions
+#include <flip_social_i.h> // Include the initialization functions
+#include <flip_social_free.h> // Include the cleanup functions
 
 /**
  * @brief Entry point for the Hello World application.
@@ -18,20 +18,17 @@
  * @param p Input parameter - unused
  * @return 0 to indicate success, -1 on failure
  */
-int32_t main_flip_social(void *p)
-{
+int32_t main_flip_social(void* p) {
     UNUSED(p);
 
     // Initialize the Hello World application
     app_instance = flip_social_app_alloc();
-    if (!app_instance)
-    {
+    if(!app_instance) {
         // Allocation failed
         return -1; // Indicate failure
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 142 - 200
flip_social/easy_flipper.h

@@ -29,11 +29,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -47,16 +45,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -75,39 +70,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -121,22 +109,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -153,29 +137,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -192,24 +171,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -226,29 +201,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -267,33 +237,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -306,38 +273,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -352,40 +319,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -409,63 +377,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -489,48 +446,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -546,24 +495,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -576,16 +521,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -593,4 +535,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

Разница между файлами не показана из-за своего большого размера
+ 336 - 241
flip_social/flip_social_callback.h


Разница между файлами не показана из-за своего большого размера
+ 308 - 298
flip_social/flip_social_draw.h


+ 214 - 185
flip_social/flip_social_e.h

@@ -10,36 +10,36 @@
 #define TAG "FlipSocial"
 
 #define MAX_PRE_SAVED_MESSAGES 25 // Maximum number of pre-saved messages
-#define MAX_MESSAGE_LENGTH 100    // Maximum length of a message in the feed
-#define MAX_EXPLORE_USERS 50      // Maximum number of users to explore
-#define MAX_USER_LENGTH 32        // Maximum length of a username
-#define MAX_FRIENDS 50            // Maximum number of friends
-#define MAX_TOKENS 450            // Adjust based on expected JSON tokens
-#define MAX_FEED_ITEMS 41         // Maximum number of feed items
-#define MAX_LINE_LENGTH 30
-#define MAX_MESSAGE_USERS 20 // Maximum number of users to display in the submenu
-#define MAX_MESSAGES 20      // Maximum number of meesages between each user
+#define MAX_MESSAGE_LENGTH     100 // Maximum length of a message in the feed
+#define MAX_EXPLORE_USERS      50 // Maximum number of users to explore
+#define MAX_USER_LENGTH        32 // Maximum length of a username
+#define MAX_FRIENDS            50 // Maximum number of friends
+#define MAX_TOKENS             450 // Adjust based on expected JSON tokens
+#define MAX_FEED_ITEMS         41 // Maximum number of feed items
+#define MAX_LINE_LENGTH        30
+#define MAX_MESSAGE_USERS      20 // Maximum number of users to display in the submenu
+#define MAX_MESSAGES           20 // Maximum number of meesages between each user
 
 // Define the submenu items for our Hello World application
-typedef enum
-{
-    FlipSocialSubmenuLoggedOutIndexLogin,        // click to go to the login screen
-    FlipSocialSubmenuLoggedOutIndexRegister,     // click to go to the register screen
-    FlipSocialSubmenuLoggedOutIndexAbout,        // click to go to the about screen
+typedef enum {
+    FlipSocialSubmenuLoggedOutIndexLogin, // click to go to the login screen
+    FlipSocialSubmenuLoggedOutIndexRegister, // click to go to the register screen
+    FlipSocialSubmenuLoggedOutIndexAbout, // click to go to the about screen
     FlipSocialSubmenuLoggedOutIndexWifiSettings, // click to go to the wifi settings screen
     //
-    FlipSocialSubmenuLoggedInIndexProfile,  // click to go to the profile screen
-    FlipSocialSubmenuExploreIndex,          // click to go to the explore
-    FlipSocialSubmenuLoggedInIndexFeed,     // click to go to the feed screen
+    FlipSocialSubmenuLoggedInIndexProfile, // click to go to the profile screen
+    FlipSocialSubmenuExploreIndex, // click to go to the explore
+    FlipSocialSubmenuLoggedInIndexFeed, // click to go to the feed screen
     FlipSocialSubmenuLoggedInIndexMessages, // click to go to the messages screen
-    FlipSocialSubmenuLoggedInIndexCompose,  // click to go to the compose screen
+    FlipSocialSubmenuLoggedInIndexCompose, // click to go to the compose screen
     FlipSocialSubmenuLoggedInIndexSettings, // click to go to the settings screen
     FlipSocialSubmenuLoggedInSignOutButton, // click to sign out
     //
     FlipSocialSubmenuLoggedInIndexMessagesNewMessage, // click to add a new message
     //
-    FlipSocialSubmenuComposeIndexAddPreSave,       // click to add a pre-saved message
-    FlipSocialSubemnuComposeIndexStartIndex = 100, // starting index for the first pre saved message
+    FlipSocialSubmenuComposeIndexAddPreSave, // click to add a pre-saved message
+    FlipSocialSubemnuComposeIndexStartIndex =
+        100, // starting index for the first pre saved message
     //
     FlipSocialSubmenuExploreIndexStartIndex = 150, // starting index for the users to explore
     //
@@ -47,11 +47,11 @@ typedef enum
     //
     FlipSocialSubmenuLoggedInIndexMessagesUsersStart = 250, // starting index for the messages
     //
-    FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart = 300, // click to select a user to message
+    FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart =
+        300, // click to select a user to message
 } FlipSocialSubmenuIndex;
 
-typedef enum
-{
+typedef enum {
     ActionNone,
     ActionBack,
     ActionNext,
@@ -62,16 +62,14 @@ typedef enum
 static Action action = ActionNone;
 
 // Define the ScriptPlaylist structure
-typedef struct
-{
-    char *messages[MAX_PRE_SAVED_MESSAGES];
+typedef struct {
+    char* messages[MAX_PRE_SAVED_MESSAGES];
     size_t count;
 } PreSavedPlaylist;
 
-typedef struct
-{
-    char *usernames[MAX_FEED_ITEMS];
-    char *messages[MAX_FEED_ITEMS];
+typedef struct {
+    char* usernames[MAX_FEED_ITEMS];
+    char* messages[MAX_FEED_ITEMS];
     bool is_flipped[MAX_FEED_ITEMS];
     int ids[MAX_FEED_ITEMS];
     int flips[MAX_FEED_ITEMS];
@@ -79,232 +77,263 @@ typedef struct
     size_t index;
 } FlipSocialFeed;
 
-typedef struct
-{
-    char *usernames[MAX_EXPLORE_USERS];
+typedef struct {
+    char* usernames[MAX_EXPLORE_USERS];
     int count;
     int index;
 } FlipSocialModel;
 
-typedef struct
-{
-    char *usernames[MAX_MESSAGE_USERS];
+typedef struct {
+    char* usernames[MAX_MESSAGE_USERS];
     int count;
     int index;
 } FlipSocialModel2;
 
-typedef struct
-{
-    char *usernames[MAX_MESSAGES];
-    char *messages[MAX_MESSAGES];
+typedef struct {
+    char* usernames[MAX_MESSAGES];
+    char* messages[MAX_MESSAGES];
     int count;
     int index;
 } FlipSocialMessage;
 
 // Define views for our Hello World application
-typedef enum
-{
-    FlipSocialViewLoggedOutSubmenu,      // The menu if the user is not logged in
-    FlipSocialViewLoggedOutLogin,        // The login screen
-    FlipSocialViewLoggedOutRegister,     // The register screen
-    FlipSocialViewLoggedOutAbout,        // The about screen
+typedef enum {
+    FlipSocialViewLoggedOutSubmenu, // The menu if the user is not logged in
+    FlipSocialViewLoggedOutLogin, // The login screen
+    FlipSocialViewLoggedOutRegister, // The register screen
+    FlipSocialViewLoggedOutAbout, // The about screen
     FlipSocialViewLoggedOutWifiSettings, // The wifi settings screen
     //
-    FlipSocialViewLoggedOutLoginUsernameInput,        // Text input screen for username input on login screen
-    FlipSocialViewLoggedOutLoginPasswordInput,        // Text input screen for password input on login screen
-    FlipSocialViewLoggedOutRegisterUsernameInput,     // Text input screen for username input on register screen
-    FlipSocialViewLoggedOutRegisterPasswordInput,     // Text input screen for password input on register screen
-    FlipSocialViewLoggedOutRegisterPassword2Input,    // Text input screen for password 2 input on register screen
-    FlipSocialViewLoggedOutWifiSettingsSSIDInput,     // Text input screen for SSID input on wifi screen
+    FlipSocialViewLoggedOutLoginUsernameInput, // Text input screen for username input on login screen
+    FlipSocialViewLoggedOutLoginPasswordInput, // Text input screen for password input on login screen
+    FlipSocialViewLoggedOutRegisterUsernameInput, // Text input screen for username input on register screen
+    FlipSocialViewLoggedOutRegisterPasswordInput, // Text input screen for password input on register screen
+    FlipSocialViewLoggedOutRegisterPassword2Input, // Text input screen for password 2 input on register screen
+    FlipSocialViewLoggedOutWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
     FlipSocialViewLoggedOutWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
-    FlipSocialViewLoggedOutProcessLogin,              // The screen displayed after clicking login
-    FlipSocialViewLoggedOutProcessRegister,           // The screen displayed after clicking register
+    FlipSocialViewLoggedOutProcessLogin, // The screen displayed after clicking login
+    FlipSocialViewLoggedOutProcessRegister, // The screen displayed after clicking register
     //
-    FlipSocialViewLoggedInSubmenu,  // The menu if the user is logged in
-    FlipSocialViewLoggedInProfile,  // The profile screen
-    FlipSocialViewLoggedInFeed,     // The feed screen
-    FlipSocialViewLoggedInCompose,  // The compose screen
+    FlipSocialViewLoggedInSubmenu, // The menu if the user is logged in
+    FlipSocialViewLoggedInProfile, // The profile screen
+    FlipSocialViewLoggedInFeed, // The feed screen
+    FlipSocialViewLoggedInCompose, // The compose screen
     FlipSocialViewLoggedInSettings, // The settings screen
     //
-    FlipSocialViewLoggedInChangePasswordInput,    // Text input screen for password input on change password screen
+    FlipSocialViewLoggedInChangePasswordInput, // Text input screen for password input on change password screen
     FlipSocialViewLoggedInComposeAddPreSaveInput, // Text input screen for add text input on compose screen
     //
-    FlipSocialViewLoggedInMessagesNewMessageInput,            // Text input screen for new message input on messages screen
+    FlipSocialViewLoggedInMessagesNewMessageInput, // Text input screen for new message input on messages screen
     FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput, // Text input screen for new message input on messages screen
-    FlipSocialViewLoggedInMessagesUserChoices,                // the view after clicking [New Message] - select a user to message, then direct to input view
+    FlipSocialViewLoggedInMessagesUserChoices, // the view after clicking [New Message] - select a user to message, then direct to input view
     //
-    FlipSocialViewLoggedInSettingsAbout,             // The about screen
-    FlipSocialViewLoggedInSettingsWifi,              // The wifi settings screen
-    FlipSocialViewLoggedInWifiSettingsSSIDInput,     // Text input screen for SSID input on wifi screen
+    FlipSocialViewLoggedInSettingsAbout, // The about screen
+    FlipSocialViewLoggedInSettingsWifi, // The wifi settings screen
+    FlipSocialViewLoggedInWifiSettingsSSIDInput, // Text input screen for SSID input on wifi screen
     FlipSocialViewLoggedInWifiSettingsPasswordInput, // Text input screen for Password input on wifi screen
-    FlipSocialViewLoggedInProcessCompose,            // The dialog view to delete or send the clicked pre-saved text
+    FlipSocialViewLoggedInProcessCompose, // The dialog view to delete or send the clicked pre-saved text
     //
     FlipSocialViewLoggedInSignOut, // The view after clicking the sign out button
     //
-    FlipSocialViewLoggedInExploreSubmenu,  // The view after clicking the explore button
+    FlipSocialViewLoggedInExploreSubmenu, // The view after clicking the explore button
     FlipSocialViewLoggedInExploreProccess, // The view after clicking on a user in the explore screen
-    FlipSocialViewLoggedInFriendsSubmenu,  // The view after clicking the friends button on the profile screen
-    FlipSocialViewLoggedInFriendsProcess,  // The view after clicking on a friend in the friends screen
+    FlipSocialViewLoggedInFriendsSubmenu, // The view after clicking the friends button on the profile screen
+    FlipSocialViewLoggedInFriendsProcess, // The view after clicking on a friend in the friends screen
     FlipSocialViewLoggedInMessagesSubmenu, // The view after clicking the messages button on the profile screen
     FlipSocialViewLoggedInMessagesProcess, // The view after clicking on a user in the messages screen
 } FlipSocialView;
 
 // Define the application structure
-typedef struct
-{
-    ViewDispatcher *view_dispatcher;        // Switches between our views
-    Submenu *submenu_logged_out;            // The application submenu (logged out)
-    Submenu *submenu_logged_in;             // The application submenu (logged in)
-    Submenu *submenu_compose;               // The application submenu (compose)
-    Submenu *submenu_explore;               // The application submenu (explore)
-    Submenu *submenu_friends;               // The application submenu (friends)
-    Submenu *submenu_messages;              // The application submenu (messages)
-    Submenu *submenu_messages_user_choices; // The application submenu (messages user choices)
-    Widget *widget_logged_out_about;        // The about screen (logged out)
-    Widget *widget_logged_in_about;         // The about screen (logged in)
-
-    View *view_process_login;    // The screen displayed after clicking login
-    View *view_process_register; // The screen displayed after clicking register
-    View *view_process_feed;     // Dialog for the feed screen
-    View *view_process_compose;  // Dialog for the compose screen (delete or send)
-    View *view_process_explore;  // Dialog for the explore screen (view user profile - add or delete friend)
-    View *view_process_friends;  // Dialog for the friends screen (view user profile - add or delete friend)
-    View *view_process_messages; // Dialog for the messages screen (next, previous, send message)
-
-    VariableItemList *variable_item_list_logged_out_wifi_settings; // The wifi settings menu
-    VariableItemList *variable_item_list_logged_out_login;         // The login menu
-    VariableItemList *variable_item_list_logged_out_register;      // The register menu
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    Submenu* submenu_logged_out; // The application submenu (logged out)
+    Submenu* submenu_logged_in; // The application submenu (logged in)
+    Submenu* submenu_compose; // The application submenu (compose)
+    Submenu* submenu_explore; // The application submenu (explore)
+    Submenu* submenu_friends; // The application submenu (friends)
+    Submenu* submenu_messages; // The application submenu (messages)
+    Submenu* submenu_messages_user_choices; // The application submenu (messages user choices)
+    Widget* widget_logged_out_about; // The about screen (logged out)
+    Widget* widget_logged_in_about; // The about screen (logged in)
+
+    View* view_process_login; // The screen displayed after clicking login
+    View* view_process_register; // The screen displayed after clicking register
+    View* view_process_feed; // Dialog for the feed screen
+    View* view_process_compose; // Dialog for the compose screen (delete or send)
+    View* view_process_explore; // Dialog for the explore screen (view user profile - add or delete friend)
+    View* view_process_friends; // Dialog for the friends screen (view user profile - add or delete friend)
+    View* view_process_messages; // Dialog for the messages screen (next, previous, send message)
+
+    VariableItemList* variable_item_list_logged_out_wifi_settings; // The wifi settings menu
+    VariableItemList* variable_item_list_logged_out_login; // The login menu
+    VariableItemList* variable_item_list_logged_out_register; // The register menu
     //
-    VariableItemList *variable_item_list_logged_in_profile;       // The profile menu
-    VariableItemList *variable_item_list_logged_in_settings;      // The settings menu
-    VariableItemList *variable_item_list_logged_in_settings_wifi; // The wifi settings menu
-
-    UART_TextInput *text_input_logged_out_wifi_settings_ssid;     // Text input for ssid input on wifi settings screen
-    UART_TextInput *text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
-    UART_TextInput *text_input_logged_out_login_username;         // Text input for username input on login screen
-    UART_TextInput *text_input_logged_out_login_password;         // Text input for password input on login screen
-    UART_TextInput *text_input_logged_out_register_username;      // Text input for username input on register screen
-    UART_TextInput *text_input_logged_out_register_password;      // Text input for password input on register screen
-    UART_TextInput *text_input_logged_out_register_password_2;    // Text input for password 2 input on register screen
+    VariableItemList* variable_item_list_logged_in_profile; // The profile menu
+    VariableItemList* variable_item_list_logged_in_settings; // The settings menu
+    VariableItemList* variable_item_list_logged_in_settings_wifi; // The wifi settings menu
+
+    UART_TextInput*
+        text_input_logged_out_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
+    UART_TextInput*
+        text_input_logged_out_wifi_settings_password; // Text input for password input on wifi settings screen
+    UART_TextInput*
+        text_input_logged_out_login_username; // Text input for username input on login screen
+    UART_TextInput*
+        text_input_logged_out_login_password; // Text input for password input on login screen
+    UART_TextInput*
+        text_input_logged_out_register_username; // Text input for username input on register screen
+    UART_TextInput*
+        text_input_logged_out_register_password; // Text input for password input on register screen
+    UART_TextInput*
+        text_input_logged_out_register_password_2; // Text input for password 2 input on register screen
     //
-    UART_TextInput *text_input_logged_in_change_password;        // Text input for password input on change password screen
-    UART_TextInput *text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
-    UART_TextInput *text_input_logged_in_wifi_settings_ssid;     // Text input for ssid input on wifi settings screen
-    UART_TextInput *text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
+    UART_TextInput*
+        text_input_logged_in_change_password; // Text input for password input on change password screen
+    UART_TextInput*
+        text_input_logged_in_compose_pre_save_input; // Text input for pre save input on compose screen
+    UART_TextInput*
+        text_input_logged_in_wifi_settings_ssid; // Text input for ssid input on wifi settings screen
+    UART_TextInput*
+        text_input_logged_in_wifi_settings_password; // Text input for password input on wifi settings screen
     //
-    UART_TextInput *text_input_logged_in_messages_new_message;              // Text input for new message input on messages screen
-    UART_TextInput *text_input_logged_in_messages_new_message_user_choices; //
-
-    VariableItem *variable_item_logged_out_wifi_settings_ssid;     // Reference to the ssid configuration item
-    VariableItem *variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
-    VariableItem *variable_item_logged_out_login_username;         // Reference to the username configuration item
-    VariableItem *variable_item_logged_out_login_password;         // Reference to the password configuration item
-    VariableItem *variable_item_logged_out_login_button;           // Reference to the login button configuration item
-    VariableItem *variable_item_logged_out_register_username;      // Reference to the username configuration item
-    VariableItem *variable_item_logged_out_register_password;      // Reference to the password configuration item
-    VariableItem *variable_item_logged_out_register_password_2;    // Reference to the password 2 configuration item
-    VariableItem *variable_item_logged_out_register_button;        // Reference to the register button configuration item
+    UART_TextInput*
+        text_input_logged_in_messages_new_message; // Text input for new message input on messages screen
+    UART_TextInput* text_input_logged_in_messages_new_message_user_choices; //
+
+    VariableItem*
+        variable_item_logged_out_wifi_settings_ssid; // Reference to the ssid configuration item
+    VariableItem*
+        variable_item_logged_out_wifi_settings_password; // Reference to the password configuration item
+    VariableItem*
+        variable_item_logged_out_login_username; // Reference to the username configuration item
+    VariableItem*
+        variable_item_logged_out_login_password; // Reference to the password configuration item
+    VariableItem*
+        variable_item_logged_out_login_button; // Reference to the login button configuration item
+    VariableItem*
+        variable_item_logged_out_register_username; // Reference to the username configuration item
+    VariableItem*
+        variable_item_logged_out_register_password; // Reference to the password configuration item
+    VariableItem*
+        variable_item_logged_out_register_password_2; // Reference to the password 2 configuration item
+    VariableItem*
+        variable_item_logged_out_register_button; // Reference to the register button configuration item
     //
-    VariableItem *variable_item_logged_in_profile_username;        // Reference to the username configuration item
-    VariableItem *variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
-    VariableItem *variable_item_logged_in_settings_about;          // Reference to the about configuration item
-    VariableItem *variable_item_logged_in_settings_wifi;           // Reference to the wifi settings configuration item
-    VariableItem *variable_item_logged_in_wifi_settings_ssid;      // Reference to the ssid configuration item
-    VariableItem *variable_item_logged_in_wifi_settings_password;  // Reference to the password configuration item
+    VariableItem*
+        variable_item_logged_in_profile_username; // Reference to the username configuration item
+    VariableItem*
+        variable_item_logged_in_profile_change_password; // Reference to the change password configuration item
+    VariableItem*
+        variable_item_logged_in_settings_about; // Reference to the about configuration item
+    VariableItem*
+        variable_item_logged_in_settings_wifi; // Reference to the wifi settings configuration item
+    VariableItem*
+        variable_item_logged_in_wifi_settings_ssid; // Reference to the ssid configuration item
+    VariableItem*
+        variable_item_logged_in_wifi_settings_password; // Reference to the password configuration item
     //
-    VariableItem *variable_item_logged_in_profile_friends; // Reference to the friends configuration item
+    VariableItem*
+        variable_item_logged_in_profile_friends; // Reference to the friends configuration item
     //
-    FuriPubSub *input_event_queue;
-    FuriPubSubSubscription *input_event;
+    FuriPubSub* input_event_queue;
+    FuriPubSubSubscription* input_event;
 
     PreSavedPlaylist pre_saved_messages; // Pre-saved messages for the feed screen
 
-    char *is_logged_in;         // Store the login status
+    char* is_logged_in; // Store the login status
     uint32_t is_logged_in_size; // Size of the login status buffer
 
-    char *login_username_logged_in;                     // Store the entered login username
-    char *login_username_logged_in_temp_buffer;         // Temporary buffer for login username text input
-    uint32_t login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
+    char* login_username_logged_in; // Store the entered login username
+    char* login_username_logged_in_temp_buffer; // Temporary buffer for login username text input
+    uint32_t
+        login_username_logged_in_temp_buffer_size; // Size of the login username temporary buffer
 
-    char *wifi_ssid_logged_out;                     // Store the entered wifi ssid
-    char *wifi_ssid_logged_out_temp_buffer;         // Temporary buffer for wifi ssid text input
+    char* wifi_ssid_logged_out; // Store the entered wifi ssid
+    char* wifi_ssid_logged_out_temp_buffer; // Temporary buffer for wifi ssid text input
     uint32_t wifi_ssid_logged_out_temp_buffer_size; // Size of the wifi ssid temporary buffer
 
-    char *wifi_password_logged_out;                     // Store the entered wifi password
-    char *wifi_password_logged_out_temp_buffer;         // Temporary buffer for wifi_password text input
+    char* wifi_password_logged_out; // Store the entered wifi password
+    char* wifi_password_logged_out_temp_buffer; // Temporary buffer for wifi_password text input
     uint32_t wifi_password_logged_out_temp_buffer_size; // Size of the wifi_password temporary buffer
 
-    char *login_username_logged_out;                     // Store the entered login username
-    char *login_username_logged_out_temp_buffer;         // Temporary buffer for login username text input
-    uint32_t login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
+    char* login_username_logged_out; // Store the entered login username
+    char* login_username_logged_out_temp_buffer; // Temporary buffer for login username text input
+    uint32_t
+        login_username_logged_out_temp_buffer_size; // Size of the login username temporary buffer
 
-    char *login_password_logged_out;                     // Store the entered login password
-    char *login_password_logged_out_temp_buffer;         // Temporary buffer for login password text input
-    uint32_t login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
+    char* login_password_logged_out; // Store the entered login password
+    char* login_password_logged_out_temp_buffer; // Temporary buffer for login password text input
+    uint32_t
+        login_password_logged_out_temp_buffer_size; // Size of the login password temporary buffer
 
-    char *register_username_logged_out;                     // Store the entered register username
-    char *register_username_logged_out_temp_buffer;         // Temporary buffer for register username text input
-    uint32_t register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
+    char* register_username_logged_out; // Store the entered register username
+    char* register_username_logged_out_temp_buffer; // Temporary buffer for register username text input
+    uint32_t
+        register_username_logged_out_temp_buffer_size; // Size of the register username temporary buffer
 
-    char *register_password_logged_out;                     // Store the entered register password
-    char *register_password_logged_out_temp_buffer;         // Temporary buffer for register password text input
-    uint32_t register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
+    char* register_password_logged_out; // Store the entered register password
+    char* register_password_logged_out_temp_buffer; // Temporary buffer for register password text input
+    uint32_t
+        register_password_logged_out_temp_buffer_size; // Size of the register password temporary buffer
 
-    char *register_password_2_logged_out;                     // Store the entered register password 2
-    char *register_password_2_logged_out_temp_buffer;         // Temporary buffer for register password 2 text input
-    uint32_t register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
+    char* register_password_2_logged_out; // Store the entered register password 2
+    char* register_password_2_logged_out_temp_buffer; // Temporary buffer for register password 2 text input
+    uint32_t
+        register_password_2_logged_out_temp_buffer_size; // Size of the register password 2 temporary buffer
 
     //
-    char *change_password_logged_in;                     // Store the entered change password
-    char *change_password_logged_in_temp_buffer;         // Temporary buffer for change password text input
-    uint32_t change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
+    char* change_password_logged_in; // Store the entered change password
+    char* change_password_logged_in_temp_buffer; // Temporary buffer for change password text input
+    uint32_t
+        change_password_logged_in_temp_buffer_size; // Size of the change password temporary buffer
 
-    char *compose_pre_save_logged_in;                     // Store the entered add text
-    char *compose_pre_save_logged_in_temp_buffer;         // Temporary buffer for add text text input
+    char* compose_pre_save_logged_in; // Store the entered add text
+    char* compose_pre_save_logged_in_temp_buffer; // Temporary buffer for add text text input
     uint32_t compose_pre_save_logged_in_temp_buffer_size; // Size of the add text temporary buffer
 
-    char *wifi_ssid_logged_in;                     // Store the entered wifi ssid
-    char *wifi_ssid_logged_in_temp_buffer;         // Temporary buffer for wifi ssid text input
+    char* wifi_ssid_logged_in; // Store the entered wifi ssid
+    char* wifi_ssid_logged_in_temp_buffer; // Temporary buffer for wifi ssid text input
     uint32_t wifi_ssid_logged_in_temp_buffer_size; // Size of the wifi ssid temporary buffer
 
-    char *wifi_password_logged_in;                     // Store the entered wifi password
-    char *wifi_password_logged_in_temp_buffer;         // Temporary buffer for wifi_password text input
+    char* wifi_password_logged_in; // Store the entered wifi password
+    char* wifi_password_logged_in_temp_buffer; // Temporary buffer for wifi_password text input
     uint32_t wifi_password_logged_in_temp_buffer_size; // Size of the wifi_password temporary buffer
 
     //
-    char *messages_new_message_logged_in;                     // Store the entered new message
-    char *messages_new_message_logged_in_temp_buffer;         // Temporary buffer for new message text input
-    uint32_t messages_new_message_logged_in_temp_buffer_size; // Size of the new message temporary buffer
-
-    char *message_user_choice_logged_in;                     // Store the entered message to send to the selected user
-    char *message_user_choice_logged_in_temp_buffer;         // Temporary buffer for message to send to the selected user
-    uint32_t message_user_choice_logged_in_temp_buffer_size; // Size of the message to send to the selected user temporary buffer
+    char* messages_new_message_logged_in; // Store the entered new message
+    char* messages_new_message_logged_in_temp_buffer; // Temporary buffer for new message text input
+    uint32_t
+        messages_new_message_logged_in_temp_buffer_size; // Size of the new message temporary buffer
+
+    char* message_user_choice_logged_in; // Store the entered message to send to the selected user
+    char* message_user_choice_logged_in_temp_buffer; // Temporary buffer for message to send to the selected user
+    uint32_t
+        message_user_choice_logged_in_temp_buffer_size; // Size of the message to send to the selected user temporary buffer
 } FlipSocialApp;
 
-static FlipSocialFeed *flip_social_feed = NULL;            // Store the feed
-static FlipSocialModel *flip_social_friends = NULL;        // Store the friends
-static FlipSocialModel2 *flip_social_message_users = NULL; // Store the users that have sent messages to the logged in user
-static FlipSocialModel *flip_social_explore = NULL;        // Store the users to explore
-static FlipSocialMessage *flip_social_messages = NULL;     // Store the messages between the logged in user and the selected user
+static FlipSocialFeed* flip_social_feed = NULL; // Store the feed
+static FlipSocialModel* flip_social_friends = NULL; // Store the friends
+static FlipSocialModel2* flip_social_message_users =
+    NULL; // Store the users that have sent messages to the logged in user
+static FlipSocialModel* flip_social_explore = NULL; // Store the users to explore
+static FlipSocialMessage* flip_social_messages =
+    NULL; // Store the messages between the logged in user and the selected user
 
 // include strndup (otherwise NULL pointer dereference)
-char *strndup(const char *s, size_t n)
-{
-    char *result;
+char* strndup(const char* s, size_t n) {
+    char* result;
     size_t len = strlen(s);
 
-    if (n < len)
-        len = n;
+    if(n < len) len = n;
 
-    result = (char *)malloc(len + 1);
-    if (!result)
-        return NULL;
+    result = (char*)malloc(len + 1);
+    if(!result) return NULL;
 
     result[len] = '\0';
-    return (char *)memcpy(result, s, len);
+    return (char*)memcpy(result, s, len);
 }
 
-static FlipSocialApp *app_instance = NULL;
-static void flip_social_logged_in_compose_pre_save_updated(void *context);
-static void flip_social_callback_submenu_choices(void *context, uint32_t index);
-#endif
+static FlipSocialApp* app_instance = NULL;
+static void flip_social_logged_in_compose_pre_save_updated(void* context);
+static void flip_social_callback_submenu_choices(void* context, uint32_t index);
+#endif

+ 50 - 59
flip_social/flip_social_explore.h

@@ -1,22 +1,17 @@
 #ifndef FLIP_SOCIAL_EXPLORE_H
 #define FLIP_SOCIAL_EXPLORE_H
 
-static FlipSocialModel *flip_social_explore_alloc()
-{
+static FlipSocialModel* flip_social_explore_alloc() {
     // Allocate memory for each username only if not already allocated
-    FlipSocialModel *explore = malloc(sizeof(FlipSocialModel));
-    if (explore == NULL)
-    {
+    FlipSocialModel* explore = malloc(sizeof(FlipSocialModel));
+    if(explore == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for explore model.");
         return NULL;
     }
-    for (size_t i = 0; i < MAX_EXPLORE_USERS; i++)
-    {
-        if (explore->usernames[i] == NULL)
-        {
+    for(size_t i = 0; i < MAX_EXPLORE_USERS; i++) {
+        if(explore->usernames[i] == NULL) {
             explore->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (explore->usernames[i] == NULL)
-            {
+            if(explore->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return NULL; // Return false on memory allocation failure
             }
@@ -25,27 +20,23 @@ static FlipSocialModel *flip_social_explore_alloc()
     return explore;
 }
 
-static void flip_social_free_explore()
-{
-    if (!flip_social_explore)
-    {
+static void flip_social_free_explore() {
+    if(!flip_social_explore) {
         FURI_LOG_E(TAG, "Explore model is NULL");
         return;
     }
-    for (int i = 0; i < flip_social_explore->count; i++)
-    {
+    for(int i = 0; i < flip_social_explore->count; i++) {
         free(flip_social_explore->usernames[i]);
     }
 }
 
 // for now we're just listing the current users
 // as the feed is upgraded, then we can port more to the explore view
-static bool flip_social_get_explore()
-{
+static bool flip_social_get_explore() {
     // will return true unless the devboard is not connected
-    bool success = flipper_http_get_request_with_headers("https://www.flipsocial.net/api/user/users/", jsmn("Content-Type", "application/json"));
-    if (!success)
-    {
+    bool success = flipper_http_get_request_with_headers(
+        "https://www.flipsocial.net/api/user/users/", jsmn("Content-Type", "application/json"));
+    if(!success) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for explore");
         return false;
     }
@@ -53,26 +44,22 @@ static bool flip_social_get_explore()
     return true;
 }
 
-static bool flip_social_parse_json_explore()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_explore() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each username only if not already allocated
     flip_social_explore = flip_social_explore_alloc();
-    if (flip_social_explore == NULL)
-    {
+    if(flip_social_explore == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for explore usernames.");
         return false;
     }
 
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -80,54 +67,58 @@ static bool flip_social_parse_json_explore()
     flip_social_explore->count = 0;
 
     // Extract the users array from the JSON
-    char *json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
-    if (json_users == NULL)
-    {
+    char* json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
+    if(json_users == NULL) {
         FURI_LOG_E(TAG, "Failed to parse users array.");
         return false;
     }
 
     // Manual tokenization for comma-separated values
-    char *start = json_users + 1; // Skip the opening bracket
-    char *end;
-    while ((end = strchr(start, ',')) != NULL && flip_social_explore->count < MAX_EXPLORE_USERS)
-    {
+    char* start = json_users + 1; // Skip the opening bracket
+    char* end;
+    while((end = strchr(start, ',')) != NULL && flip_social_explore->count < MAX_EXPLORE_USERS) {
         *end = '\0'; // Null-terminate the current token
 
         // Remove quotes
-        if (*start == '"')
-            start++;
-        if (*(end - 1) == '"')
-            *(end - 1) = '\0';
+        if(*start == '"') start++;
+        if(*(end - 1) == '"') *(end - 1) = '\0';
 
         // Copy username to pre-allocated memory
-        strncpy(flip_social_explore->usernames[flip_social_explore->count], start, MAX_USER_LENGTH - 1);
-        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+        strncpy(
+            flip_social_explore->usernames[flip_social_explore->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_explore->count++;
         start = end + 1;
     }
 
     // Handle the last token
-    if (*start != '\0' && flip_social_explore->count < MAX_EXPLORE_USERS)
-    {
-        if (*start == '"')
-            start++;
-        if (*(start + strlen(start) - 1) == ']')
-            *(start + strlen(start) - 1) = '\0';
-        if (*(start + strlen(start) - 1) == '"')
-            *(start + strlen(start) - 1) = '\0';
-
-        strncpy(flip_social_explore->usernames[flip_social_explore->count], start, MAX_USER_LENGTH - 1);
-        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+    if(*start != '\0' && flip_social_explore->count < MAX_EXPLORE_USERS) {
+        if(*start == '"') start++;
+        if(*(start + strlen(start) - 1) == ']') *(start + strlen(start) - 1) = '\0';
+        if(*(start + strlen(start) - 1) == '"') *(start + strlen(start) - 1) = '\0';
+
+        strncpy(
+            flip_social_explore->usernames[flip_social_explore->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_explore->count++;
     }
 
     // Add submenu items for the users
     submenu_reset(app_instance->submenu_explore);
     submenu_set_header(app_instance->submenu_explore, "Explore");
-    for (int i = 0; i < flip_social_explore->count; i++)
-    {
-        submenu_add_item(app_instance->submenu_explore, flip_social_explore->usernames[i], FlipSocialSubmenuExploreIndexStartIndex + i, flip_social_callback_submenu_choices, app_instance);
+    for(int i = 0; i < flip_social_explore->count; i++) {
+        submenu_add_item(
+            app_instance->submenu_explore,
+            flip_social_explore->usernames[i],
+            FlipSocialSubmenuExploreIndexStartIndex + i,
+            flip_social_callback_submenu_choices,
+            app_instance);
     }
 
     // Free the json_users
@@ -138,4 +129,4 @@ static bool flip_social_parse_json_explore()
     return true;
 }
 
-#endif // FLIP_SOCIAL_EXPLORE_H
+#endif // FLIP_SOCIAL_EXPLORE_H

+ 47 - 69
flip_social/flip_social_feed.h

@@ -2,33 +2,25 @@
 #define FLIP_SOCIAL_FEED_H
 
 // Set failure FlipSocialFeed object
-static bool flip_social_temp_feed()
-{
-    if (flip_social_feed == NULL)
-    {
+static bool flip_social_temp_feed() {
+    if(flip_social_feed == NULL) {
         flip_social_feed = malloc(sizeof(FlipSocialFeed));
-        if (flip_social_feed == NULL)
-        {
+        if(flip_social_feed == NULL) {
             FURI_LOG_E(TAG, "Failed to allocate memory for feed");
             return false;
         }
     }
-    for (int i = 0; i < 3; i++)
-    {
-        if (flip_social_feed->usernames[i] == NULL)
-        {
+    for(int i = 0; i < 3; i++) {
+        if(flip_social_feed->usernames[i] == NULL) {
             flip_social_feed->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (flip_social_feed->usernames[i] == NULL)
-            {
+            if(flip_social_feed->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return false;
             }
         }
-        if (flip_social_feed->messages[i] == NULL)
-        {
+        if(flip_social_feed->messages[i] == NULL) {
             flip_social_feed->messages[i] = malloc(MAX_MESSAGE_LENGTH);
-            if (flip_social_feed->messages[i] == NULL)
-            {
+            if(flip_social_feed->messages[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for message %zu", i);
                 return false;
             }
@@ -38,7 +30,8 @@ static bool flip_social_temp_feed()
     flip_social_feed->usernames[1] = "FlipperKing";
     flip_social_feed->usernames[2] = "FlipperQueen";
     //
-    flip_social_feed->messages[0] = "Welcome. This is a temp message. Either the feed didn't load or there was a server error.";
+    flip_social_feed->messages[0] =
+        "Welcome. This is a temp message. Either the feed didn't load or there was a server error.";
     flip_social_feed->messages[1] = "I am the Chosen Flipper.";
     flip_social_feed->messages[2] = "No one can flip like me.";
     //
@@ -61,31 +54,24 @@ static bool flip_social_temp_feed()
 }
 
 // Allocate memory for each feed item if not already allocated
-static FlipSocialFeed *flip_social_feed_alloc()
-{
+static FlipSocialFeed* flip_social_feed_alloc() {
     // Initialize the feed
-    FlipSocialFeed *feed = (FlipSocialFeed *)malloc(sizeof(FlipSocialFeed));
-    if (!feed)
-    {
+    FlipSocialFeed* feed = (FlipSocialFeed*)malloc(sizeof(FlipSocialFeed));
+    if(!feed) {
         FURI_LOG_E(TAG, "Failed to allocate memory for feed");
         return feed;
     }
-    for (size_t i = 0; i < MAX_FEED_ITEMS; i++)
-    {
-        if (feed->usernames[i] == NULL)
-        {
+    for(size_t i = 0; i < MAX_FEED_ITEMS; i++) {
+        if(feed->usernames[i] == NULL) {
             feed->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (feed->usernames[i] == NULL)
-            {
+            if(feed->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return NULL;
             }
         }
-        if (feed->messages[i] == NULL)
-        {
+        if(feed->messages[i] == NULL) {
             feed->messages[i] = malloc(MAX_MESSAGE_LENGTH);
-            if (feed->messages[i] == NULL)
-            {
+            if(feed->messages[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for message %zu", i);
                 return NULL;
             }
@@ -94,32 +80,31 @@ static FlipSocialFeed *flip_social_feed_alloc()
     return feed;
 }
 
-static void flip_social_free_feed()
-{
-    if (!flip_social_feed)
-    {
+static void flip_social_free_feed() {
+    if(!flip_social_feed) {
         FURI_LOG_E(TAG, "Feed model is NULL");
         return;
     }
-    for (uint32_t i = 0; i < flip_social_feed->count; i++)
-    {
+    for(uint32_t i = 0; i < flip_social_feed->count; i++) {
         free(flip_social_feed->usernames[i]);
     }
 }
 
-static bool flip_social_get_feed()
-{
+static bool flip_social_get_feed() {
     // Get the feed from the server
-    if (app_instance->login_username_logged_out == NULL)
-    {
+    if(app_instance->login_username_logged_out == NULL) {
         FURI_LOG_E(TAG, "Username is NULL");
         return false;
     }
     char command[128];
-    snprintf(command, 128, "https://www.flipsocial.net/api/feed/40/%s/extended/", app_instance->login_username_logged_out);
-    bool success = flipper_http_get_request_with_headers(command, jsmn("Content-Type", "application/json"));
-    if (!success)
-    {
+    snprintf(
+        command,
+        128,
+        "https://www.flipsocial.net/api/feed/40/%s/extended/",
+        app_instance->login_username_logged_out);
+    bool success =
+        flipper_http_get_request_with_headers(command, jsmn("Content-Type", "application/json"));
+    if(!success) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
         return false;
     }
@@ -127,24 +112,20 @@ static bool flip_social_get_feed()
     return true;
 }
 
-static bool flip_social_parse_json_feed()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_feed() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each feed item if not already allocated
     flip_social_feed = flip_social_feed_alloc();
-    if (flip_social_feed == NULL)
-    {
+    if(flip_social_feed == NULL) {
         return false;
     }
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -152,24 +133,21 @@ static bool flip_social_parse_json_feed()
     flip_social_feed->count = 0;
 
     // Iterate through the feed array
-    for (int i = 0; i < MAX_FEED_ITEMS; i++)
-    {
+    for(int i = 0; i < MAX_FEED_ITEMS; i++) {
         // Parse each item in the array
-        char *item = get_json_array_value("feed", i, fhttp.received_data, MAX_TOKENS);
-        if (item == NULL)
-        {
+        char* item = get_json_array_value("feed", i, fhttp.received_data, MAX_TOKENS);
+        if(item == NULL) {
             break;
         }
 
         // Extract individual fields from the JSON object
-        char *username = get_json_value("username", item, MAX_TOKENS);
-        char *message = get_json_value("message", item, MAX_TOKENS);
-        char *flipped = get_json_value("flipped", item, MAX_TOKENS);
-        char *flips = get_json_value("flip_count", item, MAX_TOKENS);
-        char *id = get_json_value("id", item, MAX_TOKENS);
-
-        if (username == NULL || message == NULL || flipped == NULL || id == NULL)
-        {
+        char* username = get_json_value("username", item, MAX_TOKENS);
+        char* message = get_json_value("message", item, MAX_TOKENS);
+        char* flipped = get_json_value("flipped", item, MAX_TOKENS);
+        char* flips = get_json_value("flip_count", item, MAX_TOKENS);
+        char* id = get_json_value("id", item, MAX_TOKENS);
+
+        if(username == NULL || message == NULL || flipped == NULL || id == NULL) {
             FURI_LOG_E(TAG, "Failed to parse item fields.");
             free(item);
             free(username);
@@ -206,4 +184,4 @@ static bool flip_social_parse_json_feed()
     return flip_social_feed->count > 0;
 }
 
-#endif // FLIP_SOCIAL_FEED_H
+#endif // FLIP_SOCIAL_FEED_H

+ 100 - 147
flip_social/flip_social_free.h

@@ -8,273 +8,227 @@
  * @param app The FlipSocialApp object to free.
  * @return void
  */
-static void flip_social_app_free(FlipSocialApp *app)
-{
-    if (!app)
-    {
+static void flip_social_app_free(FlipSocialApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipSocialApp is NULL");
         return;
     }
-    if (!app->view_dispatcher)
-    {
+    if(!app->view_dispatcher) {
         FURI_LOG_E(TAG, "ViewDispatcher is NULL");
         return;
     }
 
     // Free Submenu(s)
-    if (app->submenu_logged_out)
-    {
+    if(app->submenu_logged_out) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutSubmenu);
         submenu_free(app->submenu_logged_out);
     }
-    if (app->submenu_logged_in)
-    {
+    if(app->submenu_logged_in) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSubmenu);
         submenu_free(app->submenu_logged_in);
     }
-    if (app->submenu_compose)
-    {
+    if(app->submenu_compose) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInCompose);
         submenu_free(app->submenu_compose);
     }
-    if (app->submenu_explore)
-    {
+    if(app->submenu_explore) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInExploreSubmenu);
         submenu_free(app->submenu_explore);
     }
-    if (app->submenu_friends)
-    {
+    if(app->submenu_friends) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsSubmenu);
         submenu_free(app->submenu_friends);
     }
-    if (app->submenu_messages)
-    {
+    if(app->submenu_messages) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesSubmenu);
         submenu_free(app->submenu_messages);
     }
-    if (app->submenu_messages_user_choices)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesUserChoices);
+    if(app->submenu_messages_user_choices) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInMessagesUserChoices);
         submenu_free(app->submenu_messages_user_choices);
     }
 
     // Free Variable Item List(s)
-    if (app->variable_item_list_logged_out_wifi_settings)
-    {
+    if(app->variable_item_list_logged_out_wifi_settings) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettings);
         variable_item_list_free(app->variable_item_list_logged_out_wifi_settings);
     }
-    if (app->variable_item_list_logged_out_login)
-    {
+    if(app->variable_item_list_logged_out_login) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLogin);
         variable_item_list_free(app->variable_item_list_logged_out_login);
     }
-    if (app->variable_item_list_logged_out_register)
-    {
+    if(app->variable_item_list_logged_out_register) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegister);
         variable_item_list_free(app->variable_item_list_logged_out_register);
     }
-    if (app->variable_item_list_logged_in_profile)
-    {
+    if(app->variable_item_list_logged_in_profile) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInProfile);
         variable_item_list_free(app->variable_item_list_logged_in_profile);
     }
-    if (app->variable_item_list_logged_in_settings)
-    {
+    if(app->variable_item_list_logged_in_settings) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettings);
         variable_item_list_free(app->variable_item_list_logged_in_settings);
     }
-    if (app->variable_item_list_logged_in_settings_wifi)
-    {
+    if(app->variable_item_list_logged_in_settings_wifi) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsWifi);
         variable_item_list_free(app->variable_item_list_logged_in_settings_wifi);
     }
 
     // Free Text Input(s)
-    if (app->text_input_logged_out_wifi_settings_ssid)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
+    if(app->text_input_logged_out_wifi_settings_ssid) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsSSIDInput);
         uart_text_input_free(app->text_input_logged_out_wifi_settings_ssid);
     }
-    if (app->text_input_logged_out_wifi_settings_password)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
+    if(app->text_input_logged_out_wifi_settings_password) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutWifiSettingsPasswordInput);
         uart_text_input_free(app->text_input_logged_out_wifi_settings_password);
     }
-    if (app->text_input_logged_out_login_username)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
+    if(app->text_input_logged_out_login_username) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutLoginUsernameInput);
         uart_text_input_free(app->text_input_logged_out_login_username);
     }
-    if (app->text_input_logged_out_login_password)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
+    if(app->text_input_logged_out_login_password) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutLoginPasswordInput);
         uart_text_input_free(app->text_input_logged_out_login_password);
     }
-    if (app->text_input_logged_out_register_username)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
+    if(app->text_input_logged_out_register_username) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutRegisterUsernameInput);
         uart_text_input_free(app->text_input_logged_out_register_username);
     }
-    if (app->text_input_logged_out_register_password)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
+    if(app->text_input_logged_out_register_password) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutRegisterPasswordInput);
         uart_text_input_free(app->text_input_logged_out_register_password);
     }
-    if (app->text_input_logged_out_register_password_2)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
+    if(app->text_input_logged_out_register_password_2) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedOutRegisterPassword2Input);
         uart_text_input_free(app->text_input_logged_out_register_password_2);
     }
-    if (app->text_input_logged_in_change_password)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
+    if(app->text_input_logged_in_change_password) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInChangePasswordInput);
         uart_text_input_free(app->text_input_logged_in_change_password);
     }
-    if (app->text_input_logged_in_compose_pre_save_input)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
+    if(app->text_input_logged_in_compose_pre_save_input) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInComposeAddPreSaveInput);
         uart_text_input_free(app->text_input_logged_in_compose_pre_save_input);
     }
-    if (app->text_input_logged_in_wifi_settings_ssid)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
+    if(app->text_input_logged_in_wifi_settings_ssid) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsSSIDInput);
         uart_text_input_free(app->text_input_logged_in_wifi_settings_ssid);
     }
-    if (app->text_input_logged_in_wifi_settings_password)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
+    if(app->text_input_logged_in_wifi_settings_password) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInWifiSettingsPasswordInput);
         uart_text_input_free(app->text_input_logged_in_wifi_settings_password);
     }
-    if (app->text_input_logged_in_messages_new_message)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
+    if(app->text_input_logged_in_messages_new_message) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageInput);
         uart_text_input_free(app->text_input_logged_in_messages_new_message);
     }
-    if (app->text_input_logged_in_messages_new_message_user_choices)
-    {
-        view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
+    if(app->text_input_logged_in_messages_new_message_user_choices) {
+        view_dispatcher_remove_view(
+            app->view_dispatcher, FlipSocialViewLoggedInMessagesNewMessageUserChoicesInput);
         uart_text_input_free(app->text_input_logged_in_messages_new_message_user_choices);
     }
 
     // Free Widget(s)
-    if (app->widget_logged_out_about)
-    {
+    if(app->widget_logged_out_about) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutAbout);
         widget_free(app->widget_logged_out_about);
     }
-    if (app->widget_logged_in_about)
-    {
+    if(app->widget_logged_in_about) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInSettingsAbout);
         widget_free(app->widget_logged_in_about);
     }
 
     // Free View(s)
-    if (app->view_process_login)
-    {
+    if(app->view_process_login) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessLogin);
         view_free(app->view_process_login);
     }
-    if (app->view_process_register)
-    {
+    if(app->view_process_register) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedOutProcessRegister);
         view_free(app->view_process_register);
     }
-    if (app->view_process_feed)
-    {
+    if(app->view_process_feed) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFeed);
         view_free(app->view_process_feed);
     }
-    if (app->view_process_compose)
-    {
+    if(app->view_process_compose) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInProcessCompose);
         view_free(app->view_process_compose);
     }
-    if (app->view_process_explore)
-    {
+    if(app->view_process_explore) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInExploreProccess);
         view_free(app->view_process_explore);
     }
-    if (app->view_process_friends)
-    {
+    if(app->view_process_friends) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInFriendsProcess);
         view_free(app->view_process_friends);
     }
-    if (app->view_process_messages)
-    {
+    if(app->view_process_messages) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipSocialViewLoggedInMessagesProcess);
         view_free(app->view_process_messages);
     }
 
-    if (app->view_dispatcher)
-        view_dispatcher_free(app->view_dispatcher);
+    if(app->view_dispatcher) view_dispatcher_free(app->view_dispatcher);
 
     // Free the app structure members
-    if (app->wifi_ssid_logged_out)
-        free(app->wifi_ssid_logged_out);
-    if (app->wifi_ssid_logged_out_temp_buffer)
-        free(app->wifi_ssid_logged_out_temp_buffer);
-    if (app->wifi_password_logged_out)
-        free(app->wifi_password_logged_out);
-    if (app->wifi_password_logged_out_temp_buffer)
-        free(app->wifi_password_logged_out_temp_buffer);
-    if (app->login_username_logged_out)
-        free(app->login_username_logged_out);
-    if (app->login_username_logged_out_temp_buffer)
+    if(app->wifi_ssid_logged_out) free(app->wifi_ssid_logged_out);
+    if(app->wifi_ssid_logged_out_temp_buffer) free(app->wifi_ssid_logged_out_temp_buffer);
+    if(app->wifi_password_logged_out) free(app->wifi_password_logged_out);
+    if(app->wifi_password_logged_out_temp_buffer) free(app->wifi_password_logged_out_temp_buffer);
+    if(app->login_username_logged_out) free(app->login_username_logged_out);
+    if(app->login_username_logged_out_temp_buffer)
         free(app->login_username_logged_out_temp_buffer);
-    if (app->login_password_logged_out)
-        free(app->login_password_logged_out);
-    if (app->login_password_logged_out_temp_buffer)
+    if(app->login_password_logged_out) free(app->login_password_logged_out);
+    if(app->login_password_logged_out_temp_buffer)
         free(app->login_password_logged_out_temp_buffer);
-    if (app->register_username_logged_out)
-        free(app->register_username_logged_out);
-    if (app->register_username_logged_out_temp_buffer)
+    if(app->register_username_logged_out) free(app->register_username_logged_out);
+    if(app->register_username_logged_out_temp_buffer)
         free(app->register_username_logged_out_temp_buffer);
-    if (app->register_password_logged_out)
-        free(app->register_password_logged_out);
-    if (app->register_password_logged_out_temp_buffer)
+    if(app->register_password_logged_out) free(app->register_password_logged_out);
+    if(app->register_password_logged_out_temp_buffer)
         free(app->register_password_logged_out_temp_buffer);
-    if (app->register_password_2_logged_out)
-        free(app->register_password_2_logged_out);
-    if (app->register_password_2_logged_out_temp_buffer)
+    if(app->register_password_2_logged_out) free(app->register_password_2_logged_out);
+    if(app->register_password_2_logged_out_temp_buffer)
         free(app->register_password_2_logged_out_temp_buffer);
-    if (app->change_password_logged_in)
-        free(app->change_password_logged_in);
-    if (app->change_password_logged_in_temp_buffer)
+    if(app->change_password_logged_in) free(app->change_password_logged_in);
+    if(app->change_password_logged_in_temp_buffer)
         free(app->change_password_logged_in_temp_buffer);
-    if (app->compose_pre_save_logged_in)
-        free(app->compose_pre_save_logged_in);
-    if (app->compose_pre_save_logged_in_temp_buffer)
+    if(app->compose_pre_save_logged_in) free(app->compose_pre_save_logged_in);
+    if(app->compose_pre_save_logged_in_temp_buffer)
         free(app->compose_pre_save_logged_in_temp_buffer);
-    if (app->wifi_ssid_logged_in)
-        free(app->wifi_ssid_logged_in);
-    if (app->wifi_ssid_logged_in_temp_buffer)
-        free(app->wifi_ssid_logged_in_temp_buffer);
-    if (app->wifi_password_logged_in)
-        free(app->wifi_password_logged_in);
-    if (app->wifi_password_logged_in_temp_buffer)
-        free(app->wifi_password_logged_in_temp_buffer);
-    if (app->is_logged_in)
-        free(app->is_logged_in);
-    if (app->login_username_logged_in)
-        free(app->login_username_logged_in);
-    if (app->login_username_logged_in_temp_buffer)
-        free(app->login_username_logged_in_temp_buffer);
-    if (app->messages_new_message_logged_in)
-        free(app->messages_new_message_logged_in);
-    if (app->messages_new_message_logged_in_temp_buffer)
+    if(app->wifi_ssid_logged_in) free(app->wifi_ssid_logged_in);
+    if(app->wifi_ssid_logged_in_temp_buffer) free(app->wifi_ssid_logged_in_temp_buffer);
+    if(app->wifi_password_logged_in) free(app->wifi_password_logged_in);
+    if(app->wifi_password_logged_in_temp_buffer) free(app->wifi_password_logged_in_temp_buffer);
+    if(app->is_logged_in) free(app->is_logged_in);
+    if(app->login_username_logged_in) free(app->login_username_logged_in);
+    if(app->login_username_logged_in_temp_buffer) free(app->login_username_logged_in_temp_buffer);
+    if(app->messages_new_message_logged_in) free(app->messages_new_message_logged_in);
+    if(app->messages_new_message_logged_in_temp_buffer)
         free(app->messages_new_message_logged_in_temp_buffer);
-    if (app->message_user_choice_logged_in)
-        free(app->message_user_choice_logged_in);
-    if (app->message_user_choice_logged_in_temp_buffer)
+    if(app->message_user_choice_logged_in) free(app->message_user_choice_logged_in);
+    if(app->message_user_choice_logged_in_temp_buffer)
         free(app->message_user_choice_logged_in_temp_buffer);
 
-    if (app->input_event && app->input_event_queue)
+    if(app->input_event && app->input_event_queue)
         furi_pubsub_unsubscribe(app->input_event_queue, app->input_event);
 
     // free received_data
-    if (fhttp.received_data)
-        free(fhttp.received_data);
+    if(fhttp.received_data) free(fhttp.received_data);
 
     // free playlist and explore page
     flip_social_free_explore();
@@ -287,8 +241,7 @@ static void flip_social_app_free(FlipSocialApp *app)
     flipper_http_deinit();
 
     // Free the app structure
-    if (app_instance)
-        free(app_instance);
+    if(app_instance) free(app_instance);
 }
 
-#endif // FLIP_SOCIAL_FREE_H
+#endif // FLIP_SOCIAL_FREE_H

+ 58 - 66
flip_social/flip_social_friends.h

@@ -1,17 +1,13 @@
 #ifndef FLIP_SOCIAL_FRIENDS
 #define FLIP_SOCIAL_FRIENDS
 
-static FlipSocialModel *flip_social_friends_alloc()
-{
+static FlipSocialModel* flip_social_friends_alloc() {
     // Allocate memory for each username only if not already allocated
-    FlipSocialModel *friends = malloc(sizeof(FlipSocialModel));
-    for (size_t i = 0; i < MAX_FRIENDS; i++)
-    {
-        if (friends->usernames[i] == NULL)
-        {
+    FlipSocialModel* friends = malloc(sizeof(FlipSocialModel));
+    for(size_t i = 0; i < MAX_FRIENDS; i++) {
+        if(friends->usernames[i] == NULL) {
             friends->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (friends->usernames[i] == NULL)
-            {
+            if(friends->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return NULL; // Return false on memory allocation failure
             }
@@ -20,29 +16,29 @@ static FlipSocialModel *flip_social_friends_alloc()
     return friends;
 }
 
-static void flip_social_free_friends()
-{
-    if (!flip_social_friends)
-    {
+static void flip_social_free_friends() {
+    if(!flip_social_friends) {
         FURI_LOG_E(TAG, "Friends model is NULL");
         return;
     }
-    for (int i = 0; i < flip_social_friends->count; i++)
-    {
+    for(int i = 0; i < flip_social_friends->count; i++) {
         free(flip_social_friends->usernames[i]);
     }
 }
 
 // for now we're just listing the current users
 // as the feed is upgraded, then we can port more to the friends view
-static bool flip_social_get_friends()
-{
+static bool flip_social_get_friends() {
     // will return true unless the devboard is not connected
     char url[100];
-    snprintf(url, 100, "https://www.flipsocial.net/api/user/friends/%s/", app_instance->login_username_logged_in);
-    bool success = flipper_http_get_request_with_headers(url, jsmn("Content-Type", "application/json"));
-    if (!success)
-    {
+    snprintf(
+        url,
+        100,
+        "https://www.flipsocial.net/api/user/friends/%s/",
+        app_instance->login_username_logged_in);
+    bool success =
+        flipper_http_get_request_with_headers(url, jsmn("Content-Type", "application/json"));
+    if(!success) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for friends");
         return false;
     }
@@ -50,48 +46,45 @@ static bool flip_social_get_friends()
     return true;
 }
 
-static bool flip_social_update_friends()
-{
-    if (!app_instance->submenu_friends)
-    {
+static bool flip_social_update_friends() {
+    if(!app_instance->submenu_friends) {
         FURI_LOG_E(TAG, "Friends submenu is NULL");
         return false;
     }
-    if (!flip_social_friends)
-    {
+    if(!flip_social_friends) {
         FURI_LOG_E(TAG, "Friends model is NULL");
         return false;
     }
     // Add submenu items for the users
     submenu_reset(app_instance->submenu_friends);
     submenu_set_header(app_instance->submenu_friends, "Friends");
-    for (int i = 0; i < flip_social_friends->count; i++)
-    {
-        submenu_add_item(app_instance->submenu_friends, flip_social_friends->usernames[i], FlipSocialSubmenuLoggedInIndexFriendsStart + i, flip_social_callback_submenu_choices, app_instance);
+    for(int i = 0; i < flip_social_friends->count; i++) {
+        submenu_add_item(
+            app_instance->submenu_friends,
+            flip_social_friends->usernames[i],
+            FlipSocialSubmenuLoggedInIndexFriendsStart + i,
+            flip_social_callback_submenu_choices,
+            app_instance);
     }
     return true;
 }
 
-static bool flip_social_parse_json_friends()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_friends() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each username only if not already allocated
     flip_social_friends = flip_social_friends_alloc();
-    if (flip_social_friends == NULL)
-    {
+    if(flip_social_friends == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for friends usernames.");
         return false;
     }
 
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -99,51 +92,50 @@ static bool flip_social_parse_json_friends()
     flip_social_friends->count = 0;
 
     // Extract the users array from the JSON
-    char *json_users = get_json_value("friends", fhttp.received_data, MAX_TOKENS);
-    if (json_users == NULL)
-    {
+    char* json_users = get_json_value("friends", fhttp.received_data, MAX_TOKENS);
+    if(json_users == NULL) {
         FURI_LOG_E(TAG, "Failed to parse friends array.");
         return false;
     }
 
     // Manual tokenization for comma-separated values
-    char *start = json_users + 1; // Skip the opening bracket
-    char *end;
-    while ((end = strchr(start, ',')) != NULL && flip_social_friends->count < MAX_FRIENDS)
-    {
+    char* start = json_users + 1; // Skip the opening bracket
+    char* end;
+    while((end = strchr(start, ',')) != NULL && flip_social_friends->count < MAX_FRIENDS) {
         *end = '\0'; // Null-terminate the current token
 
         // Remove quotes
-        if (*start == '"')
-            start++;
-        if (*(end - 1) == '"')
-            *(end - 1) = '\0';
+        if(*start == '"') start++;
+        if(*(end - 1) == '"') *(end - 1) = '\0';
 
         // Copy username to pre-allocated memory
-        strncpy(flip_social_friends->usernames[flip_social_friends->count], start, MAX_USER_LENGTH - 1);
-        flip_social_friends->usernames[flip_social_friends->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+        strncpy(
+            flip_social_friends->usernames[flip_social_friends->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_friends->usernames[flip_social_friends->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_friends->count++;
         start = end + 1;
     }
 
     // Handle the last token
-    if (*start != '\0' && flip_social_friends->count < MAX_FRIENDS)
-    {
-        if (*start == '"')
-            start++;
-        if (*(start + strlen(start) - 1) == ']')
-            *(start + strlen(start) - 1) = '\0';
-        if (*(start + strlen(start) - 1) == '"')
-            *(start + strlen(start) - 1) = '\0';
-
-        strncpy(flip_social_friends->usernames[flip_social_friends->count], start, MAX_USER_LENGTH - 1);
-        flip_social_friends->usernames[flip_social_friends->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+    if(*start != '\0' && flip_social_friends->count < MAX_FRIENDS) {
+        if(*start == '"') start++;
+        if(*(start + strlen(start) - 1) == ']') *(start + strlen(start) - 1) = '\0';
+        if(*(start + strlen(start) - 1) == '"') *(start + strlen(start) - 1) = '\0';
+
+        strncpy(
+            flip_social_friends->usernames[flip_social_friends->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_friends->usernames[flip_social_friends->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_friends->count++;
     }
 
     // Add submenu items for the friends
-    if (!flip_social_update_friends())
-    {
+    if(!flip_social_update_friends()) {
         FURI_LOG_E(TAG, "Failed to update friends submenu");
         return false;
     }
@@ -155,4 +147,4 @@ static bool flip_social_parse_json_friends()
 
     return true;
 }
-#endif // FLIP_SOCIAL_FRIENDS
+#endif // FLIP_SOCIAL_FRIENDS

Разница между файлами не показана из-за своего большого размера
+ 732 - 333
flip_social/flip_social_i.h


+ 140 - 158
flip_social/flip_social_messages.h

@@ -1,22 +1,17 @@
 #ifndef FLIP_SOCIAL_MESSAGES_H
 #define FLIP_SOCIAL_MESSAGES_H
 
-static FlipSocialModel2 *flip_social_messages_alloc()
-{
+static FlipSocialModel2* flip_social_messages_alloc() {
     // Allocate memory for each username only if not already allocated
-    FlipSocialModel2 *users = malloc(sizeof(FlipSocialModel2));
-    if (users == NULL)
-    {
+    FlipSocialModel2* users = malloc(sizeof(FlipSocialModel2));
+    if(users == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for message users");
         return NULL;
     }
-    for (size_t i = 0; i < MAX_MESSAGE_USERS; i++)
-    {
-        if (users->usernames[i] == NULL)
-        {
+    for(size_t i = 0; i < MAX_MESSAGE_USERS; i++) {
+        if(users->usernames[i] == NULL) {
             users->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (users->usernames[i] == NULL)
-            {
+            if(users->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return NULL; // Return false on memory allocation failure
             }
@@ -25,31 +20,24 @@ static FlipSocialModel2 *flip_social_messages_alloc()
     return users;
 }
 
-static FlipSocialMessage *flip_social_user_messages_alloc()
-{
+static FlipSocialMessage* flip_social_user_messages_alloc() {
     // Allocate memory for each username only if not already allocated
-    FlipSocialMessage *messages = malloc(sizeof(FlipSocialMessage));
-    if (messages == NULL)
-    {
+    FlipSocialMessage* messages = malloc(sizeof(FlipSocialMessage));
+    if(messages == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for messages");
         return NULL;
     }
-    for (size_t i = 0; i < MAX_MESSAGE_USERS; i++)
-    {
-        if (messages->usernames[i] == NULL)
-        {
+    for(size_t i = 0; i < MAX_MESSAGE_USERS; i++) {
+        if(messages->usernames[i] == NULL) {
             messages->usernames[i] = malloc(MAX_USER_LENGTH);
-            if (messages->usernames[i] == NULL)
-            {
+            if(messages->usernames[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for username %zu", i);
                 return NULL; // Return false on memory allocation failure
             }
         }
-        if (messages->messages[i] == NULL)
-        {
+        if(messages->messages[i] == NULL) {
             messages->messages[i] = malloc(MAX_MESSAGE_LENGTH);
-            if (messages->messages[i] == NULL)
-            {
+            if(messages->messages[i] == NULL) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for message %zu", i);
                 return NULL; // Return false on memory allocation failure
             }
@@ -58,89 +46,92 @@ static FlipSocialMessage *flip_social_user_messages_alloc()
     return messages;
 }
 
-static void flip_social_free_message_users()
-{
-    if (flip_social_message_users == NULL)
-    {
+static void flip_social_free_message_users() {
+    if(flip_social_message_users == NULL) {
         FURI_LOG_E(TAG, "Message users model is NULL");
         return;
     }
-    for (int i = 0; i < flip_social_message_users->count; i++)
-    {
+    for(int i = 0; i < flip_social_message_users->count; i++) {
         free(flip_social_message_users->usernames[i]);
     }
 }
 
-static void flip_social_free_messages()
-{
-    if (flip_social_messages == NULL)
-    {
+static void flip_social_free_messages() {
+    if(flip_social_messages == NULL) {
         FURI_LOG_E(TAG, "Messages model is NULL");
         return;
     }
-    for (int i = 0; i < flip_social_messages->count; i++)
-    {
+    for(int i = 0; i < flip_social_messages->count; i++) {
         free(flip_social_messages->usernames[i]);
         free(flip_social_messages->messages[i]);
     }
 }
 
-static bool flip_social_update_messages_submenu()
-{
-    if (app_instance->submenu_messages == NULL)
-    {
+static bool flip_social_update_messages_submenu() {
+    if(app_instance->submenu_messages == NULL) {
         FURI_LOG_E(TAG, "Submenu is NULL");
         return false;
     }
-    if (flip_social_message_users == NULL)
-    {
+    if(flip_social_message_users == NULL) {
         FURI_LOG_E(TAG, "Message users model is NULL");
         return false;
     }
     submenu_reset(app_instance->submenu_messages);
     submenu_set_header(app_instance->submenu_messages, "Messages");
-    submenu_add_item(app_instance->submenu_messages, "[New Message]", FlipSocialSubmenuLoggedInIndexMessagesNewMessage, flip_social_callback_submenu_choices, app_instance);
-    for (int i = 0; i < flip_social_message_users->count; i++)
-    {
-        submenu_add_item(app_instance->submenu_messages, flip_social_message_users->usernames[i], FlipSocialSubmenuLoggedInIndexMessagesUsersStart + i, flip_social_callback_submenu_choices, app_instance);
+    submenu_add_item(
+        app_instance->submenu_messages,
+        "[New Message]",
+        FlipSocialSubmenuLoggedInIndexMessagesNewMessage,
+        flip_social_callback_submenu_choices,
+        app_instance);
+    for(int i = 0; i < flip_social_message_users->count; i++) {
+        submenu_add_item(
+            app_instance->submenu_messages,
+            flip_social_message_users->usernames[i],
+            FlipSocialSubmenuLoggedInIndexMessagesUsersStart + i,
+            flip_social_callback_submenu_choices,
+            app_instance);
     }
     return true;
 }
 
-static bool flip_social_update_submenu_user_choices()
-{
-    if (app_instance->submenu_messages_user_choices == NULL)
-    {
+static bool flip_social_update_submenu_user_choices() {
+    if(app_instance->submenu_messages_user_choices == NULL) {
         FURI_LOG_E(TAG, "Submenu is NULL");
         return false;
     }
-    if (flip_social_explore == NULL)
-    {
+    if(flip_social_explore == NULL) {
         FURI_LOG_E(TAG, "Explore model is NULL");
         return false;
     }
     submenu_reset(app_instance->submenu_messages_user_choices);
     submenu_set_header(app_instance->submenu_messages_user_choices, "Users");
-    for (int i = 0; i < flip_social_explore->count; i++)
-    {
-        submenu_add_item(app_instance->submenu_messages_user_choices, flip_social_explore->usernames[i], FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + i, flip_social_callback_submenu_choices, app_instance);
+    for(int i = 0; i < flip_social_explore->count; i++) {
+        submenu_add_item(
+            app_instance->submenu_messages_user_choices,
+            flip_social_explore->usernames[i],
+            FlipSocialSubmenuLoggedInIndexMessagesUserChoicesIndexStart + i,
+            flip_social_callback_submenu_choices,
+            app_instance);
     }
     return true;
 }
 
 // Get all the users that have sent messages to the logged in user
-static bool flip_social_get_message_users()
-{
-    if (app_instance->login_username_logged_out == NULL)
-    {
+static bool flip_social_get_message_users() {
+    if(app_instance->login_username_logged_out == NULL) {
         FURI_LOG_E(TAG, "Username is NULL");
         return false;
     }
     char command[128];
-    snprintf(command, 128, "https://www.flipsocial.net/api/messages/%s/get/list/", app_instance->login_username_logged_out);
-    bool success = flipper_http_get_request_with_headers(command, "{\"Content-Type\":\"application/json\"}");
-    if (!success)
-    {
+    snprintf(
+        command,
+        128,
+        "https://www.flipsocial.net/api/messages/%s/get/list/",
+        app_instance->login_username_logged_out);
+    bool success =
+        flipper_http_get_request_with_headers(command, "{\"Content-Type\":\"application/json\"}");
+    if(!success) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         return false;
     }
@@ -149,18 +140,21 @@ static bool flip_social_get_message_users()
 }
 
 // Get all the messages between the logged in user and the selected user
-static bool flip_social_get_messages_with_user()
-{
-    if (app_instance->login_username_logged_out == NULL)
-    {
+static bool flip_social_get_messages_with_user() {
+    if(app_instance->login_username_logged_out == NULL) {
         FURI_LOG_E(TAG, "Username is NULL");
         return false;
     }
     char command[128];
-    snprintf(command, 128, "https://www.flipsocial.net/api/messages/%s/get/%s/", app_instance->login_username_logged_out, flip_social_message_users->usernames[flip_social_message_users->index]);
-    bool success = flipper_http_get_request_with_headers(command, "{\"Content-Type\":\"application/json\"}");
-    if (!success)
-    {
+    snprintf(
+        command,
+        128,
+        "https://www.flipsocial.net/api/messages/%s/get/%s/",
+        app_instance->login_username_logged_out,
+        flip_social_message_users->usernames[flip_social_message_users->index]);
+    bool success =
+        flipper_http_get_request_with_headers(command, "{\"Content-Type\":\"application/json\"}");
+    if(!success) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         return false;
     }
@@ -169,26 +163,22 @@ static bool flip_social_get_messages_with_user()
 }
 
 // Parse the users that have sent messages to the logged-in user
-static bool flip_social_parse_json_message_users()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_message_users() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each username only if not already allocated
     flip_social_message_users = flip_social_messages_alloc();
-    if (flip_social_message_users == NULL)
-    {
+    if(flip_social_message_users == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for message users.");
         return false;
     }
 
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -196,45 +186,48 @@ static bool flip_social_parse_json_message_users()
     flip_social_message_users->count = 0;
 
     // Extract the users array from the JSON
-    char *json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
-    if (json_users == NULL)
-    {
+    char* json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
+    if(json_users == NULL) {
         FURI_LOG_E(TAG, "Failed to parse users array.");
         return false;
     }
 
     // Manual tokenization for comma-separated values
-    char *start = json_users + 1; // Skip the opening bracket
-    char *end;
-    while ((end = strchr(start, ',')) != NULL && flip_social_message_users->count < MAX_MESSAGE_USERS)
-    {
+    char* start = json_users + 1; // Skip the opening bracket
+    char* end;
+    while((end = strchr(start, ',')) != NULL &&
+          flip_social_message_users->count < MAX_MESSAGE_USERS) {
         *end = '\0'; // Null-terminate the current token
 
         // Remove quotes
-        if (*start == '"')
-            start++;
-        if (*(end - 1) == '"')
-            *(end - 1) = '\0';
+        if(*start == '"') start++;
+        if(*(end - 1) == '"') *(end - 1) = '\0';
 
         // Copy username to pre-allocated memory
-        strncpy(flip_social_message_users->usernames[flip_social_message_users->count], start, MAX_USER_LENGTH - 1);
-        flip_social_message_users->usernames[flip_social_message_users->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+        strncpy(
+            flip_social_message_users->usernames[flip_social_message_users->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_message_users
+            ->usernames[flip_social_message_users->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_message_users->count++;
         start = end + 1;
     }
 
     // Handle the last token
-    if (*start != '\0' && flip_social_message_users->count < MAX_MESSAGE_USERS)
-    {
-        if (*start == '"')
-            start++;
-        if (*(start + strlen(start) - 1) == ']')
-            *(start + strlen(start) - 1) = '\0';
-        if (*(start + strlen(start) - 1) == '"')
-            *(start + strlen(start) - 1) = '\0';
-
-        strncpy(flip_social_message_users->usernames[flip_social_message_users->count], start, MAX_USER_LENGTH - 1);
-        flip_social_message_users->usernames[flip_social_message_users->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+    if(*start != '\0' && flip_social_message_users->count < MAX_MESSAGE_USERS) {
+        if(*start == '"') start++;
+        if(*(start + strlen(start) - 1) == ']') *(start + strlen(start) - 1) = '\0';
+        if(*(start + strlen(start) - 1) == '"') *(start + strlen(start) - 1) = '\0';
+
+        strncpy(
+            flip_social_message_users->usernames[flip_social_message_users->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_message_users
+            ->usernames[flip_social_message_users->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_message_users->count++;
     }
 
@@ -250,26 +243,22 @@ static bool flip_social_parse_json_message_users()
 }
 
 // Parse the users that the logged in user can message
-static bool flip_social_parse_json_message_user_choices()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_message_user_choices() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each username only if not already allocated
     flip_social_explore = flip_social_explore_alloc();
-    if (flip_social_explore == NULL)
-    {
+    if(flip_social_explore == NULL) {
         FURI_LOG_E(TAG, "Failed to allocate memory for explore usernames.");
         return false;
     }
 
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -277,45 +266,45 @@ static bool flip_social_parse_json_message_user_choices()
     flip_social_explore->count = 0;
 
     // Extract the users array from the JSON
-    char *json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
-    if (json_users == NULL)
-    {
+    char* json_users = get_json_value("users", fhttp.received_data, MAX_TOKENS);
+    if(json_users == NULL) {
         FURI_LOG_E(TAG, "Failed to parse users array.");
         return false;
     }
 
     // Manual tokenization for comma-separated values
-    char *start = json_users + 1; // Skip the opening bracket
-    char *end;
-    while ((end = strchr(start, ',')) != NULL && flip_social_explore->count < MAX_EXPLORE_USERS)
-    {
+    char* start = json_users + 1; // Skip the opening bracket
+    char* end;
+    while((end = strchr(start, ',')) != NULL && flip_social_explore->count < MAX_EXPLORE_USERS) {
         *end = '\0'; // Null-terminate the current token
 
         // Remove quotes
-        if (*start == '"')
-            start++;
-        if (*(end - 1) == '"')
-            *(end - 1) = '\0';
+        if(*start == '"') start++;
+        if(*(end - 1) == '"') *(end - 1) = '\0';
 
         // Copy username to pre-allocated memory
-        strncpy(flip_social_explore->usernames[flip_social_explore->count], start, MAX_USER_LENGTH - 1);
-        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+        strncpy(
+            flip_social_explore->usernames[flip_social_explore->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_explore->count++;
         start = end + 1;
     }
 
     // Handle the last token
-    if (*start != '\0' && flip_social_explore->count < MAX_EXPLORE_USERS)
-    {
-        if (*start == '"')
-            start++;
-        if (*(start + strlen(start) - 1) == ']')
-            *(start + strlen(start) - 1) = '\0';
-        if (*(start + strlen(start) - 1) == '"')
-            *(start + strlen(start) - 1) = '\0';
-
-        strncpy(flip_social_explore->usernames[flip_social_explore->count], start, MAX_USER_LENGTH - 1);
-        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] = '\0'; // Ensure null termination
+    if(*start != '\0' && flip_social_explore->count < MAX_EXPLORE_USERS) {
+        if(*start == '"') start++;
+        if(*(start + strlen(start) - 1) == ']') *(start + strlen(start) - 1) = '\0';
+        if(*(start + strlen(start) - 1) == '"') *(start + strlen(start) - 1) = '\0';
+
+        strncpy(
+            flip_social_explore->usernames[flip_social_explore->count],
+            start,
+            MAX_USER_LENGTH - 1);
+        flip_social_explore->usernames[flip_social_explore->count][MAX_USER_LENGTH - 1] =
+            '\0'; // Ensure null termination
         flip_social_explore->count++;
     }
 
@@ -331,26 +320,22 @@ static bool flip_social_parse_json_message_user_choices()
 }
 
 // parse messages between the logged in user and the selected user
-static bool flip_social_parse_json_messages()
-{
-    if (fhttp.received_data == NULL)
-    {
+static bool flip_social_parse_json_messages() {
+    if(fhttp.received_data == NULL) {
         FURI_LOG_E(TAG, "No data received.");
         return false;
     }
 
     // Allocate memory for each message only if not already allocated
     flip_social_messages = flip_social_user_messages_alloc();
-    if (!flip_social_messages)
-    {
+    if(!flip_social_messages) {
         FURI_LOG_E(TAG, "Failed to allocate memory for messages.");
         return false;
     }
 
     // Remove newlines
-    char *pos = fhttp.received_data;
-    while ((pos = strchr(pos, '\n')) != NULL)
-    {
+    char* pos = fhttp.received_data;
+    while((pos = strchr(pos, '\n')) != NULL) {
         *pos = ' ';
     }
 
@@ -358,21 +343,18 @@ static bool flip_social_parse_json_messages()
     flip_social_messages->count = 0;
 
     // Iterate through the messages array
-    for (int i = 0; i < MAX_MESSAGES; i++)
-    {
+    for(int i = 0; i < MAX_MESSAGES; i++) {
         // Parse each item in the array
-        char *item = get_json_array_value("conversations", i, fhttp.received_data, MAX_TOKENS);
-        if (item == NULL)
-        {
+        char* item = get_json_array_value("conversations", i, fhttp.received_data, MAX_TOKENS);
+        if(item == NULL) {
             break;
         }
 
         // Extract individual fields from the JSON object
-        char *sender = get_json_value("sender", item, MAX_TOKENS);
-        char *content = get_json_value("content", item, MAX_TOKENS);
+        char* sender = get_json_value("sender", item, MAX_TOKENS);
+        char* content = get_json_value("content", item, MAX_TOKENS);
 
-        if (sender == NULL || content == NULL)
-        {
+        if(sender == NULL || content == NULL) {
             FURI_LOG_E(TAG, "Failed to parse item fields.");
             free(item);
             continue;
@@ -393,4 +375,4 @@ static bool flip_social_parse_json_messages()
     return true;
 }
 
-#endif // FLIP_SOCIAL_MESSAGES_H
+#endif // FLIP_SOCIAL_MESSAGES_H

+ 113 - 137
flip_social/flip_social_storage.h

@@ -6,28 +6,27 @@
 #include <storage/storage.h>
 
 #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/settings.bin"
-#define PRE_SAVED_MESSAGES_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/pre_saved_messages.txt"
+#define PRE_SAVED_MESSAGES_PATH \
+    STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/pre_saved_messages.txt"
 
 // Function to save the playlist
-void save_playlist(const PreSavedPlaylist *playlist)
-{
-    if (!playlist)
-    {
+void save_playlist(const PreSavedPlaylist* playlist) {
+    if(!playlist) {
         FURI_LOG_E(TAG, "Playlist is NULL");
         return;
     }
     // Create the directory for saving settings
     char directory_path[128];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, PRE_SAVED_MESSAGES_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, PRE_SAVED_MESSAGES_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", PRE_SAVED_MESSAGES_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -35,17 +34,15 @@ void save_playlist(const PreSavedPlaylist *playlist)
     }
 
     // Write each playlist message on a separate line
-    for (size_t i = 0; i < playlist->count; ++i)
-    {
+    for(size_t i = 0; i < playlist->count; ++i) {
         // Add a newline character after each message
-        if (storage_file_write(file, playlist->messages[i], strlen(playlist->messages[i])) != strlen(playlist->messages[i]))
-        {
+        if(storage_file_write(file, playlist->messages[i], strlen(playlist->messages[i])) !=
+           strlen(playlist->messages[i])) {
             FURI_LOG_E(TAG, "Failed to write playlist message %zu", i);
         }
 
         // Write a newline after each message
-        if (storage_file_write(file, "\n", 1) != 1)
-        {
+        if(storage_file_write(file, "\n", 1) != 1) {
             FURI_LOG_E(TAG, "Failed to write newline after message %zu", i);
         }
     }
@@ -57,23 +54,19 @@ void save_playlist(const PreSavedPlaylist *playlist)
 
 // Function to load the playlist
 // Function to load the playlist
-bool load_playlist(PreSavedPlaylist *playlist)
-{
+bool load_playlist(PreSavedPlaylist* playlist) {
     // Ensure playlist is not NULL
-    if (!playlist)
-    {
+    if(!playlist) {
         FURI_LOG_E(TAG, "Playlist is NULL");
         return false;
     }
 
     // Ensure playlist->messages is not NULL and allocate memory for each message
-    for (size_t i = 0; i < MAX_PRE_SAVED_MESSAGES; ++i)
-    {
-        if (!playlist->messages[i]) // Check if memory is already allocated
+    for(size_t i = 0; i < MAX_PRE_SAVED_MESSAGES; ++i) {
+        if(!playlist->messages[i]) // Check if memory is already allocated
         {
-            playlist->messages[i] = (char *)malloc(MAX_MESSAGE_LENGTH * sizeof(char));
-            if (!playlist->messages[i])
-            {
+            playlist->messages[i] = (char*)malloc(MAX_MESSAGE_LENGTH * sizeof(char));
+            if(!playlist->messages[i]) {
                 FURI_LOG_E(TAG, "Failed to allocate memory for message %zu", i);
                 return false; // Return false on memory allocation failure
             }
@@ -81,12 +74,14 @@ bool load_playlist(PreSavedPlaylist *playlist)
     }
 
     // Open the storage
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
-
-    if (!storage_file_open(file, PRE_SAVED_MESSAGES_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
-        FURI_LOG_E(TAG, "Failed to open pre-saved messages file for reading: %s", PRE_SAVED_MESSAGES_PATH);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
+
+    if(!storage_file_open(file, PRE_SAVED_MESSAGES_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
+        FURI_LOG_E(
+            TAG,
+            "Failed to open pre-saved messages file for reading: %s",
+            PRE_SAVED_MESSAGES_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
         return false; // Return false if the file does not exist
@@ -100,39 +95,36 @@ bool load_playlist(PreSavedPlaylist *playlist)
     size_t message_pos = 0;
     bool message_started = false;
 
-    while (storage_file_read(file, &ch, 1) == 1) // Read one character at a time
+    while(storage_file_read(file, &ch, 1) == 1) // Read one character at a time
     {
         message_started = true;
 
-        if (ch == '\n' || message_pos >= (MAX_MESSAGE_LENGTH - 1)) // End of line or message is too long
+        if(ch == '\n' ||
+           message_pos >= (MAX_MESSAGE_LENGTH - 1)) // End of line or message is too long
         {
             playlist->messages[playlist->count][message_pos] = '\0'; // Null-terminate the message
-            playlist->count++;                                       // Move to the next message
-            message_pos = 0;                                         // Reset for the next message
+            playlist->count++; // Move to the next message
+            message_pos = 0; // Reset for the next message
             message_started = false;
 
             // Ensure the playlist count does not exceed the maximum
-            if (playlist->count >= MAX_PRE_SAVED_MESSAGES)
-            {
+            if(playlist->count >= MAX_PRE_SAVED_MESSAGES) {
                 FURI_LOG_W(TAG, "Reached maximum playlist messages");
                 break;
             }
-        }
-        else
-        {
-            playlist->messages[playlist->count][message_pos++] = ch; // Add character to current message
+        } else {
+            playlist->messages[playlist->count][message_pos++] =
+                ch; // Add character to current message
         }
     }
 
     // Handle the case where the last message does not end with a newline
-    if (message_started && message_pos > 0)
-    {
+    if(message_started && message_pos > 0) {
         playlist->messages[playlist->count][message_pos] = '\0'; // Null-terminate the last message
-        playlist->count++;                                       // Increment the count for the last message
+        playlist->count++; // Increment the count for the last message
 
         // Ensure the playlist count does not exceed the maximum
-        if (playlist->count >= MAX_PRE_SAVED_MESSAGES)
-        {
+        if(playlist->count >= MAX_PRE_SAVED_MESSAGES) {
             FURI_LOG_W(TAG, "Reached maximum playlist messages");
         }
     }
@@ -145,26 +137,25 @@ bool load_playlist(PreSavedPlaylist *playlist)
     return true;
 }
 static void save_settings(
-    const char *ssid,
-    const char *password,
-    const char *login_username_logged_out,
-    const char *login_username_logged_in,
-    const char *login_password_logged_out,
-    const char *change_password_logged_in,
-    const char *is_logged_in)
-{
+    const char* ssid,
+    const char* password,
+    const char* login_username_logged_out,
+    const char* login_username_logged_in,
+    const char* login_password_logged_out,
+    const char* change_password_logged_in,
+    const char* is_logged_in) {
     // Create the directory for saving settings
     char directory_path[128];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -173,57 +164,55 @@ static void save_settings(
 
     // Save the ssid length and data
     size_t ssid_length = strlen(ssid) + 1; // Include null terminator
-    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to write SSID");
     }
 
     // Save the password length and data
     size_t password_length = strlen(password) + 1; // Include null terminator
-    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, password, password_length) != password_length)
-    {
+    if(storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to write password");
     }
 
     // Save the login_username_logged_out length and data
     size_t username_out_length = strlen(login_username_logged_out) + 1; // Include null terminator
-    if (storage_file_write(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, login_username_logged_out, username_out_length) != username_out_length)
-    {
+    if(storage_file_write(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, login_username_logged_out, username_out_length) !=
+           username_out_length) {
         FURI_LOG_E(TAG, "Failed to write login_username_logged_out");
     }
 
     // Save the login_username_logged_in length and data
     size_t username_in_length = strlen(login_username_logged_in) + 1; // Include null terminator
-    if (storage_file_write(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, login_username_logged_in, username_in_length) != username_in_length)
-    {
+    if(storage_file_write(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, login_username_logged_in, username_in_length) !=
+           username_in_length) {
         FURI_LOG_E(TAG, "Failed to write login_username_logged_in");
     }
 
     // Save the login_password_logged_out length and data
     size_t password_out_length = strlen(login_password_logged_out) + 1; // Include null terminator
-    if (storage_file_write(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, login_password_logged_out, password_out_length) != password_out_length)
-    {
+    if(storage_file_write(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, login_password_logged_out, password_out_length) !=
+           password_out_length) {
         FURI_LOG_E(TAG, "Failed to write login_password_logged_out");
     }
 
     // Save the change_password_logged_in length and data
-    size_t change_password_length = strlen(change_password_logged_in) + 1; // Include null terminator
-    if (storage_file_write(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, change_password_logged_in, change_password_length) != change_password_length)
-    {
+    size_t change_password_length =
+        strlen(change_password_logged_in) + 1; // Include null terminator
+    if(storage_file_write(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, change_password_logged_in, change_password_length) !=
+           change_password_length) {
         FURI_LOG_E(TAG, "Failed to write change_password_logged_in");
     }
 
     // Save the is_logged_in length and data
     size_t is_logged_in_length = strlen(is_logged_in) + 1; // Include null terminator
-    if (storage_file_write(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, is_logged_in, is_logged_in_length) != is_logged_in_length)
-    {
+    if(storage_file_write(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, is_logged_in, is_logged_in_length) != is_logged_in_length) {
         FURI_LOG_E(TAG, "Failed to write is_logged_in");
     }
 
@@ -233,26 +222,24 @@ static void save_settings(
 }
 
 static bool load_settings(
-    char *ssid,
+    char* ssid,
     size_t ssid_size,
-    char *password,
+    char* password,
     size_t password_size,
-    char *login_username_logged_out,
+    char* login_username_logged_out,
     size_t username_out_size,
-    char *login_username_logged_in,
+    char* login_username_logged_in,
     size_t username_in_size,
-    char *login_password_logged_out,
+    char* login_password_logged_out,
     size_t password_out_size,
-    char *change_password_logged_in,
+    char* change_password_logged_in,
     size_t change_password_size,
-    char *is_logged_in,
-    size_t is_logged_in_size)
-{
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
+    char* is_logged_in,
+    size_t is_logged_in_size) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
 
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -261,113 +248,102 @@ static bool load_settings(
 
     // Load the ssid
     size_t ssid_length;
-    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
-        storage_file_read(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       ssid_length > ssid_size || storage_file_read(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to read SSID");
         storage_file_close(file);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
         return false;
-    }
-    else
-    {
+    } else {
         ssid[ssid_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the password
     size_t password_length;
-    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
-        storage_file_read(file, password, password_length) != password_length)
-    {
+    if(storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_length > password_size ||
+       storage_file_read(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to read password");
         storage_file_close(file);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
         return false;
-    }
-    else
-    {
+    } else {
         password[password_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the login_username_logged_out
     size_t username_out_length;
-    if (storage_file_read(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) || username_out_length > username_out_size ||
-        storage_file_read(file, login_username_logged_out, username_out_length) != username_out_length)
-    {
+    if(storage_file_read(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) ||
+       username_out_length > username_out_size ||
+       storage_file_read(file, login_username_logged_out, username_out_length) !=
+           username_out_length) {
         FURI_LOG_E(TAG, "Failed to read login_username_logged_out");
         // storage_file_close(file);
         // storage_file_free(file);
         // furi_record_close(RECORD_STORAGE);
         // return false;
-    }
-    else
-    {
+    } else {
         login_username_logged_out[username_out_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the login_username_logged_in
     size_t username_in_length;
-    if (storage_file_read(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) || username_in_length > username_in_size ||
-        storage_file_read(file, login_username_logged_in, username_in_length) != username_in_length)
-    {
+    if(storage_file_read(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) ||
+       username_in_length > username_in_size ||
+       storage_file_read(file, login_username_logged_in, username_in_length) !=
+           username_in_length) {
         FURI_LOG_E(TAG, "Failed to read login_username_logged_in");
         // storage_file_close(file);
         // storage_file_free(file);
         // furi_record_close(RECORD_STORAGE);
         // return false;
-    }
-    else
-    {
+    } else {
         login_username_logged_in[username_in_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the login_password_logged_out
     size_t password_out_length;
-    if (storage_file_read(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) || password_out_length > password_out_size ||
-        storage_file_read(file, login_password_logged_out, password_out_length) != password_out_length)
-    {
+    if(storage_file_read(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_out_length > password_out_size ||
+       storage_file_read(file, login_password_logged_out, password_out_length) !=
+           password_out_length) {
         FURI_LOG_E(TAG, "Failed to read login_password_logged_out");
         // storage_file_close(file);
         // storage_file_free(file);
         // furi_record_close(RECORD_STORAGE);
         // return false;
-    }
-    else
-    {
+    } else {
         login_password_logged_out[password_out_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the change_password_logged_in
     size_t change_password_length;
-    if (storage_file_read(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) || change_password_length > change_password_size ||
-        storage_file_read(file, change_password_logged_in, change_password_length) != change_password_length)
-    {
+    if(storage_file_read(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) ||
+       change_password_length > change_password_size ||
+       storage_file_read(file, change_password_logged_in, change_password_length) !=
+           change_password_length) {
         FURI_LOG_E(TAG, "Failed to read change_password_logged_in");
         // storage_file_close(file);
         // storage_file_free(file);
         // furi_record_close(RECORD_STORAGE);
         //  return false;
-    }
-    else
-    {
+    } else {
         change_password_logged_in[change_password_length - 1] = '\0'; // Ensure null-termination
     }
 
     // Load the is_logged_in
     size_t is_logged_in_length;
-    if (storage_file_read(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) || is_logged_in_length > is_logged_in_size ||
-        storage_file_read(file, is_logged_in, is_logged_in_length) != is_logged_in_length)
-    {
+    if(storage_file_read(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) ||
+       is_logged_in_length > is_logged_in_size ||
+       storage_file_read(file, is_logged_in, is_logged_in_length) != is_logged_in_length) {
         FURI_LOG_E(TAG, "Failed to read is_logged_in");
         // storage_file_close(file);
         // storage_file_free(file);
         // furi_record_close(RECORD_STORAGE);
         //  return false;
-    }
-    else
-    {
+    } else {
         is_logged_in[is_logged_in_length - 1] = '\0'; // Ensure null-termination
     }
 

Разница между файлами не показана из-за своего большого размера
+ 269 - 343
flip_social/flipper_http.h


+ 531 - 614
flip_social/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
+            }
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -540,326 +495,288 @@ extern "C"
 #include <furi.h>
 
 // Helper function to create a JSON object
-char *jsmn(const char *key, const char *value)
-{
-  int length = strlen(key) + strlen(value) + 8;         // Calculate required length
-  char *result = (char *)malloc(length * sizeof(char)); // Allocate memory
-  if (result == NULL)
-  {
-    return NULL; // Handle memory allocation failure
-  }
-  snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
-  return result; // Caller is responsible for freeing this memory
+char* jsmn(const char* key, const char* value) {
+    int length = strlen(key) + strlen(value) + 8; // Calculate required length
+    char* result = (char*)malloc(length * sizeof(char)); // Allocate memory
+    if(result == NULL) {
+        return NULL; // Handle memory allocation failure
+    }
+    snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
+    return result; // Caller is responsible for freeing this memory
 }
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_social/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

+ 4 - 7
flip_store/app.c

@@ -5,21 +5,18 @@
 #include <flip_store_free.h>
 
 // Entry point for the Hello World application
-int32_t main_flip_store(void *p)
-{
+int32_t main_flip_store(void* p) {
     // Suppress unused parameter warning
     UNUSED(p);
 
     // Initialize the Hello World application
-    FlipStoreApp *app = flip_store_app_alloc();
-    if (!app)
-    {
+    FlipStoreApp* app = flip_store_app_alloc();
+    if(!app) {
         FURI_LOG_E(TAG, "Failed to allocate FlipStoreApp");
         return -1;
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 142 - 200
flip_store/easy_flipper.h

@@ -26,11 +26,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -44,16 +42,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -72,39 +67,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -118,22 +106,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -150,29 +134,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -189,24 +168,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -223,29 +198,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -264,33 +234,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -303,38 +270,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -349,40 +316,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -406,63 +374,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -486,48 +443,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -543,24 +492,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -573,16 +518,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -590,4 +532,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

+ 166 - 224
flip_store/flip_store_apps.h

@@ -3,17 +3,16 @@
 
 // Define maximum limits
 #define MAX_APP_NAME_LENGTH 32
-#define MAX_ID_LENGTH 32
-#define MAX_APP_COUNT 100
+#define MAX_ID_LENGTH       32
+#define MAX_APP_COUNT       100
 
-typedef struct
-{
+typedef struct {
     char app_name[MAX_APP_NAME_LENGTH];
     char app_id[MAX_APP_NAME_LENGTH];
     char app_build_id[MAX_ID_LENGTH];
 } FlipStoreAppInfo;
 
-static FlipStoreAppInfo *flip_catalog = NULL;
+static FlipStoreAppInfo* flip_catalog = NULL;
 
 static uint32_t app_selected_index = 0;
 static bool flip_store_sent_request = false;
@@ -22,31 +21,25 @@ static bool flip_store_saved_data = false;
 static bool flip_store_saved_success = false;
 static uint32_t flip_store_category_index = 0;
 
-enum ObjectState
-{
+enum ObjectState {
     OBJECT_EXPECT_KEY,
     OBJECT_EXPECT_COLON,
     OBJECT_EXPECT_VALUE,
     OBJECT_EXPECT_COMMA_OR_END
 };
 
-static void flip_catalog_free()
-{
-    if (flip_catalog)
-    {
+static void flip_catalog_free() {
+    if(flip_catalog) {
         free(flip_catalog);
         flip_catalog = NULL;
     }
 }
 
-static bool flip_catalog_alloc()
-{
-    if (!flip_catalog)
-    {
-        flip_catalog = (FlipStoreAppInfo *)malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
+static bool flip_catalog_alloc() {
+    if(!flip_catalog) {
+        flip_catalog = (FlipStoreAppInfo*)malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
     }
-    if (!flip_catalog)
-    {
+    if(!flip_catalog) {
         FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
         return false;
     }
@@ -54,23 +47,20 @@ static bool flip_catalog_alloc()
 }
 
 // Utility function to parse JSON incrementally from a file
-static bool flip_store_process_app_list(const char *file_path)
-{
-    if (file_path == NULL)
-    {
+static bool flip_store_process_app_list(const char* file_path) {
+    if(file_path == NULL) {
         FURI_LOG_E(TAG, "JSON file path is NULL.");
         return false;
     }
 
     // initialize the flip_catalog
-    if (!flip_catalog_alloc())
-    {
+    if(!flip_catalog_alloc()) {
         FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
         return false;
     }
 
-    Storage *_storage = NULL;
-    File *_file = NULL;
+    Storage* _storage = NULL;
+    File* _file = NULL;
     char buffer[BUFFER_SIZE];
     size_t bytes_read;
     bool in_string = false;
@@ -89,8 +79,7 @@ static bool flip_store_process_app_list(const char *file_path)
     enum ObjectState object_state = OBJECT_EXPECT_KEY; // Initialize object_state
 
     // Initialize parser state
-    enum
-    {
+    enum {
         STATE_SEARCH_APPS_KEY,
         STATE_SEARCH_ARRAY_START,
         STATE_READ_ARRAY_ELEMENTS,
@@ -99,131 +88,106 @@ static bool flip_store_process_app_list(const char *file_path)
 
     // Open storage and file
     _storage = furi_record_open(RECORD_STORAGE);
-    if (!_storage)
-    {
+    if(!_storage) {
         FURI_LOG_E(TAG, "Failed to open storage.");
         return false;
     }
 
     _file = storage_file_alloc(_storage);
-    if (!_file)
-    {
+    if(!_file) {
         FURI_LOG_E(TAG, "Failed to allocate file.");
         furi_record_close(RECORD_STORAGE);
         return false;
     }
 
-    if (!storage_file_open(_file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(_file, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open JSON file for reading.");
         storage_file_free(_file);
         furi_record_close(RECORD_STORAGE);
         return false;
     }
 
-    while ((bytes_read = storage_file_read(_file, buffer, BUFFER_SIZE)) > 0 && state != STATE_DONE)
-    {
-        for (size_t i = 0; i < bytes_read; ++i)
-        {
+    while((bytes_read = storage_file_read(_file, buffer, BUFFER_SIZE)) > 0 &&
+          state != STATE_DONE) {
+        for(size_t i = 0; i < bytes_read; ++i) {
             char c = buffer[i];
 
-            if (is_escaped)
-            {
+            if(is_escaped) {
                 is_escaped = false;
-                if (reading_key)
-                {
-                    if (key_index < MAX_KEY_LENGTH - 1)
-                    {
+                if(reading_key) {
+                    if(key_index < MAX_KEY_LENGTH - 1) {
                         current_key[key_index++] = c;
                     }
-                }
-                else if (reading_value)
-                {
-                    if (value_index < MAX_VALUE_LENGTH - 1)
-                    {
+                } else if(reading_value) {
+                    if(value_index < MAX_VALUE_LENGTH - 1) {
                         current_value[value_index++] = c;
                     }
                 }
                 continue;
             }
 
-            if (c == '\\')
-            {
+            if(c == '\\') {
                 is_escaped = true;
                 continue;
             }
 
-            if (c == '\"')
-            {
+            if(c == '\"') {
                 in_string = !in_string;
 
-                if (in_string)
-                {
+                if(in_string) {
                     // Start of a string
-                    if (!reading_key && !reading_value)
-                    {
-                        if (state == STATE_SEARCH_APPS_KEY)
-                        {
+                    if(!reading_key && !reading_value) {
+                        if(state == STATE_SEARCH_APPS_KEY) {
                             reading_key = true;
                             key_index = 0;
                             current_key[0] = '\0';
-                        }
-                        else if (inside_app_object)
-                        {
-                            if (object_state == OBJECT_EXPECT_KEY)
-                            {
+                        } else if(inside_app_object) {
+                            if(object_state == OBJECT_EXPECT_KEY) {
                                 reading_key = true;
                                 key_index = 0;
                                 current_key[0] = '\0';
-                            }
-                            else if (object_state == OBJECT_EXPECT_VALUE)
-                            {
+                            } else if(object_state == OBJECT_EXPECT_VALUE) {
                                 reading_value = true;
                                 value_index = 0;
                                 current_value[0] = '\0';
                             }
                         }
                     }
-                }
-                else
-                {
+                } else {
                     // End of a string
-                    if (reading_key)
-                    {
+                    if(reading_key) {
                         reading_key = false;
                         current_key[key_index] = '\0';
 
-                        if (state == STATE_SEARCH_APPS_KEY && strcmp(current_key, "apps") == 0)
-                        {
+                        if(state == STATE_SEARCH_APPS_KEY && strcmp(current_key, "apps") == 0) {
                             state = STATE_SEARCH_ARRAY_START;
-                        }
-                        else if (inside_app_object)
-                        {
+                        } else if(inside_app_object) {
                             object_state = OBJECT_EXPECT_COLON;
                         }
-                    }
-                    else if (reading_value)
-                    {
+                    } else if(reading_value) {
                         reading_value = false;
                         current_value[value_index] = '\0';
 
-                        if (inside_app_object)
-                        {
-                            if (strcmp(current_key, "name") == 0)
-                            {
-                                strncpy(flip_catalog[app_count].app_name, current_value, MAX_APP_NAME_LENGTH - 1);
+                        if(inside_app_object) {
+                            if(strcmp(current_key, "name") == 0) {
+                                strncpy(
+                                    flip_catalog[app_count].app_name,
+                                    current_value,
+                                    MAX_APP_NAME_LENGTH - 1);
                                 flip_catalog[app_count].app_name[MAX_APP_NAME_LENGTH - 1] = '\0';
                                 found_name = true;
-                            }
-                            else if (strcmp(current_key, "id") == 0)
-                            {
-                                strncpy(flip_catalog[app_count].app_id, current_value, MAX_APP_NAME_LENGTH - 1);
+                            } else if(strcmp(current_key, "id") == 0) {
+                                strncpy(
+                                    flip_catalog[app_count].app_id,
+                                    current_value,
+                                    MAX_APP_NAME_LENGTH - 1);
                                 flip_catalog[app_count].app_id[MAX_APP_NAME_LENGTH - 1] = '\0';
                                 found_id = true;
-                            }
-                            else if (strcmp(current_key, "build_id") == 0)
-                            {
-                                strncpy(flip_catalog[app_count].app_build_id, current_value, MAX_APP_NAME_LENGTH - 1);
+                            } else if(strcmp(current_key, "build_id") == 0) {
+                                strncpy(
+                                    flip_catalog[app_count].app_build_id,
+                                    current_value,
+                                    MAX_APP_NAME_LENGTH - 1);
                                 flip_catalog[app_count].app_build_id[MAX_ID_LENGTH - 1] = '\0';
                                 found_build_id = true;
                             }
@@ -232,11 +196,9 @@ static bool flip_store_process_app_list(const char *file_path)
                             object_state = OBJECT_EXPECT_COMMA_OR_END;
 
                             // Check if both name and id are found
-                            if (found_name && found_id && found_build_id)
-                            {
+                            if(found_name && found_id && found_build_id) {
                                 app_count++;
-                                if (app_count >= MAX_APP_COUNT)
-                                {
+                                if(app_count >= MAX_APP_COUNT) {
                                     FURI_LOG_I(TAG, "Reached maximum app count.");
                                     state = STATE_DONE;
                                     break;
@@ -253,19 +215,13 @@ static bool flip_store_process_app_list(const char *file_path)
                 continue;
             }
 
-            if (in_string)
-            {
-                if (reading_key)
-                {
-                    if (key_index < MAX_KEY_LENGTH - 1)
-                    {
+            if(in_string) {
+                if(reading_key) {
+                    if(key_index < MAX_KEY_LENGTH - 1) {
                         current_key[key_index++] = c;
                     }
-                }
-                else if (reading_value)
-                {
-                    if (value_index < MAX_VALUE_LENGTH - 1)
-                    {
+                } else if(reading_value) {
+                    if(value_index < MAX_VALUE_LENGTH - 1) {
                         current_value[value_index++] = c;
                     }
                 }
@@ -274,46 +230,32 @@ static bool flip_store_process_app_list(const char *file_path)
 
             // Not inside a string
 
-            if (state == STATE_SEARCH_ARRAY_START)
-            {
-                if (c == '[')
-                {
+            if(state == STATE_SEARCH_ARRAY_START) {
+                if(c == '[') {
                     state = STATE_READ_ARRAY_ELEMENTS;
                 }
                 continue;
             }
 
-            if (state == STATE_READ_ARRAY_ELEMENTS)
-            {
-                if (c == '{')
-                {
+            if(state == STATE_READ_ARRAY_ELEMENTS) {
+                if(c == '{') {
                     inside_app_object = true;
                     found_name = false;
                     found_id = false;
                     found_build_id = false;
                     object_state = OBJECT_EXPECT_KEY;
-                }
-                else if (c == '}')
-                {
+                } else if(c == '}') {
                     inside_app_object = false;
                     object_state = OBJECT_EXPECT_KEY;
-                }
-                else if (c == ']')
-                {
+                } else if(c == ']') {
                     state = STATE_DONE;
                     break;
-                }
-                else if (c == ':')
-                {
-                    if (inside_app_object && object_state == OBJECT_EXPECT_COLON)
-                    {
+                } else if(c == ':') {
+                    if(inside_app_object && object_state == OBJECT_EXPECT_COLON) {
                         object_state = OBJECT_EXPECT_VALUE;
                     }
-                }
-                else if (c == ',')
-                {
-                    if (inside_app_object && object_state == OBJECT_EXPECT_COMMA_OR_END)
-                    {
+                } else if(c == ',') {
+                    if(inside_app_object && object_state == OBJECT_EXPECT_COMMA_OR_END) {
                         object_state = OBJECT_EXPECT_KEY;
                     }
                     // Else, separator between objects or values
@@ -329,106 +271,99 @@ static bool flip_store_process_app_list(const char *file_path)
     storage_file_free(_file);
     furi_record_close(RECORD_STORAGE);
 
-    if (app_count == 0)
-    {
+    if(app_count == 0) {
         FURI_LOG_E(TAG, "No valid apps were parsed.");
         return false;
     }
     return true;
 }
 
-static bool flip_store_get_fap_file(char *build_id, char *target, char *api)
-{
+static bool flip_store_get_fap_file(char* build_id, char* target, char* api) {
     is_compile_app_request = true;
     char url[164];
-    snprintf(url, sizeof(url), "https://catalog.flipperzero.one/api/v0/application/version/%s/build/compatible?target=%s&api=%s", build_id, target, api);
+    snprintf(
+        url,
+        sizeof(url),
+        "https://catalog.flipperzero.one/api/v0/application/version/%s/build/compatible?target=%s&api=%s",
+        build_id,
+        target,
+        api);
     return flipper_http_get_request_bytes(url, jsmn("Content-Type", "application/octet-stream"));
 }
 
-static void flip_store_request_error(Canvas *canvas)
-{
-    if (fhttp.received_data == NULL)
-    {
-        if (fhttp.last_response != NULL)
-        {
-            if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
-            {
+static void flip_store_request_error(Canvas* canvas) {
+    if(fhttp.received_data == NULL) {
+        if(fhttp.last_response != NULL) {
+            if(strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") !=
+               NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
-            {
+            } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else
-            {
+            } else {
                 FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
                 canvas_draw_str(canvas, 0, 42, "Unusual error...");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
             }
-        }
-        else
-        {
+        } else {
             canvas_clear(canvas);
             canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
             canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
-    }
-    else
-    {
+    } else {
         canvas_clear(canvas);
         canvas_draw_str(canvas, 0, 10, "Failed to receive data.");
         canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
     }
 }
 // function to handle the entire installation process "asynchronously"
-static bool flip_store_install_app(Canvas *canvas, char *category)
-{
+static bool flip_store_install_app(Canvas* canvas, char* category) {
     // create /apps/FlipStore directory if it doesn't exist
     char directory_path[128];
     snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps/%s", category);
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Adjusted to access flip_catalog as an array of structures
-    char *app_name = flip_catalog[app_selected_index].app_name;
+    char* app_name = flip_catalog[app_selected_index].app_name;
     char installing_text[128];
     snprintf(installing_text, sizeof(installing_text), "Installing %s", app_name);
     char bin_path[256];
-    snprintf(bin_path, sizeof(bin_path), STORAGE_EXT_PATH_PREFIX "/apps/%s/%s.fap", category, flip_catalog[app_selected_index].app_id);
+    snprintf(
+        bin_path,
+        sizeof(bin_path),
+        STORAGE_EXT_PATH_PREFIX "/apps/%s/%s.fap",
+        category,
+        flip_catalog[app_selected_index].app_id);
     strncpy(fhttp.file_path, bin_path, sizeof(fhttp.file_path) - 1);
     canvas_draw_str(canvas, 0, 10, installing_text);
     canvas_draw_str(canvas, 0, 20, "Sending request..");
-    if (fhttp.state != INACTIVE && flip_store_get_fap_file(flip_catalog[app_selected_index].app_build_id, "f7", "73.0"))
-    {
+    if(fhttp.state != INACTIVE &&
+       flip_store_get_fap_file(flip_catalog[app_selected_index].app_build_id, "f7", "73.0")) {
         canvas_draw_str(canvas, 0, 30, "Request sent.");
         fhttp.state = RECEIVING;
         // furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         canvas_draw_str(canvas, 0, 40, "Receiving...");
-    }
-    else
-    {
+    } else {
         FURI_LOG_E(TAG, "Failed to send the request");
         flip_store_success = false;
         return false;
     }
-    while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
-    {
+    while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
         // Wait for the feed to be received
         furi_delay_ms(10);
     }
     // furi_timer_stop(fhttp.get_timeout_timer);
-    if (fhttp.state == ISSUE || fhttp.received_data == NULL)
-    {
+    if(fhttp.state == ISSUE || fhttp.received_data == NULL) {
         flip_store_request_error(canvas);
         flip_store_success = false;
         return false;
@@ -438,97 +373,104 @@ static bool flip_store_install_app(Canvas *canvas, char *category)
 }
 
 // process the app list and return view
-static int32_t flip_store_handle_app_list(FlipStoreApp *app, int32_t success_view, char *category, Submenu **submenu)
-{
+static int32_t flip_store_handle_app_list(
+    FlipStoreApp* app,
+    int32_t success_view,
+    char* category,
+    Submenu** submenu) {
     // reset the flip_catalog
-    if (flip_catalog)
-    {
+    if(flip_catalog) {
         flip_catalog_free();
     }
 
-    if (!app)
-    {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return FlipStoreViewPopup;
     }
     char url[128];
     is_compile_app_request = false;
     // append the category to the end of the url
-    snprintf(url, sizeof(url), "https://www.flipsocial.net/api/flipper/apps/%s/extended/", category);
+    snprintf(
+        url, sizeof(url), "https://www.flipsocial.net/api/flipper/apps/%s/extended/", category);
     // async call to the app list with timer
-    if (fhttp.state != INACTIVE && flipper_http_get_request_with_headers(url, jsmn("Content-Type", "application/json")))
-    {
+    if(fhttp.state != INACTIVE &&
+       flipper_http_get_request_with_headers(url, jsmn("Content-Type", "application/json"))) {
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-    }
-    else
-    {
+    } else {
         FURI_LOG_E(TAG, "Failed to send the request");
         return FlipStoreViewPopup;
     }
-    while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
-    {
+    while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
         // Wait for the feed to be received
         furi_delay_ms(100);
     }
     furi_timer_stop(fhttp.get_timeout_timer);
-    if (fhttp.state == ISSUE || fhttp.received_data == NULL)
-    {
-        if (fhttp.received_data == NULL)
-        {
+    if(fhttp.state == ISSUE || fhttp.received_data == NULL) {
+        if(fhttp.received_data == NULL) {
             FURI_LOG_E(TAG, "Failed to receive data");
-            if (fhttp.last_response != NULL)
-            {
-                if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
-                {
-                    popup_set_text(app->popup, "[ERROR] WiFi Disconnected.\n\n\nUpdate your WiFi settings.\nPress BACK to return.", 0, 10, AlignLeft, AlignTop);
-                }
-                else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
-                {
-                    popup_set_text(app->popup, "[ERROR] WiFi Disconnected.\n\n\nUpdate your WiFi settings.\nPress BACK to return.", 0, 10, AlignLeft, AlignTop);
-                }
-                else
-                {
+            if(fhttp.last_response != NULL) {
+                if(strstr(
+                       fhttp.last_response,
+                       "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL) {
+                    popup_set_text(
+                        app->popup,
+                        "[ERROR] WiFi Disconnected.\n\n\nUpdate your WiFi settings.\nPress BACK to return.",
+                        0,
+                        10,
+                        AlignLeft,
+                        AlignTop);
+                } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
+                    popup_set_text(
+                        app->popup,
+                        "[ERROR] WiFi Disconnected.\n\n\nUpdate your WiFi settings.\nPress BACK to return.",
+                        0,
+                        10,
+                        AlignLeft,
+                        AlignTop);
+                } else {
                     popup_set_text(app->popup, fhttp.last_response, 0, 10, AlignLeft, AlignTop);
                 }
-            }
-            else
-            {
-                popup_set_text(app->popup, "[ERROR] Unknown Error.\n\n\nUpdate your WiFi settings.\nPress BACK to return.", 0, 10, AlignLeft, AlignTop);
+            } else {
+                popup_set_text(
+                    app->popup,
+                    "[ERROR] Unknown Error.\n\n\nUpdate your WiFi settings.\nPress BACK to return.",
+                    0,
+                    10,
+                    AlignLeft,
+                    AlignTop);
             }
             return FlipStoreViewPopup;
-        }
-        else
-        {
+        } else {
             FURI_LOG_E(TAG, "Failed to receive data");
             popup_set_text(app->popup, "Failed to received data.", 0, 10, AlignLeft, AlignTop);
             return FlipStoreViewPopup;
         }
-    }
-    else
-    {
+    } else {
         // process the app list
-        const char *output_file_path = STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag "/received_data.txt";
-        if (flip_store_process_app_list(output_file_path))
-        {
+        const char* output_file_path = STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag
+                                                               "/received_data.txt";
+        if(flip_store_process_app_list(output_file_path)) {
             submenu_reset(*submenu);
             // add each app name to submenu
-            for (int i = 0; i < MAX_APP_COUNT; i++)
-            {
-                if (strlen(flip_catalog[i].app_name) > 0)
-                {
-                    submenu_add_item(*submenu, flip_catalog[i].app_name, FlipStoreSubmenuIndexStartAppList + i, callback_submenu_choices, app);
+            for(int i = 0; i < MAX_APP_COUNT; i++) {
+                if(strlen(flip_catalog[i].app_name) > 0) {
+                    submenu_add_item(
+                        *submenu,
+                        flip_catalog[i].app_name,
+                        FlipStoreSubmenuIndexStartAppList + i,
+                        callback_submenu_choices,
+                        app);
                 }
             }
             return success_view;
-        }
-        else
-        {
+        } else {
             FURI_LOG_E(TAG, "Failed to process the app list");
-            popup_set_text(app->popup, "Failed to process the app list", 0, 10, AlignLeft, AlignTop);
+            popup_set_text(
+                app->popup, "Failed to process the app list", 0, 10, AlignLeft, AlignTop);
             return FlipStoreViewPopup;
         }
     }
 }
 
-#endif // FLIP_STORE_APPS_H
+#endif // FLIP_STORE_APPS_H

+ 118 - 128
flip_store/flip_store_callback.h

@@ -8,13 +8,11 @@
 #include <flip_store_apps.h>
 
 // Callback for drawing the main screen
-static void flip_store_view_draw_callback_main(Canvas *canvas, void *model)
-{
+static void flip_store_view_draw_callback_main(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_set_font(canvas, FontSecondary);
 
-    if (fhttp.state == INACTIVE)
-    {
+    if(fhttp.state == INACTIVE) {
         canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
         canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
         canvas_draw_str(canvas, 0, 32, "If your board is connected,");
@@ -24,37 +22,27 @@ static void flip_store_view_draw_callback_main(Canvas *canvas, void *model)
         return;
     }
 
-    if (!flip_store_sent_request)
-    {
+    if(!flip_store_sent_request) {
         flip_store_sent_request = true;
 
-        if (!flip_store_install_app(canvas, categories[flip_store_category_index]))
-        {
+        if(!flip_store_install_app(canvas, categories[flip_store_category_index])) {
             canvas_clear(canvas);
             canvas_draw_str(canvas, 0, 10, "Failed to install app.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
-    }
-    else
-    {
-        if (flip_store_success)
-        {
-            if (fhttp.state == RECEIVING)
-            {
+    } else {
+        if(flip_store_success) {
+            if(fhttp.state == RECEIVING) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "Downloading app...");
                 canvas_draw_str(canvas, 0, 60, "Please wait...");
                 return;
-            }
-            else if (fhttp.state == IDLE)
-            {
+            } else if(fhttp.state == IDLE) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "App installed successfully.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
             }
-        }
-        else
-        {
+        } else {
             canvas_clear(canvas);
             canvas_draw_str(canvas, 0, 10, "Failed to install app.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
@@ -62,8 +50,7 @@ static void flip_store_view_draw_callback_main(Canvas *canvas, void *model)
     }
 }
 
-static void flip_store_view_draw_callback_app_list(Canvas *canvas, void *model)
-{
+static void flip_store_view_draw_callback_app_list(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontPrimary);
@@ -77,16 +64,13 @@ static void flip_store_view_draw_callback_app_list(Canvas *canvas, void *model)
     canvas_draw_str_aligned(canvas, 97, 54, AlignLeft, AlignTop, "Install");
 }
 
-static bool flip_store_input_callback(InputEvent *event, void *context)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+static bool flip_store_input_callback(InputEvent* event, void* context) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return false;
     }
-    if (event->type == InputTypeShort)
-    {
+    if(event->type == InputTypeShort) {
         // Future implementation
         // if (event->key == InputKeyLeft)
         //{
@@ -94,17 +78,13 @@ static bool flip_store_input_callback(InputEvent *event, void *context)
         // view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppDelete);
         //    return true;
         //}
-        if (event->key == InputKeyRight)
-        {
+        if(event->key == InputKeyRight) {
             // Right button clicked, download the app
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewMain);
             return true;
         }
-    }
-    else if (event->type == InputTypePress)
-    {
-        if (event->key == InputKeyBack)
-        {
+    } else if(event->type == InputTypePress) {
+        if(event->key == InputKeyBack) {
             // Back button clicked, switch to the previous view.
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
             return true;
@@ -114,36 +94,37 @@ static bool flip_store_input_callback(InputEvent *event, void *context)
     return false;
 }
 
-static void flip_store_text_updated_ssid(void *context)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+static void flip_store_text_updated_ssid(void* context) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_ssid, app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid);
+    strncpy(
+        app->uart_text_input_buffer_ssid,
+        app->uart_text_input_temp_buffer_ssid,
+        app->uart_text_input_buffer_size_ssid);
 
     // Ensure null-termination
     app->uart_text_input_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_ssid)
-    {
-        variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+    if(app->variable_item_ssid) {
+        variable_item_set_current_value_text(
+            app->variable_item_ssid, app->uart_text_input_buffer_ssid);
     }
 
     // save the settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass);
 
     // if SSID and PASS are not empty, connect to the WiFi
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_pass) > 0)
-    {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_pass) > 0) {
         // save wifi settings
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass))
-        {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass)) {
             FURI_LOG_E(TAG, "Failed to save WiFi settings");
         }
     }
@@ -151,36 +132,37 @@ static void flip_store_text_updated_ssid(void *context)
     // switch to the settings view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
 }
-static void flip_store_text_updated_pass(void *context)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+static void flip_store_text_updated_pass(void* context) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_pass, app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass);
+    strncpy(
+        app->uart_text_input_buffer_pass,
+        app->uart_text_input_temp_buffer_pass,
+        app->uart_text_input_buffer_size_pass);
 
     // Ensure null-termination
     app->uart_text_input_buffer_pass[app->uart_text_input_buffer_size_pass - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_pass)
-    {
-        variable_item_set_current_value_text(app->variable_item_pass, app->uart_text_input_buffer_pass);
+    if(app->variable_item_pass) {
+        variable_item_set_current_value_text(
+            app->variable_item_pass, app->uart_text_input_buffer_pass);
     }
 
     // save the settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass);
 
     // if SSID and PASS are not empty, connect to the WiFi
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_pass) > 0)
-    {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_pass) > 0) {
         // save wifi settings
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass))
-        {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_pass)) {
             FURI_LOG_E(TAG, "Failed to save WiFi settings");
         }
     }
@@ -189,10 +171,8 @@ static void flip_store_text_updated_pass(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
 }
 
-static uint32_t callback_to_submenu(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -200,10 +180,8 @@ static uint32_t callback_to_submenu(void *context)
     return FlipStoreViewSubmenu;
 }
 
-static uint32_t callback_to_app_list(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_app_list(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -215,16 +193,13 @@ static uint32_t callback_to_app_list(void *context)
     return FlipStoreViewAppList;
 }
 
-static void settings_item_selected(void *context, uint32_t index)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+static void settings_item_selected(void* context, uint32_t index) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case 0: // Input SSID
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewTextInputSSID);
         break;
@@ -237,16 +212,13 @@ static void settings_item_selected(void *context, uint32_t index)
     }
 }
 
-void dialog_callback(DialogExResult result, void *context)
-{
+void dialog_callback(DialogExResult result, void* context) {
     furi_assert(context);
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (result == DialogExResultLeft) // No
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(result == DialogExResultLeft) // No
     {
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppList);
-    }
-    else if (result == DialogExResultRight)
-    {
+    } else if(result == DialogExResultRight) {
         // delete the app then return to the app list
 
         // pop up a message
@@ -258,11 +230,9 @@ void dialog_callback(DialogExResult result, void *context)
     }
 }
 
-void popup_callback(void *context)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+void popup_callback(void* context) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
@@ -274,11 +244,9 @@ void popup_callback(void *context)
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-static uint32_t callback_exit_app(void *context)
-{
+static uint32_t callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -286,16 +254,13 @@ static uint32_t callback_exit_app(void *context)
     return VIEW_NONE; // Return VIEW_NONE to exit the app
 }
 
-static void callback_submenu_choices(void *context, uint32_t index)
-{
-    FlipStoreApp *app = (FlipStoreApp *)context;
-    if (!app)
-    {
+static void callback_submenu_choices(void* context, uint32_t index) {
+    FlipStoreApp* app = (FlipStoreApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case FlipStoreSubmenuIndexMain:
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewMain);
         break;
@@ -311,79 +276,104 @@ static void callback_submenu_choices(void *context, uint32_t index)
         break;
     case FlipStoreSubmenuIndexAppListBluetooth:
         flip_store_category_index = 0;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListBluetooth, "Bluetooth", &app->submenu_app_list_bluetooth));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListBluetooth, "Bluetooth", &app->submenu_app_list_bluetooth));
         break;
     case FlipStoreSubmenuIndexAppListGames:
         flip_store_category_index = 1;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListGames, "Games", &app->submenu_app_list_games));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListGames, "Games", &app->submenu_app_list_games));
         break;
     case FlipStoreSubmenuIndexAppListGPIO:
         flip_store_category_index = 2;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListGPIO, "GPIO", &app->submenu_app_list_gpio));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListGPIO, "GPIO", &app->submenu_app_list_gpio));
         break;
     case FlipStoreSubmenuIndexAppListInfrared:
         flip_store_category_index = 3;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListInfrared, "Infrared", &app->submenu_app_list_infrared));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListInfrared, "Infrared", &app->submenu_app_list_infrared));
         break;
     case FlipStoreSubmenuIndexAppListiButton:
         flip_store_category_index = 4;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListiButton, "iButton", &app->submenu_app_list_ibutton));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListiButton, "iButton", &app->submenu_app_list_ibutton));
         break;
     case FlipStoreSubmenuIndexAppListMedia:
         flip_store_category_index = 5;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListMedia, "Media", &app->submenu_app_list_media));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListMedia, "Media", &app->submenu_app_list_media));
         break;
     case FlipStoreSubmenuIndexAppListNFC:
         flip_store_category_index = 6;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListNFC, "NFC", &app->submenu_app_list_nfc));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListNFC, "NFC", &app->submenu_app_list_nfc));
         break;
     case FlipStoreSubmenuIndexAppListRFID:
         flip_store_category_index = 7;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListRFID, "RFID", &app->submenu_app_list_rfid));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListRFID, "RFID", &app->submenu_app_list_rfid));
         break;
     case FlipStoreSubmenuIndexAppListSubGHz:
         flip_store_category_index = 8;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListSubGHz, "Sub-GHz", &app->submenu_app_list_subghz));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListSubGHz, "Sub-GHz", &app->submenu_app_list_subghz));
         break;
     case FlipStoreSubmenuIndexAppListTools:
         flip_store_category_index = 9;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListTools, "Tools", &app->submenu_app_list_tools));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListTools, "Tools", &app->submenu_app_list_tools));
         break;
     case FlipStoreSubmenuIndexAppListUSB:
         flip_store_category_index = 10;
-        view_dispatcher_switch_to_view(app->view_dispatcher, flip_store_handle_app_list(app, FlipStoreViewAppListUSB, "USB", &app->submenu_app_list_usb));
+        view_dispatcher_switch_to_view(
+            app->view_dispatcher,
+            flip_store_handle_app_list(
+                app, FlipStoreViewAppListUSB, "USB", &app->submenu_app_list_usb));
         break;
     default:
         // Check if the index is within the app list range
-        if (index >= FlipStoreSubmenuIndexStartAppList && index < FlipStoreSubmenuIndexStartAppList + MAX_APP_COUNT)
-        {
+        if(index >= FlipStoreSubmenuIndexStartAppList &&
+           index < FlipStoreSubmenuIndexStartAppList + MAX_APP_COUNT) {
             // Get the app index
             uint32_t app_index = index - FlipStoreSubmenuIndexStartAppList;
 
             // Check if the app index is valid
-            if ((int)app_index >= 0 && app_index < MAX_APP_COUNT)
-            {
+            if((int)app_index >= 0 && app_index < MAX_APP_COUNT) {
                 // Get the app name
-                char *app_name = flip_catalog[app_index].app_name;
+                char* app_name = flip_catalog[app_index].app_name;
 
                 // Check if the app name is valid
-                if (app_name != NULL && strlen(app_name) > 0)
-                {
+                if(app_name != NULL && strlen(app_name) > 0) {
                     app_selected_index = app_index;
                     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewAppInfo);
-                }
-                else
-                {
+                } else {
                     FURI_LOG_E(TAG, "Invalid app name");
                 }
-            }
-            else
-            {
+            } else {
                 FURI_LOG_E(TAG, "Invalid app index");
             }
-        }
-        else
-        {
+        } else {
             FURI_LOG_E(TAG, "Unknown submenu index");
         }
         break;

+ 57 - 63
flip_store/flip_store_e.h

@@ -15,7 +15,7 @@
 #define TAG "FlipStore"
 
 // define the list of categories
-char *categories[] = {
+char* categories[] = {
     "Bluetooth",
     "Games",
     "GPIO",
@@ -30,8 +30,7 @@ char *categories[] = {
 };
 
 // Define the submenu items for our FlipStore application
-typedef enum
-{
+typedef enum {
     FlipStoreSubmenuIndexMain, // Click to start downloading the selected app
     FlipStoreSubmenuIndexAbout,
     FlipStoreSubmenuIndexSettings,
@@ -53,92 +52,87 @@ typedef enum
 } FlipStoreSubmenuIndex;
 
 // Define a single view for our FlipStore application
-typedef enum
-{
-    FlipStoreViewMain,          // The main screen
-    FlipStoreViewSubmenu,       // The submenu
-    FlipStoreViewAbout,         // The about screen
-    FlipStoreViewSettings,      // The settings screen
+typedef enum {
+    FlipStoreViewMain, // The main screen
+    FlipStoreViewSubmenu, // The submenu
+    FlipStoreViewAbout, // The about screen
+    FlipStoreViewSettings, // The settings screen
     FlipStoreViewTextInputSSID, // The text input screen for SSID
     FlipStoreViewTextInputPass, // The text input screen for password
     //
     FlipStoreViewPopup, // The popup screen
     //
-    FlipStoreViewAppList,     // The app list screen
-    FlipStoreViewAppInfo,     // The app info screen (widget) of the selected app
+    FlipStoreViewAppList, // The app list screen
+    FlipStoreViewAppInfo, // The app info screen (widget) of the selected app
     FlipStoreViewAppDownload, // The app download screen (widget) of the selected app
-    FlipStoreViewAppDelete,   // The app delete screen (DialogEx) of the selected app
+    FlipStoreViewAppDelete, // The app delete screen (DialogEx) of the selected app
     //
     FlipStoreViewAppListBluetooth, // the app list screen for Bluetooth
-    FlipStoreViewAppListGames,     // the app list screen for Games
-    FlipStoreViewAppListGPIO,      // the app list screen for GPIO
-    FlipStoreViewAppListInfrared,  // the app list screen for Infrared
-    FlipStoreViewAppListiButton,   // the app list screen for iButton
-    FlipStoreViewAppListMedia,     // the app list screen for Media
-    FlipStoreViewAppListNFC,       // the app list screen for NFC
-    FlipStoreViewAppListRFID,      // the app list screen for RFID
-    FlipStoreViewAppListSubGHz,    // the app list screen for Sub-GHz
-    FlipStoreViewAppListTools,     // the app list screen for Tools
-    FlipStoreViewAppListUSB,       // the app list screen for USB
+    FlipStoreViewAppListGames, // the app list screen for Games
+    FlipStoreViewAppListGPIO, // the app list screen for GPIO
+    FlipStoreViewAppListInfrared, // the app list screen for Infrared
+    FlipStoreViewAppListiButton, // the app list screen for iButton
+    FlipStoreViewAppListMedia, // the app list screen for Media
+    FlipStoreViewAppListNFC, // the app list screen for NFC
+    FlipStoreViewAppListRFID, // the app list screen for RFID
+    FlipStoreViewAppListSubGHz, // the app list screen for Sub-GHz
+    FlipStoreViewAppListTools, // the app list screen for Tools
+    FlipStoreViewAppListUSB, // the app list screen for USB
 } FlipStoreView;
 
 // Each screen will have its own view
-typedef struct
-{
-    ViewDispatcher *view_dispatcher; // Switches between our views
-    View *view_main;                 // The main screen for downloading apps
-    View *view_app_info;             // The app info screen (view) of the selected app
-    Submenu *submenu;                // The submenu (main)
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    View* view_main; // The main screen for downloading apps
+    View* view_app_info; // The app info screen (view) of the selected app
+    Submenu* submenu; // The submenu (main)
     //
-    Submenu *submenu_app_list; // The submenu (app list) for the selected category
+    Submenu* submenu_app_list; // The submenu (app list) for the selected category
     //
-    Submenu *submenu_app_list_bluetooth; // The submenu (app list) for Bluetooth
-    Submenu *submenu_app_list_games;     // The submenu (app list) for Games
-    Submenu *submenu_app_list_gpio;      // The submenu (app list) for GPIO
-    Submenu *submenu_app_list_infrared;  // The submenu (app list) for Infrared
-    Submenu *submenu_app_list_ibutton;   // The submenu (app list) for iButton
-    Submenu *submenu_app_list_media;     // The submenu (app list) for Media
-    Submenu *submenu_app_list_nfc;       // The submenu (app list) for NFC
-    Submenu *submenu_app_list_rfid;      // The submenu (app list) for RFID
-    Submenu *submenu_app_list_subghz;    // The submenu (app list) for Sub-GHz
-    Submenu *submenu_app_list_tools;     // The submenu (app list) for Tools
-    Submenu *submenu_app_list_usb;       // The submenu (app list) for USB
+    Submenu* submenu_app_list_bluetooth; // The submenu (app list) for Bluetooth
+    Submenu* submenu_app_list_games; // The submenu (app list) for Games
+    Submenu* submenu_app_list_gpio; // The submenu (app list) for GPIO
+    Submenu* submenu_app_list_infrared; // The submenu (app list) for Infrared
+    Submenu* submenu_app_list_ibutton; // The submenu (app list) for iButton
+    Submenu* submenu_app_list_media; // The submenu (app list) for Media
+    Submenu* submenu_app_list_nfc; // The submenu (app list) for NFC
+    Submenu* submenu_app_list_rfid; // The submenu (app list) for RFID
+    Submenu* submenu_app_list_subghz; // The submenu (app list) for Sub-GHz
+    Submenu* submenu_app_list_tools; // The submenu (app list) for Tools
+    Submenu* submenu_app_list_usb; // The submenu (app list) for USB
     //
-    Widget *widget;                       // The widget
-    Popup *popup;                         // The popup
-    DialogEx *dialog_delete;              // The dialog for deleting an app
-    VariableItemList *variable_item_list; // The variable item list (settngs)
-    VariableItem *variable_item_ssid;     // The variable item
-    VariableItem *variable_item_pass;     // The variable item
-    UART_TextInput *uart_text_input_ssid; // The text input
-    UART_TextInput *uart_text_input_pass; // The text input
+    Widget* widget; // The widget
+    Popup* popup; // The popup
+    DialogEx* dialog_delete; // The dialog for deleting an app
+    VariableItemList* variable_item_list; // The variable item list (settngs)
+    VariableItem* variable_item_ssid; // The variable item
+    VariableItem* variable_item_pass; // The variable item
+    UART_TextInput* uart_text_input_ssid; // The text input
+    UART_TextInput* uart_text_input_pass; // The text input
 
-    char *uart_text_input_buffer_ssid;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_ssid;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_ssid; // Buffer for the text input
+    char* uart_text_input_temp_buffer_ssid; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_ssid; // Size of the text input buffer
 
-    char *uart_text_input_buffer_pass;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_pass;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_pass; // Buffer for the text input
+    char* uart_text_input_temp_buffer_pass; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_pass; // Size of the text input buffer
 } FlipStoreApp;
 
 // include strndup (otherwise NULL pointer dereference)
-char *strndup(const char *s, size_t n)
-{
-    char *result;
+char* strndup(const char* s, size_t n) {
+    char* result;
     size_t len = strlen(s);
 
-    if (n < len)
-        len = n;
+    if(n < len) len = n;
 
-    result = (char *)malloc(len + 1);
-    if (!result)
-        return NULL;
+    result = (char*)malloc(len + 1);
+    if(!result) return NULL;
 
     result[len] = '\0';
-    return (char *)memcpy(result, s, len);
+    return (char*)memcpy(result, s, len);
 }
 
-static void callback_submenu_choices(void *context, uint32_t index);
+static void callback_submenu_choices(void* context, uint32_t index);
 
-#endif // FLIP_STORE_E_H
+#endif // FLIP_STORE_E_H

+ 24 - 47
flip_store/flip_store_free.h

@@ -2,129 +2,106 @@
 #define FLIP_STORE_FREE_H
 
 // Function to free the resources used by FlipStoreApp
-static void flip_store_app_free(FlipStoreApp *app)
-{
-    if (!app)
-    {
+static void flip_store_app_free(FlipStoreApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
     }
 
     // Free View(s)
-    if (app->view_main)
-    {
+    if(app->view_main) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewMain);
         view_free(app->view_main);
     }
-    if (app->view_app_info)
-    {
+    if(app->view_app_info) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppInfo);
         view_free(app->view_app_info);
     }
 
     // Free Submenu(s)
-    if (app->submenu)
-    {
+    if(app->submenu) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSubmenu);
         submenu_free(app->submenu);
     }
-    if (app->submenu_app_list)
-    {
+    if(app->submenu_app_list) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppList);
         submenu_free(app->submenu_app_list);
     }
-    if (app->submenu_app_list_bluetooth)
-    {
+    if(app->submenu_app_list_bluetooth) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListBluetooth);
         submenu_free(app->submenu_app_list_bluetooth);
     }
-    if (app->submenu_app_list_games)
-    {
+    if(app->submenu_app_list_games) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListGames);
         submenu_free(app->submenu_app_list_games);
     }
-    if (app->submenu_app_list_gpio)
-    {
+    if(app->submenu_app_list_gpio) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListGPIO);
         submenu_free(app->submenu_app_list_gpio);
     }
-    if (app->submenu_app_list_infrared)
-    {
+    if(app->submenu_app_list_infrared) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListInfrared);
         submenu_free(app->submenu_app_list_infrared);
     }
-    if (app->submenu_app_list_ibutton)
-    {
+    if(app->submenu_app_list_ibutton) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListiButton);
         submenu_free(app->submenu_app_list_ibutton);
     }
-    if (app->submenu_app_list_media)
-    {
+    if(app->submenu_app_list_media) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListMedia);
         submenu_free(app->submenu_app_list_media);
     }
-    if (app->submenu_app_list_nfc)
-    {
+    if(app->submenu_app_list_nfc) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListNFC);
         submenu_free(app->submenu_app_list_nfc);
     }
-    if (app->submenu_app_list_rfid)
-    {
+    if(app->submenu_app_list_rfid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListRFID);
         submenu_free(app->submenu_app_list_rfid);
     }
-    if (app->submenu_app_list_subghz)
-    {
+    if(app->submenu_app_list_subghz) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListSubGHz);
         submenu_free(app->submenu_app_list_subghz);
     }
-    if (app->submenu_app_list_tools)
-    {
+    if(app->submenu_app_list_tools) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListTools);
         submenu_free(app->submenu_app_list_tools);
     }
-    if (app->submenu_app_list_usb)
-    {
+    if(app->submenu_app_list_usb) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppListUSB);
         submenu_free(app->submenu_app_list_usb);
     }
 
     // Free Widget(s)
-    if (app->widget)
-    {
+    if(app->widget) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAbout);
         widget_free(app->widget);
     }
 
     // Free Variable Item List(s)
-    if (app->variable_item_list)
-    {
+    if(app->variable_item_list) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewSettings);
         variable_item_list_free(app->variable_item_list);
     }
 
     // Free Text Input(s)
-    if (app->uart_text_input_ssid)
-    {
+    if(app->uart_text_input_ssid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewTextInputSSID);
         uart_text_input_free(app->uart_text_input_ssid);
     }
-    if (app->uart_text_input_pass)
-    {
+    if(app->uart_text_input_pass) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewTextInputPass);
         uart_text_input_free(app->uart_text_input_pass);
     }
 
     // Free popup
-    if (app->popup)
-    {
+    if(app->popup) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewPopup);
         popup_free(app->popup);
     }
 
     // Free dialog
-    if (app->dialog_delete)
-    {
+    if(app->dialog_delete) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipStoreViewAppDelete);
         dialog_ex_free(app->dialog_delete);
     }
@@ -145,4 +122,4 @@ static void flip_store_app_free(FlipStoreApp *app)
     free(app);
 }
 
-#endif // FLIP_STORE_FREE_H
+#endif // FLIP_STORE_FREE_H

+ 268 - 107
flip_store/flip_store_i.h

@@ -2,14 +2,12 @@
 #define FLIP_STORE_I_H
 
 // Function to allocate resources for the FlipStoreApp
-static FlipStoreApp *flip_store_app_alloc()
-{
-    FlipStoreApp *app = (FlipStoreApp *)malloc(sizeof(FlipStoreApp));
+static FlipStoreApp* flip_store_app_alloc() {
+    FlipStoreApp* app = (FlipStoreApp*)malloc(sizeof(FlipStoreApp));
 
-    Gui *gui = furi_record_open(RECORD_GUI);
+    Gui* gui = furi_record_open(RECORD_GUI);
 
-    if (!flipper_http_init(flipper_http_rx_callback, app))
-    {
+    if(!flipper_http_init(flipper_http_rx_callback, app)) {
         FURI_LOG_E(TAG, "Failed to initialize flipper http");
         return NULL;
     }
@@ -17,184 +15,347 @@ static FlipStoreApp *flip_store_app_alloc()
     // Allocate the text input buffer
     app->uart_text_input_buffer_size_ssid = 64;
     app->uart_text_input_buffer_size_pass = 64;
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass)) {
         return NULL;
     }
 
     // Allocate ViewDispatcher
-    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
-    {
+    if(!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app)) {
         return NULL;
     }
 
     // Main view
-    if (!easy_flipper_set_view(&app->view_main, FlipStoreViewMain, flip_store_view_draw_callback_main, NULL, callback_to_app_list, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_main,
+           FlipStoreViewMain,
+           flip_store_view_draw_callback_main,
+           NULL,
+           callback_to_app_list,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_view(&app->view_app_info, FlipStoreViewAppInfo, flip_store_view_draw_callback_app_list, flip_store_input_callback, callback_to_app_list, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_app_info,
+           FlipStoreViewAppInfo,
+           flip_store_view_draw_callback_app_list,
+           flip_store_input_callback,
+           callback_to_app_list,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Widget
-    if (!easy_flipper_set_widget(
-            &app->widget,
-            FlipStoreViewAbout,
-            "Welcome to the FlipStore!\n------\nDownload apps via WiFi and\nrun them on your Flipper!\n------\nwww.github.com/jblanked",
-            callback_to_submenu,
-            &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget,
+           FlipStoreViewAbout,
+           "Welcome to the FlipStore!\n------\nDownload apps via WiFi and\nrun them on your Flipper!\n------\nwww.github.com/jblanked",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
 
     // Popup
-    if (!easy_flipper_set_popup(&app->popup, FlipStoreViewPopup, "Failed", 0, 0, "You are not connected to Wifi.\n\nIf you have the FlipperHTTP\nflash installed, then update\nyour WiFi credentials.", 0, 10, popup_callback, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_popup(
+           &app->popup,
+           FlipStoreViewPopup,
+           "Failed",
+           0,
+           0,
+           "You are not connected to Wifi.\n\nIf you have the FlipperHTTP\nflash installed, then update\nyour WiFi credentials.",
+           0,
+           10,
+           popup_callback,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         FURI_LOG_E(TAG, "Failed to create popup");
     }
 
     // Dialog
-    if (!easy_flipper_set_dialog_ex(
-            &app->dialog_delete,
-            FlipStoreViewAppDelete,
-            "Delete App",
-            0,
-            0,
-            "Are you sure you want to delete this app?",
-            0,
-            10,
-            "No",
-            "Yes",
-            NULL,
-            dialog_callback,
-            callback_to_app_list,
-            &app->view_dispatcher,
-            app))
-    {
+    if(!easy_flipper_set_dialog_ex(
+           &app->dialog_delete,
+           FlipStoreViewAppDelete,
+           "Delete App",
+           0,
+           0,
+           "Are you sure you want to delete this app?",
+           0,
+           10,
+           "No",
+           "Yes",
+           NULL,
+           dialog_callback,
+           callback_to_app_list,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Text Input
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_ssid, FlipStoreViewTextInputSSID, "Enter SSID", app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid, flip_store_text_updated_ssid, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_ssid,
+           FlipStoreViewTextInputSSID,
+           "Enter SSID",
+           app->uart_text_input_temp_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           flip_store_text_updated_ssid,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_pass, FlipStoreViewTextInputPass, "Enter Password", app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_size_pass, flip_store_text_updated_pass, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_pass,
+           FlipStoreViewTextInputPass,
+           "Enter Password",
+           app->uart_text_input_temp_buffer_pass,
+           app->uart_text_input_buffer_size_pass,
+           flip_store_text_updated_pass,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Variable Item List
-    if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipStoreViewSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_variable_item_list(
+           &app->variable_item_list,
+           FlipStoreViewSettings,
+           settings_item_selected,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    app->variable_item_ssid = variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
-    app->variable_item_pass = variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
+    app->variable_item_ssid =
+        variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
+    app->variable_item_pass =
+        variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
 
     // Submenu
-    if (!easy_flipper_set_submenu(&app->submenu, FlipStoreViewSubmenu, "FlipStore", callback_exit_app, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu,
+           FlipStoreViewSubmenu,
+           "FlipStore",
+           callback_exit_app,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list, FlipStoreViewAppList, "App Catalog", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list,
+           FlipStoreViewAppList,
+           "App Catalog",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_bluetooth, FlipStoreViewAppListBluetooth, "Bluetooth", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_bluetooth,
+           FlipStoreViewAppListBluetooth,
+           "Bluetooth",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_games, FlipStoreViewAppListGames, "Games", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_games,
+           FlipStoreViewAppListGames,
+           "Games",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_gpio, FlipStoreViewAppListGPIO, "GPIO", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_gpio,
+           FlipStoreViewAppListGPIO,
+           "GPIO",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_infrared, FlipStoreViewAppListInfrared, "Infrared", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_infrared,
+           FlipStoreViewAppListInfrared,
+           "Infrared",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_ibutton, FlipStoreViewAppListiButton, "iButton", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_ibutton,
+           FlipStoreViewAppListiButton,
+           "iButton",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_media, FlipStoreViewAppListMedia, "Media", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_media,
+           FlipStoreViewAppListMedia,
+           "Media",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_nfc, FlipStoreViewAppListNFC, "NFC", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_nfc,
+           FlipStoreViewAppListNFC,
+           "NFC",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_rfid, FlipStoreViewAppListRFID, "RFID", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_rfid,
+           FlipStoreViewAppListRFID,
+           "RFID",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_subghz, FlipStoreViewAppListSubGHz, "Sub-GHz", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_subghz,
+           FlipStoreViewAppListSubGHz,
+           "Sub-GHz",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_tools, FlipStoreViewAppListTools, "Tools", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_tools,
+           FlipStoreViewAppListTools,
+           "Tools",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_app_list_usb, FlipStoreViewAppListUSB, "USB", callback_to_app_list, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_app_list_usb,
+           FlipStoreViewAppListUSB,
+           "USB",
+           callback_to_app_list,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    submenu_add_item(app->submenu, "Catalog", FlipStoreSubmenuIndexAppList, callback_submenu_choices, app);
-    submenu_add_item(app->submenu, "About", FlipStoreSubmenuIndexAbout, callback_submenu_choices, app);
-    submenu_add_item(app->submenu, "Settings", FlipStoreSubmenuIndexSettings, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "Catalog", FlipStoreSubmenuIndexAppList, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "About", FlipStoreSubmenuIndexAbout, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "Settings", FlipStoreSubmenuIndexSettings, callback_submenu_choices, app);
     //
-    submenu_add_item(app->submenu_app_list, "Bluetooth", FlipStoreSubmenuIndexAppListBluetooth, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "Games", FlipStoreSubmenuIndexAppListGames, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "GPIO", FlipStoreSubmenuIndexAppListGPIO, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "Infrared", FlipStoreSubmenuIndexAppListInfrared, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "iButton", FlipStoreSubmenuIndexAppListiButton, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "Media", FlipStoreSubmenuIndexAppListMedia, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "NFC", FlipStoreSubmenuIndexAppListNFC, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "RFID", FlipStoreSubmenuIndexAppListRFID, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "Sub-GHz", FlipStoreSubmenuIndexAppListSubGHz, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "Tools", FlipStoreSubmenuIndexAppListTools, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_app_list, "USB", FlipStoreSubmenuIndexAppListUSB, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Bluetooth",
+        FlipStoreSubmenuIndexAppListBluetooth,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Games",
+        FlipStoreSubmenuIndexAppListGames,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "GPIO",
+        FlipStoreSubmenuIndexAppListGPIO,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Infrared",
+        FlipStoreSubmenuIndexAppListInfrared,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "iButton",
+        FlipStoreSubmenuIndexAppListiButton,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Media",
+        FlipStoreSubmenuIndexAppListMedia,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "NFC",
+        FlipStoreSubmenuIndexAppListNFC,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "RFID",
+        FlipStoreSubmenuIndexAppListRFID,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Sub-GHz",
+        FlipStoreSubmenuIndexAppListSubGHz,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "Tools",
+        FlipStoreSubmenuIndexAppListTools,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_app_list,
+        "USB",
+        FlipStoreSubmenuIndexAppListUSB,
+        callback_submenu_choices,
+        app);
     //
     // dont add any items to the app list submenu of each category yet
 
     // load settings
-    if (load_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid, app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass))
-    {
+    if(load_settings(
+           app->uart_text_input_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           app->uart_text_input_buffer_pass,
+           app->uart_text_input_buffer_size_pass)) {
         // Update variable items
-        if (app->variable_item_ssid)
-            variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+        if(app->variable_item_ssid)
+            variable_item_set_current_value_text(
+                app->variable_item_ssid, app->uart_text_input_buffer_ssid);
         // do not display the password
 
         // Copy items into their temp buffers with safety checks
-        if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
-        {
-            strncpy(app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid - 1);
-            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
+        if(app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid) {
+            strncpy(
+                app->uart_text_input_temp_buffer_ssid,
+                app->uart_text_input_buffer_ssid,
+                app->uart_text_input_buffer_size_ssid - 1);
+            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] =
+                '\0';
         }
-        if (app->uart_text_input_buffer_pass && app->uart_text_input_temp_buffer_pass)
-        {
-            strncpy(app->uart_text_input_temp_buffer_pass, app->uart_text_input_buffer_pass, app->uart_text_input_buffer_size_pass - 1);
-            app->uart_text_input_temp_buffer_pass[app->uart_text_input_buffer_size_pass - 1] = '\0';
+        if(app->uart_text_input_buffer_pass && app->uart_text_input_temp_buffer_pass) {
+            strncpy(
+                app->uart_text_input_temp_buffer_pass,
+                app->uart_text_input_buffer_pass,
+                app->uart_text_input_buffer_size_pass - 1);
+            app->uart_text_input_temp_buffer_pass[app->uart_text_input_buffer_size_pass - 1] =
+                '\0';
         }
     }
 
@@ -204,4 +365,4 @@ static FlipStoreApp *flip_store_app_alloc()
     return app;
 }
 
-#endif // FLIP_STORE_I_H
+#endif // FLIP_STORE_I_H

+ 72 - 114
flip_store/flip_store_storage.h

@@ -6,22 +6,19 @@
 
 #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/settings.bin"
 
-static void save_settings(
-    const char *ssid,
-    const char *password)
-{
+static void save_settings(const char* ssid, const char* password) {
     // Create the directory for saving settings
     char directory_path[128];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -30,17 +27,15 @@ static void save_settings(
 
     // Save the ssid length and data
     size_t ssid_length = strlen(ssid) + 1; // Include null terminator
-    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to write SSID");
     }
 
     // Save the password length and data
     size_t password_length = strlen(password) + 1; // Include null terminator
-    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, password, password_length) != password_length)
-    {
+    if(storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to write password");
     }
 
@@ -49,17 +44,11 @@ static void save_settings(
     furi_record_close(RECORD_STORAGE);
 }
 
-static bool load_settings(
-    char *ssid,
-    size_t ssid_size,
-    char *password,
-    size_t password_size)
-{
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
-
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+static bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
+
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -68,9 +57,8 @@ static bool load_settings(
 
     // Load the ssid
     size_t ssid_length;
-    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
-        storage_file_read(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       ssid_length > ssid_size || storage_file_read(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to read SSID");
         storage_file_close(file);
         storage_file_free(file);
@@ -81,9 +69,9 @@ static bool load_settings(
 
     // Load the password
     size_t password_length;
-    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
-        storage_file_read(file, password, password_length) != password_length)
-    {
+    if(storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_length > password_size ||
+       storage_file_read(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to read password");
         storage_file_close(file);
         storage_file_free(file);
@@ -100,16 +88,19 @@ static bool load_settings(
 }
 
 // future implenetation because we need the app category
-bool delete_app(const char *app_id, const char *app_category)
-{
+bool delete_app(const char* app_id, const char* app_category) {
     // Create the directory for saving settings
     char directory_path[128];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps/%s/%s", app_category, app_id);
+    snprintf(
+        directory_path,
+        sizeof(directory_path),
+        STORAGE_EXT_PATH_PREFIX "/apps/%s/%s",
+        app_category,
+        app_id);
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    if (!storage_simply_remove_recursive(storage, directory_path))
-    {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(!storage_simply_remove_recursive(storage, directory_path)) {
         FURI_LOG_E(TAG, "Failed to delete app: %s", app_id);
         furi_record_close(RECORD_STORAGE);
         return false;
@@ -119,15 +110,18 @@ bool delete_app(const char *app_id, const char *app_category)
     return true;
 }
 
-#define BUFFER_SIZE 64
-#define MAX_KEY_LENGTH 32
+#define BUFFER_SIZE      64
+#define MAX_KEY_LENGTH   32
 #define MAX_VALUE_LENGTH 64
 
 // Function to parse JSON incrementally from a file
-bool parse_json_incrementally(const char *file_path, const char *target_key, char *value_buffer, size_t value_buffer_size)
-{
-    Storage *_storage = NULL;
-    File *_file = NULL;
+bool parse_json_incrementally(
+    const char* file_path,
+    const char* target_key,
+    char* value_buffer,
+    size_t value_buffer_size) {
+    Storage* _storage = NULL;
+    File* _file = NULL;
     char buffer[BUFFER_SIZE];
     size_t bytes_read;
     bool key_found = false;
@@ -141,93 +135,71 @@ bool parse_json_incrementally(const char *file_path, const char *target_key, cha
 
     // Open storage and file
     _storage = furi_record_open(RECORD_STORAGE);
-    if (!_storage)
-    {
+    if(!_storage) {
         FURI_LOG_E("JSON_PARSE", "Failed to open storage.");
         return false;
     }
 
     _file = storage_file_alloc(_storage);
-    if (!_file)
-    {
+    if(!_file) {
         FURI_LOG_E("JSON_PARSE", "Failed to allocate file.");
         furi_record_close(RECORD_STORAGE);
         return false;
     }
 
-    if (!storage_file_open(_file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(_file, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E("JSON_PARSE", "Failed to open JSON file for reading.");
         goto cleanup;
     }
 
-    while ((bytes_read = storage_file_read(_file, buffer, BUFFER_SIZE)) > 0)
-    {
-        for (size_t i = 0; i < bytes_read; ++i)
-        {
+    while((bytes_read = storage_file_read(_file, buffer, BUFFER_SIZE)) > 0) {
+        for(size_t i = 0; i < bytes_read; ++i) {
             char c = buffer[i];
 
-            if (is_escaped)
-            {
+            if(is_escaped) {
                 is_escaped = false;
-                if (reading_key)
-                {
-                    if (key_index < MAX_KEY_LENGTH - 1)
-                    {
+                if(reading_key) {
+                    if(key_index < MAX_KEY_LENGTH - 1) {
                         current_key[key_index++] = c;
                     }
-                }
-                else if (reading_value)
-                {
-                    if (value_index < value_buffer_size - 1)
-                    {
+                } else if(reading_value) {
+                    if(value_index < value_buffer_size - 1) {
                         value_buffer[value_index++] = c;
                     }
                 }
                 continue;
             }
 
-            if (c == '\\')
-            {
+            if(c == '\\') {
                 is_escaped = true;
                 continue;
             }
 
-            if (c == '\"')
-            {
+            if(c == '\"') {
                 in_string = !in_string;
 
-                if (in_string)
-                {
+                if(in_string) {
                     // Start of a string
-                    if (!reading_key && !reading_value)
-                    {
+                    if(!reading_key && !reading_value) {
                         // Possible start of a key
                         reading_key = true;
                         key_index = 0;
                         current_key[0] = '\0';
                     }
-                }
-                else
-                {
+                } else {
                     // End of a string
-                    if (reading_key)
-                    {
+                    if(reading_key) {
                         reading_key = false;
                         current_key[key_index] = '\0';
 
-                        if (strcmp(current_key, target_key) == 0)
-                        {
+                        if(strcmp(current_key, target_key) == 0) {
                             key_found = true;
                         }
-                    }
-                    else if (reading_value)
-                    {
+                    } else if(reading_value) {
                         reading_value = false;
                         value_buffer[value_index] = '\0';
 
-                        if (key_found)
-                        {
+                        if(key_found) {
                             // Found the target value
                             goto success;
                         }
@@ -236,43 +208,33 @@ bool parse_json_incrementally(const char *file_path, const char *target_key, cha
                 continue;
             }
 
-            if (in_string)
-            {
-                if (reading_key)
-                {
-                    if (key_index < MAX_KEY_LENGTH - 1)
-                    {
+            if(in_string) {
+                if(reading_key) {
+                    if(key_index < MAX_KEY_LENGTH - 1) {
                         current_key[key_index++] = c;
                     }
-                }
-                else if (reading_value)
-                {
-                    if (value_index < value_buffer_size - 1)
-                    {
+                } else if(reading_value) {
+                    if(value_index < value_buffer_size - 1) {
                         value_buffer[value_index++] = c;
                     }
                 }
                 continue;
             }
 
-            if (c == ':' && key_found && !reading_value)
-            {
+            if(c == ':' && key_found && !reading_value) {
                 // After colon, start reading the value
                 // Skip whitespace and possible opening quote
-                while (i + 1 < bytes_read && (buffer[i + 1] == ' ' || buffer[i + 1] == '\n' || buffer[i + 1] == '\r'))
-                {
+                while(i + 1 < bytes_read &&
+                      (buffer[i + 1] == ' ' || buffer[i + 1] == '\n' || buffer[i + 1] == '\r')) {
                     i++;
                 }
 
-                if (i + 1 < bytes_read && buffer[i + 1] == '\"')
-                {
+                if(i + 1 < bytes_read && buffer[i + 1] == '\"') {
                     i++; // Move to the quote
                     in_string = true;
                     reading_value = true;
                     value_index = 0;
-                }
-                else
-                {
+                } else {
                     // Handle non-string values (e.g., numbers, booleans)
                     reading_value = true;
                     value_index = 0;
@@ -280,14 +242,12 @@ bool parse_json_incrementally(const char *file_path, const char *target_key, cha
                 continue;
             }
 
-            if (reading_value && (c == ',' || c == '}' || c == ']'))
-            {
+            if(reading_value && (c == ',' || c == '}' || c == ']')) {
                 // End of the value
                 reading_value = false;
                 value_buffer[value_index] = '\0';
 
-                if (key_found)
-                {
+                if(key_found) {
                     // Found the target value
                     goto success;
                 }
@@ -303,15 +263,13 @@ success:
     return key_found;
 
 cleanup:
-    if (_file)
-    {
+    if(_file) {
         storage_file_free(_file);
     }
-    if (_storage)
-    {
+    if(_storage) {
         furi_record_close(RECORD_STORAGE);
     }
     return false;
 }
 
-#endif
+#endif

Разница между файлами не показана из-за своего большого размера
+ 256 - 311
flip_store/flipper_http.h


+ 531 - 614
flip_store/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
+            }
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -538,326 +493,288 @@ extern "C"
 #include <furi.h>
 
 // Helper function to create a JSON object
-char *jsmn(const char *key, const char *value)
-{
-  int length = strlen(key) + strlen(value) + 8;         // Calculate required length
-  char *result = (char *)malloc(length * sizeof(char)); // Allocate memory
-  if (result == NULL)
-  {
-    return NULL; // Handle memory allocation failure
-  }
-  snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
-  return result; // Caller is responsible for freeing this memory
+char* jsmn(const char* key, const char* value) {
+    int length = strlen(key) + strlen(value) + 8; // Calculate required length
+    char* result = (char*)malloc(length * sizeof(char)); // Allocate memory
+    if(result == NULL) {
+        return NULL; // Handle memory allocation failure
+    }
+    snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
+    return result; // Caller is responsible for freeing this memory
 }
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_store/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

+ 4 - 7
flip_trader/app.c

@@ -5,21 +5,18 @@
 #include "flip_trader_free.h"
 
 // Entry point for the FlipTrader application
-int32_t flip_trader_app(void *p)
-{
+int32_t flip_trader_app(void* p) {
     // Suppress unused parameter warning
     UNUSED(p);
 
     // Initialize the FlipTrader application
-    FlipTraderApp *app = flip_trader_app_alloc();
-    if (!app)
-    {
+    FlipTraderApp* app = flip_trader_app_alloc();
+    if(!app) {
         FURI_LOG_E(TAG, "Failed to allocate FlipTraderApp");
         return -1;
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 1 - 1
flip_trader/application.fam

@@ -10,5 +10,5 @@ App(
     fap_description="Use WiFi to get the price of stocks and currency pairs on your Flipper Zero.",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipTrader",
-    fap_version = "1.1",
+    fap_version="1.1",
 )

+ 142 - 200
flip_trader/easy_flipper.h

@@ -26,11 +26,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -44,16 +42,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -72,39 +67,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -118,22 +106,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -150,29 +134,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -189,24 +168,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -223,29 +198,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -264,33 +234,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -303,38 +270,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -349,40 +316,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -406,63 +374,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -486,48 +443,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -543,24 +492,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -573,16 +518,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -590,4 +532,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

+ 81 - 119
flip_trader/flip_trader_callback.h

@@ -9,67 +9,56 @@ static bool sent_get_request = false;
 static bool get_request_success = false;
 static bool request_processed = false;
 
-void flip_trader_request_error(Canvas *canvas)
-{
-    if (fhttp.received_data == NULL)
-    {
-        if (fhttp.last_response != NULL)
-        {
-            if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
-            {
+void flip_trader_request_error(Canvas* canvas) {
+    if(fhttp.received_data == NULL) {
+        if(fhttp.last_response != NULL) {
+            if(strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") !=
+               NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
-            {
+            } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else if (strstr(fhttp.last_response, "[ERROR] WiFi SSID or Password is empty") != NULL)
-            {
+            } else if(strstr(fhttp.last_response, "[ERROR] WiFi SSID or Password is empty") != NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else
-            {
+            } else {
                 canvas_clear(canvas);
                 FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
                 canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
             }
-        }
-        else
-        {
+        } else {
             canvas_clear(canvas);
             canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
             canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
-    }
-    else
-    {
+    } else {
         canvas_clear(canvas);
         canvas_draw_str(canvas, 0, 10, "Failed to receive data.");
         canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
     }
 }
 
-static bool send_price_request()
-{
-    if (!sent_get_request && fhttp.state == IDLE)
-    {
+static bool send_price_request() {
+    if(!sent_get_request && fhttp.state == IDLE) {
         sent_get_request = true;
         char url[128] = {0};
-        snprintf(url, 128, "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=%s&apikey=2X90WLEFMP43OJKE", asset_names[asset_index]);
-        get_request_success = flipper_http_get_request_with_headers(url, "{\"Content-Type\": \"application/json\"}");
-        if (!get_request_success)
-        {
+        snprintf(
+            url,
+            128,
+            "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=%s&apikey=2X90WLEFMP43OJKE",
+            asset_names[asset_index]);
+        get_request_success =
+            flipper_http_get_request_with_headers(url, "{\"Content-Type\": \"application/json\"}");
+        if(!get_request_success) {
             FURI_LOG_E(TAG, "Failed to send GET request");
             return false;
         }
@@ -78,20 +67,16 @@ static bool send_price_request()
     return true;
 }
 
-static void process_asset_price()
-{
-    if (!request_processed && fhttp.received_data != NULL)
-    {
+static void process_asset_price() {
+    if(!request_processed && fhttp.received_data != NULL) {
         request_processed = true;
-        char *global_quote = get_json_value("Global Quote", fhttp.received_data, MAX_TOKENS);
-        if (global_quote == NULL)
-        {
+        char* global_quote = get_json_value("Global Quote", fhttp.received_data, MAX_TOKENS);
+        if(global_quote == NULL) {
             FURI_LOG_E(TAG, "Failed to get Global Quote");
             return;
         }
-        char *price = get_json_value("05. price", global_quote, MAX_TOKENS);
-        if (price == NULL)
-        {
+        char* price = get_json_value("05. price", global_quote, MAX_TOKENS);
+        if(price == NULL) {
             FURI_LOG_E(TAG, "Failed to get price");
             return;
         }
@@ -99,9 +84,7 @@ static void process_asset_price()
         snprintf(asset_price, 64, "%s: $%s", asset_names[asset_index], price);
 
         fhttp.state = IDLE;
-    }
-    else if (!request_processed && fhttp.received_data == NULL)
-    {
+    } else if(!request_processed && fhttp.received_data == NULL) {
         request_processed = true;
         // store an error message instead of the price
         snprintf(asset_price, 64, "Failed. Update WiFi settings.");
@@ -110,18 +93,15 @@ static void process_asset_price()
 }
 
 // Callback for drawing the main screen
-static void flip_trader_view_draw_callback(Canvas *canvas, void *model)
-{
-    if (!canvas)
-    {
+static void flip_trader_view_draw_callback(Canvas* canvas, void* model) {
+    if(!canvas) {
         return;
     }
     UNUSED(model);
 
     canvas_set_font(canvas, FontSecondary);
 
-    if (fhttp.state == INACTIVE)
-    {
+    if(fhttp.state == INACTIVE) {
         canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
         canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
         canvas_draw_str(canvas, 0, 32, "If your board is connected,");
@@ -135,18 +115,15 @@ static void flip_trader_view_draw_callback(Canvas *canvas, void *model)
     // canvas_draw_str(canvas, 0, 10, asset_names[asset_index]);
 
     // start the process
-    if (!send_price_request())
-    {
+    if(!send_price_request()) {
         flip_trader_request_error(canvas);
     }
     // wait until the request is processed
-    if (!sent_get_request || !get_request_success || fhttp.state == RECEIVING)
-    {
+    if(!sent_get_request || !get_request_success || fhttp.state == RECEIVING) {
         return;
     }
     // check status
-    if (fhttp.state == ISSUE || fhttp.received_data == NULL)
-    {
+    if(fhttp.state == ISSUE || fhttp.received_data == NULL) {
         flip_trader_request_error(canvas);
     }
     // success, process the data
@@ -156,11 +133,9 @@ static void flip_trader_view_draw_callback(Canvas *canvas, void *model)
 }
 
 // Input callback for the view (async input handling)
-bool flip_trader_view_input_callback(InputEvent *event, void *context)
-{
-    FlipTraderApp *app = (FlipTraderApp *)context;
-    if (event->type == InputTypePress && event->key == InputKeyBack)
-    {
+bool flip_trader_view_input_callback(InputEvent* event, void* context) {
+    FlipTraderApp* app = (FlipTraderApp*)context;
+    if(event->type == InputTypePress && event->key == InputKeyBack) {
         // Exit the app when the back button is pressed
         view_dispatcher_stop(app->view_dispatcher);
         return true;
@@ -168,16 +143,13 @@ bool flip_trader_view_input_callback(InputEvent *event, void *context)
     return false;
 }
 
-static void callback_submenu_choices(void *context, uint32_t index)
-{
-    FlipTraderApp *app = (FlipTraderApp *)context;
-    if (!app)
-    {
+static void callback_submenu_choices(void* context, uint32_t index) {
+    FlipTraderApp* app = (FlipTraderApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipTraderApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     // view the assets submenu
     case FlipTradeSubmenuIndexAssets:
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipTraderViewAssetsSubmenu);
@@ -192,48 +164,46 @@ static void callback_submenu_choices(void *context, uint32_t index)
         break;
     default:
         // handle FlipTraderSubmenuIndexAssetStartIndex + index
-        if (index >= FlipTraderSubmenuIndexAssetStartIndex)
-        {
+        if(index >= FlipTraderSubmenuIndexAssetStartIndex) {
             asset_index = index - FlipTraderSubmenuIndexAssetStartIndex;
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipTraderViewMain);
-        }
-        else
-        {
+        } else {
             FURI_LOG_E(TAG, "Unknown submenu index");
         }
         break;
     }
 }
 
-static void text_updated_ssid(void *context)
-{
-    FlipTraderApp *app = (FlipTraderApp *)context;
-    if (!app)
-    {
+static void text_updated_ssid(void* context) {
+    FlipTraderApp* app = (FlipTraderApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipTraderApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_ssid, app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid);
+    strncpy(
+        app->uart_text_input_buffer_ssid,
+        app->uart_text_input_temp_buffer_ssid,
+        app->uart_text_input_buffer_size_ssid);
 
     // Ensure null-termination
     app->uart_text_input_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_ssid)
-    {
-        variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+    if(app->variable_item_ssid) {
+        variable_item_set_current_value_text(
+            app->variable_item_ssid, app->uart_text_input_buffer_ssid);
     }
 
     // save settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
 
     // save wifi settings to devboard
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
-    {
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
-        {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_password) > 0) {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password)) {
             FURI_LOG_E(TAG, "Failed to save wifi settings");
         }
     }
@@ -242,35 +212,36 @@ static void text_updated_ssid(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipTraderViewWiFiSettings);
 }
 
-static void text_updated_password(void *context)
-{
-    FlipTraderApp *app = (FlipTraderApp *)context;
-    if (!app)
-    {
+static void text_updated_password(void* context) {
+    FlipTraderApp* app = (FlipTraderApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipTraderApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_password, app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password);
+    strncpy(
+        app->uart_text_input_buffer_password,
+        app->uart_text_input_temp_buffer_password,
+        app->uart_text_input_buffer_size_password);
 
     // Ensure null-termination
     app->uart_text_input_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_password)
-    {
-        variable_item_set_current_value_text(app->variable_item_password, app->uart_text_input_buffer_password);
+    if(app->variable_item_password) {
+        variable_item_set_current_value_text(
+            app->variable_item_password, app->uart_text_input_buffer_password);
     }
 
     // save settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
 
     // save wifi settings to devboard
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
-    {
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
-        {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_password) > 0) {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password)) {
             FURI_LOG_E(TAG, "Failed to save wifi settings");
         }
     }
@@ -279,10 +250,8 @@ static void text_updated_password(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipTraderViewWiFiSettings);
 }
 
-static uint32_t callback_to_submenu(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -294,10 +263,8 @@ static uint32_t callback_to_submenu(void *context)
     return FlipTraderViewMainSubmenu;
 }
 
-static uint32_t callback_to_wifi_settings(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_wifi_settings(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -305,10 +272,8 @@ static uint32_t callback_to_wifi_settings(void *context)
     return FlipTraderViewWiFiSettings;
 }
 
-static uint32_t callback_to_assets_submenu(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_assets_submenu(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -320,16 +285,13 @@ static uint32_t callback_to_assets_submenu(void *context)
     return FlipTraderViewAssetsSubmenu;
 }
 
-static void settings_item_selected(void *context, uint32_t index)
-{
-    FlipTraderApp *app = (FlipTraderApp *)context;
-    if (!app)
-    {
+static void settings_item_selected(void* context, uint32_t index) {
+    FlipTraderApp* app = (FlipTraderApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipTraderApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case 0: // Input SSID
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipTraderViewTextInputSSID);
         break;
@@ -342,4 +304,4 @@ static void settings_item_selected(void *context, uint32_t index)
     }
 }
 
-#endif // FLIP_TRADER_CALLBACK_H
+#endif // FLIP_TRADER_CALLBACK_H

+ 28 - 31
flip_trader/flip_trader_e.h

@@ -16,54 +16,51 @@
 #define TAG "FlipTrader"
 
 // Define the submenu items for our FlipTrader application
-typedef enum
-{
+typedef enum {
     // FlipTraderSubmenuIndexMain,     // Click to run get the info of the selected pair
-    FlipTradeSubmenuIndexAssets,           // Click to view the assets screen (ETHUSD, BTCUSD, etc.)
-    FlipTraderSubmenuIndexAbout,           // Click to view the about screen
-    FlipTraderSubmenuIndexSettings,        // Click to view the WiFi settings screen
-                                           //
+    FlipTradeSubmenuIndexAssets, // Click to view the assets screen (ETHUSD, BTCUSD, etc.)
+    FlipTraderSubmenuIndexAbout, // Click to view the about screen
+    FlipTraderSubmenuIndexSettings, // Click to view the WiFi settings screen
+        //
     FlipTraderSubmenuIndexAssetStartIndex, // Start of the submenu items for the assets
 } FlipTraderSubmenuIndex;
 
 // Define a single view for our FlipTrader application
-typedef enum
-{
-    FlipTraderViewMain,              // The screen that displays the info of the selected pair
-    FlipTraderViewMainSubmenu,       // The main submenu of the FlipTrader app
-    FlipTraderViewAbout,             // The about screen
-    FlipTraderViewWiFiSettings,      // The WiFi settings screen
-    FlipTraderViewTextInputSSID,     // The text input screen for the SSID
+typedef enum {
+    FlipTraderViewMain, // The screen that displays the info of the selected pair
+    FlipTraderViewMainSubmenu, // The main submenu of the FlipTrader app
+    FlipTraderViewAbout, // The about screen
+    FlipTraderViewWiFiSettings, // The WiFi settings screen
+    FlipTraderViewTextInputSSID, // The text input screen for the SSID
     FlipTraderViewTextInputPassword, // The text input screen for the password
     //
     FlipTraderViewAssetsSubmenu, // The submenu for the assets
 } FlipTraderView;
 
 // Each screen will have its own view
-typedef struct
-{
-    ViewDispatcher *view_dispatcher;           // Switches between our views
-    View *view_main;                           // The main screen that displays "Hello, World!"
-    Submenu *submenu_main;                     // The submenu
-    Submenu *submenu_assets;                   // The submenu for the assets
-    Widget *widget;                            // The widget
-    VariableItemList *variable_item_list_wifi; // The variable item list (settngs)
-    VariableItem *variable_item_ssid;          // The variable item for the SSID
-    VariableItem *variable_item_password;      // The variable item for the password
-    UART_TextInput *uart_text_input_ssid;      // The text input for the SSID
-    UART_TextInput *uart_text_input_password;  // The text input for the password
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    View* view_main; // The main screen that displays "Hello, World!"
+    Submenu* submenu_main; // The submenu
+    Submenu* submenu_assets; // The submenu for the assets
+    Widget* widget; // The widget
+    VariableItemList* variable_item_list_wifi; // The variable item list (settngs)
+    VariableItem* variable_item_ssid; // The variable item for the SSID
+    VariableItem* variable_item_password; // The variable item for the password
+    UART_TextInput* uart_text_input_ssid; // The text input for the SSID
+    UART_TextInput* uart_text_input_password; // The text input for the password
 
-    char *uart_text_input_buffer_ssid;         // Buffer for the text input (SSID)
-    char *uart_text_input_temp_buffer_ssid;    // Temporary buffer for the text input (SSID)
+    char* uart_text_input_buffer_ssid; // Buffer for the text input (SSID)
+    char* uart_text_input_temp_buffer_ssid; // Temporary buffer for the text input (SSID)
     uint32_t uart_text_input_buffer_size_ssid; // Size of the text input buffer (SSID)
 
-    char *uart_text_input_buffer_password;         // Buffer for the text input (password)
-    char *uart_text_input_temp_buffer_password;    // Temporary buffer for the text input (password)
+    char* uart_text_input_buffer_password; // Buffer for the text input (password)
+    char* uart_text_input_temp_buffer_password; // Temporary buffer for the text input (password)
     uint32_t uart_text_input_buffer_size_password; // Size of the text input buffer (password)
 
 } FlipTraderApp;
 
-static char *asset_names[] = {
+static char* asset_names[] = {
     // Crypto pairs
     "ETHUSD",
     "BTCUSD",
@@ -112,4 +109,4 @@ static char *asset_names[] = {
 // index
 static uint32_t asset_index = 0;
 
-#endif // FLIP_TRADE_E_H
+#endif // FLIP_TRADE_E_H

+ 11 - 21
flip_trader/flip_trader_free.h

@@ -2,60 +2,50 @@
 #define FLIP_TRADER_FREE_H
 
 // Function to free the resources used by FlipTraderApp
-static void flip_trader_app_free(FlipTraderApp *app)
-{
-    if (!app)
-    {
+static void flip_trader_app_free(FlipTraderApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipTraderApp is NULL");
         return;
     }
 
-    if (!flipper_http_disconnect_wifi())
-    {
+    if(!flipper_http_disconnect_wifi()) {
         FURI_LOG_E(TAG, "Failed to disconnect from wifi");
     }
 
     // Free View(s)
-    if (app->view_main)
-    {
+    if(app->view_main) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewMain);
         view_free(app->view_main);
     }
 
     // Free Submenu(s)
-    if (app->submenu_main)
-    {
+    if(app->submenu_main) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewMainSubmenu);
         submenu_free(app->submenu_main);
     }
-    if (app->submenu_assets)
-    {
+    if(app->submenu_assets) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAssetsSubmenu);
         submenu_free(app->submenu_assets);
     }
 
     // Free Widget(s)
-    if (app->widget)
-    {
+    if(app->widget) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAbout);
         widget_free(app->widget);
     }
 
     // Free Variable Item List(s)
-    if (app->variable_item_list_wifi)
-    {
+    if(app->variable_item_list_wifi) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewWiFiSettings);
         variable_item_list_free(app->variable_item_list_wifi);
     }
 
     // Free Text Input(s)
-    if (app->uart_text_input_ssid)
-    {
+    if(app->uart_text_input_ssid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputSSID);
         uart_text_input_free(app->uart_text_input_ssid);
     }
-    if (app->uart_text_input_password)
-    {
+    if(app->uart_text_input_password) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputPassword);
         uart_text_input_free(app->uart_text_input_password);
     }
@@ -73,4 +63,4 @@ static void flip_trader_app_free(FlipTraderApp *app)
     free(app);
 }
 
-#endif // FLIP_TRADER_FREE_H
+#endif // FLIP_TRADER_FREE_H

+ 107 - 51
flip_trader/flip_trader_i.h

@@ -2,15 +2,13 @@
 #define FLIP_TRADER_I_H
 
 // Function to allocate resources for the FlipTraderApp
-static FlipTraderApp *flip_trader_app_alloc()
-{
-    FlipTraderApp *app = (FlipTraderApp *)malloc(sizeof(FlipTraderApp));
+static FlipTraderApp* flip_trader_app_alloc() {
+    FlipTraderApp* app = (FlipTraderApp*)malloc(sizeof(FlipTraderApp));
 
-    Gui *gui = furi_record_open(RECORD_GUI);
+    Gui* gui = furi_record_open(RECORD_GUI);
 
     // initialize uart
-    if (!flipper_http_init(flipper_http_rx_callback, app))
-    {
+    if(!flipper_http_init(flipper_http_rx_callback, app)) {
         FURI_LOG_E(TAG, "Failed to initialize flipper http");
         return NULL;
     }
@@ -18,97 +16,155 @@ static FlipTraderApp *flip_trader_app_alloc()
     // Allocate the text input buffer
     app->uart_text_input_buffer_size_ssid = 64;
     app->uart_text_input_buffer_size_password = 64;
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
 
     // Allocate ViewDispatcher
-    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
-    {
+    if(!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app)) {
         return NULL;
     }
 
     // Main view
-    if (!easy_flipper_set_view(&app->view_main, FlipTraderViewMain, flip_trader_view_draw_callback, NULL, callback_to_assets_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_main,
+           FlipTraderViewMain,
+           flip_trader_view_draw_callback,
+           NULL,
+           callback_to_assets_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Widget
-    if (!easy_flipper_set_widget(&app->widget, FlipTraderViewAbout, "FlipTrader v1.1\n-----\nUse WiFi to get the price of\nstocks and currency pairs.\n-----\nwww.github.com/jblanked", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget,
+           FlipTraderViewAbout,
+           "FlipTrader v1.1\n-----\nUse WiFi to get the price of\nstocks and currency pairs.\n-----\nwww.github.com/jblanked",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
 
     // Text Input
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_ssid, FlipTraderViewTextInputSSID, "Enter SSID", app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid, text_updated_ssid, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_ssid,
+           FlipTraderViewTextInputSSID,
+           "Enter SSID",
+           app->uart_text_input_temp_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           text_updated_ssid,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_password, FlipTraderViewTextInputPassword, "Enter password", app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password, text_updated_password, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_password,
+           FlipTraderViewTextInputPassword,
+           "Enter password",
+           app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password,
+           text_updated_password,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Variable Item List
-    if (!easy_flipper_set_variable_item_list(&app->variable_item_list_wifi, FlipTraderViewWiFiSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_variable_item_list(
+           &app->variable_item_list_wifi,
+           FlipTraderViewWiFiSettings,
+           settings_item_selected,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    app->variable_item_ssid = variable_item_list_add(app->variable_item_list_wifi, "SSID", 0, NULL, NULL);
-    app->variable_item_password = variable_item_list_add(app->variable_item_list_wifi, "Password", 0, NULL, NULL);
+    app->variable_item_ssid =
+        variable_item_list_add(app->variable_item_list_wifi, "SSID", 0, NULL, NULL);
+    app->variable_item_password =
+        variable_item_list_add(app->variable_item_list_wifi, "Password", 0, NULL, NULL);
     variable_item_set_current_value_text(app->variable_item_ssid, "");
     variable_item_set_current_value_text(app->variable_item_password, "");
 
     // Submenu
-    if (!easy_flipper_set_submenu(&app->submenu_main, FlipTraderViewMainSubmenu, "FlipTrader v1.1", easy_flipper_callback_exit_app, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_main,
+           FlipTraderViewMainSubmenu,
+           "FlipTrader v1.1",
+           easy_flipper_callback_exit_app,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    if (!easy_flipper_set_submenu(&app->submenu_assets, FlipTraderViewAssetsSubmenu, "Assets", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu_assets,
+           FlipTraderViewAssetsSubmenu,
+           "Assets",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    submenu_add_item(app->submenu_main, "Assets", FlipTradeSubmenuIndexAssets, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "About", FlipTraderSubmenuIndexAbout, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "WiFi", FlipTraderSubmenuIndexSettings, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_main, "Assets", FlipTradeSubmenuIndexAssets, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_main, "About", FlipTraderSubmenuIndexAbout, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_main, "WiFi", FlipTraderSubmenuIndexSettings, callback_submenu_choices, app);
     // add the assets
-    for (uint32_t i = 0; i < sizeof(asset_names) / sizeof(asset_names[0]); i++)
-    {
-        submenu_add_item(app->submenu_assets, asset_names[i], FlipTraderSubmenuIndexAssetStartIndex + i, callback_submenu_choices, app);
+    for(uint32_t i = 0; i < sizeof(asset_names) / sizeof(asset_names[0]); i++) {
+        submenu_add_item(
+            app->submenu_assets,
+            asset_names[i],
+            FlipTraderSubmenuIndexAssetStartIndex + i,
+            callback_submenu_choices,
+            app);
     }
 
     // load settings
-    if (load_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(load_settings(
+           app->uart_text_input_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           app->uart_text_input_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         // Update variable items
-        if (app->variable_item_ssid)
-            variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+        if(app->variable_item_ssid)
+            variable_item_set_current_value_text(
+                app->variable_item_ssid, app->uart_text_input_buffer_ssid);
         // dont show password
 
         // Copy items into their temp buffers with safety checks
-        if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
-        {
-            strncpy(app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid - 1);
-            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
+        if(app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid) {
+            strncpy(
+                app->uart_text_input_temp_buffer_ssid,
+                app->uart_text_input_buffer_ssid,
+                app->uart_text_input_buffer_size_ssid - 1);
+            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] =
+                '\0';
         }
-        if (app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password)
-        {
-            strncpy(app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password - 1);
-            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
+        if(app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password) {
+            strncpy(
+                app->uart_text_input_temp_buffer_password,
+                app->uart_text_input_buffer_password,
+                app->uart_text_input_buffer_size_password - 1);
+            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] =
+                '\0';
         }
     }
 
@@ -118,4 +174,4 @@ static FlipTraderApp *flip_trader_app_alloc()
     return app;
 }
 
-#endif // FLIP_TRADER_I_H
+#endif // FLIP_TRADER_I_H

+ 20 - 32
flip_trader/flip_trader_storage.h

@@ -6,22 +6,19 @@
 
 #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_trader/settings.bin"
 
-static void save_settings(
-    const char *ssid,
-    const char *password)
-{
+static void save_settings(const char* ssid, const char* password) {
     // Create the directory for saving settings
     char directory_path[256];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_trader");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_trader");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -30,17 +27,15 @@ static void save_settings(
 
     // Save the ssid length and data
     size_t ssid_length = strlen(ssid) + 1; // Include null terminator
-    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to write SSID");
     }
 
     // Save the password length and data
     size_t password_length = strlen(password) + 1; // Include null terminator
-    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, password, password_length) != password_length)
-    {
+    if(storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to write password");
     }
 
@@ -49,17 +44,11 @@ static void save_settings(
     furi_record_close(RECORD_STORAGE);
 }
 
-static bool load_settings(
-    char *ssid,
-    size_t ssid_size,
-    char *password,
-    size_t password_size)
-{
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
+static bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
 
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -68,9 +57,8 @@ static bool load_settings(
 
     // Load the ssid
     size_t ssid_length;
-    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
-        storage_file_read(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       ssid_length > ssid_size || storage_file_read(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to read SSID");
         storage_file_close(file);
         storage_file_free(file);
@@ -81,9 +69,9 @@ static bool load_settings(
 
     // Load the password
     size_t password_length;
-    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
-        storage_file_read(file, password, password_length) != password_length)
-    {
+    if(storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_length > password_size ||
+       storage_file_read(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to read password");
         storage_file_close(file);
         storage_file_free(file);
@@ -99,4 +87,4 @@ static bool load_settings(
     return true;
 }
 
-#endif // FLIP_TRADER_STORAGE_H
+#endif // FLIP_TRADER_STORAGE_H

Разница между файлами не показана из-за своего большого размера
+ 251 - 299
flip_trader/flipper_http.h


+ 523 - 604
flip_trader/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
+            }
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -538,313 +493,277 @@ extern "C"
 #include <furi.h>
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_trader/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

+ 4 - 7
flip_weather/app.c

@@ -6,21 +6,18 @@
 #include <flip_weather_free.h>
 
 // Entry point for the FlipWeather application
-int32_t flip_weather_app(void *p)
-{
+int32_t flip_weather_app(void* p) {
     // Suppress unused parameter warning
     UNUSED(p);
 
     // Initialize the FlipWeather application
-    FlipWeatherApp *app = flip_weather_app_alloc();
-    if (!app)
-    {
+    FlipWeatherApp* app = flip_weather_app_alloc();
+    if(!app) {
         FURI_LOG_E(TAG, "Failed to allocate FlipWeatherApp");
         return -1;
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 1 - 1
flip_weather/application.fam

@@ -10,5 +10,5 @@ App(
     fap_description="Use WiFi to get GPS and Weather information on your Flipper Zero.",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipWeather",
-    fap_version = "1.1",
+    fap_version="1.1",
 )

+ 142 - 200
flip_weather/easy_flipper.h

@@ -26,11 +26,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -44,16 +42,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -72,39 +67,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -118,22 +106,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -150,29 +134,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -189,24 +168,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -223,29 +198,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -264,33 +234,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -303,38 +270,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -349,40 +316,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -406,63 +374,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -486,48 +443,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -543,24 +492,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -573,16 +518,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -590,4 +532,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

+ 87 - 130
flip_weather/flip_weather_callback.h

@@ -5,75 +5,56 @@ static bool weather_request_success = false;
 static bool sent_weather_request = false;
 static bool got_weather_data = false;
 
-void flip_weather_request_error(Canvas *canvas)
-{
-    if (fhttp.last_response == NULL)
-    {
-        if (fhttp.last_response != NULL)
-        {
-            if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
-            {
+void flip_weather_request_error(Canvas* canvas) {
+    if(fhttp.last_response == NULL) {
+        if(fhttp.last_response != NULL) {
+            if(strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") !=
+               NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
-            {
+            } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
                 canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
                 canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-            else
-            {
+            } else {
                 canvas_clear(canvas);
                 FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
                 canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
                 canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
             }
-        }
-        else
-        {
+        } else {
             canvas_clear(canvas);
             canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
             canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
-    }
-    else
-    {
+    } else {
         canvas_clear(canvas);
         canvas_draw_str(canvas, 0, 10, "Failed to receive data.");
         canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
     }
 }
 
-static void flip_weather_handle_gps_draw(Canvas *canvas, bool show_gps_data)
-{
-    if (sent_get_request)
-    {
-        if (fhttp.state == RECEIVING)
-        {
-            if (show_gps_data)
-            {
+static void flip_weather_handle_gps_draw(Canvas* canvas, bool show_gps_data) {
+    if(sent_get_request) {
+        if(fhttp.state == RECEIVING) {
+            if(show_gps_data) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, "Loading GPS...");
                 canvas_draw_str(canvas, 0, 22, "Receiving...");
             }
         }
         // check status
-        else if (fhttp.state == ISSUE || !get_request_success || fhttp.last_response == NULL)
-        {
+        else if(fhttp.state == ISSUE || !get_request_success || fhttp.last_response == NULL) {
             flip_weather_request_error(canvas);
-        }
-        else if (fhttp.state == IDLE && fhttp.last_response != NULL)
-        {
+        } else if(fhttp.state == IDLE && fhttp.last_response != NULL) {
             // success, draw GPS
             process_geo_location();
 
-            if (show_gps_data)
-            {
+            if(show_gps_data) {
                 canvas_clear(canvas);
                 canvas_draw_str(canvas, 0, 10, city_data);
                 canvas_draw_str(canvas, 0, 20, region_data);
@@ -87,18 +68,15 @@ static void flip_weather_handle_gps_draw(Canvas *canvas, bool show_gps_data)
 }
 
 // Callback for drawing the weather screen
-static void flip_weather_view_draw_callback_weather(Canvas *canvas, void *model)
-{
-    if (!canvas)
-    {
+static void flip_weather_view_draw_callback_weather(Canvas* canvas, void* model) {
+    if(!canvas) {
         return;
     }
     UNUSED(model);
 
     canvas_set_font(canvas, FontSecondary);
 
-    if (fhttp.state == INACTIVE)
-    {
+    if(fhttp.state == INACTIVE) {
         canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
         canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
         canvas_draw_str(canvas, 0, 32, "If your board is connected,");
@@ -112,51 +90,46 @@ static void flip_weather_view_draw_callback_weather(Canvas *canvas, void *model)
     // handle geo location until it's processed and then handle weather
 
     // start the process
-    if (!send_geo_location_request())
-    {
+    if(!send_geo_location_request()) {
         flip_weather_request_error(canvas);
     }
     // wait until geo location is processed
-    if (!sent_get_request || !get_request_success || fhttp.state == RECEIVING)
-    {
+    if(!sent_get_request || !get_request_success || fhttp.state == RECEIVING) {
         return;
     }
     // get/set geo lcoation once
-    if (!geo_information_processed)
-    {
+    if(!geo_information_processed) {
         flip_weather_handle_gps_draw(canvas, false);
     }
     // start the weather process
-    if (!sent_weather_request && fhttp.state == IDLE)
-    {
+    if(!sent_weather_request && fhttp.state == IDLE) {
         sent_weather_request = true;
         char url[512];
-        char *lattitude = lat_data + 10;
-        char *longitude = lon_data + 11;
-        snprintf(url, 512, "https://api.open-meteo.com/v1/forecast?latitude=%s&longitude=%s&current=temperature_2m,precipitation,rain,showers,snowfall&temperature_unit=celsius&wind_speed_unit=mph&precipitation_unit=inch&forecast_days=1", lattitude, longitude);
-        weather_request_success = flipper_http_get_request_with_headers(url, "{\"Content-Type\": \"application/json\"}");
-        if (!weather_request_success)
-        {
+        char* lattitude = lat_data + 10;
+        char* longitude = lon_data + 11;
+        snprintf(
+            url,
+            512,
+            "https://api.open-meteo.com/v1/forecast?latitude=%s&longitude=%s&current=temperature_2m,precipitation,rain,showers,snowfall&temperature_unit=celsius&wind_speed_unit=mph&precipitation_unit=inch&forecast_days=1",
+            lattitude,
+            longitude);
+        weather_request_success =
+            flipper_http_get_request_with_headers(url, "{\"Content-Type\": \"application/json\"}");
+        if(!weather_request_success) {
             FURI_LOG_E(TAG, "Failed to send GET request");
             flip_weather_request_error(canvas);
         }
         fhttp.state = RECEIVING;
-    }
-    else
-    {
-        if (fhttp.state == RECEIVING)
-        {
+    } else {
+        if(fhttp.state == RECEIVING) {
             canvas_draw_str(canvas, 0, 10, "Loading Weather...");
             canvas_draw_str(canvas, 0, 22, "Receiving...");
             return;
         }
         // check status
-        else if (fhttp.state == ISSUE || !weather_request_success || fhttp.last_response == NULL)
-        {
+        else if(fhttp.state == ISSUE || !weather_request_success || fhttp.last_response == NULL) {
             flip_weather_request_error(canvas);
-        }
-        else
-        {
+        } else {
             // success, draw weather
             process_weather();
             canvas_clear(canvas);
@@ -171,16 +144,13 @@ static void flip_weather_view_draw_callback_weather(Canvas *canvas, void *model)
 }
 
 // Callback for drawing the GPS screen
-static void flip_weather_view_draw_callback_gps(Canvas *canvas, void *model)
-{
-    if (!canvas)
-    {
+static void flip_weather_view_draw_callback_gps(Canvas* canvas, void* model) {
+    if(!canvas) {
         return;
     }
     UNUSED(model);
 
-    if (fhttp.state == INACTIVE)
-    {
+    if(fhttp.state == INACTIVE) {
         canvas_set_font(canvas, FontSecondary);
         canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
         canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
@@ -191,34 +161,28 @@ static void flip_weather_view_draw_callback_gps(Canvas *canvas, void *model)
         return;
     }
 
-    if (!send_geo_location_request())
-    {
+    if(!send_geo_location_request()) {
         flip_weather_request_error(canvas);
     }
 
     flip_weather_handle_gps_draw(canvas, true);
 }
 
-static void callback_submenu_choices(void *context, uint32_t index)
-{
-    FlipWeatherApp *app = (FlipWeatherApp *)context;
-    if (!app)
-    {
+static void callback_submenu_choices(void* context, uint32_t index) {
+    FlipWeatherApp* app = (FlipWeatherApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case FlipWeatherSubmenuIndexWeather:
-        if (!flip_weather_handle_ip_address())
-        {
+        if(!flip_weather_handle_ip_address()) {
             return;
         }
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewWeather);
         break;
     case FlipWeatherSubmenuIndexGPS:
-        if (!flip_weather_handle_ip_address())
-        {
+        if(!flip_weather_handle_ip_address()) {
             return;
         }
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewGPS);
@@ -234,35 +198,36 @@ static void callback_submenu_choices(void *context, uint32_t index)
     }
 }
 
-static void text_updated_ssid(void *context)
-{
-    FlipWeatherApp *app = (FlipWeatherApp *)context;
-    if (!app)
-    {
+static void text_updated_ssid(void* context) {
+    FlipWeatherApp* app = (FlipWeatherApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_ssid, app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid);
+    strncpy(
+        app->uart_text_input_buffer_ssid,
+        app->uart_text_input_temp_buffer_ssid,
+        app->uart_text_input_buffer_size_ssid);
 
     // Ensure null-termination
     app->uart_text_input_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_ssid)
-    {
-        variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+    if(app->variable_item_ssid) {
+        variable_item_set_current_value_text(
+            app->variable_item_ssid, app->uart_text_input_buffer_ssid);
     }
 
     // save settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
 
     // save wifi settings to devboard
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
-    {
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
-        {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_password) > 0) {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password)) {
             FURI_LOG_E(TAG, "Failed to save wifi settings");
         }
     }
@@ -271,35 +236,36 @@ static void text_updated_ssid(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewSettings);
 }
 
-static void text_updated_password(void *context)
-{
-    FlipWeatherApp *app = (FlipWeatherApp *)context;
-    if (!app)
-    {
+static void text_updated_password(void* context) {
+    FlipWeatherApp* app = (FlipWeatherApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_password, app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password);
+    strncpy(
+        app->uart_text_input_buffer_password,
+        app->uart_text_input_temp_buffer_password,
+        app->uart_text_input_buffer_size_password);
 
     // Ensure null-termination
     app->uart_text_input_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
 
     // update the variable item text
-    if (app->variable_item_password)
-    {
-        variable_item_set_current_value_text(app->variable_item_password, app->uart_text_input_buffer_password);
+    if(app->variable_item_password) {
+        variable_item_set_current_value_text(
+            app->variable_item_password, app->uart_text_input_buffer_password);
     }
 
     // save settings
     save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
 
     // save wifi settings to devboard
-    if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
-    {
-        if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
-        {
+    if(strlen(app->uart_text_input_buffer_ssid) > 0 &&
+       strlen(app->uart_text_input_buffer_password) > 0) {
+        if(!flipper_http_save_wifi(
+               app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password)) {
             FURI_LOG_E(TAG, "Failed to save wifi settings");
         }
     }
@@ -308,10 +274,8 @@ static void text_updated_password(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewSettings);
 }
 
-static uint32_t callback_to_submenu(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -327,16 +291,13 @@ static uint32_t callback_to_submenu(void *context)
     return FlipWeatherViewSubmenu;
 }
 
-static void settings_item_selected(void *context, uint32_t index)
-{
-    FlipWeatherApp *app = (FlipWeatherApp *)context;
-    if (!app)
-    {
+static void settings_item_selected(void* context, uint32_t index) {
+    FlipWeatherApp* app = (FlipWeatherApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case 0: // Input SSID
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewTextInputSSID);
         break;
@@ -354,11 +315,9 @@ static void settings_item_selected(void *context, uint32_t index)
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-static uint32_t callback_exit_app(void *context)
-{
+static uint32_t callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -366,10 +325,8 @@ static uint32_t callback_exit_app(void *context)
     return VIEW_NONE; // Return VIEW_NONE to exit the app
 }
 
-static uint32_t callback_to_wifi_settings(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_wifi_settings(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -377,4 +334,4 @@ static uint32_t callback_to_wifi_settings(void *context)
     return FlipWeatherViewSettings;
 }
 
-#endif
+#endif

+ 27 - 30
flip_weather/flip_weather_e.h

@@ -8,46 +8,43 @@
 #define TAG "FlipWeather"
 
 // Define the submenu items for our FlipWeather application
-typedef enum
-{
-    FlipWeatherSubmenuIndexWeather,  // Click to view the weather
-    FlipWeatherSubmenuIndexGPS,      // Click to view the GPS
-    FlipWeatherSubmenuIndexAbout,    // Click to view the about screen
+typedef enum {
+    FlipWeatherSubmenuIndexWeather, // Click to view the weather
+    FlipWeatherSubmenuIndexGPS, // Click to view the GPS
+    FlipWeatherSubmenuIndexAbout, // Click to view the about screen
     FlipWeatherSubmenuIndexSettings, // Click to view the settings screen
 } FlipWeatherSubmenuIndex;
 
 // Define a single view for our FlipWeather application
-typedef enum
-{
-    FlipWeatherViewWeather,           // The weather screen
-    FlipWeatherViewGPS,               // The GPS screen
-    FlipWeatherViewSubmenu,           // The main submenu
-    FlipWeatherViewAbout,             // The about screen
-    FlipWeatherViewSettings,          // The wifi settings screen
-    FlipWeatherViewTextInputSSID,     // The text input screen for SSID
+typedef enum {
+    FlipWeatherViewWeather, // The weather screen
+    FlipWeatherViewGPS, // The GPS screen
+    FlipWeatherViewSubmenu, // The main submenu
+    FlipWeatherViewAbout, // The about screen
+    FlipWeatherViewSettings, // The wifi settings screen
+    FlipWeatherViewTextInputSSID, // The text input screen for SSID
     FlipWeatherViewTextInputPassword, // The text input screen for password
 } FlipWeatherView;
 
 // Each screen will have its own view
-typedef struct
-{
-    ViewDispatcher *view_dispatcher;          // Switches between our views
-    View *view_weather;                       // The weather view
-    View *view_gps;                           // The GPS view
-    Submenu *submenu;                         // The main submenu
-    Widget *widget;                           // The widget (about)
-    VariableItemList *variable_item_list;     // The variable item list (settngs)
-    VariableItem *variable_item_ssid;         // The variable item
-    VariableItem *variable_item_password;     // The variable item
-    UART_TextInput *uart_text_input_ssid;     // The text input
-    UART_TextInput *uart_text_input_password; // The text input
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    View* view_weather; // The weather view
+    View* view_gps; // The GPS view
+    Submenu* submenu; // The main submenu
+    Widget* widget; // The widget (about)
+    VariableItemList* variable_item_list; // The variable item list (settngs)
+    VariableItem* variable_item_ssid; // The variable item
+    VariableItem* variable_item_password; // The variable item
+    UART_TextInput* uart_text_input_ssid; // The text input
+    UART_TextInput* uart_text_input_password; // The text input
 
-    char *uart_text_input_buffer_ssid;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_ssid;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_ssid; // Buffer for the text input
+    char* uart_text_input_temp_buffer_ssid; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_ssid; // Size of the text input buffer
 
-    char *uart_text_input_buffer_password;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_password;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_password; // Buffer for the text input
+    char* uart_text_input_temp_buffer_password; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_password; // Size of the text input buffer
 } FlipWeatherApp;
 
@@ -67,4 +64,4 @@ static char ip_address[16];
 
 #define MAX_TOKENS 64 // Adjust based on expected JSON size (50)
 
-#endif
+#endif

+ 16 - 31
flip_weather/flip_weather_free.h

@@ -2,82 +2,67 @@
 #define FLIP_WEATHER_FREE_H
 
 // Function to free the resources used by FlipWeatherApp
-static void flip_weather_app_free(FlipWeatherApp *app)
-{
-    if (!app)
-    {
+static void flip_weather_app_free(FlipWeatherApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
         return;
     }
 
     // Free View(s)
-    if (app->view_weather)
-    {
+    if(app->view_weather) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewWeather);
         view_free(app->view_weather);
     }
-    if (app->view_gps)
-    {
+    if(app->view_gps) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewGPS);
         view_free(app->view_gps);
     }
 
     // Free Submenu(s)
-    if (app->submenu)
-    {
+    if(app->submenu) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewSubmenu);
         submenu_free(app->submenu);
     }
 
     // Free Widget(s)
-    if (app->widget)
-    {
+    if(app->widget) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewAbout);
         widget_free(app->widget);
     }
 
     // Free Variable Item List(s)
-    if (app->variable_item_list)
-    {
+    if(app->variable_item_list) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewSettings);
         variable_item_list_free(app->variable_item_list);
     }
 
     // Free Text Input(s)
-    if (app->uart_text_input_ssid)
-    {
+    if(app->uart_text_input_ssid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewTextInputSSID);
         uart_text_input_free(app->uart_text_input_ssid);
     }
-    if (app->uart_text_input_password)
-    {
+    if(app->uart_text_input_password) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewTextInputPassword);
         uart_text_input_free(app->uart_text_input_password);
     }
 
     // Free the text input buffer
-    if (app->uart_text_input_buffer_ssid)
-        free(app->uart_text_input_buffer_ssid);
-    if (app->uart_text_input_temp_buffer_ssid)
-        free(app->uart_text_input_temp_buffer_ssid);
-    if (app->uart_text_input_buffer_password)
-        free(app->uart_text_input_buffer_password);
-    if (app->uart_text_input_temp_buffer_password)
-        free(app->uart_text_input_temp_buffer_password);
+    if(app->uart_text_input_buffer_ssid) free(app->uart_text_input_buffer_ssid);
+    if(app->uart_text_input_temp_buffer_ssid) free(app->uart_text_input_temp_buffer_ssid);
+    if(app->uart_text_input_buffer_password) free(app->uart_text_input_buffer_password);
+    if(app->uart_text_input_temp_buffer_password) free(app->uart_text_input_temp_buffer_password);
 
     // deinitalize flipper http
     flipper_http_deinit();
 
     // free the view dispatcher
-    if (app->view_dispatcher)
-        view_dispatcher_free(app->view_dispatcher);
+    if(app->view_dispatcher) view_dispatcher_free(app->view_dispatcher);
 
     // close the gui
     furi_record_close(RECORD_GUI);
 
     // free the app
-    if (app)
-        free(app);
+    if(app) free(app);
 }
 
-#endif // FLIP_WEATHER_FREE_H
+#endif // FLIP_WEATHER_FREE_H

+ 104 - 49
flip_weather/flip_weather_i.h

@@ -2,15 +2,13 @@
 #define FLIP_WEATHER_I_H
 
 // Function to allocate resources for the FlipWeatherApp
-static FlipWeatherApp *flip_weather_app_alloc()
-{
-    FlipWeatherApp *app = (FlipWeatherApp *)malloc(sizeof(FlipWeatherApp));
+static FlipWeatherApp* flip_weather_app_alloc() {
+    FlipWeatherApp* app = (FlipWeatherApp*)malloc(sizeof(FlipWeatherApp));
 
-    Gui *gui = furi_record_open(RECORD_GUI);
+    Gui* gui = furi_record_open(RECORD_GUI);
 
     // initialize uart
-    if (!flipper_http_init(flipper_http_rx_callback, app))
-    {
+    if(!flipper_http_init(flipper_http_rx_callback, app)) {
         FURI_LOG_E(TAG, "Failed to initialize flipper http");
         return NULL;
     }
@@ -18,93 +16,150 @@ static FlipWeatherApp *flip_weather_app_alloc()
     // Allocate the text input buffer
     app->uart_text_input_buffer_size_ssid = 64;
     app->uart_text_input_buffer_size_password = 64;
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         return NULL;
     }
 
     // Allocate ViewDispatcher
-    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
-    {
+    if(!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app)) {
         return NULL;
     }
 
     // Main view
-    if (!easy_flipper_set_view(&app->view_weather, FlipWeatherViewWeather, flip_weather_view_draw_callback_weather, NULL, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_weather,
+           FlipWeatherViewWeather,
+           flip_weather_view_draw_callback_weather,
+           NULL,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_view(&app->view_gps, FlipWeatherViewGPS, flip_weather_view_draw_callback_gps, NULL, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_gps,
+           FlipWeatherViewGPS,
+           flip_weather_view_draw_callback_gps,
+           NULL,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Widget
-    if (!easy_flipper_set_widget(&app->widget, FlipWeatherViewAbout, "FlipWeather v1.1\n-----\nUse WiFi to get GPS and \nWeather information.\n-----\nwww.github.com/jblanked", callback_to_submenu, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget,
+           FlipWeatherViewAbout,
+           "FlipWeather v1.1\n-----\nUse WiFi to get GPS and \nWeather information.\n-----\nwww.github.com/jblanked",
+           callback_to_submenu,
+           &app->view_dispatcher)) {
         return NULL;
     }
 
     // Text Input
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_ssid, FlipWeatherViewTextInputSSID, "Enter SSID", app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid, text_updated_ssid, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_ssid,
+           FlipWeatherViewTextInputSSID,
+           "Enter SSID",
+           app->uart_text_input_temp_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           text_updated_ssid,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_password, FlipWeatherViewTextInputPassword, "Enter Password", app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password, text_updated_password, callback_to_wifi_settings, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_password,
+           FlipWeatherViewTextInputPassword,
+           "Enter Password",
+           app->uart_text_input_temp_buffer_password,
+           app->uart_text_input_buffer_size_password,
+           text_updated_password,
+           callback_to_wifi_settings,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Variable Item List
-    if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipWeatherViewSettings, settings_item_selected, callback_to_submenu, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_variable_item_list(
+           &app->variable_item_list,
+           FlipWeatherViewSettings,
+           settings_item_selected,
+           callback_to_submenu,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
-    app->variable_item_ssid = variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
-    app->variable_item_password = variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
+    app->variable_item_ssid =
+        variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
+    app->variable_item_password =
+        variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
     variable_item_set_current_value_text(app->variable_item_ssid, "");
     variable_item_set_current_value_text(app->variable_item_password, "");
 
     // Submenu
-    if (!easy_flipper_set_submenu(&app->submenu, FlipWeatherViewSubmenu, "FlipWeather v1.1", callback_exit_app, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_submenu(
+           &app->submenu,
+           FlipWeatherViewSubmenu,
+           "FlipWeather v1.1",
+           callback_exit_app,
+           &app->view_dispatcher)) {
         return NULL;
     }
-    submenu_add_item(app->submenu, "Weather", FlipWeatherSubmenuIndexWeather, callback_submenu_choices, app);
-    submenu_add_item(app->submenu, "GPS", FlipWeatherSubmenuIndexGPS, callback_submenu_choices, app);
-    submenu_add_item(app->submenu, "About", FlipWeatherSubmenuIndexAbout, callback_submenu_choices, app);
-    submenu_add_item(app->submenu, "Settings", FlipWeatherSubmenuIndexSettings, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "Weather", FlipWeatherSubmenuIndexWeather, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "GPS", FlipWeatherSubmenuIndexGPS, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "About", FlipWeatherSubmenuIndexAbout, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu, "Settings", FlipWeatherSubmenuIndexSettings, callback_submenu_choices, app);
 
     // load settings
-    if (load_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
-    {
+    if(load_settings(
+           app->uart_text_input_buffer_ssid,
+           app->uart_text_input_buffer_size_ssid,
+           app->uart_text_input_buffer_password,
+           app->uart_text_input_buffer_size_password)) {
         // Update variable items
-        if (app->variable_item_ssid)
-            variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
+        if(app->variable_item_ssid)
+            variable_item_set_current_value_text(
+                app->variable_item_ssid, app->uart_text_input_buffer_ssid);
         // dont show password
 
         // Copy items into their temp buffers with safety checks
-        if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
-        {
-            strncpy(app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid - 1);
-            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
+        if(app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid) {
+            strncpy(
+                app->uart_text_input_temp_buffer_ssid,
+                app->uart_text_input_buffer_ssid,
+                app->uart_text_input_buffer_size_ssid - 1);
+            app->uart_text_input_temp_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] =
+                '\0';
         }
-        if (app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password)
-        {
-            strncpy(app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password - 1);
-            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
+        if(app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password) {
+            strncpy(
+                app->uart_text_input_temp_buffer_password,
+                app->uart_text_input_buffer_password,
+                app->uart_text_input_buffer_size_password - 1);
+            app->uart_text_input_temp_buffer_password[app->uart_text_input_buffer_size_password - 1] =
+                '\0';
         }
     }
 
@@ -114,4 +169,4 @@ static FlipWeatherApp *flip_weather_app_alloc()
     return app;
 }
 
-#endif
+#endif

+ 38 - 58
flip_weather/flip_weather_parse.h

@@ -6,25 +6,21 @@ static bool got_ip_address = false;
 static bool geo_information_processed = false;
 static bool weather_information_processed = false;
 
-static bool flip_weather_parse_ip_address()
-{
+static bool flip_weather_parse_ip_address() {
     // load the received data from the saved file
-    FuriString *returned_data = flipper_http_load_from_file(fhttp.file_path);
-    if (returned_data == NULL)
-    {
+    FuriString* returned_data = flipper_http_load_from_file(fhttp.file_path);
+    if(returned_data == NULL) {
         FURI_LOG_E(TAG, "Failed to load received data from file.");
         return false;
     }
-    const char *data_cstr = furi_string_get_cstr(returned_data);
-    if (data_cstr == NULL)
-    {
+    const char* data_cstr = furi_string_get_cstr(returned_data);
+    if(data_cstr == NULL) {
         FURI_LOG_E(TAG, "Failed to get C-string from FuriString.");
         furi_string_free(returned_data);
         return false;
     }
-    char *ip = get_json_value("origin", (char *)data_cstr, MAX_TOKENS);
-    if (ip == NULL)
-    {
+    char* ip = get_json_value("origin", (char*)data_cstr, MAX_TOKENS);
+    if(ip == NULL) {
         FURI_LOG_E(TAG, "Failed to get IP address");
         sent_get_request = true;
         get_request_success = false;
@@ -41,10 +37,8 @@ static bool flip_weather_parse_ip_address()
 }
 
 // handle the async-to-sync process to get and set the IP address
-static bool flip_weather_handle_ip_address()
-{
-    if (!got_ip_address)
-    {
+static bool flip_weather_handle_ip_address() {
+    if(!got_ip_address) {
         got_ip_address = true;
         snprintf(
             fhttp.file_path,
@@ -52,24 +46,19 @@ static bool flip_weather_handle_ip_address()
             STORAGE_EXT_PATH_PREFIX "/apps_data/flip_weather/ip.txt");
 
         fhttp.save_received_data = true;
-        if (!flipper_http_get_request("https://httpbin.org/get"))
-        {
+        if(!flipper_http_get_request("https://httpbin.org/get")) {
             FURI_LOG_E(TAG, "Failed to get IP address");
             return false;
-        }
-        else
-        {
+        } else {
             fhttp.state = RECEIVING;
             furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         }
-        while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
-        {
+        while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
             // Wait for the feed to be received
             furi_delay_ms(100);
         }
         furi_timer_stop(fhttp.get_timeout_timer);
-        if (!flip_weather_parse_ip_address())
-        {
+        if(!flip_weather_parse_ip_address()) {
             FURI_LOG_E(TAG, "Failed to get IP address");
             sent_get_request = true;
             get_request_success = false;
@@ -80,14 +69,12 @@ static bool flip_weather_handle_ip_address()
     return true;
 }
 
-static bool send_geo_location_request()
-{
-    if (!sent_get_request && fhttp.state == IDLE)
-    {
+static bool send_geo_location_request() {
+    if(!sent_get_request && fhttp.state == IDLE) {
         sent_get_request = true;
-        get_request_success = flipper_http_get_request_with_headers("https://ipwhois.app/json/", jsmn("Content-Type", "application/json"));
-        if (!get_request_success)
-        {
+        get_request_success = flipper_http_get_request_with_headers(
+            "https://ipwhois.app/json/", jsmn("Content-Type", "application/json"));
+        if(!get_request_success) {
             FURI_LOG_E(TAG, "Failed to send GET request");
             return false;
         }
@@ -96,16 +83,14 @@ static bool send_geo_location_request()
     return true;
 }
 
-static void process_geo_location()
-{
-    if (!geo_information_processed && fhttp.last_response != NULL)
-    {
+static void process_geo_location() {
+    if(!geo_information_processed && fhttp.last_response != NULL) {
         geo_information_processed = true;
-        char *city = get_json_value("city", fhttp.last_response, MAX_TOKENS);
-        char *region = get_json_value("region", fhttp.last_response, MAX_TOKENS);
-        char *country = get_json_value("country", fhttp.last_response, MAX_TOKENS);
-        char *latitude = get_json_value("latitude", fhttp.last_response, MAX_TOKENS);
-        char *longitude = get_json_value("longitude", fhttp.last_response, MAX_TOKENS);
+        char* city = get_json_value("city", fhttp.last_response, MAX_TOKENS);
+        char* region = get_json_value("region", fhttp.last_response, MAX_TOKENS);
+        char* country = get_json_value("country", fhttp.last_response, MAX_TOKENS);
+        char* latitude = get_json_value("latitude", fhttp.last_response, MAX_TOKENS);
+        char* longitude = get_json_value("longitude", fhttp.last_response, MAX_TOKENS);
 
         snprintf(city_data, 64, "City: %s", city);
         snprintf(region_data, 64, "Region: %s", region);
@@ -118,23 +103,20 @@ static void process_geo_location()
     }
 }
 
-static void process_weather()
-{
-    if (!weather_information_processed && fhttp.last_response != NULL)
-    {
+static void process_weather() {
+    if(!weather_information_processed && fhttp.last_response != NULL) {
         weather_information_processed = true;
-        char *current_data = get_json_value("current", fhttp.last_response, MAX_TOKENS);
-        char *temperature = get_json_value("temperature_2m", current_data, MAX_TOKENS);
-        char *precipitation = get_json_value("precipitation", current_data, MAX_TOKENS);
-        char *rain = get_json_value("rain", current_data, MAX_TOKENS);
-        char *showers = get_json_value("showers", current_data, MAX_TOKENS);
-        char *snowfall = get_json_value("snowfall", current_data, MAX_TOKENS);
-        char *time = get_json_value("time", current_data, MAX_TOKENS);
+        char* current_data = get_json_value("current", fhttp.last_response, MAX_TOKENS);
+        char* temperature = get_json_value("temperature_2m", current_data, MAX_TOKENS);
+        char* precipitation = get_json_value("precipitation", current_data, MAX_TOKENS);
+        char* rain = get_json_value("rain", current_data, MAX_TOKENS);
+        char* showers = get_json_value("showers", current_data, MAX_TOKENS);
+        char* snowfall = get_json_value("snowfall", current_data, MAX_TOKENS);
+        char* time = get_json_value("time", current_data, MAX_TOKENS);
 
         // replace the "T" in time with a space
-        char *ptr = strstr(time, "T");
-        if (ptr != NULL)
-        {
+        char* ptr = strstr(time, "T");
+        if(ptr != NULL) {
             *ptr = ' ';
         }
 
@@ -146,12 +128,10 @@ static void process_weather()
         snprintf(time_data, 64, "Time: %s", time);
 
         fhttp.state = IDLE;
-    }
-    else if (!weather_information_processed && fhttp.last_response == NULL)
-    {
+    } else if(!weather_information_processed && fhttp.last_response == NULL) {
         FURI_LOG_E(TAG, "Failed to process weather data");
         // store error message
         snprintf(temperature_data, 64, "Failed. Update WiFi settings.");
         fhttp.state = ISSUE;
     }
-}
+}

+ 20 - 32
flip_weather/flip_weather_storage.h

@@ -6,22 +6,19 @@
 
 #define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_weather/settings.bin"
 
-static void save_settings(
-    const char *ssid,
-    const char *password)
-{
+static void save_settings(const char* ssid, const char* password) {
     // Create the directory for saving settings
     char directory_path[256];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_weather");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_weather");
 
     // Create the directory
-    Storage *storage = furi_record_open(RECORD_STORAGE);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    File* file = storage_file_alloc(storage);
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -30,17 +27,15 @@ static void save_settings(
 
     // Save the ssid length and data
     size_t ssid_length = strlen(ssid) + 1; // Include null terminator
-    if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to write SSID");
     }
 
     // Save the password length and data
     size_t password_length = strlen(password) + 1; // Include null terminator
-    if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
-        storage_file_write(file, password, password_length) != password_length)
-    {
+    if(storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       storage_file_write(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to write password");
     }
 
@@ -49,17 +44,11 @@ static void save_settings(
     furi_record_close(RECORD_STORAGE);
 }
 
-static bool load_settings(
-    char *ssid,
-    size_t ssid_size,
-    char *password,
-    size_t password_size)
-{
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    File *file = storage_file_alloc(storage);
+static bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
 
-    if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -68,9 +57,8 @@ static bool load_settings(
 
     // Load the ssid
     size_t ssid_length;
-    if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
-        storage_file_read(file, ssid, ssid_length) != ssid_length)
-    {
+    if(storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
+       ssid_length > ssid_size || storage_file_read(file, ssid, ssid_length) != ssid_length) {
         FURI_LOG_E(TAG, "Failed to read SSID");
         storage_file_close(file);
         storage_file_free(file);
@@ -81,9 +69,9 @@ static bool load_settings(
 
     // Load the password
     size_t password_length;
-    if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
-        storage_file_read(file, password, password_length) != password_length)
-    {
+    if(storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
+       password_length > password_size ||
+       storage_file_read(file, password, password_length) != password_length) {
         FURI_LOG_E(TAG, "Failed to read password");
         storage_file_close(file);
         storage_file_free(file);
@@ -99,4 +87,4 @@ static bool load_settings(
     return true;
 }
 
-#endif // FLIP_WEATHER_STORAGE_H
+#endif // FLIP_WEATHER_STORAGE_H

Разница между файлами не показана из-за своего большого размера
+ 190 - 302
flip_weather/flipper_http.h


+ 531 - 614
flip_weather/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
+            }
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -538,326 +493,288 @@ extern "C"
 #include <furi.h>
 
 // Helper function to create a JSON object
-char *jsmn(const char *key, const char *value)
-{
-  int length = strlen(key) + strlen(value) + 8;         // Calculate required length
-  char *result = (char *)malloc(length * sizeof(char)); // Allocate memory
-  if (result == NULL)
-  {
-    return NULL; // Handle memory allocation failure
-  }
-  snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
-  return result; // Caller is responsible for freeing this memory
+char* jsmn(const char* key, const char* value) {
+    int length = strlen(key) + strlen(value) + 8; // Calculate required length
+    char* result = (char*)malloc(length * sizeof(char)); // Allocate memory
+    if(result == NULL) {
+        return NULL; // Handle memory allocation failure
+    }
+    snprintf(result, length, "{\"%s\":\"%s\"}", key, value);
+    return result; // Caller is responsible for freeing this memory
 }
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_weather/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

+ 4 - 7
flip_wifi/app.c

@@ -5,21 +5,18 @@
 #include <flip_wifi_free.h>
 
 // Entry point for the FlipWiFi application
-int32_t flip_wifi_main(void *p)
-{
+int32_t flip_wifi_main(void* p) {
     // Suppress unused parameter warning
     UNUSED(p);
 
     // Initialize the FlipWiFi application
-    FlipWiFiApp *app = flip_wifi_app_alloc();
-    if (!app)
-    {
+    FlipWiFiApp* app = flip_wifi_app_alloc();
+    if(!app) {
         FURI_LOG_E(TAG, "Failed to allocate FlipWiFiApp");
         return -1;
     }
 
-    if (!flipper_http_ping())
-    {
+    if(!flipper_http_ping()) {
         FURI_LOG_E(TAG, "Failed to ping the device");
         return -1;
     }

+ 142 - 200
flip_wifi/easy_flipper.h

@@ -29,11 +29,9 @@
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-uint32_t easy_flipper_callback_exit_app(void *context)
-{
+uint32_t easy_flipper_callback_exit_app(void* context) {
     // Exit the application
-    if (!context)
-    {
+    if(!context) {
         FURI_LOG_E(EASY_TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -47,16 +45,13 @@ uint32_t easy_flipper_callback_exit_app(void *context)
  * @param buffer_size The size of the buffer
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
-{
-    if (!buffer)
-    {
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size) {
+    if(!buffer) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer");
         return false;
     }
-    *buffer = (char *)malloc(buffer_size);
-    if (!*buffer)
-    {
+    *buffer = (char*)malloc(buffer_size);
+    if(!*buffer) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate buffer");
         return false;
     }
@@ -75,39 +70,32 @@ bool easy_flipper_set_buffer(char **buffer, uint32_t buffer_size)
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_view(
-    View **view,
+    View** view,
     int32_t view_id,
-    void draw_callback(Canvas *, void *),
-    bool input_callback(InputEvent *, void *),
-    uint32_t (*previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!view || !view_dispatcher)
-    {
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!view || !view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view");
         return false;
     }
     *view = view_alloc();
-    if (!*view)
-    {
+    if(!*view) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate View");
         return false;
     }
-    if (draw_callback)
-    {
+    if(draw_callback) {
         view_set_draw_callback(*view, draw_callback);
     }
-    if (input_callback)
-    {
+    if(input_callback) {
         view_set_input_callback(*view, input_callback);
     }
-    if (context)
-    {
+    if(context) {
         view_set_context(*view, context);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(*view, previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, *view);
@@ -121,22 +109,18 @@ bool easy_flipper_set_view(
  * @param context The context to pass to the event callback
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui, void *context)
-{
-    if (!view_dispatcher)
-    {
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context) {
+    if(!view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_view_dispatcher");
         return false;
     }
     *view_dispatcher = view_dispatcher_alloc();
-    if (!*view_dispatcher)
-    {
+    if(!*view_dispatcher) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate ViewDispatcher");
         return false;
     }
     view_dispatcher_attach_to_gui(*view_dispatcher, gui, ViewDispatcherTypeFullscreen);
-    if (context)
-    {
+    if(context) {
         view_dispatcher_set_event_callback_context(*view_dispatcher, context);
     }
     return true;
@@ -153,29 +137,24 @@ bool easy_flipper_set_view_dispatcher(ViewDispatcher **view_dispatcher, Gui *gui
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_submenu(
-    Submenu **submenu,
+    Submenu** submenu,
     int32_t view_id,
-    char *title,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!submenu)
-    {
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!submenu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_submenu");
         return false;
     }
     *submenu = submenu_alloc();
-    if (!*submenu)
-    {
+    if(!*submenu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Submenu");
         return false;
     }
-    if (title)
-    {
+    if(title) {
         submenu_set_header(*submenu, title);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(submenu_get_view(*submenu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, submenu_get_view(*submenu));
@@ -192,24 +171,20 @@ bool easy_flipper_set_submenu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_menu(
-    Menu **menu,
+    Menu** menu,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!menu)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!menu) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_menu");
         return false;
     }
     *menu = menu_alloc();
-    if (!*menu)
-    {
+    if(!*menu) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Menu");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(menu_get_view(*menu), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, menu_get_view(*menu));
@@ -226,29 +201,24 @@ bool easy_flipper_set_menu(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_widget(
-    Widget **widget,
+    Widget** widget,
     int32_t view_id,
-    char *text,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!widget)
-    {
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!widget) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_widget");
         return false;
     }
     *widget = widget_alloc();
-    if (!*widget)
-    {
+    if(!*widget) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Widget");
         return false;
     }
-    if (text)
-    {
+    if(text) {
         widget_add_text_scroll_element(*widget, 0, 0, 128, 64, text);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(widget_get_view(*widget), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, widget_get_view(*widget));
@@ -267,33 +237,30 @@ bool easy_flipper_set_widget(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_variable_item_list(
-    VariableItemList **variable_item_list,
+    VariableItemList** variable_item_list,
     int32_t view_id,
-    void (*enter_callback)(void *, uint32_t),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!variable_item_list)
-    {
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_variable_item_list");
         return false;
     }
     *variable_item_list = variable_item_list_alloc();
-    if (!*variable_item_list)
-    {
+    if(!*variable_item_list) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate VariableItemList");
         return false;
     }
-    if (enter_callback)
-    {
+    if(enter_callback) {
         variable_item_list_set_enter_callback(*variable_item_list, enter_callback, context);
     }
-    if (previous_callback)
-    {
-        view_set_previous_callback(variable_item_list_get_view(*variable_item_list), previous_callback);
+    if(previous_callback) {
+        view_set_previous_callback(
+            variable_item_list_get_view(*variable_item_list), previous_callback);
     }
-    view_dispatcher_add_view(*view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, variable_item_list_get_view(*variable_item_list));
     return true;
 }
 
@@ -306,38 +273,38 @@ bool easy_flipper_set_variable_item_list(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_text_input(
-    TextInput **text_input,
+    TextInput** text_input,
     int32_t view_id,
-    char *header_text,
-    char *text_input_temp_buffer,
+    char* header_text,
+    char* text_input_temp_buffer,
     uint32_t text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_text_input");
         return false;
     }
     *text_input = text_input_alloc();
-    if (!*text_input)
-    {
+    if(!*text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(text_input_get_view(*text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         text_input_set_header_text(*text_input, header_text);
     }
-    if (text_input_temp_buffer && text_input_buffer_size && result_callback)
-    {
-        text_input_set_result_callback(*text_input, result_callback, context, text_input_temp_buffer, text_input_buffer_size, false);
+    if(text_input_temp_buffer && text_input_buffer_size && result_callback) {
+        text_input_set_result_callback(
+            *text_input,
+            result_callback,
+            context,
+            text_input_temp_buffer,
+            text_input_buffer_size,
+            false);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, text_input_get_view(*text_input));
     return true;
@@ -352,40 +319,41 @@ bool easy_flipper_set_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_uart_text_input(
-    UART_TextInput **uart_text_input,
+    UART_TextInput** uart_text_input,
     int32_t view_id,
-    char *header_text,
-    char *uart_text_input_temp_buffer,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
     uint32_t uart_text_input_buffer_size,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!uart_text_input)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_uart_text_input");
         return false;
     }
     *uart_text_input = uart_text_input_alloc();
-    if (!*uart_text_input)
-    {
+    if(!*uart_text_input) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate UART_TextInput");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(uart_text_input_get_view(*uart_text_input), previous_callback);
     }
-    if (header_text)
-    {
+    if(header_text) {
         uart_text_input_set_header_text(*uart_text_input, header_text);
     }
-    if (uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback)
-    {
-        uart_text_input_set_result_callback(*uart_text_input, result_callback, context, uart_text_input_temp_buffer, uart_text_input_buffer_size, false);
-    }
-    view_dispatcher_add_view(*view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
+    if(uart_text_input_temp_buffer && uart_text_input_buffer_size && result_callback) {
+        uart_text_input_set_result_callback(
+            *uart_text_input,
+            result_callback,
+            context,
+            uart_text_input_temp_buffer,
+            uart_text_input_buffer_size,
+            false);
+    }
+    view_dispatcher_add_view(
+        *view_dispatcher, view_id, uart_text_input_get_view(*uart_text_input));
     return true;
 }
 
@@ -409,63 +377,52 @@ bool easy_flipper_set_uart_text_input(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_dialog_ex(
-    DialogEx **dialog_ex,
+    DialogEx** dialog_ex,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    char *left_button_text,
-    char *right_button_text,
-    char *center_button_text,
-    void (*result_callback)(DialogExResult, void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!dialog_ex)
-    {
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_dialog_ex");
         return false;
     }
     *dialog_ex = dialog_ex_alloc();
-    if (!*dialog_ex)
-    {
+    if(!*dialog_ex) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate DialogEx");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         dialog_ex_set_header(*dialog_ex, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         dialog_ex_set_text(*dialog_ex, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (left_button_text)
-    {
+    if(left_button_text) {
         dialog_ex_set_left_button_text(*dialog_ex, left_button_text);
     }
-    if (right_button_text)
-    {
+    if(right_button_text) {
         dialog_ex_set_right_button_text(*dialog_ex, right_button_text);
     }
-    if (center_button_text)
-    {
+    if(center_button_text) {
         dialog_ex_set_center_button_text(*dialog_ex, center_button_text);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         dialog_ex_set_result_callback(*dialog_ex, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(dialog_ex_get_view(*dialog_ex), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         dialog_ex_set_context(*dialog_ex, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, dialog_ex_get_view(*dialog_ex));
@@ -489,48 +446,40 @@ bool easy_flipper_set_dialog_ex(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_popup(
-    Popup **popup,
+    Popup** popup,
     int32_t view_id,
-    char *header,
+    char* header,
     uint16_t header_x,
     uint16_t header_y,
-    char *text,
+    char* text,
     uint16_t text_x,
     uint16_t text_y,
-    void (*result_callback)(void *),
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher,
-    void *context)
-{
-    if (!popup)
-    {
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context) {
+    if(!popup) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_popup");
         return false;
     }
     *popup = popup_alloc();
-    if (!*popup)
-    {
+    if(!*popup) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Popup");
         return false;
     }
-    if (header)
-    {
+    if(header) {
         popup_set_header(*popup, header, header_x, header_y, AlignLeft, AlignTop);
     }
-    if (text)
-    {
+    if(text) {
         popup_set_text(*popup, text, text_x, text_y, AlignLeft, AlignTop);
     }
-    if (result_callback)
-    {
+    if(result_callback) {
         popup_set_callback(*popup, result_callback);
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(popup_get_view(*popup), previous_callback);
     }
-    if (context)
-    {
+    if(context) {
         popup_set_context(*popup, context);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, popup_get_view(*popup));
@@ -546,24 +495,20 @@ bool easy_flipper_set_popup(
  * @return true if successful, false otherwise
  */
 bool easy_flipper_set_loading(
-    Loading **loading,
+    Loading** loading,
     int32_t view_id,
-    uint32_t(previous_callback)(void *),
-    ViewDispatcher **view_dispatcher)
-{
-    if (!loading)
-    {
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher) {
+    if(!loading) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_loading");
         return false;
     }
     *loading = loading_alloc();
-    if (!*loading)
-    {
+    if(!*loading) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate Loading");
         return false;
     }
-    if (previous_callback)
-    {
+    if(previous_callback) {
         view_set_previous_callback(loading_get_view(*loading), previous_callback);
     }
     view_dispatcher_add_view(*view_dispatcher, view_id, loading_get_view(*loading));
@@ -576,16 +521,13 @@ bool easy_flipper_set_loading(
  * @param buffer The buffer to copy the string to
  * @return true if successful, false otherwise
  */
-bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer)
-{
-    if (!furi_string)
-    {
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer) {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Invalid arguments provided to set_buffer_to_furi_string");
         return false;
     }
     *furi_string = furi_string_alloc();
-    if (!furi_string)
-    {
+    if(!furi_string) {
         FURI_LOG_E(EASY_TAG, "Failed to allocate FuriString");
         return false;
     }
@@ -593,4 +535,4 @@ bool easy_flipper_set_char_to_furi_string(FuriString **furi_string, char *buffer
     return true;
 }
 
-#endif // EASY_FLIPPER_H
+#endif // EASY_FLIPPER_H

+ 144 - 150
flip_wifi/flip_wifi_callback.h

@@ -1,29 +1,35 @@
 #ifndef FLIP_WIFI_CALLBACK_H
 #define FLIP_WIFI_CALLBACK_H
 
-FlipWiFiApp *app_instance;
+FlipWiFiApp* app_instance;
 
-static void callback_submenu_choices(void *context, uint32_t index);
+static void callback_submenu_choices(void* context, uint32_t index);
 // array to store each SSID
-char *ssid_list[64];
+char* ssid_list[64];
 uint32_t ssid_index = 0;
 
-static void flip_wifi_redraw_submenu_saved(FlipWiFiApp *app)
-{
+static void flip_wifi_redraw_submenu_saved(FlipWiFiApp* app) {
     // re draw the saved submenu
     submenu_reset(app->submenu_wifi_saved);
     submenu_set_header(app->submenu_wifi_saved, "Saved APs");
-    submenu_add_item(app->submenu_wifi_saved, "[Add Network]", FlipWiFiSubmenuIndexWiFiSavedAddSSID, callback_submenu_choices, app);
-    for (uint32_t i = 0; i < app->wifi_playlist.count; i++)
-    {
-        submenu_add_item(app->submenu_wifi_saved, app->wifi_playlist.ssids[i], FlipWiFiSubmenuIndexWiFiSavedStart + i, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_wifi_saved,
+        "[Add Network]",
+        FlipWiFiSubmenuIndexWiFiSavedAddSSID,
+        callback_submenu_choices,
+        app);
+    for(uint32_t i = 0; i < app->wifi_playlist.count; i++) {
+        submenu_add_item(
+            app->submenu_wifi_saved,
+            app->wifi_playlist.ssids[i],
+            FlipWiFiSubmenuIndexWiFiSavedStart + i,
+            callback_submenu_choices,
+            app);
     }
 }
 
-static uint32_t callback_to_submenu_main(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu_main(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -31,10 +37,8 @@ static uint32_t callback_to_submenu_main(void *context)
     ssid_index = 0;
     return FlipWiFiViewSubmenuMain;
 }
-static uint32_t callback_to_submenu_scan(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu_scan(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -42,10 +46,8 @@ static uint32_t callback_to_submenu_scan(void *context)
     ssid_index = 0;
     return FlipWiFiViewSubmenuScan;
 }
-static uint32_t callback_to_submenu_saved(void *context)
-{
-    if (!context)
-    {
+static uint32_t callback_to_submenu_saved(void* context) {
+    if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
     }
@@ -53,21 +55,17 @@ static uint32_t callback_to_submenu_saved(void *context)
     ssid_index = 0;
     return FlipWiFiViewSubmenuSaved;
 }
-void popup_callback_saved(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+void popup_callback_saved(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "HelloWorldApp is NULL");
         return;
     }
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewSubmenuSaved);
 }
-void popup_callback_main(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+void popup_callback_main(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "HelloWorldApp is NULL");
         return;
     }
@@ -75,8 +73,7 @@ void popup_callback_main(void *context)
 }
 
 // Callback for drawing the main screen
-static void flip_wifi_view_draw_callback_scan(Canvas *canvas, void *model)
-{
+static void flip_wifi_view_draw_callback_scan(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontPrimary);
@@ -86,15 +83,15 @@ static void flip_wifi_view_draw_callback_scan(Canvas *canvas, void *model)
     canvas_draw_icon(canvas, 96, 53, &I_ButtonRight_4x7);
     canvas_draw_str_aligned(canvas, 103, 54, AlignLeft, AlignTop, "Add");
 }
-static void flip_wifi_view_draw_callback_saved(Canvas *canvas, void *model)
-{
+static void flip_wifi_view_draw_callback_saved(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontPrimary);
     canvas_draw_str(canvas, 0, 10, app_instance->wifi_playlist.ssids[ssid_index]);
     canvas_set_font(canvas, FontSecondary);
     char password[64];
-    snprintf(password, sizeof(password), "Pass: %s", app_instance->wifi_playlist.passwords[ssid_index]);
+    snprintf(
+        password, sizeof(password), "Pass: %s", app_instance->wifi_playlist.passwords[ssid_index]);
     canvas_draw_str(canvas, 0, 20, password);
     canvas_draw_icon(canvas, 0, 54, &I_ButtonLeft_4x7);
     canvas_draw_str_aligned(canvas, 7, 54, AlignLeft, AlignTop, "Delete");
@@ -107,11 +104,9 @@ static void flip_wifi_view_draw_callback_saved(Canvas *canvas, void *model)
 }
 
 // Input callback for the view (async input handling)
-bool flip_wifi_view_input_callback_scan(InputEvent *event, void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (event->type == InputTypePress && event->key == InputKeyRight)
-    {
+bool flip_wifi_view_input_callback_scan(InputEvent* event, void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(event->type == InputTypePress && event->key == InputKeyRight) {
         // switch to text input to set password
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewTextInputScan);
         return true;
@@ -119,52 +114,55 @@ bool flip_wifi_view_input_callback_scan(InputEvent *event, void *context)
     return false;
 }
 // Input callback for the view (async input handling)
-bool flip_wifi_view_input_callback_saved(InputEvent *event, void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+bool flip_wifi_view_input_callback_saved(InputEvent* event, void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return false;
     }
-    if (event->type == InputTypePress && event->key == InputKeyRight)
-    {
+    if(event->type == InputTypePress && event->key == InputKeyRight) {
         // set text input buffer as the selected password
-        strncpy(app->uart_text_input_temp_buffer_password_saved, app->wifi_playlist.passwords[ssid_index], app->uart_text_input_buffer_size_password_saved);
+        strncpy(
+            app->uart_text_input_temp_buffer_password_saved,
+            app->wifi_playlist.passwords[ssid_index],
+            app->uart_text_input_buffer_size_password_saved);
         // switch to text input to set password
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewTextInputSaved);
         return true;
-    }
-    else if (event->type == InputTypePress && event->key == InputKeyOk)
-    {
+    } else if(event->type == InputTypePress && event->key == InputKeyOk) {
         // save the settings
-        if (app->wifi_playlist.ssids[ssid_index] == NULL || app->wifi_playlist.passwords[ssid_index] == NULL)
-        {
+        if(app->wifi_playlist.ssids[ssid_index] == NULL ||
+           app->wifi_playlist.passwords[ssid_index] == NULL) {
             return false;
         }
-        save_settings(app->wifi_playlist.ssids[ssid_index], app->wifi_playlist.passwords[ssid_index]);
+        save_settings(
+            app->wifi_playlist.ssids[ssid_index], app->wifi_playlist.passwords[ssid_index]);
 
-        flipper_http_save_wifi(app->wifi_playlist.ssids[ssid_index], app->wifi_playlist.passwords[ssid_index]);
+        flipper_http_save_wifi(
+            app->wifi_playlist.ssids[ssid_index], app->wifi_playlist.passwords[ssid_index]);
 
         flipper_http_connect_wifi();
 
         popup_set_header(app->popup, "[SUCCESS]", 0, 0, AlignLeft, AlignTop);
-        popup_set_text(app->popup, "All FlipperHTTP apps will now\nuse the selected network.", 0, 40, AlignLeft, AlignTop);
+        popup_set_text(
+            app->popup,
+            "All FlipperHTTP apps will now\nuse the selected network.",
+            0,
+            40,
+            AlignLeft,
+            AlignTop);
         view_set_previous_callback(popup_get_view(app->popup), callback_to_submenu_saved);
         popup_set_callback(app->popup, popup_callback_saved);
 
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewPopup);
         return true;
-    }
-    else if (event->type == InputTypePress && event->key == InputKeyLeft)
-    {
+    } else if(event->type == InputTypePress && event->key == InputKeyLeft) {
         // delete the selected ssid and password
         free(app->wifi_playlist.ssids[ssid_index]);
         free(app->wifi_playlist.passwords[ssid_index]);
         free(ssid_list[ssid_index]);
         // shift the remaining ssids and passwords
-        for (uint32_t i = ssid_index; i < app->wifi_playlist.count - 1; i++)
-        {
+        for(uint32_t i = ssid_index; i < app->wifi_playlist.count - 1; i++) {
             app->wifi_playlist.ssids[i] = app->wifi_playlist.ssids[i + 1];
             app->wifi_playlist.passwords[i] = app->wifi_playlist.passwords[i + 1];
             ssid_list[i] = ssid_list[i + 1];
@@ -185,58 +183,50 @@ bool flip_wifi_view_input_callback_saved(InputEvent *event, void *context)
 
 // Function to trim leading and trailing whitespace
 // Returns the trimmed start pointer and updates the length
-char *trim_whitespace(char *start, size_t *length)
-{
+char* trim_whitespace(char* start, size_t* length) {
     // Trim leading whitespace
-    while (*length > 0 && isspace((unsigned char)*start))
-    {
+    while(*length > 0 && isspace((unsigned char)*start)) {
         start++;
         (*length)--;
     }
 
     // Trim trailing whitespace
-    while (*length > 0 && isspace((unsigned char)start[*length - 1]))
-    {
+    while(*length > 0 && isspace((unsigned char)start[*length - 1])) {
         (*length)--;
     }
 
     return start;
 }
 
-bool flip_wifi_handle_scan(FlipWiFiApp *app)
-{
-    if (fhttp.last_response == NULL || fhttp.last_response[0] == '\0')
-    {
+bool flip_wifi_handle_scan(FlipWiFiApp* app) {
+    if(fhttp.last_response == NULL || fhttp.last_response[0] == '\0') {
         FURI_LOG_E(TAG, "Failed to receive WiFi scan");
         return false;
     }
 
     uint32_t ssid_count = 0;
 
-    char *current_position = fhttp.last_response;
-    char *next_comma = NULL;
+    char* current_position = fhttp.last_response;
+    char* next_comma = NULL;
 
     // Manually split the string on commas
-    while ((next_comma = strchr(current_position, ',')) != NULL)
-    {
+    while((next_comma = strchr(current_position, ',')) != NULL) {
         // Calculate length of the SSID
         size_t ssid_length = next_comma - current_position;
 
         // Trim leading and trailing whitespace
         size_t trimmed_length = ssid_length;
-        char *trim_start = trim_whitespace(current_position, &trimmed_length);
+        char* trim_start = trim_whitespace(current_position, &trimmed_length);
 
         // Handle empty SSIDs resulting from consecutive commas
-        if (trimmed_length == 0)
-        {
+        if(trimmed_length == 0) {
             current_position = next_comma + 1; // Move past the comma
             continue;
         }
 
         // Allocate memory for the SSID and copy it
         ssid_list[ssid_count] = malloc(trimmed_length + 1);
-        if (ssid_list[ssid_count] == NULL)
-        {
+        if(ssid_list[ssid_count] == NULL) {
             FURI_LOG_E(TAG, "Memory allocation failed");
             return false;
         }
@@ -244,8 +234,7 @@ bool flip_wifi_handle_scan(FlipWiFiApp *app)
         ssid_list[ssid_count][trimmed_length] = '\0'; // Null-terminate the string
 
         ssid_count++;
-        if (ssid_count >= MAX_WIFI_NETWORKS)
-        {
+        if(ssid_count >= MAX_WIFI_NETWORKS) {
             FURI_LOG_E(TAG, "Maximum SSID limit reached");
             break;
         }
@@ -254,20 +243,17 @@ bool flip_wifi_handle_scan(FlipWiFiApp *app)
     }
 
     // Handle the last SSID after the last comma (if any)
-    if (*current_position != '\0' && ssid_count < MAX_WIFI_NETWORKS)
-    {
+    if(*current_position != '\0' && ssid_count < MAX_WIFI_NETWORKS) {
         size_t ssid_length = strlen(current_position);
 
         // Trim leading and trailing whitespace
         size_t trimmed_length = ssid_length;
-        char *trim_start = trim_whitespace(current_position, &trimmed_length);
+        char* trim_start = trim_whitespace(current_position, &trimmed_length);
 
         // Handle empty SSIDs
-        if (trimmed_length > 0)
-        {
+        if(trimmed_length > 0) {
             ssid_list[ssid_count] = malloc(trimmed_length + 1);
-            if (ssid_list[ssid_count] == NULL)
-            {
+            if(ssid_list[ssid_count] == NULL) {
                 FURI_LOG_E(TAG, "Memory allocation failed for the last SSID");
                 return false;
             }
@@ -279,70 +265,68 @@ bool flip_wifi_handle_scan(FlipWiFiApp *app)
 
     // Add each SSID as a submenu item
     submenu_set_header(app->submenu_wifi_scan, "WiFi Nearby");
-    for (uint32_t i = 0; i < ssid_count; i++)
-    {
-        char *ssid_item = ssid_list[i];
-        if (ssid_item == NULL)
-        {
+    for(uint32_t i = 0; i < ssid_count; i++) {
+        char* ssid_item = ssid_list[i];
+        if(ssid_item == NULL) {
             // skip any NULL entries
             continue;
         }
         char ssid[64];
         snprintf(ssid, sizeof(ssid), "%s", ssid_item);
-        submenu_add_item(app->submenu_wifi_scan, ssid, FlipWiFiSubmenuIndexWiFiScanStart + i, callback_submenu_choices, app);
+        submenu_add_item(
+            app->submenu_wifi_scan,
+            ssid,
+            FlipWiFiSubmenuIndexWiFiScanStart + i,
+            callback_submenu_choices,
+            app);
     }
 
     return true;
 }
-static void callback_submenu_choices(void *context, uint32_t index)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+static void callback_submenu_choices(void* context, uint32_t index) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
-    switch (index)
-    {
+    switch(index) {
     case FlipWiFiSubmenuIndexWiFiScan:
-        if (fhttp.state == INACTIVE)
-        {
+        if(fhttp.state == INACTIVE) {
             popup_set_header(app->popup, "[ERROR]", 0, 0, AlignLeft, AlignTop);
-            popup_set_text(app->popup, "WiFi Devboard Disconnected.\nPlease reconnect the board.", 0, 40, AlignLeft, AlignTop);
+            popup_set_text(
+                app->popup,
+                "WiFi Devboard Disconnected.\nPlease reconnect the board.",
+                0,
+                40,
+                AlignLeft,
+                AlignTop);
             view_set_previous_callback(popup_get_view(app->popup), callback_to_submenu_main);
             popup_set_callback(app->popup, popup_callback_main);
             // switch to the popup view
             view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewPopup);
         }
         // scan for wifi
-        if (!flipper_http_scan_wifi())
-        {
+        if(!flipper_http_scan_wifi()) {
             FURI_LOG_E(TAG, "Failed to scan for WiFi");
             return;
-        }
-        else // start the async feed request
+        } else // start the async feed request
         {
             furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
             fhttp.state = RECEIVING;
         }
-        while (fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0)
-        {
+        while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
             // Wait for the feed to be received
             furi_delay_ms(100);
         }
         furi_timer_stop(fhttp.get_timeout_timer);
         // set each SSID as a submenu item
-        if (fhttp.state != IDLE || fhttp.last_response == NULL)
-        {
+        if(fhttp.state != IDLE || fhttp.last_response == NULL) {
             FURI_LOG_E(TAG, "Failed to receive WiFi scan");
             return;
-        }
-        else
-        {
+        } else {
             submenu_reset(app->submenu_wifi_scan);
             submenu_set_header(app->submenu_wifi_scan, "WiFi Nearby");
-            if (flip_wifi_handle_scan(app))
-            {
+            if(flip_wifi_handle_scan(app)) {
                 // switch to the submenu
                 view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewSubmenuScan);
             }
@@ -373,24 +357,27 @@ static void callback_submenu_choices(void *context, uint32_t index)
     }
 }
 
-static void flip_wifi_text_updated_password_scan(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+static void flip_wifi_text_updated_password_scan(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_password_scan, app->uart_text_input_temp_buffer_password_scan, app->uart_text_input_buffer_size_password_scan);
+    strncpy(
+        app->uart_text_input_buffer_password_scan,
+        app->uart_text_input_temp_buffer_password_scan,
+        app->uart_text_input_buffer_size_password_scan);
 
     // Ensure null-termination
-    app->uart_text_input_buffer_password_scan[app->uart_text_input_buffer_size_password_scan - 1] = '\0';
+    app->uart_text_input_buffer_password_scan[app->uart_text_input_buffer_size_password_scan - 1] =
+        '\0';
 
     // add the SSID and password_scan to the playlist
     app->wifi_playlist.ssids[app->wifi_playlist.count] = strdup(ssid_list[ssid_index]);
-    app->wifi_playlist.passwords[app->wifi_playlist.count] = strdup(app->uart_text_input_buffer_password_scan);
+    app->wifi_playlist.passwords[app->wifi_playlist.count] =
+        strdup(app->uart_text_input_buffer_password_scan);
     app->wifi_playlist.count++;
 
     // save the playlist to storage
@@ -401,20 +388,22 @@ static void flip_wifi_text_updated_password_scan(void *context)
     // switch to back to the scan view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewSubmenuScan);
 }
-static void flip_wifi_text_updated_password_saved(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+static void flip_wifi_text_updated_password_saved(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_password_saved, app->uart_text_input_temp_buffer_password_saved, app->uart_text_input_buffer_size_password_saved);
+    strncpy(
+        app->uart_text_input_buffer_password_saved,
+        app->uart_text_input_temp_buffer_password_saved,
+        app->uart_text_input_buffer_size_password_saved);
 
     // Ensure null-termination
-    app->uart_text_input_buffer_password_saved[app->uart_text_input_buffer_size_password_saved - 1] = '\0';
+    app->uart_text_input_buffer_password_saved[app->uart_text_input_buffer_size_password_saved - 1] =
+        '\0';
 
     // update the password_saved in the playlist
     app->wifi_playlist.passwords[ssid_index] = strdup(app->uart_text_input_buffer_password_saved);
@@ -426,17 +415,18 @@ static void flip_wifi_text_updated_password_saved(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewSubmenuSaved);
 }
 
-static void flip_wifi_text_updated_add_ssid(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+static void flip_wifi_text_updated_add_ssid(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_add_ssid, app->uart_text_input_temp_buffer_add_ssid, app->uart_text_input_buffer_size_add_ssid);
+    strncpy(
+        app->uart_text_input_buffer_add_ssid,
+        app->uart_text_input_temp_buffer_add_ssid,
+        app->uart_text_input_buffer_size_add_ssid);
 
     // Ensure null-termination
     app->uart_text_input_buffer_add_ssid[app->uart_text_input_buffer_size_add_ssid - 1] = '\0';
@@ -444,24 +434,28 @@ static void flip_wifi_text_updated_add_ssid(void *context)
     // do nothing for now, go to the next text input to set the password
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewTextInputSavedAddPassword);
 }
-static void flip_wifi_text_updated_add_password(void *context)
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)context;
-    if (!app)
-    {
+static void flip_wifi_text_updated_add_password(void* context) {
+    FlipWiFiApp* app = (FlipWiFiApp*)context;
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
 
     // store the entered text
-    strncpy(app->uart_text_input_buffer_add_password, app->uart_text_input_temp_buffer_add_password, app->uart_text_input_buffer_size_add_password);
+    strncpy(
+        app->uart_text_input_buffer_add_password,
+        app->uart_text_input_temp_buffer_add_password,
+        app->uart_text_input_buffer_size_add_password);
 
     // Ensure null-termination
-    app->uart_text_input_buffer_add_password[app->uart_text_input_buffer_size_add_password - 1] = '\0';
+    app->uart_text_input_buffer_add_password[app->uart_text_input_buffer_size_add_password - 1] =
+        '\0';
 
     // add the SSID and password_scan to the playlist
-    app->wifi_playlist.ssids[app->wifi_playlist.count] = strdup(app->uart_text_input_buffer_add_ssid);
-    app->wifi_playlist.passwords[app->wifi_playlist.count] = strdup(app->uart_text_input_buffer_add_password);
+    app->wifi_playlist.ssids[app->wifi_playlist.count] =
+        strdup(app->uart_text_input_buffer_add_ssid);
+    app->wifi_playlist.passwords[app->wifi_playlist.count] =
+        strdup(app->uart_text_input_buffer_add_password);
     app->wifi_playlist.count++;
 
     // save the playlist to storage
@@ -473,4 +467,4 @@ static void flip_wifi_text_updated_add_password(void *context)
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWiFiViewSubmenuSaved);
 }
 
-#endif // FLIP_WIFI_CALLBACK_H
+#endif // FLIP_WIFI_CALLBACK_H

+ 38 - 42
flip_wifi/flip_wifi_e.h

@@ -5,12 +5,11 @@
 #include <easy_flipper.h>
 #include <storage/storage.h>
 
-#define TAG "FlipWiFi"
+#define TAG               "FlipWiFi"
 #define MAX_WIFI_NETWORKS 25
 
 // Define the submenu items for our FlipWiFi application
-typedef enum
-{
+typedef enum {
     FlipWiFiSubmenuIndexAbout,
     //
     FlipWiFiSubmenuIndexWiFiScan,
@@ -23,67 +22,64 @@ typedef enum
 } FlipWiFiSubmenuIndex;
 
 // Define a single view for our FlipWiFi application
-typedef enum
-{
-    FlipWiFiViewWiFiScan,       // The view for the wifi scan screen
-    FlipWiFiViewWiFiSaved,      // The view for the wifi scan screen
-    FlipWiFiViewSubmenuMain,    // The submenu for the main screen
-    FlipWiFiViewSubmenuScan,    // The submenu for the wifi scan screen
-    FlipWiFiViewSubmenuSaved,   // The submenu for the wifi scan screen
-    FlipWiFiViewAbout,          // The about screen
-    FlipWiFiViewTextInputScan,  // The text input screen for the wifi scan screen
+typedef enum {
+    FlipWiFiViewWiFiScan, // The view for the wifi scan screen
+    FlipWiFiViewWiFiSaved, // The view for the wifi scan screen
+    FlipWiFiViewSubmenuMain, // The submenu for the main screen
+    FlipWiFiViewSubmenuScan, // The submenu for the wifi scan screen
+    FlipWiFiViewSubmenuSaved, // The submenu for the wifi scan screen
+    FlipWiFiViewAbout, // The about screen
+    FlipWiFiViewTextInputScan, // The text input screen for the wifi scan screen
     FlipWiFiViewTextInputSaved, // The text input screen for the wifi saved screen
     //
-    FlipWiFiViewTextInputSavedAddSSID,     // The text input screen for the wifi saved screen
+    FlipWiFiViewTextInputSavedAddSSID, // The text input screen for the wifi saved screen
     FlipWiFiViewTextInputSavedAddPassword, // The text input screen for the wifi saved screen
     //
     FlipWiFiViewPopup, // The popup screen
 } FlipWiFiView;
 
 // Define the WiFiPlaylist structure
-typedef struct
-{
-    char *ssids[MAX_WIFI_NETWORKS];
-    char *passwords[MAX_WIFI_NETWORKS];
+typedef struct {
+    char* ssids[MAX_WIFI_NETWORKS];
+    char* passwords[MAX_WIFI_NETWORKS];
     size_t count;
 } WiFiPlaylist;
 
 // Each screen will have its own view
-typedef struct
-{
-    ViewDispatcher *view_dispatcher;                // Switches between our views
-    Popup *popup;                                   // The popup for the app
-    View *view_wifi_scan;                           // The view for the wifi scan screen
-    View *view_wifi_saved;                          // The view for the wifi saved screen
-    Submenu *submenu_main;                          // The submenu for the main screen
-    Submenu *submenu_wifi_scan;                     // The submenu for the wifi scan screen
-    Submenu *submenu_wifi_saved;                    // The submenu for the saved wifi screen
-    Widget *widget_info;                            // The widget
-    VariableItemList *variable_item_list_wifi;      // The variable item list (settngs)
-    VariableItem *variable_item_ssid;               // The variable item
-    UART_TextInput *uart_text_input_password_scan;  // The text input for the wifi scan screen
-    UART_TextInput *uart_text_input_password_saved; // The text input for the wifi saved screen
+typedef struct {
+    ViewDispatcher* view_dispatcher; // Switches between our views
+    Popup* popup; // The popup for the app
+    View* view_wifi_scan; // The view for the wifi scan screen
+    View* view_wifi_saved; // The view for the wifi saved screen
+    Submenu* submenu_main; // The submenu for the main screen
+    Submenu* submenu_wifi_scan; // The submenu for the wifi scan screen
+    Submenu* submenu_wifi_saved; // The submenu for the saved wifi screen
+    Widget* widget_info; // The widget
+    VariableItemList* variable_item_list_wifi; // The variable item list (settngs)
+    VariableItem* variable_item_ssid; // The variable item
+    UART_TextInput* uart_text_input_password_scan; // The text input for the wifi scan screen
+    UART_TextInput* uart_text_input_password_saved; // The text input for the wifi saved screen
     //
-    UART_TextInput *uart_text_input_add_ssid;     // The text input for the wifi saved screen
-    UART_TextInput *uart_text_input_add_password; // The text input for the wifi saved screen
+    UART_TextInput* uart_text_input_add_ssid; // The text input for the wifi saved screen
+    UART_TextInput* uart_text_input_add_password; // The text input for the wifi saved screen
 
-    char *uart_text_input_buffer_password_scan;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_password_scan;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_password_scan; // Buffer for the text input
+    char* uart_text_input_temp_buffer_password_scan; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_password_scan; // Size of the text input buffer
 
-    char *uart_text_input_buffer_password_saved;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_password_saved;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_password_saved; // Buffer for the text input
+    char* uart_text_input_temp_buffer_password_saved; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_password_saved; // Size of the text input buffer
 
-    char *uart_text_input_buffer_add_ssid;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_add_ssid;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_add_ssid; // Buffer for the text input
+    char* uart_text_input_temp_buffer_add_ssid; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_add_ssid; // Size of the text input buffer
 
-    char *uart_text_input_buffer_add_password;         // Buffer for the text input
-    char *uart_text_input_temp_buffer_add_password;    // Temporary buffer for the text input
+    char* uart_text_input_buffer_add_password; // Buffer for the text input
+    char* uart_text_input_temp_buffer_add_password; // Temporary buffer for the text input
     uint32_t uart_text_input_buffer_size_add_password; // Size of the text input buffer
 
     WiFiPlaylist wifi_playlist; // The playlist of wifi networks
 } FlipWiFiApp;
 
-#endif // FLIP_WIFI_E_H
+#endif // FLIP_WIFI_E_H

+ 19 - 37
flip_wifi/flip_wifi_free.h

@@ -2,84 +2,68 @@
 #define FLIP_WIFI_FREE_H
 
 // Function to free the resources used by FlipWiFiApp
-static void flip_wifi_app_free(FlipWiFiApp *app)
-{
-    if (!app)
-    {
+static void flip_wifi_app_free(FlipWiFiApp* app) {
+    if(!app) {
         FURI_LOG_E(TAG, "FlipWiFiApp is NULL");
         return;
     }
 
     // Free View(s)
-    if (app->view_wifi_scan)
-    {
+    if(app->view_wifi_scan) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewWiFiScan);
         view_free(app->view_wifi_scan);
     }
-    if (app->view_wifi_saved)
-    {
+    if(app->view_wifi_saved) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewWiFiSaved);
         view_free(app->view_wifi_saved);
     }
 
     // Free Submenu(s)
-    if (app->submenu_main)
-    {
+    if(app->submenu_main) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewSubmenuMain);
         submenu_free(app->submenu_main);
     }
-    if (app->submenu_wifi_scan)
-    {
+    if(app->submenu_wifi_scan) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewSubmenuScan);
         submenu_free(app->submenu_wifi_scan);
     }
-    if (app->submenu_wifi_saved)
-    {
+    if(app->submenu_wifi_saved) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewSubmenuSaved);
         submenu_free(app->submenu_wifi_saved);
     }
 
     // Free Widget(s)
-    if (app->widget_info)
-    {
+    if(app->widget_info) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewAbout);
         widget_free(app->widget_info);
     }
 
     // Free Text Input(s)
-    if (app->uart_text_input_password_scan)
-    {
+    if(app->uart_text_input_password_scan) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewTextInputScan);
         uart_text_input_free(app->uart_text_input_password_scan);
     }
-    if (app->uart_text_input_password_saved)
-    {
+    if(app->uart_text_input_password_saved) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewTextInputSaved);
         uart_text_input_free(app->uart_text_input_password_saved);
     }
-    if (app->uart_text_input_add_ssid)
-    {
+    if(app->uart_text_input_add_ssid) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewTextInputSavedAddSSID);
         uart_text_input_free(app->uart_text_input_add_ssid);
     }
-    if (app->uart_text_input_add_password)
-    {
+    if(app->uart_text_input_add_password) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewTextInputSavedAddPassword);
         uart_text_input_free(app->uart_text_input_add_password);
     }
 
     // free playlist
-    for (size_t i = 0; i < app->wifi_playlist.count; i++)
-    {
-        if (app->wifi_playlist.ssids[i])
-            free(app->wifi_playlist.ssids[i]);
-        if (app->wifi_playlist.passwords[i])
-            free(app->wifi_playlist.passwords[i]);
+    for(size_t i = 0; i < app->wifi_playlist.count; i++) {
+        if(app->wifi_playlist.ssids[i]) free(app->wifi_playlist.ssids[i]);
+        if(app->wifi_playlist.passwords[i]) free(app->wifi_playlist.passwords[i]);
     }
 
     // free popup
-    if (app->popup)
-    {
+    if(app->popup) {
         view_dispatcher_remove_view(app->view_dispatcher, FlipWiFiViewPopup);
         popup_free(app->popup);
     }
@@ -88,15 +72,13 @@ static void flip_wifi_app_free(FlipWiFiApp *app)
     flipper_http_deinit();
 
     // free the view dispatcher
-    if (app->view_dispatcher)
-        view_dispatcher_free(app->view_dispatcher);
+    if(app->view_dispatcher) view_dispatcher_free(app->view_dispatcher);
 
     // close the gui
     furi_record_close(RECORD_GUI);
 
     // free the app
-    if (app)
-        free(app);
+    if(app) free(app);
 }
 
-#endif // FLIP_WIFI_FREE_H
+#endif // FLIP_WIFI_FREE_H

+ 148 - 69
flip_wifi/flip_wifi_i.h

@@ -2,15 +2,13 @@
 #define FLIP_WIFI_I_H
 
 // Function to allocate resources for the FlipWiFiApp
-static FlipWiFiApp *flip_wifi_app_alloc()
-{
-    FlipWiFiApp *app = (FlipWiFiApp *)malloc(sizeof(FlipWiFiApp));
+static FlipWiFiApp* flip_wifi_app_alloc() {
+    FlipWiFiApp* app = (FlipWiFiApp*)malloc(sizeof(FlipWiFiApp));
 
-    Gui *gui = furi_record_open(RECORD_GUI);
+    Gui* gui = furi_record_open(RECORD_GUI);
 
     // initialize uart
-    if (!flipper_http_init(flipper_http_rx_callback, app))
-    {
+    if(!flipper_http_init(flipper_http_rx_callback, app)) {
         FURI_LOG_E(TAG, "Failed to initialize flipper http");
         return NULL;
     }
@@ -20,109 +18,190 @@ static FlipWiFiApp *flip_wifi_app_alloc()
     app->uart_text_input_buffer_size_password_saved = 64;
     app->uart_text_input_buffer_size_add_ssid = 64;
     app->uart_text_input_buffer_size_add_password = 64;
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password_scan, app->uart_text_input_buffer_size_password_scan))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_password_scan,
+           app->uart_text_input_buffer_size_password_scan)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_password_scan, app->uart_text_input_buffer_size_password_scan))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_password_scan,
+           app->uart_text_input_buffer_size_password_scan)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password_saved, app->uart_text_input_buffer_size_password_saved))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_password_saved,
+           app->uart_text_input_buffer_size_password_saved)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_password_saved, app->uart_text_input_buffer_size_password_saved))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_password_saved,
+           app->uart_text_input_buffer_size_password_saved)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_add_ssid, app->uart_text_input_buffer_size_add_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_add_ssid, app->uart_text_input_buffer_size_add_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_add_ssid, app->uart_text_input_buffer_size_add_ssid))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_add_ssid,
+           app->uart_text_input_buffer_size_add_ssid)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_add_password, app->uart_text_input_buffer_size_add_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_buffer_add_password,
+           app->uart_text_input_buffer_size_add_password)) {
         return NULL;
     }
-    if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_add_password, app->uart_text_input_buffer_size_add_password))
-    {
+    if(!easy_flipper_set_buffer(
+           &app->uart_text_input_temp_buffer_add_password,
+           app->uart_text_input_buffer_size_add_password)) {
         return NULL;
     }
 
     // Allocate ViewDispatcher
-    if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
-    {
+    if(!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app)) {
         return NULL;
     }
 
     // View(s)
-    if (!easy_flipper_set_view(&app->view_wifi_scan, FlipWiFiViewWiFiScan, flip_wifi_view_draw_callback_scan, flip_wifi_view_input_callback_scan, callback_to_submenu_scan, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_view(&app->view_wifi_saved, FlipWiFiViewWiFiSaved, flip_wifi_view_draw_callback_saved, flip_wifi_view_input_callback_saved, callback_to_submenu_saved, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_view(
+           &app->view_wifi_scan,
+           FlipWiFiViewWiFiScan,
+           flip_wifi_view_draw_callback_scan,
+           flip_wifi_view_input_callback_scan,
+           callback_to_submenu_scan,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_view(
+           &app->view_wifi_saved,
+           FlipWiFiViewWiFiSaved,
+           flip_wifi_view_draw_callback_saved,
+           flip_wifi_view_input_callback_saved,
+           callback_to_submenu_saved,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Widget
-    if (!easy_flipper_set_widget(&app->widget_info, FlipWiFiViewAbout, "FlipWiFi v1.0\n-----\nFlipperHTTP companion app.\nScan and save WiFi networks.\n-----\nwww.github.com/jblanked", callback_to_submenu_main, &app->view_dispatcher))
-    {
+    if(!easy_flipper_set_widget(
+           &app->widget_info,
+           FlipWiFiViewAbout,
+           "FlipWiFi v1.0\n-----\nFlipperHTTP companion app.\nScan and save WiFi networks.\n-----\nwww.github.com/jblanked",
+           callback_to_submenu_main,
+           &app->view_dispatcher)) {
         return NULL;
     }
 
     // Text Input
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_password_scan, FlipWiFiViewTextInputScan, "Enter WiFi Password", app->uart_text_input_temp_buffer_password_scan, app->uart_text_input_buffer_size_password_scan, flip_wifi_text_updated_password_scan, callback_to_submenu_scan, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_password_saved, FlipWiFiViewTextInputSaved, "Enter WiFi Password", app->uart_text_input_temp_buffer_password_saved, app->uart_text_input_buffer_size_password_saved, flip_wifi_text_updated_password_saved, callback_to_submenu_saved, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_add_ssid, FlipWiFiViewTextInputSavedAddSSID, "Enter SSID", app->uart_text_input_temp_buffer_add_ssid, app->uart_text_input_buffer_size_add_ssid, flip_wifi_text_updated_add_ssid, callback_to_submenu_saved, &app->view_dispatcher, app))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_uart_text_input(&app->uart_text_input_add_password, FlipWiFiViewTextInputSavedAddPassword, "Enter Password", app->uart_text_input_temp_buffer_add_password, app->uart_text_input_buffer_size_add_password, flip_wifi_text_updated_add_password, callback_to_submenu_saved, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_password_scan,
+           FlipWiFiViewTextInputScan,
+           "Enter WiFi Password",
+           app->uart_text_input_temp_buffer_password_scan,
+           app->uart_text_input_buffer_size_password_scan,
+           flip_wifi_text_updated_password_scan,
+           callback_to_submenu_scan,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_password_saved,
+           FlipWiFiViewTextInputSaved,
+           "Enter WiFi Password",
+           app->uart_text_input_temp_buffer_password_saved,
+           app->uart_text_input_buffer_size_password_saved,
+           flip_wifi_text_updated_password_saved,
+           callback_to_submenu_saved,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_add_ssid,
+           FlipWiFiViewTextInputSavedAddSSID,
+           "Enter SSID",
+           app->uart_text_input_temp_buffer_add_ssid,
+           app->uart_text_input_buffer_size_add_ssid,
+           flip_wifi_text_updated_add_ssid,
+           callback_to_submenu_saved,
+           &app->view_dispatcher,
+           app)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_uart_text_input(
+           &app->uart_text_input_add_password,
+           FlipWiFiViewTextInputSavedAddPassword,
+           "Enter Password",
+           app->uart_text_input_temp_buffer_add_password,
+           app->uart_text_input_buffer_size_add_password,
+           flip_wifi_text_updated_add_password,
+           callback_to_submenu_saved,
+           &app->view_dispatcher,
+           app)) {
         return NULL;
     }
 
     // Submenu
-    if (!easy_flipper_set_submenu(&app->submenu_main, FlipWiFiViewSubmenuMain, "FlipWiFi v1.0", easy_flipper_callback_exit_app, &app->view_dispatcher))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_submenu(&app->submenu_wifi_scan, FlipWiFiViewSubmenuScan, "WiFi Scan", callback_to_submenu_main, &app->view_dispatcher))
-    {
-        return NULL;
-    }
-    if (!easy_flipper_set_submenu(&app->submenu_wifi_saved, FlipWiFiViewSubmenuSaved, "Saved APs", callback_to_submenu_main, &app->view_dispatcher))
-    {
-        return NULL;
-    }
-    submenu_add_item(app->submenu_main, "Scan", FlipWiFiSubmenuIndexWiFiScan, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "Saved APs", FlipWiFiSubmenuIndexWiFiSaved, callback_submenu_choices, app);
-    submenu_add_item(app->submenu_main, "Info", FlipWiFiSubmenuIndexAbout, callback_submenu_choices, app);
+    if(!easy_flipper_set_submenu(
+           &app->submenu_main,
+           FlipWiFiViewSubmenuMain,
+           "FlipWiFi v1.0",
+           easy_flipper_callback_exit_app,
+           &app->view_dispatcher)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_submenu(
+           &app->submenu_wifi_scan,
+           FlipWiFiViewSubmenuScan,
+           "WiFi Scan",
+           callback_to_submenu_main,
+           &app->view_dispatcher)) {
+        return NULL;
+    }
+    if(!easy_flipper_set_submenu(
+           &app->submenu_wifi_saved,
+           FlipWiFiViewSubmenuSaved,
+           "Saved APs",
+           callback_to_submenu_main,
+           &app->view_dispatcher)) {
+        return NULL;
+    }
+    submenu_add_item(
+        app->submenu_main, "Scan", FlipWiFiSubmenuIndexWiFiScan, callback_submenu_choices, app);
+    submenu_add_item(
+        app->submenu_main,
+        "Saved APs",
+        FlipWiFiSubmenuIndexWiFiSaved,
+        callback_submenu_choices,
+        app);
+    submenu_add_item(
+        app->submenu_main, "Info", FlipWiFiSubmenuIndexAbout, callback_submenu_choices, app);
 
     // Popup
-    if (!easy_flipper_set_popup(&app->popup, FlipWiFiViewPopup, "Success", 0, 0, "The WiFi setting has been set.", 0, 10, popup_callback_saved, callback_to_submenu_saved, &app->view_dispatcher, app))
-    {
+    if(!easy_flipper_set_popup(
+           &app->popup,
+           FlipWiFiViewPopup,
+           "Success",
+           0,
+           0,
+           "The WiFi setting has been set.",
+           0,
+           10,
+           popup_callback_saved,
+           callback_to_submenu_saved,
+           &app->view_dispatcher,
+           app)) {
         return false;
     }
 
     // Load the playlist from storage
-    if (!load_playlist(&app->wifi_playlist))
-    {
+    if(!load_playlist(&app->wifi_playlist)) {
         FURI_LOG_E(TAG, "Failed to load playlist");
-    }
-    else
-    {
+    } else {
         // Update the submenu
         flip_wifi_redraw_submenu_saved(app);
     }
@@ -135,4 +214,4 @@ static FlipWiFiApp *flip_wifi_app_alloc()
     return app;
 }
 
-#endif // FLIP_WIFI_I_H
+#endif // FLIP_WIFI_I_H

+ 101 - 144
flip_wifi/flip_wifi_storage.h

@@ -5,22 +5,20 @@
 #define WIFI_SSID_LIST_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_wifi/wifi_list.txt"
 
 // Function to save the playlist
-void save_playlist(const WiFiPlaylist *playlist)
-{
-    if (!playlist)
-    {
+void save_playlist(const WiFiPlaylist* playlist) {
+    if(!playlist) {
         FURI_LOG_E(TAG, "Playlist is NULL");
         return;
     }
 
     // Create the directory for saving settings
     char directory_path[128];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_wifi");
+    snprintf(
+        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_wifi");
 
     // Open storage
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    if (!storage)
-    {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(!storage) {
         FURI_LOG_E(TAG, "Failed to open storage record");
         return;
     }
@@ -29,35 +27,30 @@ void save_playlist(const WiFiPlaylist *playlist)
     storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
-    File *file = storage_file_alloc(storage);
-    if (!file)
-    {
+    File* file = storage_file_alloc(storage);
+    if(!file) {
         FURI_LOG_E(TAG, "Failed to allocate file handle");
         furi_record_close(RECORD_STORAGE);
         return;
     }
-    if (!storage_file_open(file, WIFI_SSID_LIST_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-    {
+    if(!storage_file_open(file, WIFI_SSID_LIST_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", WIFI_SSID_LIST_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
         return;
     }
 
-    for (size_t i = 0; i < playlist->count; i++)
-    {
-        if (!playlist->ssids[i] || !playlist->passwords[i])
-        {
+    for(size_t i = 0; i < playlist->count; i++) {
+        if(!playlist->ssids[i] || !playlist->passwords[i]) {
             FURI_LOG_E(TAG, "Invalid SSID or password at index %zu", i);
             continue;
         }
         size_t ssid_length = strlen(playlist->ssids[i]);
         size_t password_length = strlen(playlist->passwords[i]);
-        if (storage_file_write(file, playlist->ssids[i], ssid_length) != ssid_length ||
-            storage_file_write(file, ",", 1) != 1 ||
-            storage_file_write(file, playlist->passwords[i], password_length) != password_length ||
-            storage_file_write(file, "\n", 1) != 1)
-        {
+        if(storage_file_write(file, playlist->ssids[i], ssid_length) != ssid_length ||
+           storage_file_write(file, ",", 1) != 1 ||
+           storage_file_write(file, playlist->passwords[i], password_length) != password_length ||
+           storage_file_write(file, "\n", 1) != 1) {
             FURI_LOG_E(TAG, "Failed to write playlist");
         }
     }
@@ -68,10 +61,8 @@ void save_playlist(const WiFiPlaylist *playlist)
 }
 
 // Function to load the playlist
-bool load_playlist(WiFiPlaylist *playlist)
-{
-    if (!playlist)
-    {
+bool load_playlist(WiFiPlaylist* playlist) {
+    if(!playlist) {
         FURI_LOG_E(TAG, "Playlist is NULL");
         return false;
     }
@@ -80,24 +71,19 @@ bool load_playlist(WiFiPlaylist *playlist)
     playlist->count = 0;
 
     // Allocate memory for SSIDs and passwords if not already allocated
-    for (size_t i = 0; i < MAX_WIFI_NETWORKS; i++)
-    {
-        if (!playlist->ssids[i])
-        {
+    for(size_t i = 0; i < MAX_WIFI_NETWORKS; i++) {
+        if(!playlist->ssids[i]) {
             playlist->ssids[i] = malloc(64); // Adjust size as needed
-            if (!playlist->ssids[i])
-            {
+            if(!playlist->ssids[i]) {
                 FURI_LOG_E(TAG, "Memory allocation failed for ssids[%zu]", i);
                 // Handle memory allocation failure (e.g., clean up and return)
                 return false;
             }
         }
 
-        if (!playlist->passwords[i])
-        {
+        if(!playlist->passwords[i]) {
             playlist->passwords[i] = malloc(64); // Adjust size as needed
-            if (!playlist->passwords[i])
-            {
+            if(!playlist->passwords[i]) {
                 FURI_LOG_E(TAG, "Memory allocation failed for passwords[%zu]", i);
                 // Handle memory allocation failure (e.g., clean up and return)
                 return false;
@@ -106,23 +92,20 @@ bool load_playlist(WiFiPlaylist *playlist)
     }
 
     // Open the settings file
-    Storage *storage = furi_record_open(RECORD_STORAGE);
-    if (!storage)
-    {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(!storage) {
         FURI_LOG_E(TAG, "Failed to open storage record");
         return false;
     }
 
-    File *file = storage_file_alloc(storage);
-    if (!file)
-    {
+    File* file = storage_file_alloc(storage);
+    if(!file) {
         FURI_LOG_E(TAG, "Failed to allocate file handle");
         furi_record_close(RECORD_STORAGE);
         return false;
     }
 
-    if (!storage_file_open(file, WIFI_SSID_LIST_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
-    {
+    if(!storage_file_open(file, WIFI_SSID_LIST_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", WIFI_SSID_LIST_PATH);
         storage_file_free(file);
         furi_record_close(RECORD_STORAGE);
@@ -134,17 +117,14 @@ bool load_playlist(WiFiPlaylist *playlist)
     size_t line_pos = 0;
     char ch;
 
-    while (storage_file_read(file, &ch, 1) == 1)
-    {
-        if (ch == '\n')
-        {
+    while(storage_file_read(file, &ch, 1) == 1) {
+        if(ch == '\n') {
             // Null-terminate the line
             line_buffer[line_pos] = '\0';
 
             // Split the line into SSID and Password
-            char *comma_pos = strchr(line_buffer, ',');
-            if (comma_pos)
-            {
+            char* comma_pos = strchr(line_buffer, ',');
+            if(comma_pos) {
                 *comma_pos = '\0'; // Replace comma with null character
 
                 // Copy SSID
@@ -157,28 +137,21 @@ bool load_playlist(WiFiPlaylist *playlist)
 
                 playlist->count++;
 
-                if (playlist->count >= MAX_WIFI_NETWORKS)
-                {
-                    FURI_LOG_W(TAG, "Reached maximum number of WiFi networks: %d", MAX_WIFI_NETWORKS);
+                if(playlist->count >= MAX_WIFI_NETWORKS) {
+                    FURI_LOG_W(
+                        TAG, "Reached maximum number of WiFi networks: %d", MAX_WIFI_NETWORKS);
                     break;
                 }
-            }
-            else
-            {
+            } else {
                 FURI_LOG_E(TAG, "Invalid line format (no comma found): %s", line_buffer);
             }
 
             // Reset line buffer position for the next line
             line_pos = 0;
-        }
-        else
-        {
-            if (line_pos < sizeof(line_buffer) - 1)
-            {
+        } else {
+            if(line_pos < sizeof(line_buffer) - 1) {
                 line_buffer[line_pos++] = ch;
-            }
-            else
-            {
+            } else {
                 FURI_LOG_E(TAG, "Line buffer overflow");
                 // Optionally handle line overflow (e.g., skip the rest of the line)
                 line_pos = 0;
@@ -187,12 +160,10 @@ bool load_playlist(WiFiPlaylist *playlist)
     }
 
     // Handle the last line if it does not end with a newline
-    if (line_pos > 0)
-    {
+    if(line_pos > 0) {
         line_buffer[line_pos] = '\0';
-        char *comma_pos = strchr(line_buffer, ',');
-        if (comma_pos)
-        {
+        char* comma_pos = strchr(line_buffer, ',');
+        if(comma_pos) {
             *comma_pos = '\0'; // Replace comma with null character
 
             // Copy SSID
@@ -205,13 +176,10 @@ bool load_playlist(WiFiPlaylist *playlist)
 
             playlist->count++;
 
-            if (playlist->count >= MAX_WIFI_NETWORKS)
-            {
+            if(playlist->count >= MAX_WIFI_NETWORKS) {
                 FURI_LOG_W(TAG, "Reached maximum number of WiFi networks: %d", MAX_WIFI_NETWORKS);
             }
-        }
-        else
-        {
+        } else {
             FURI_LOG_E(TAG, "Invalid line format (no comma found): %s", line_buffer);
         }
     }
@@ -224,7 +192,7 @@ bool load_playlist(WiFiPlaylist *playlist)
     return true;
 }
 
-char *app_ids[7] = {
+char* app_ids[7] = {
     "flip_wifi",
     "flip_store",
     "flip_social",
@@ -233,21 +201,26 @@ char *app_ids[7] = {
     "flip_library",
     "web_crawler"};
 
-void save_settings(const char *ssid, const char *password)
-{
+void save_settings(const char* ssid, const char* password) {
     char edited_directory_path[128];
     char edited_file_path[128];
 
-    for (size_t i = 0; i < 7; i++)
-    {
+    for(size_t i = 0; i < 7; i++) {
         // Construct the directory and file paths for the current app
-        snprintf(edited_directory_path, sizeof(edited_directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/%s", app_ids[i]);
-        snprintf(edited_file_path, sizeof(edited_file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/%s/settings.bin", app_ids[i]);
+        snprintf(
+            edited_directory_path,
+            sizeof(edited_directory_path),
+            STORAGE_EXT_PATH_PREFIX "/apps_data/%s",
+            app_ids[i]);
+        snprintf(
+            edited_file_path,
+            sizeof(edited_file_path),
+            STORAGE_EXT_PATH_PREFIX "/apps_data/%s/settings.bin",
+            app_ids[i]);
 
         // Open the storage record
-        Storage *storage = furi_record_open(RECORD_STORAGE);
-        if (!storage)
-        {
+        Storage* storage = furi_record_open(RECORD_STORAGE);
+        if(!storage) {
             FURI_LOG_E(TAG, "Failed to open storage record for app: %s", app_ids[i]);
             continue; // Skip to the next app
         }
@@ -256,26 +229,24 @@ void save_settings(const char *ssid, const char *password)
         storage_common_mkdir(storage, edited_directory_path);
 
         // Allocate a file handle
-        File *file = storage_file_alloc(storage);
-        if (!file)
-        {
+        File* file = storage_file_alloc(storage);
+        if(!file) {
             FURI_LOG_E(TAG, "Failed to allocate storage file for app: %s", app_ids[i]);
             furi_record_close(RECORD_STORAGE);
             continue; // Skip to the next app
         }
 
         // Open the file in read mode to read existing data
-        bool file_opened = storage_file_open(file, edited_file_path, FSAM_READ, FSOM_OPEN_EXISTING);
+        bool file_opened =
+            storage_file_open(file, edited_file_path, FSAM_READ, FSOM_OPEN_EXISTING);
         size_t file_size = 0;
-        uint8_t *buffer = NULL;
+        uint8_t* buffer = NULL;
 
-        if (file_opened)
-        {
+        if(file_opened) {
             // Get the file size
             file_size = storage_file_size(file);
             buffer = malloc(file_size);
-            if (!buffer)
-            {
+            if(!buffer) {
                 FURI_LOG_E(TAG, "Failed to allocate buffer for app: %s", app_ids[i]);
                 storage_file_close(file);
                 storage_file_free(file);
@@ -284,8 +255,7 @@ void save_settings(const char *ssid, const char *password)
             }
 
             // Read the existing data
-            if (storage_file_read(file, buffer, file_size) != file_size)
-            {
+            if(storage_file_read(file, buffer, file_size) != file_size) {
                 FURI_LOG_E(TAG, "Failed to read settings file for app: %s", app_ids[i]);
                 free(buffer);
                 storage_file_close(file);
@@ -296,79 +266,72 @@ void save_settings(const char *ssid, const char *password)
 
             storage_file_close(file);
             storage_file_free(file);
-        }
-        else
-        {
+        } else {
             // If the file doesn't exist, initialize an empty buffer
             file_size = 0;
             buffer = NULL;
         }
 
         // Prepare new SSID and Password
-        size_t new_ssid_length = strlen(ssid) + 1;         // Including null terminator
+        size_t new_ssid_length = strlen(ssid) + 1; // Including null terminator
         size_t new_password_length = strlen(password) + 1; // Including null terminator
 
         // Calculate the new file size
-        size_t new_file_size = sizeof(size_t) + new_ssid_length + sizeof(size_t) + new_password_length;
+        size_t new_file_size =
+            sizeof(size_t) + new_ssid_length + sizeof(size_t) + new_password_length;
 
         // If there is additional data beyond SSID and Password, preserve it
         size_t additional_data_size = 0;
-        uint8_t *additional_data = NULL;
+        uint8_t* additional_data = NULL;
 
-        if (buffer)
-        {
+        if(buffer) {
             // Parse existing SSID length
-            if (file_size >= sizeof(size_t))
-            {
+            if(file_size >= sizeof(size_t)) {
                 size_t existing_ssid_length;
                 memcpy(&existing_ssid_length, buffer, sizeof(size_t));
 
                 // Parse existing Password length
-                if (file_size >= sizeof(size_t) + existing_ssid_length + sizeof(size_t))
-                {
+                if(file_size >= sizeof(size_t) + existing_ssid_length + sizeof(size_t)) {
                     size_t existing_password_length;
-                    memcpy(&existing_password_length, buffer + sizeof(size_t) + existing_ssid_length, sizeof(size_t));
+                    memcpy(
+                        &existing_password_length,
+                        buffer + sizeof(size_t) + existing_ssid_length,
+                        sizeof(size_t));
 
                     // Calculate the offset where additional data starts
-                    size_t additional_offset = sizeof(size_t) + existing_ssid_length + sizeof(size_t) + existing_password_length;
-                    if (additional_offset < file_size)
-                    {
+                    size_t additional_offset = sizeof(size_t) + existing_ssid_length +
+                                               sizeof(size_t) + existing_password_length;
+                    if(additional_offset < file_size) {
                         additional_data_size = file_size - additional_offset;
                         additional_data = malloc(additional_data_size);
-                        if (additional_data)
-                        {
-                            memcpy(additional_data, buffer + additional_offset, additional_data_size);
-                        }
-                        else
-                        {
-                            FURI_LOG_E(TAG, "Failed to allocate memory for additional data for app: %s", app_ids[i]);
+                        if(additional_data) {
+                            memcpy(
+                                additional_data, buffer + additional_offset, additional_data_size);
+                        } else {
+                            FURI_LOG_E(
+                                TAG,
+                                "Failed to allocate memory for additional data for app: %s",
+                                app_ids[i]);
                             free(buffer);
                             furi_record_close(RECORD_STORAGE);
                             continue;
                         }
                     }
-                }
-                else
-                {
+                } else {
                     FURI_LOG_E(TAG, "Settings file format invalid for app: %s", app_ids[i]);
                 }
-            }
-            else
-            {
+            } else {
                 FURI_LOG_E(TAG, "Settings file too small for app: %s", app_ids[i]);
             }
         }
 
         // Allocate a new buffer for updated data
         size_t total_new_size = new_file_size + additional_data_size;
-        uint8_t *new_buffer = malloc(total_new_size);
-        if (!new_buffer)
-        {
+        uint8_t* new_buffer = malloc(total_new_size);
+        if(!new_buffer) {
             FURI_LOG_E(TAG, "Failed to allocate new buffer for app: %s", app_ids[i]);
-            if (buffer)
-                free(buffer);
-            if (additional_data)
-                free(additional_data);
+            if(buffer) free(buffer);
+            if(additional_data) free(additional_data);
             furi_record_close(RECORD_STORAGE);
             continue;
         }
@@ -388,30 +351,25 @@ void save_settings(const char *ssid, const char *password)
         offset += new_password_length;
 
         // Append any additional data if present
-        if (additional_data_size > 0 && additional_data)
-        {
+        if(additional_data_size > 0 && additional_data) {
             memcpy(new_buffer + offset, additional_data, additional_data_size);
             offset += additional_data_size;
         }
 
         // Free temporary buffers
-        if (buffer)
-            free(buffer);
-        if (additional_data)
-            free(additional_data);
+        if(buffer) free(buffer);
+        if(additional_data) free(additional_data);
 
         // Open the file in write mode with FSOM_CREATE_ALWAYS to overwrite it
         file = storage_file_alloc(storage);
-        if (!file)
-        {
+        if(!file) {
             FURI_LOG_E(TAG, "Failed to allocate storage file for writing: %s", app_ids[i]);
             free(new_buffer);
             furi_record_close(RECORD_STORAGE);
             continue;
         }
 
-        if (!storage_file_open(file, edited_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
-        {
+        if(!storage_file_open(file, edited_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
             FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", edited_file_path);
             storage_file_free(file);
             free(new_buffer);
@@ -420,8 +378,7 @@ void save_settings(const char *ssid, const char *password)
         }
 
         // Write the updated buffer back to the file
-        if (storage_file_write(file, new_buffer, total_new_size) != total_new_size)
-        {
+        if(storage_file_write(file, new_buffer, total_new_size) != total_new_size) {
             FURI_LOG_E(TAG, "Failed to write updated settings for app: %s", app_ids[i]);
         }
 

Разница между файлами не показана из-за своего большого размера
+ 254 - 304
flip_wifi/flipper_http.h


+ 523 - 604
flip_wifi/jsmn.h

@@ -27,8 +27,7 @@
 #include <stddef.h>
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #ifdef JSMN_STATIC
@@ -37,40 +36,37 @@ extern "C"
 #define JSMN_API extern
 #endif
 
-  /**
+/**
    * JSON type identifier. Basic types are:
    * 	o Object
    * 	o Array
    * 	o String
    * 	o Other primitive: number, boolean (true/false) or null
    */
-  typedef enum
-  {
+typedef enum {
     JSMN_UNDEFINED = 0,
     JSMN_OBJECT = 1 << 0,
     JSMN_ARRAY = 1 << 1,
     JSMN_STRING = 1 << 2,
     JSMN_PRIMITIVE = 1 << 3
-  } jsmntype_t;
+} jsmntype_t;
 
-  enum jsmnerr
-  {
+enum jsmnerr {
     /* Not enough tokens were provided */
     JSMN_ERROR_NOMEM = -1,
     /* Invalid character inside JSON string */
     JSMN_ERROR_INVAL = -2,
     /* The string is not a full JSON packet, more bytes expected */
     JSMN_ERROR_PART = -3
-  };
+};
 
-  /**
+/**
    * JSON token description.
    * type		type (object, array, string etc.)
    * start	start position in JSON data string
    * end		end position in JSON data string
    */
-  typedef struct jsmntok
-  {
+typedef struct jsmntok {
     jsmntype_t type;
     int start;
     int end;
@@ -78,43 +74,44 @@ extern "C"
 #ifdef JSMN_PARENT_LINKS
     int parent;
 #endif
-  } jsmntok_t;
+} jsmntok_t;
 
-  /**
+/**
    * JSON parser. Contains an array of token blocks available. Also stores
    * the string being parsed now and current position in that string.
    */
-  typedef struct jsmn_parser
-  {
-    unsigned int pos;     /* offset in the JSON string */
+typedef struct jsmn_parser {
+    unsigned int pos; /* offset in the JSON string */
     unsigned int toknext; /* next token to allocate */
-    int toksuper;         /* superior token node, e.g. parent object or array */
-  } jsmn_parser;
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
 
-  /**
+/**
    * Create JSON parser over an array of tokens
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser);
+JSMN_API void jsmn_init(jsmn_parser* parser);
 
-  /**
+/**
    * Run JSON parser. It parses a JSON data string into and array of tokens, each
    * describing
    * a single JSON object.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens);
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
 
 #ifndef JSMN_HEADER
-  /**
+/**
    * Allocates a fresh unused token from the token pool.
    */
-  static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens,
-                                     const size_t num_tokens)
-  {
-    jsmntok_t *tok;
-    if (parser->toknext >= num_tokens)
-    {
-      return NULL;
+static jsmntok_t*
+    jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
+    jsmntok_t* tok;
+    if(parser->toknext >= num_tokens) {
+        return NULL;
     }
     tok = &tokens[parser->toknext++];
     tok->start = tok->end = -1;
@@ -123,57 +120,55 @@ extern "C"
     tok->parent = -1;
 #endif
     return tok;
-  }
+}
 
-  /**
+/**
    * Fills token type and boundaries.
    */
-  static void jsmn_fill_token(jsmntok_t *token, const jsmntype_t type,
-                              const int start, const int end)
-  {
+static void
+    jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
     token->start = start;
     token->end = end;
     token->size = 0;
-  }
+}
 
-  /**
+/**
    * Fills next available token with JSON primitive.
    */
-  static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-                                  const size_t len, jsmntok_t *tokens,
-                                  const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_primitive(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
     int start;
 
     start = parser->pos;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      switch (js[parser->pos])
-      {
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        switch(js[parser->pos]) {
 #ifndef JSMN_STRICT
-      /* In strict mode primitive must be followed by "," or "}" or "]" */
-      case ':':
+        /* In strict mode primitive must be followed by "," or "}" or "]" */
+        case ':':
 #endif
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-      case ',':
-      case ']':
-      case '}':
-        goto found;
-      default:
-        /* to quiet a warning from gcc*/
-        break;
-      }
-      if (js[parser->pos] < 32 || js[parser->pos] >= 127)
-      {
-        parser->pos = start;
-        return JSMN_ERROR_INVAL;
-      }
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+        case ',':
+        case ']':
+        case '}':
+            goto found;
+        default:
+            /* to quiet a warning from gcc*/
+            break;
+        }
+        if(js[parser->pos] < 32 || js[parser->pos] >= 127) {
+            parser->pos = start;
+            return JSMN_ERROR_INVAL;
+        }
     }
 #ifdef JSMN_STRICT
     /* In strict mode primitive must be followed by a comma/object/array */
@@ -181,17 +176,15 @@ extern "C"
     return JSMN_ERROR_PART;
 #endif
 
-  found:
-    if (tokens == NULL)
-    {
-      parser->pos--;
-      return 0;
+found:
+    if(tokens == NULL) {
+        parser->pos--;
+        return 0;
     }
     token = jsmn_alloc_token(parser, tokens, num_tokens);
-    if (token == NULL)
-    {
-      parser->pos = start;
-      return JSMN_ERROR_NOMEM;
+    if(token == NULL) {
+        parser->pos = start;
+        return JSMN_ERROR_NOMEM;
     }
     jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
 #ifdef JSMN_PARENT_LINKS
@@ -199,325 +192,287 @@ extern "C"
 #endif
     parser->pos--;
     return 0;
-  }
+}
 
-  /**
+/**
    * Fills next token with JSON string.
    */
-  static int jsmn_parse_string(jsmn_parser *parser, const char *js,
-                               const size_t len, jsmntok_t *tokens,
-                               const size_t num_tokens)
-  {
-    jsmntok_t *token;
+static int jsmn_parse_string(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const size_t num_tokens) {
+    jsmntok_t* token;
 
     int start = parser->pos;
 
     /* Skip starting quote */
     parser->pos++;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c = js[parser->pos];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c = js[parser->pos];
 
-      /* Quote: end of string */
-      if (c == '\"')
-      {
-        if (tokens == NULL)
-        {
-          return 0;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          parser->pos = start;
-          return JSMN_ERROR_NOMEM;
-        }
-        jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
+        /* Quote: end of string */
+        if(c == '\"') {
+            if(tokens == NULL) {
+                return 0;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                parser->pos = start;
+                return JSMN_ERROR_NOMEM;
+            }
+            jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
 #ifdef JSMN_PARENT_LINKS
-        token->parent = parser->toksuper;
+            token->parent = parser->toksuper;
 #endif
-        return 0;
-      }
-
-      /* Backslash: Quoted symbol expected */
-      if (c == '\\' && parser->pos + 1 < len)
-      {
-        int i;
-        parser->pos++;
-        switch (js[parser->pos])
-        {
-        /* Allowed escaped symbols */
-        case '\"':
-        case '/':
-        case '\\':
-        case 'b':
-        case 'f':
-        case 'r':
-        case 'n':
-        case 't':
-          break;
-        /* Allows escaped symbol \uXXXX */
-        case 'u':
-          parser->pos++;
-          for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
-               i++)
-          {
-            /* If it isn't a hex character we have an error */
-            if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
-                  (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
-                  (js[parser->pos] >= 97 && js[parser->pos] <= 102)))
-            { /* a-f */
-              parser->pos = start;
-              return JSMN_ERROR_INVAL;
-            }
+            return 0;
+        }
+
+        /* Backslash: Quoted symbol expected */
+        if(c == '\\' && parser->pos + 1 < len) {
+            int i;
             parser->pos++;
-          }
-          parser->pos--;
-          break;
-        /* Unexpected symbol */
-        default:
-          parser->pos = start;
-          return JSMN_ERROR_INVAL;
+            switch(js[parser->pos]) {
+            /* Allowed escaped symbols */
+            case '\"':
+            case '/':
+            case '\\':
+            case 'b':
+            case 'f':
+            case 'r':
+            case 'n':
+            case 't':
+                break;
+            /* Allows escaped symbol \uXXXX */
+            case 'u':
+                parser->pos++;
+                for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) {
+                    /* If it isn't a hex character we have an error */
+                    if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */
+                         (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */
+                         (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
+                        parser->pos = start;
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->pos++;
+                }
+                parser->pos--;
+                break;
+            /* Unexpected symbol */
+            default:
+                parser->pos = start;
+                return JSMN_ERROR_INVAL;
+            }
         }
-      }
     }
     parser->pos = start;
     return JSMN_ERROR_PART;
-  }
+}
 
-  /**
+/**
    * Parse JSON string and fill tokens.
    */
-  JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
-                          jsmntok_t *tokens, const unsigned int num_tokens)
-  {
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens) {
     int r;
     int i;
-    jsmntok_t *token;
+    jsmntok_t* token;
     int count = parser->toknext;
 
-    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
-    {
-      char c;
-      jsmntype_t type;
-
-      c = js[parser->pos];
-      switch (c)
-      {
-      case '{':
-      case '[':
-        count++;
-        if (tokens == NULL)
-        {
-          break;
-        }
-        token = jsmn_alloc_token(parser, tokens, num_tokens);
-        if (token == NULL)
-        {
-          return JSMN_ERROR_NOMEM;
-        }
-        if (parser->toksuper != -1)
-        {
-          jsmntok_t *t = &tokens[parser->toksuper];
+    for(; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
+        char c;
+        jsmntype_t type;
+
+        c = js[parser->pos];
+        switch(c) {
+        case '{':
+        case '[':
+            count++;
+            if(tokens == NULL) {
+                break;
+            }
+            token = jsmn_alloc_token(parser, tokens, num_tokens);
+            if(token == NULL) {
+                return JSMN_ERROR_NOMEM;
+            }
+            if(parser->toksuper != -1) {
+                jsmntok_t* t = &tokens[parser->toksuper];
 #ifdef JSMN_STRICT
-          /* In strict mode an object or array can't become a key */
-          if (t->type == JSMN_OBJECT)
-          {
-            return JSMN_ERROR_INVAL;
-          }
+                /* In strict mode an object or array can't become a key */
+                if(t->type == JSMN_OBJECT) {
+                    return JSMN_ERROR_INVAL;
+                }
 #endif
-          t->size++;
+                t->size++;
 #ifdef JSMN_PARENT_LINKS
-          token->parent = parser->toksuper;
+                token->parent = parser->toksuper;
 #endif
-        }
-        token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
-        token->start = parser->pos;
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case '}':
-      case ']':
-        if (tokens == NULL)
-        {
-          break;
-        }
-        type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
-#ifdef JSMN_PARENT_LINKS
-        if (parser->toknext < 1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        token = &tokens[parser->toknext - 1];
-        for (;;)
-        {
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
             }
-            token->end = parser->pos + 1;
-            parser->toksuper = token->parent;
+            token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
+            token->start = parser->pos;
+            parser->toksuper = parser->toknext - 1;
             break;
-          }
-          if (token->parent == -1)
-          {
-            if (token->type != type || parser->toksuper == -1)
-            {
-              return JSMN_ERROR_INVAL;
+        case '}':
+        case ']':
+            if(tokens == NULL) {
+                break;
+            }
+            type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
+#ifdef JSMN_PARENT_LINKS
+            if(parser->toknext < 1) {
+                return JSMN_ERROR_INVAL;
+            }
+            token = &tokens[parser->toknext - 1];
+            for(;;) {
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    token->end = parser->pos + 1;
+                    parser->toksuper = token->parent;
+                    break;
+                }
+                if(token->parent == -1) {
+                    if(token->type != type || parser->toksuper == -1) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    break;
+                }
+                token = &tokens[token->parent];
             }
-            break;
-          }
-          token = &tokens[token->parent];
-        }
 #else
-        for (i = parser->toknext - 1; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            if (token->type != type)
-            {
-              return JSMN_ERROR_INVAL;
+            for(i = parser->toknext - 1; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    if(token->type != type) {
+                        return JSMN_ERROR_INVAL;
+                    }
+                    parser->toksuper = -1;
+                    token->end = parser->pos + 1;
+                    break;
+                }
+            }
+            /* Error if unmatched closing bracket */
+            if(i == -1) {
+                return JSMN_ERROR_INVAL;
+            }
+            for(; i >= 0; i--) {
+                token = &tokens[i];
+                if(token->start != -1 && token->end == -1) {
+                    parser->toksuper = i;
+                    break;
+                }
             }
-            parser->toksuper = -1;
-            token->end = parser->pos + 1;
+#endif
             break;
-          }
-        }
-        /* Error if unmatched closing bracket */
-        if (i == -1)
-        {
-          return JSMN_ERROR_INVAL;
-        }
-        for (; i >= 0; i--)
-        {
-          token = &tokens[i];
-          if (token->start != -1 && token->end == -1)
-          {
-            parser->toksuper = i;
+        case '\"':
+            r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
             break;
-          }
-        }
-#endif
-        break;
-      case '\"':
-        r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
-      case '\t':
-      case '\r':
-      case '\n':
-      case ' ':
-        break;
-      case ':':
-        parser->toksuper = parser->toknext - 1;
-        break;
-      case ',':
-        if (tokens != NULL && parser->toksuper != -1 &&
-            tokens[parser->toksuper].type != JSMN_ARRAY &&
-            tokens[parser->toksuper].type != JSMN_OBJECT)
-        {
+        case '\t':
+        case '\r':
+        case '\n':
+        case ' ':
+            break;
+        case ':':
+            parser->toksuper = parser->toknext - 1;
+            break;
+        case ',':
+            if(tokens != NULL && parser->toksuper != -1 &&
+               tokens[parser->toksuper].type != JSMN_ARRAY &&
+               tokens[parser->toksuper].type != JSMN_OBJECT) {
 #ifdef JSMN_PARENT_LINKS
-          parser->toksuper = tokens[parser->toksuper].parent;
+                parser->toksuper = tokens[parser->toksuper].parent;
 #else
-          for (i = parser->toknext - 1; i >= 0; i--)
-          {
-            if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT)
-            {
-              if (tokens[i].start != -1 && tokens[i].end == -1)
-              {
-                parser->toksuper = i;
-                break;
-              }
-            }
-          }
+                for(i = parser->toknext - 1; i >= 0; i--) {
+                    if(tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
+                        if(tokens[i].start != -1 && tokens[i].end == -1) {
+                            parser->toksuper = i;
+                            break;
+                        }
+                    }
+                }
 #endif
-        }
-        break;
+            }
+            break;
 #ifdef JSMN_STRICT
-      /* In strict mode primitives are: numbers and booleans */
-      case '-':
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-      case 't':
-      case 'f':
-      case 'n':
-        /* And they must not be keys of the object */
-        if (tokens != NULL && parser->toksuper != -1)
-        {
-          const jsmntok_t *t = &tokens[parser->toksuper];
-          if (t->type == JSMN_OBJECT ||
-              (t->type == JSMN_STRING && t->size != 0))
-          {
-            return JSMN_ERROR_INVAL;
-          }
-        }
+        /* In strict mode primitives are: numbers and booleans */
+        case '-':
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+        case 't':
+        case 'f':
+        case 'n':
+            /* And they must not be keys of the object */
+            if(tokens != NULL && parser->toksuper != -1) {
+                const jsmntok_t* t = &tokens[parser->toksuper];
+                if(t->type == JSMN_OBJECT || (t->type == JSMN_STRING && t->size != 0)) {
+                    return JSMN_ERROR_INVAL;
+                }
+            }
 #else
-      /* In non-strict mode every unquoted value is a primitive */
-      default:
+        /* In non-strict mode every unquoted value is a primitive */
+        default:
 #endif
-        r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
-        if (r < 0)
-        {
-          return r;
-        }
-        count++;
-        if (parser->toksuper != -1 && tokens != NULL)
-        {
-          tokens[parser->toksuper].size++;
-        }
-        break;
+            r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
+            if(r < 0) {
+                return r;
+            }
+            count++;
+            if(parser->toksuper != -1 && tokens != NULL) {
+                tokens[parser->toksuper].size++;
+            }
+            break;
 
 #ifdef JSMN_STRICT
-      /* Unexpected char in strict mode */
-      default:
-        return JSMN_ERROR_INVAL;
+        /* Unexpected char in strict mode */
+        default:
+            return JSMN_ERROR_INVAL;
 #endif
-      }
+        }
     }
 
-    if (tokens != NULL)
-    {
-      for (i = parser->toknext - 1; i >= 0; i--)
-      {
-        /* Unmatched opened object or array */
-        if (tokens[i].start != -1 && tokens[i].end == -1)
-        {
-          return JSMN_ERROR_PART;
+    if(tokens != NULL) {
+        for(i = parser->toknext - 1; i >= 0; i--) {
+            /* Unmatched opened object or array */
+            if(tokens[i].start != -1 && tokens[i].end == -1) {
+                return JSMN_ERROR_PART;
+            }
         }
-      }
     }
 
     return count;
-  }
+}
 
-  /**
+/**
    * Creates a new parser based over a given buffer with an array of tokens
    * available.
    */
-  JSMN_API void jsmn_init(jsmn_parser *parser)
-  {
+JSMN_API void jsmn_init(jsmn_parser* parser) {
     parser->pos = 0;
     parser->toknext = 0;
     parser->toksuper = -1;
-  }
+}
 
 #endif /* JSMN_HEADER */
 
@@ -538,313 +493,277 @@ extern "C"
 #include <furi.h>
 
 // Helper function to compare JSON keys
-int jsoneq(const char *json, jsmntok_t *tok, const char *s)
-{
-  if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
-      strncmp(json + tok->start, s, tok->end - tok->start) == 0)
-  {
-    return 0;
-  }
-  return -1;
+int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
+    if(tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
+       strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+        return 0;
+    }
+    return -1;
 }
 
 // return the value of the key in the JSON data
-char *get_json_value(char *key, char *json_data, uint32_t max_tokens)
-{
-  // Parse the JSON feed
-  if (json_data != NULL)
-  {
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    // Allocate tokens array on the heap
-    jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-    if (tokens == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-      return NULL;
-    }
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
+    // Parse the JSON feed
+    if(json_data != NULL) {
+        jsmn_parser parser;
+        jsmn_init(&parser);
+
+        // Allocate tokens array on the heap
+        jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+        if(tokens == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+            return NULL;
+        }
 
-    int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
-    if (ret < 0)
-    {
-      // Handle parsing errors
-      FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
-      free(tokens);
-      return NULL;
-    }
+        int ret = jsmn_parse(&parser, json_data, strlen(json_data), tokens, max_tokens);
+        if(ret < 0) {
+            // Handle parsing errors
+            FURI_LOG_E("JSMM.H", "Failed to parse JSON: %d", ret);
+            free(tokens);
+            return NULL;
+        }
 
-    // Ensure that the root element is an object
-    if (ret < 1 || tokens[0].type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Root element is not an object.");
-      free(tokens);
-      return NULL;
-    }
+        // Ensure that the root element is an object
+        if(ret < 1 || tokens[0].type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Root element is not an object.");
+            free(tokens);
+            return NULL;
+        }
 
-    // Loop through the tokens to find the key
-    for (int i = 1; i < ret; i++)
-    {
-      if (jsoneq(json_data, &tokens[i], key) == 0)
-      {
-        // We found the key. Now, return the associated value.
-        int length = tokens[i + 1].end - tokens[i + 1].start;
-        char *value = malloc(length + 1);
-        if (value == NULL)
-        {
-          FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
-          free(tokens);
-          return NULL;
+        // Loop through the tokens to find the key
+        for(int i = 1; i < ret; i++) {
+            if(jsoneq(json_data, &tokens[i], key) == 0) {
+                // We found the key. Now, return the associated value.
+                int length = tokens[i + 1].end - tokens[i + 1].start;
+                char* value = malloc(length + 1);
+                if(value == NULL) {
+                    FURI_LOG_E("JSMM.H", "Failed to allocate memory for value.");
+                    free(tokens);
+                    return NULL;
+                }
+                strncpy(value, json_data + tokens[i + 1].start, length);
+                value[length] = '\0'; // Null-terminate the string
+
+                free(tokens); // Free the token array
+                return value; // Return the extracted value
+            }
         }
-        strncpy(value, json_data + tokens[i + 1].start, length);
-        value[length] = '\0'; // Null-terminate the string
 
-        free(tokens); // Free the token array
-        return value; // Return the extracted value
-      }
+        // Free the token array if key was not found
+        free(tokens);
+    } else {
+        FURI_LOG_E("JSMM.H", "JSON data is NULL");
     }
-
-    // Free the token array if key was not found
-    free(tokens);
-  }
-  else
-  {
-    FURI_LOG_E("JSMM.H", "JSON data is NULL");
-  }
-  FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
-  return NULL; // Return NULL if something goes wrong
+    FURI_LOG_E("JSMM.H", "Failed to find the key in the JSON.");
+    return NULL; // Return NULL if something goes wrong
 }
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, char *json_data, uint32_t max_tokens)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
+    }
 
-  // Ensure the root element is an array
-  if (ret < 1 || tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-  // Check if the index is within bounds
-  if (index >= (uint32_t)tokens[0].size)
-  {
-    FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %d.", (unsigned long)index, tokens[0].size);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Locate the token corresponding to the desired array element
-  int current_token = 1; // Start after the array token
-  for (uint32_t i = 0; i < index; i++)
-  {
-    if (tokens[current_token].type == JSMN_OBJECT)
-    {
-      // For objects, skip all key-value pairs
-      current_token += 1 + 2 * tokens[current_token].size;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens);
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
-    else if (tokens[current_token].type == JSMN_ARRAY)
-    {
-      // For nested arrays, skip all elements
-      current_token += 1 + tokens[current_token].size;
+
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-    else
-    {
-      // For primitive types, simply move to the next token
-      current_token += 1;
+
+    // Ensure the root element is an array
+    if(ret < 1 || tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    // Safety check to prevent out-of-bounds
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Check if the index is within bounds
+    if(index >= (uint32_t)tokens[0].size) {
+        FURI_LOG_E(
+            "JSMM.H",
+            "Index %lu out of bounds for array with size %d.",
+            (unsigned long)index,
+            tokens[0].size);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
-  }
-
-  // Extract the array element
-  jsmntok_t element = tokens[current_token];
-  int length = element.end - element.start;
-  char *value = malloc(length + 1);
-  if (value == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
 
-  // Copy the element value to a new string
-  strncpy(value, array_str + element.start, length);
-  value[length] = '\0'; // Null-terminate the string
+    // Locate the token corresponding to the desired array element
+    int current_token = 1; // Start after the array token
+    for(uint32_t i = 0; i < index; i++) {
+        if(tokens[current_token].type == JSMN_OBJECT) {
+            // For objects, skip all key-value pairs
+            current_token += 1 + 2 * tokens[current_token].size;
+        } else if(tokens[current_token].type == JSMN_ARRAY) {
+            // For nested arrays, skip all elements
+            current_token += 1 + tokens[current_token].size;
+        } else {
+            // For primitive types, simply move to the next token
+            current_token += 1;
+        }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
+        // Safety check to prevent out-of-bounds
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
+    }
 
-  return value;
-}
+    // Extract the array element
+    jsmntok_t element = tokens[current_token];
+    int length = element.end - element.start;
+    char* value = malloc(length + 1);
+    if(value == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-// Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
-{
-  // Retrieve the array string for the given key
-  char *array_str = get_json_value(key, json_data, max_tokens);
-  if (array_str == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
-    return NULL;
-  }
-
-  // Initialize the JSON parser
-  jsmn_parser parser;
-  jsmn_init(&parser);
-
-  // Allocate memory for JSON tokens
-  jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
-  if (tokens == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
-    free(array_str);
-    return NULL;
-  }
-
-  // Parse the JSON array
-  int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
-  if (ret < 0)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
+    // Copy the element value to a new string
+    strncpy(value, array_str + element.start, length);
+    value[length] = '\0'; // Null-terminate the string
 
-  // Ensure the root element is an array
-  if (tokens[0].type != JSMN_ARRAY)
-  {
-    FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
-    free(tokens);
-    free(array_str);
-    return NULL;
-  }
-
-  // Allocate memory for the array of values (maximum possible)
-  int array_size = tokens[0].size;
-  char **values = malloc(array_size * sizeof(char *));
-  if (values == NULL)
-  {
-    FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+    // Clean up
     free(tokens);
     free(array_str);
-    return NULL;
-  }
-
-  int actual_num_values = 0;
-
-  // Traverse the array and extract all object values
-  int current_token = 1; // Start after the array token
-  for (int i = 0; i < array_size; i++)
-  {
-    if (current_token >= ret)
-    {
-      FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
-      break;
+
+    return value;
+}
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values) {
+    // Retrieve the array string for the given key
+    char* array_str = get_json_value(key, json_data, max_tokens);
+    if(array_str == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
+        return NULL;
     }
 
-    jsmntok_t element = tokens[current_token];
+    // Initialize the JSON parser
+    jsmn_parser parser;
+    jsmn_init(&parser);
 
-    if (element.type != JSMN_OBJECT)
-    {
-      FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
-      // Skip this element
-      current_token += 1;
-      continue;
+    // Allocate memory for JSON tokens
+    jsmntok_t* tokens = malloc(sizeof(jsmntok_t) * max_tokens); // Allocate on the heap
+    if(tokens == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for JSON tokens.");
+        free(array_str);
+        return NULL;
     }
 
-    int length = element.end - element.start;
+    // Parse the JSON array
+    int ret = jsmn_parse(&parser, array_str, strlen(array_str), tokens, max_tokens);
+    if(ret < 0) {
+        FURI_LOG_E("JSMM.H", "Failed to parse JSON array: %d", ret);
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
 
-    // Allocate a new string for the value and copy the data
-    char *value = malloc(length + 1);
-    if (value == NULL)
-    {
-      FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
-      for (int j = 0; j < actual_num_values; j++)
-      {
-        free(values[j]);
-      }
-      free(values);
-      free(tokens);
-      free(array_str);
-      return NULL;
+    // Ensure the root element is an array
+    if(tokens[0].type != JSMN_ARRAY) {
+        FURI_LOG_E("JSMM.H", "Value for key '%s' is not an array.", key);
+        free(tokens);
+        free(array_str);
+        return NULL;
     }
 
-    strncpy(value, array_str + element.start, length);
-    value[length] = '\0'; // Null-terminate the string
+    // Allocate memory for the array of values (maximum possible)
+    int array_size = tokens[0].size;
+    char** values = malloc(array_size * sizeof(char*));
+    if(values == NULL) {
+        FURI_LOG_E("JSMM.H", "Failed to allocate memory for array of values.");
+        free(tokens);
+        free(array_str);
+        return NULL;
+    }
+
+    int actual_num_values = 0;
+
+    // Traverse the array and extract all object values
+    int current_token = 1; // Start after the array token
+    for(int i = 0; i < array_size; i++) {
+        if(current_token >= ret) {
+            FURI_LOG_E("JSMM.H", "Unexpected end of tokens while traversing array.");
+            break;
+        }
+
+        jsmntok_t element = tokens[current_token];
 
-    values[actual_num_values] = value;
-    actual_num_values++;
+        if(element.type != JSMN_OBJECT) {
+            FURI_LOG_E("JSMM.H", "Array element %d is not an object, skipping.", i);
+            // Skip this element
+            current_token += 1;
+            continue;
+        }
 
-    // Skip all tokens related to this object to avoid misparsing
-    current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
-  }
+        int length = element.end - element.start;
 
-  *num_values = actual_num_values;
+        // Allocate a new string for the value and copy the data
+        char* value = malloc(length + 1);
+        if(value == NULL) {
+            FURI_LOG_E("JSMM.H", "Failed to allocate memory for array element.");
+            for(int j = 0; j < actual_num_values; j++) {
+                free(values[j]);
+            }
+            free(values);
+            free(tokens);
+            free(array_str);
+            return NULL;
+        }
 
-  // Reallocate the values array to actual_num_values if necessary
-  if (actual_num_values < array_size)
-  {
-    char **reduced_values = realloc(values, actual_num_values * sizeof(char *));
-    if (reduced_values != NULL)
-    {
-      values = reduced_values;
+        strncpy(value, array_str + element.start, length);
+        value[length] = '\0'; // Null-terminate the string
+
+        values[actual_num_values] = value;
+        actual_num_values++;
+
+        // Skip all tokens related to this object to avoid misparsing
+        current_token += 1 + (2 * element.size); // Each key-value pair consumes two tokens
     }
 
-    // Free the remaining values
-    for (int i = actual_num_values; i < array_size; i++)
-    {
-      free(values[i]);
+    *num_values = actual_num_values;
+
+    // Reallocate the values array to actual_num_values if necessary
+    if(actual_num_values < array_size) {
+        char** reduced_values = realloc(values, actual_num_values * sizeof(char*));
+        if(reduced_values != NULL) {
+            values = reduced_values;
+        }
+
+        // Free the remaining values
+        for(int i = actual_num_values; i < array_size; i++) {
+            free(values[i]);
+        }
     }
-  }
 
-  // Clean up
-  free(tokens);
-  free(array_str);
-  return values;
+    // Clean up
+    free(tokens);
+    free(array_str);
+    return values;
 }
 
-#endif /* JB_JSMN_EDIT */
+#endif /* JB_JSMN_EDIT */

+ 113 - 213
flip_wifi/uart_text_input.h

@@ -14,43 +14,40 @@
 
 /** Text input anonymous structure */
 typedef struct UART_TextInput UART_TextInput;
-typedef void (*UART_TextInputCallback)(void *context);
-typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
 
-void uart_text_input_reset(UART_TextInput *uart_text_input);
+void uart_text_input_reset(UART_TextInput* uart_text_input);
 
-struct UART_TextInput
-{
-    View *view;
-    FuriTimer *timer;
+struct UART_TextInput {
+    View* view;
+    FuriTimer* timer;
 };
 
-typedef struct
-{
+typedef struct {
     const char text;
     const uint8_t x;
     const uint8_t y;
 } UART_TextInputKey;
 
-typedef struct
-{
-    const char *header;
-    char *text_buffer;
+typedef struct {
+    const char* header;
+    char* text_buffer;
     size_t text_buffer_size;
     bool clear_default_text;
 
     UART_TextInputCallback callback;
-    void *callback_context;
+    void* callback_context;
 
     uint8_t selected_row;
     uint8_t selected_column;
 
     UART_TextInputValidatorCallback validator_callback;
-    void *validator_callback_context;
-    FuriString *validator_text;
+    void* validator_callback_context;
+    FuriString* validator_text;
     bool valadator_message_visible;
 } UART_TextInputModel;
 
@@ -60,7 +57,7 @@ static const uint8_t keyboard_row_count = 4;
 
 #define mode_AT "Send AT command to UART"
 
-#define ENTER_KEY '\r'
+#define ENTER_KEY     '\r'
 #define BACKSPACE_KEY '\b'
 
 static const UART_TextInputKey keyboard_keys_row_1[] = {
@@ -137,12 +134,10 @@ static const UART_TextInputKey keyboard_keys_row_4[] = {
     {'+', 120, 33},
 };
 
-static uint8_t get_row_size(uint8_t row_index)
-{
+static uint8_t get_row_size(uint8_t row_index) {
     uint8_t row_size = 0;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
         break;
@@ -160,12 +155,10 @@ static uint8_t get_row_size(uint8_t row_index)
     return row_size;
 }
 
-static const UART_TextInputKey *get_row(uint8_t row_index)
-{
-    const UART_TextInputKey *row = NULL;
+static const UART_TextInputKey* get_row(uint8_t row_index) {
+    const UART_TextInputKey* row = NULL;
 
-    switch (row_index + 1)
-    {
+    switch(row_index + 1) {
     case 1:
         row = keyboard_keys_row_1;
         break;
@@ -183,25 +176,20 @@ static const UART_TextInputKey *get_row(uint8_t row_index)
     return row;
 }
 
-static char get_selected_char(UART_TextInputModel *model)
-{
+static char get_selected_char(UART_TextInputModel* model) {
     return get_row(model->selected_row)[model->selected_column].text;
 }
 
-static bool char_is_lowercase(char letter)
-{
+static bool char_is_lowercase(char letter) {
     return (letter >= 0x61 && letter <= 0x7A);
 }
 
-static bool char_is_uppercase(char letter)
-{
+static bool char_is_uppercase(char letter) {
     return (letter >= 0x41 && letter <= 0x5A);
 }
 
-static char char_to_lowercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_lowercase(const char letter) {
+    switch(letter) {
     case ' ':
         return 0x5f;
         break;
@@ -230,20 +218,15 @@ static char char_to_lowercase(const char letter)
         return 0x3c;
         break;
     }
-    if (char_is_uppercase(letter))
-    {
+    if(char_is_uppercase(letter)) {
         return (letter + 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static char char_to_uppercase(const char letter)
-{
-    switch (letter)
-    {
+static char char_to_uppercase(const char letter) {
+    switch(letter) {
     case '_':
         return 0x20;
         break;
@@ -272,33 +255,27 @@ static char char_to_uppercase(const char letter)
         return 0x3e;
         break;
     }
-    if (char_is_lowercase(letter))
-    {
+    if(char_is_lowercase(letter)) {
         return (letter - 0x20);
-    }
-    else
-    {
+    } else {
         return letter;
     }
 }
 
-static void uart_text_input_backspace_cb(UART_TextInputModel *model)
-{
+static void uart_text_input_backspace_cb(UART_TextInputModel* model) {
     uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
-    if (text_length > 0)
-    {
+    if(text_length > 0) {
         model->text_buffer[text_length - 1] = 0;
     }
 }
 
-static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
-{
-    UART_TextInputModel *model = _model;
+static void uart_text_input_view_draw_callback(Canvas* canvas, void* _model) {
+    UART_TextInputModel* model = _model;
     // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
     uint8_t needed_string_width = canvas_width(canvas) - 8;
     uint8_t start_pos = 4;
 
-    const char *text = model->text_buffer;
+    const char* text = model->text_buffer;
 
     canvas_clear(canvas);
     canvas_set_color(canvas, ColorBlack);
@@ -306,26 +283,21 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
     canvas_draw_str(canvas, 2, 7, model->header);
     elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
 
-    if (canvas_string_width(canvas, text) > needed_string_width)
-    {
+    if(canvas_string_width(canvas, text) > needed_string_width) {
         canvas_draw_str(canvas, start_pos, 17, "...");
         start_pos += 6;
         needed_string_width -= 8;
     }
 
-    while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
-    {
+    while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
         text++;
     }
 
-    if (model->clear_default_text)
-    {
+    if(model->clear_default_text) {
         elements_slightly_rounded_box(
             canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
         canvas_set_color(canvas, ColorWhite);
-    }
-    else
-    {
+    } else {
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
         canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
     }
@@ -333,57 +305,43 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 
     canvas_set_font(canvas, FontKeyboard);
 
-    for (uint8_t row = 0; row <= keyboard_row_count; row++)
-    {
+    for(uint8_t row = 0; row <= keyboard_row_count; row++) {
         const uint8_t column_count = get_row_size(row);
-        const UART_TextInputKey *keys = get_row(row);
+        const UART_TextInputKey* keys = get_row(row);
 
-        for (size_t column = 0; column < column_count; column++)
-        {
-            if (keys[column].text == ENTER_KEY)
-            {
+        for(size_t column = 0; column < column_count; column++) {
+            if(keys[column].text == ENTER_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySaveSelected_24x11);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeySave_24x11);
                 }
-            }
-            else if (keys[column].text == BACKSPACE_KEY)
-            {
+            } else if(keys[column].text == BACKSPACE_KEY) {
                 canvas_set_color(canvas, ColorBlack);
-                if (model->selected_row == row && model->selected_column == column)
-                {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspaceSelected_16x9);
-                }
-                else
-                {
+                } else {
                     canvas_draw_icon(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         &I_KeyBackspace_16x9);
                 }
-            }
-            else
-            {
-                if (model->selected_row == row && model->selected_column == column)
-                {
+            } else {
+                if(model->selected_row == row && model->selected_column == column) {
                     canvas_set_color(canvas, ColorBlack);
                     canvas_draw_box(
                         canvas,
@@ -392,21 +350,16 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
                         7,
                         10);
                     canvas_set_color(canvas, ColorWhite);
-                }
-                else
-                {
+                } else {
                     canvas_set_color(canvas, ColorBlack);
                 }
-                if (0 == strcmp(model->header, mode_AT))
-                {
+                if(0 == strcmp(model->header, mode_AT)) {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
                         keyboard_origin_y + keys[column].y,
                         char_to_uppercase(keys[column].text));
-                }
-                else
-                {
+                } else {
                     canvas_draw_glyph(
                         canvas,
                         keyboard_origin_x + keys[column].x,
@@ -416,8 +369,7 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
             }
         }
     }
-    if (model->valadator_message_visible)
-    {
+    if(model->valadator_message_visible) {
         canvas_set_font(canvas, FontSecondary);
         canvas_set_color(canvas, ColorWhite);
         canvas_draw_box(canvas, 8, 10, 110, 48);
@@ -431,112 +383,82 @@ static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
 }
 
 static void
-uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_up(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row > 0)
-    {
+    if(model->selected_row > 0) {
         model->selected_row--;
-        if (model->selected_column > get_row_size(model->selected_row) - 6)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 6) {
             model->selected_column = model->selected_column + 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_down(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_row < keyboard_row_count - 1)
-    {
+    if(model->selected_row < keyboard_row_count - 1) {
         model->selected_row++;
-        if (model->selected_column > get_row_size(model->selected_row) - 4)
-        {
+        if(model->selected_column > get_row_size(model->selected_row) - 4) {
             model->selected_column = model->selected_column - 1;
         }
     }
 }
 
 static void
-uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_left(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column > 0)
-    {
+    if(model->selected_column > 0) {
         model->selected_column--;
-    }
-    else
-    {
+    } else {
         model->selected_column = get_row_size(model->selected_row) - 1;
     }
 }
 
 static void
-uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
-{
+    uart_text_input_handle_right(UART_TextInput* uart_text_input, UART_TextInputModel* model) {
     UNUSED(uart_text_input);
-    if (model->selected_column < get_row_size(model->selected_row) - 1)
-    {
+    if(model->selected_column < get_row_size(model->selected_row) - 1) {
         model->selected_column++;
-    }
-    else
-    {
+    } else {
         model->selected_column = 0;
     }
 }
 
 static void uart_text_input_handle_ok(
-    UART_TextInput *uart_text_input,
-    UART_TextInputModel *model,
-    bool shift)
-{
+    UART_TextInput* uart_text_input,
+    UART_TextInputModel* model,
+    bool shift) {
     char selected = get_selected_char(model);
     uint8_t text_length = strlen(model->text_buffer);
 
-    if (0 == strcmp(model->header, mode_AT))
-    {
+    if(0 == strcmp(model->header, mode_AT)) {
         selected = char_to_uppercase(selected);
     }
 
-    if (shift)
-    {
-        if (0 == strcmp(model->header, mode_AT))
-        {
+    if(shift) {
+        if(0 == strcmp(model->header, mode_AT)) {
             selected = char_to_lowercase(selected);
-        }
-        else
-        {
+        } else {
             selected = char_to_uppercase(selected);
         }
     }
 
-    if (selected == ENTER_KEY)
-    {
-        if (model->validator_callback &&
-            (!model->validator_callback(
-                model->text_buffer, model->validator_text, model->validator_callback_context)))
-        {
+    if(selected == ENTER_KEY) {
+        if(model->validator_callback &&
+           (!model->validator_callback(
+               model->text_buffer, model->validator_text, model->validator_callback_context))) {
             model->valadator_message_visible = true;
             furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
-        }
-        else if (model->callback != 0 && text_length > 0)
-        {
+        } else if(model->callback != 0 && text_length > 0) {
             model->callback(model->callback_context);
         }
-    }
-    else if (selected == BACKSPACE_KEY)
-    {
+    } else if(selected == BACKSPACE_KEY) {
         uart_text_input_backspace_cb(model);
-    }
-    else
-    {
-        if (model->clear_default_text)
-        {
+    } else {
+        if(model->clear_default_text) {
             text_length = 0;
         }
-        if (text_length < (model->text_buffer_size - 1))
-        {
+        if(text_length < (model->text_buffer_size - 1)) {
             model->text_buffer[text_length] = selected;
             model->text_buffer[text_length + 1] = 0;
         }
@@ -544,27 +466,22 @@ static void uart_text_input_handle_ok(
     model->clear_default_text = false;
 }
 
-static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
-{
-    UART_TextInput *uart_text_input = context;
+static bool uart_text_input_view_input_callback(InputEvent* event, void* context) {
+    UART_TextInput* uart_text_input = context;
     furi_assert(uart_text_input);
 
     bool consumed = false;
 
     // Acquire model
-    UART_TextInputModel *model = view_get_model(uart_text_input->view);
+    UART_TextInputModel* model = view_get_model(uart_text_input->view);
 
-    if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
-        model->valadator_message_visible)
-    {
+    if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
+       model->valadator_message_visible) {
         model->valadator_message_visible = false;
         consumed = true;
-    }
-    else if (event->type == InputTypeShort)
-    {
+    } else if(event->type == InputTypeShort) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -584,12 +501,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeLong)
-    {
+    } else if(event->type == InputTypeLong) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -612,12 +526,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
             consumed = false;
             break;
         }
-    }
-    else if (event->type == InputTypeRepeat)
-    {
+    } else if(event->type == InputTypeRepeat) {
         consumed = true;
-        switch (event->key)
-        {
+        switch(event->key) {
         case InputKeyUp:
             uart_text_input_handle_up(uart_text_input, model);
             break;
@@ -645,10 +556,9 @@ static bool uart_text_input_view_input_callback(InputEvent *event, void *context
     return consumed;
 }
 
-void uart_text_input_timer_callback(void *context)
-{
+void uart_text_input_timer_callback(void* context) {
     furi_assert(context);
-    UART_TextInput *uart_text_input = context;
+    UART_TextInput* uart_text_input = context;
 
     with_view_model(
         uart_text_input->view,
@@ -657,9 +567,8 @@ void uart_text_input_timer_callback(void *context)
         true);
 }
 
-UART_TextInput *uart_text_input_alloc()
-{
-    UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+UART_TextInput* uart_text_input_alloc() {
+    UART_TextInput* uart_text_input = malloc(sizeof(UART_TextInput));
     uart_text_input->view = view_alloc();
     view_set_context(uart_text_input->view, uart_text_input);
     view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
@@ -680,8 +589,7 @@ UART_TextInput *uart_text_input_alloc()
     return uart_text_input;
 }
 
-void uart_text_input_free(UART_TextInput *uart_text_input)
-{
+void uart_text_input_free(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -699,8 +607,7 @@ void uart_text_input_free(UART_TextInput *uart_text_input)
     free(uart_text_input);
 }
 
-void uart_text_input_reset(UART_TextInput *uart_text_input)
-{
+void uart_text_input_reset(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     with_view_model(
         uart_text_input->view,
@@ -723,20 +630,18 @@ void uart_text_input_reset(UART_TextInput *uart_text_input)
         true);
 }
 
-View *uart_text_input_get_view(UART_TextInput *uart_text_input)
-{
+View* uart_text_input_get_view(UART_TextInput* uart_text_input) {
     furi_assert(uart_text_input);
     return uart_text_input->view;
 }
 
 void uart_text_input_set_result_callback(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputCallback callback,
-    void *callback_context,
-    char *text_buffer,
+    void* callback_context,
+    char* text_buffer,
     size_t text_buffer_size,
-    bool clear_default_text)
-{
+    bool clear_default_text) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -746,8 +651,7 @@ void uart_text_input_set_result_callback(
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;
             model->clear_default_text = clear_default_text;
-            if (text_buffer && text_buffer[0] != '\0')
-            {
+            if(text_buffer && text_buffer[0] != '\0') {
                 // Set focus on Save
                 model->selected_row = 2;
                 model->selected_column = 8;
@@ -757,10 +661,9 @@ void uart_text_input_set_result_callback(
 }
 
 void uart_text_input_set_validator(
-    UART_TextInput *uart_text_input,
+    UART_TextInput* uart_text_input,
     UART_TextInputValidatorCallback callback,
-    void *callback_context)
-{
+    void* callback_context) {
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -772,8 +675,7 @@ void uart_text_input_set_validator(
 }
 
 UART_TextInputValidatorCallback
-uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
-{
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input) {
     UART_TextInputValidatorCallback validator_callback = NULL;
     with_view_model(
         uart_text_input->view,
@@ -783,9 +685,8 @@ uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
     return validator_callback;
 }
 
-void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
-{
-    void *validator_callback_context = NULL;
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input) {
+    void* validator_callback_context = NULL;
     with_view_model(
         uart_text_input->view,
         UART_TextInputModel * model,
@@ -794,10 +695,9 @@ void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_i
     return validator_callback_context;
 }
 
-void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
-{
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text) {
     with_view_model(
         uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
 }
 
-#endif // UART_TEXT_INPUT_H
+#endif // UART_TEXT_INPUT_H

Некоторые файлы не были показаны из-за большого количества измененных файлов