Skip to content

Commit

Permalink
FlipLibrary v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jblanked committed Oct 17, 2024
1 parent 3f53e21 commit 129435d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 63 deletions.
Binary file modified .DS_Store
Binary file not shown.
32 changes: 16 additions & 16 deletions flip_library_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static void view_draw_callback_random_facts(Canvas *canvas, void *model)

static void view_draw_callback_dictionary_run(Canvas *canvas, void *model)
{
if (!canvas || !app_instance || app_instance->text_input_buffer_dictionary == NULL)
if (!canvas || !app_instance || app_instance->uart_text_input_buffer_dictionary == NULL)
{
return;
}
Expand All @@ -452,7 +452,7 @@ static void view_draw_callback_dictionary_run(Canvas *canvas, void *model)
sent_random_fact_request = true;

char payload[128];
snprintf(payload, sizeof(payload), "{\"word\":\"%s\"}", app_instance->text_input_buffer_dictionary);
snprintf(payload, sizeof(payload), "{\"word\":\"%s\"}", app_instance->uart_text_input_buffer_dictionary);

random_fact_request_success = flipper_http_post_request_with_headers("https://www.flipsocial.net/api/define/", "{\"Content-Type\":\"application/json\"}", payload);
if (!random_fact_request_success)
Expand Down Expand Up @@ -614,24 +614,24 @@ static void text_updated_ssid(void *context)
}

// store the entered text
strncpy(app->text_input_buffer_ssid, app->text_input_temp_buffer_ssid, app->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->text_input_buffer_ssid[app->text_input_buffer_size_ssid - 1] = '\0';
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->text_input_buffer_ssid);
variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
}

// save settings
save_settings(app->text_input_buffer_ssid, app->text_input_buffer_password);
save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);

// save wifi settings to devboard
if (strlen(app->text_input_buffer_ssid) > 0 && strlen(app->text_input_buffer_password) > 0)
if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
{
if (!flipper_http_save_wifi(app->text_input_buffer_ssid, app->text_input_buffer_password))
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");
}
Expand All @@ -651,24 +651,24 @@ static void text_updated_password(void *context)
}

// store the entered text
strncpy(app->text_input_buffer_password, app->text_input_temp_buffer_password, app->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->text_input_buffer_password[app->text_input_buffer_size_password - 1] = '\0';
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->text_input_buffer_password);
variable_item_set_current_value_text(app->variable_item_password, app->uart_text_input_buffer_password);
}

// save settings
save_settings(app->text_input_buffer_ssid, app->text_input_buffer_password);
save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);

// save wifi settings to devboard
if (strlen(app->text_input_buffer_ssid) > 0 && strlen(app->text_input_buffer_password) > 0)
if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
{
if (!flipper_http_save_wifi(app->text_input_buffer_ssid, app->text_input_buffer_password))
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");
}
Expand All @@ -688,10 +688,10 @@ static void text_updated_dictionary(void *context)
}

// store the entered text
strncpy(app->text_input_buffer_dictionary, app->text_input_temp_buffer_dictionary, app->text_input_buffer_size_dictionary);
strncpy(app->uart_text_input_buffer_dictionary, app->uart_text_input_temp_buffer_dictionary, app->uart_text_input_buffer_size_dictionary);

// Ensure null-termination
app->text_input_buffer_dictionary[app->text_input_buffer_size_dictionary - 1] = '\0';
app->uart_text_input_buffer_dictionary[app->uart_text_input_buffer_size_dictionary - 1] = '\0';

// switch to the dictionary view
view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewDictionaryRun);
Expand Down
42 changes: 21 additions & 21 deletions flip_library_e.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@ typedef enum
// 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)
TextInput *text_input_ssid; // The text input for the SSID
TextInput *text_input_password; // The text input for the password
TextInput *text_input_dictionary; // The text input for the dictionary
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

