Skip to content

Commit

Permalink
Merge pull request #1 from jamisonderek/main
Browse files Browse the repository at this point in the history
Switch to FactLoaderModel
  • Loading branch information
jblanked authored Nov 19, 2024
2 parents 4ce94a4 + 5fa329d commit f2eab91
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 906 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.3
- Improved displaying progress.
- Reset wifi creds on startup.

## v1.2
- Improved memory allocation.
- Added in Dog Facts.
Expand Down
164 changes: 80 additions & 84 deletions alloc/flip_library_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,104 +8,98 @@ FlipLibraryApp *flip_library_app_alloc()
Gui *gui = furi_record_open(RECORD_GUI);

if (!flipper_http_init(flipper_http_rx_callback, app))
{
FURI_LOG_E(TAG, "Failed to initialize flipper http");
return NULL;
}
{
FURI_LOG_E(TAG, "Failed to initialize flipper http");
return NULL;
}

// Allocate the text input buffer
app->uart_text_input_buffer_size_ssid = 64;
app->uart_text_input_buffer_size_password = 64;
app->uart_text_input_buffer_size_dictionary = 64;
app->uart_text_input_buffer_size_query = 64;
if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_size_ssid))
{
return NULL;
}
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid))
{
return NULL;
}
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_password, app->uart_text_input_buffer_size_password))
{
return NULL;
}
{
return NULL;
}
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))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_dictionary, app->uart_text_input_buffer_size_dictionary))
{
return NULL;
}
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_buffer_query, app->uart_text_input_buffer_size_query))
{
return NULL;
}
if (!easy_flipper_set_buffer(&app->uart_text_input_temp_buffer_query, app->uart_text_input_buffer_size_query))
{
return NULL;
}

// Allocate ViewDispatcher
if (!easy_flipper_set_view_dispatcher(&app->view_dispatcher, gui, app))
{
return NULL;
}
{
return NULL;
}
view_dispatcher_set_custom_event_callback(app->view_dispatcher, flip_library_custom_event_callback);

// 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))
{
return NULL;
}
if (!easy_flipper_set_view(&app->view_dictionary, FlipLibraryViewDictionaryRun, view_draw_callback_dictionary_run, NULL, callback_to_submenu, &app->view_dispatcher, app))
{
return NULL;
}
if (!easy_flipper_set_view(&app->view_loader, FlipLibraryViewLoader, flip_library_loader_draw_callback, NULL, callback_to_random_facts, &app->view_dispatcher, app))
{
return NULL;
}
flip_library_loader_init(app->view_loader);

// 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))
{
return NULL;
}
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))
{
return NULL;
}
if (!easy_flipper_set_widget(&app->widget_about, FlipLibraryViewAbout, "FlipLibrary v1.3\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_result, FlipLibraryViewWidgetResult, "Error, try again.", callback_to_random_facts, &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;
}
{
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;
}
{
return NULL;
}
if (!easy_flipper_set_uart_text_input(&app->uart_text_input_query, FlipLibraryViewTextInputQuery, "Enter Query", app->uart_text_input_temp_buffer_query, app->uart_text_input_buffer_size_query, text_updated_query, 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))
{
return NULL;
}
{
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);
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_main, FlipLibraryViewSubmenuMain, "FlipLibrary v1.3", 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;
}
{
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);
Expand All @@ -119,24 +113,26 @@ FlipLibraryApp *flip_library_app_alloc()

// 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))
{
// Update variable items
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_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';
// Update variable items
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_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';
}
}
}

// assign app instance
app_instance = app;
Expand Down
35 changes: 35 additions & 0 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ int32_t flip_library_app(void *p)
return -1;
}

if(app_instance->uart_text_input_buffer_ssid != NULL &&
app_instance->uart_text_input_buffer_password != NULL) {
// Try to wait for pong response.
uint8_t counter = 10;
while(fhttp.state == INACTIVE && --counter > 0) {
FURI_LOG_D(TAG, "Waiting for PONG");
furi_delay_ms(100);
}

FURI_LOG_E(TAG, "Counter: %d", counter);
if(counter == 0) {
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
DialogMessage* message = dialog_message_alloc();
dialog_message_set_header(
message, "WIFI NOT RESPONDING", 64, 0, AlignCenter, AlignTop);
dialog_message_set_text(
message,
"Ensure ESP32 is connected\nand latest FlipperHTTP\nfirmware is installed.",
0,
63,
AlignLeft,
AlignBottom);
dialog_message_show(dialogs, message);
dialog_message_free(message);
furi_record_close(RECORD_DIALOGS);
}

// Switch to application wifi settings
if(!flipper_http_save_wifi(
app_instance->uart_text_input_buffer_ssid,
app_instance->uart_text_input_buffer_password)) {
FURI_LOG_E(TAG, "Failed to save wifi settings");
}
}

// Run the view dispatcher
view_dispatcher_run(app_instance->view_dispatcher);

Expand Down
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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.2",
fap_version = "1.3",
)
Loading

0 comments on commit f2eab91

Please sign in to comment.