char *text_input_buffer_ssid; // Buffer for the text input (SSID)
char *text_input_temp_buffer_ssid; // Temporary buffer for the text input (SSID)
uint32_t text_input_buffer_size_ssid; // Size of the text input buffer (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 *text_input_buffer_password; // Buffer for the text input (password)
char *text_input_temp_buffer_password; // Temporary buffer for the text input (password)
uint32_t text_input_buffer_size_password; // Size of the text input buffer (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 *text_input_buffer_dictionary; // Buffer for the text input (dictionary)
char *text_input_temp_buffer_dictionary; // Temporary buffer for the text input (dictionary)
uint32_t text_input_buffer_size_dictionary; // Size of the text input buffer (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
12 changes: 6 additions & 6 deletions flip_library_free.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ static void flip_library_app_free(FlipLibraryApp *app)
}

// Free Text Input(s)
if (app->text_input_ssid)
if (app->uart_text_input_ssid)
{
view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputSSID);
text_input_free(app->text_input_ssid);
uart_text_input_free(app->uart_text_input_ssid);
}
if (app->text_input_password)
if (app->uart_text_input_password)
{
view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewTextInputPassword);
text_input_free(app->text_input_password);
uart_text_input_free(app->uart_text_input_password);
}
if (app->text_input_dictionary)
if (app->uart_text_input_dictionary)
{
view_dispatcher_remove_view(app->view_dispatcher, FlipLibraryViewDictionaryTextInput);
text_input_free(app->text_input_dictionary);
uart_text_input_free(app->uart_text_input_dictionary);
}

// deinitalize flipper http
Expand Down
40 changes: 20 additions & 20 deletions flip_library_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ static FlipLibraryApp *flip_library_app_alloc()
}

// Allocate the text input buffer
app->text_input_buffer_size_ssid = 64;
app->text_input_buffer_size_password = 64;
app->text_input_buffer_size_dictionary = 64;
if (!easy_flipper_set_buffer(&app->text_input_buffer_ssid, app->text_input_buffer_size_ssid))
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))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->text_input_temp_buffer_ssid, app->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->text_input_buffer_password, app->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->text_input_temp_buffer_password, app->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->text_input_buffer_dictionary, app->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->text_input_temp_buffer_dictionary, app->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;
}
Expand Down Expand Up @@ -74,15 +74,15 @@ static FlipLibraryApp *flip_library_app_alloc()
}

// Text Input
if (!easy_flipper_set_text_input(&app->text_input_ssid, FlipLibraryViewTextInputSSID, "Enter SSID", app->text_input_temp_buffer_ssid, app->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, 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_text_input(&app->text_input_password, FlipLibraryViewTextInputPassword, "Enter Password", app->text_input_temp_buffer_password, app->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, 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_text_input(&app->text_input_dictionary, FlipLibraryViewDictionaryTextInput, "Enter a word", app->text_input_temp_buffer_dictionary, app->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_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;
}
Expand Down Expand Up @@ -117,23 +117,23 @@ static FlipLibraryApp *flip_library_app_alloc()
submenu_add_item(app->submenu_random_facts, "Random", FlipLibrarySubmenuIndexRandomFactsAll, callback_submenu_choices, app);

// load settings
if (load_settings(app->text_input_buffer_ssid, app->text_input_buffer_size_ssid, app->text_input_buffer_password, app->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->text_input_buffer_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->text_input_buffer_ssid && app->text_input_temp_buffer_ssid)
if (app->uart_text_input_buffer_ssid && app->uart_text_input_temp_buffer_ssid)
{
strncpy(app->text_input_temp_buffer_ssid, app->text_input_buffer_ssid, app->text_input_buffer_size_ssid - 1);
app->text_input_temp_buffer_ssid[app->text_input_buffer_size_ssid - 1] = '\0';
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->text_input_buffer_password && app->text_input_temp_buffer_password)
if (app->uart_text_input_buffer_password && app->uart_text_input_temp_buffer_password)
{
strncpy(app->text_input_temp_buffer_password, app->text_input_buffer_password, app->text_input_buffer_size_password - 1);
app->text_input_temp_buffer_password[app->text_input_buffer_size_password - 1] = '\0';
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';
}
}

Expand Down

0 comments on commit 129435d

Please sign in to comment.