flip_library_callback.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. #ifndef FLIP_LIBRARY_CALLBACK_H
  2. #define FLIP_LIBRARY_CALLBACK_H
  3. static uint32_t random_facts_index = 0;
  4. static bool sent_random_fact_request = false;
  5. static bool random_fact_request_success = false;
  6. static bool random_fact_request_success_all = false;
  7. char *random_fact = NULL;
  8. static FlipLibraryApp *app_instance = NULL;
  9. #define MAX_TOKENS 512 // Adjust based on expected JSON size
  10. // Parse JSON to find the "text" key
  11. char *flip_library_parse_random_fact()
  12. {
  13. return get_json_value("text", fhttp.received_data, 128);
  14. }
  15. char *flip_library_parse_cat_fact()
  16. {
  17. return get_json_value("fact", fhttp.received_data, 128);
  18. }
  19. char *flip_library_parse_dictionary()
  20. {
  21. return get_json_value("definition", fhttp.received_data, 16);
  22. }
  23. static void flip_library_request_error(Canvas *canvas)
  24. {
  25. if (fhttp.received_data == NULL)
  26. {
  27. if (fhttp.last_response != NULL)
  28. {
  29. if (strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") != NULL)
  30. {
  31. canvas_clear(canvas);
  32. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  33. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  34. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  35. }
  36. else if (strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL)
  37. {
  38. canvas_clear(canvas);
  39. canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
  40. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  41. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  42. }
  43. else
  44. {
  45. canvas_clear(canvas);
  46. FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
  47. canvas_draw_str(canvas, 0, 10, "[ERROR] Unusual error...");
  48. canvas_draw_str(canvas, 0, 60, "Press BACK and retry.");
  49. }
  50. }
  51. else
  52. {
  53. canvas_clear(canvas);
  54. canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
  55. canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
  56. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  57. }
  58. }
  59. else
  60. {
  61. canvas_clear(canvas);
  62. canvas_draw_str(canvas, 0, 10, "Failed to receive data.");
  63. canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
  64. }
  65. }
  66. static void flip_library_draw_fact(char *message, Widget **widget)
  67. {
  68. if (app_instance == NULL)
  69. {
  70. FURI_LOG_E(TAG, "App instance is NULL");
  71. return;
  72. }
  73. widget_reset(*widget);
  74. uint32_t fact_length = strlen(message); // Length of the message
  75. uint32_t i = 0; // Index tracker
  76. uint32_t formatted_index = 0; // Tracker for where we are in the formatted message
  77. char *formatted_message; // Buffer to hold the final formatted message
  78. if (!easy_flipper_set_buffer(&formatted_message, fact_length * 2 + 1))
  79. {
  80. return;
  81. }
  82. while (i < fact_length)
  83. {
  84. uint32_t max_line_length = 29; // Maximum characters per line
  85. uint32_t remaining_length = fact_length - i; // Remaining characters
  86. uint32_t line_length = (remaining_length < max_line_length) ? remaining_length : max_line_length;
  87. // Temporary buffer to hold the current line
  88. char fact_line[30];
  89. strncpy(fact_line, message + i, line_length);
  90. fact_line[line_length] = '\0';
  91. // Check if the line ends in the middle of a word and adjust accordingly
  92. if (line_length == 29 && message[i + line_length] != '\0' && message[i + line_length] != ' ')
  93. {
  94. // Find the last space within the 30-character segment
  95. char *last_space = strrchr(fact_line, ' ');
  96. if (last_space != NULL)
  97. {
  98. // Adjust the line length to avoid cutting the word
  99. line_length = last_space - fact_line;
  100. fact_line[line_length] = '\0'; // Null-terminate at the space
  101. }
  102. }
  103. // Manually copy the fixed line into the formatted_message buffer
  104. for (uint32_t j = 0; j < line_length; j++)
  105. {
  106. formatted_message[formatted_index++] = fact_line[j];
  107. }
  108. // Add a newline character for line spacing
  109. formatted_message[formatted_index++] = '\n';
  110. // Move i forward to the start of the next word
  111. i += line_length;
  112. // Skip spaces at the beginning of the next line
  113. while (message[i] == ' ')
  114. {
  115. i++;
  116. }
  117. }
  118. // Add the formatted message to the widget
  119. widget_add_text_scroll_element(
  120. *widget,
  121. 0,
  122. 0,
  123. 128,
  124. 64,
  125. formatted_message);
  126. }
  127. // Callback for drawing the main screen
  128. static void view_draw_callback_random_facts(Canvas *canvas, void *model)
  129. {
  130. if (!canvas || !app_instance)
  131. {
  132. return;
  133. }
  134. UNUSED(model);
  135. canvas_set_font(canvas, FontSecondary);
  136. if (fhttp.state == INACTIVE)
  137. {
  138. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  139. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  140. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  141. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  142. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  143. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  144. return;
  145. }
  146. if (random_facts_index == FlipLibrarySubmenuIndexRandomFactsCats)
  147. {
  148. canvas_draw_str(canvas, 0, 7, "Random Cat Fact");
  149. canvas_draw_str(canvas, 0, 15, "Loading...");
  150. if (!sent_random_fact_request)
  151. {
  152. sent_random_fact_request = true;
  153. random_fact_request_success = flipper_http_get_request_with_headers("https://catfact.ninja/fact", "{\"Content-Type\":\"application/json\"}");
  154. if (!random_fact_request_success)
  155. {
  156. FURI_LOG_E(TAG, "Failed to send request");
  157. flip_library_request_error(canvas);
  158. return;
  159. }
  160. fhttp.state = RECEIVING;
  161. }
  162. else
  163. {
  164. if (fhttp.state == RECEIVING)
  165. {
  166. canvas_draw_str(canvas, 0, 22, "Receiving...");
  167. return;
  168. }
  169. // check status
  170. else if (fhttp.state == ISSUE || !random_fact_request_success)
  171. {
  172. flip_library_request_error(canvas);
  173. }
  174. else if (fhttp.state == IDLE && fhttp.received_data != NULL && !random_fact_request_success_all)
  175. {
  176. canvas_draw_str(canvas, 0, 22, "Processing...");
  177. // success
  178. // check status
  179. // unnecessary check
  180. if (fhttp.state == ISSUE || fhttp.received_data == NULL)
  181. {
  182. flip_library_request_error(canvas);
  183. FURI_LOG_E(TAG, "HTTP request failed or received data is NULL");
  184. return;
  185. }
  186. else if (!random_fact_request_success_all)
  187. {
  188. random_fact = flip_library_parse_cat_fact();
  189. if (random_fact == NULL)
  190. {
  191. flip_library_request_error(canvas);
  192. fhttp.state = ISSUE;
  193. return;
  194. }
  195. // Mark success
  196. random_fact_request_success_all = true;
  197. // draw random facts
  198. flip_library_draw_fact(random_fact, &app_instance->widget_random_fact);
  199. // go to random facts widget
  200. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewRandomFactWidget);
  201. }
  202. }
  203. // likely redundant but just in case
  204. else if (fhttp.state == IDLE && random_fact_request_success_all && random_fact != NULL)
  205. {
  206. flip_library_draw_fact(random_fact, &app_instance->widget_random_fact);
  207. // go to random facts widget
  208. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewRandomFactWidget);
  209. }
  210. else // handle weird scenarios
  211. {
  212. // if received data isnt NULL
  213. if (fhttp.received_data != NULL)
  214. {
  215. // parse json to find the text key
  216. random_fact = flip_library_parse_cat_fact();
  217. if (random_fact == NULL)
  218. {
  219. flip_library_request_error(canvas);
  220. fhttp.state = ISSUE;
  221. return;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. else if (random_facts_index == FlipLibrarySubmenuIndexRandomFactsAll)
  228. {
  229. canvas_draw_str(canvas, 0, 10, "Random Fact");
  230. canvas_set_font(canvas, FontSecondary);
  231. canvas_draw_str(canvas, 0, 20, "Loading...");
  232. if (!sent_random_fact_request)
  233. {
  234. sent_random_fact_request = true;
  235. random_fact_request_success = flipper_http_get_request("https://uselessfacts.jsph.pl/api/v2/facts/random");
  236. if (!random_fact_request_success)
  237. {
  238. FURI_LOG_E(TAG, "Failed to send request");
  239. return;
  240. }
  241. fhttp.state = RECEIVING;
  242. }
  243. else
  244. {
  245. // check status
  246. if (fhttp.state == RECEIVING)
  247. {
  248. canvas_draw_str(canvas, 0, 30, "Receiving...");
  249. return;
  250. }
  251. // check status
  252. else if (fhttp.state == ISSUE || !random_fact_request_success)
  253. {
  254. flip_library_request_error(canvas);
  255. return;
  256. }
  257. else if (fhttp.state == IDLE && fhttp.received_data != NULL && !random_fact_request_success_all)
  258. {
  259. canvas_draw_str(canvas, 0, 30, "Processing...");
  260. // success
  261. // check status
  262. if (fhttp.state == ISSUE || fhttp.received_data == NULL)
  263. {
  264. flip_library_request_error(canvas);
  265. FURI_LOG_E(TAG, "HTTP request failed or received data is NULL");
  266. return;
  267. }
  268. // parse json to find the text key
  269. random_fact = flip_library_parse_random_fact();
  270. if (random_fact == NULL)
  271. {
  272. flip_library_request_error(canvas);
  273. fhttp.state = ISSUE;
  274. return;
  275. }
  276. // Mark success
  277. random_fact_request_success_all = true;
  278. // draw random facts
  279. flip_library_draw_fact(random_fact, &app_instance->widget_random_fact);
  280. // go to random facts widget
  281. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewRandomFactWidget);
  282. }
  283. // likely redundant but just in case
  284. else if (fhttp.state == IDLE && random_fact_request_success_all && random_fact != NULL)
  285. {
  286. // draw random facts
  287. flip_library_draw_fact(random_fact, &app_instance->widget_random_fact);
  288. // go to random facts widget
  289. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewRandomFactWidget);
  290. }
  291. else // handle weird scenarios
  292. {
  293. // if received data isnt NULL
  294. if (fhttp.received_data != NULL)
  295. {
  296. // parse json to find the text key
  297. random_fact = flip_library_parse_random_fact();
  298. if (random_fact == NULL)
  299. {
  300. flip_library_request_error(canvas);
  301. fhttp.state = ISSUE;
  302. return;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. else
  309. {
  310. canvas_draw_str(canvas, 0, 7, "Random Fact");
  311. }
  312. }
  313. static void view_draw_callback_dictionary_run(Canvas *canvas, void *model)
  314. {
  315. if (!canvas || !app_instance || app_instance->uart_text_input_buffer_dictionary == NULL)
  316. {
  317. return;
  318. }
  319. UNUSED(model);
  320. canvas_set_font(canvas, FontSecondary);
  321. if (fhttp.state == INACTIVE)
  322. {
  323. canvas_draw_str(canvas, 0, 7, "Wifi Dev Board disconnected.");
  324. canvas_draw_str(canvas, 0, 17, "Please connect to the board.");
  325. canvas_draw_str(canvas, 0, 32, "If your board is connected,");
  326. canvas_draw_str(canvas, 0, 42, "make sure you have flashed");
  327. canvas_draw_str(canvas, 0, 52, "your WiFi Devboard with the");
  328. canvas_draw_str(canvas, 0, 62, "latest FlipperHTTP flash.");
  329. return;
  330. }
  331. canvas_draw_str(canvas, 0, 10, "Defining, please wait...");
  332. if (!sent_random_fact_request)
  333. {
  334. sent_random_fact_request = true;
  335. char payload[128];
  336. snprintf(payload, sizeof(payload), "{\"word\":\"%s\"}", app_instance->uart_text_input_buffer_dictionary);
  337. random_fact_request_success = flipper_http_post_request_with_headers("https://www.flipsocial.net/api/define/", "{\"Content-Type\":\"application/json\"}", payload);
  338. if (!random_fact_request_success)
  339. {
  340. FURI_LOG_E(TAG, "Failed to send request");
  341. return;
  342. }
  343. fhttp.state = RECEIVING;
  344. }
  345. else
  346. {
  347. // check status
  348. if (fhttp.state == RECEIVING)
  349. {
  350. canvas_draw_str(canvas, 0, 20, "Receiving...");
  351. return;
  352. }
  353. // check status
  354. else if (fhttp.state == ISSUE || !random_fact_request_success)
  355. {
  356. flip_library_request_error(canvas);
  357. return;
  358. }
  359. else if (fhttp.state == IDLE && fhttp.received_data != NULL && !random_fact_request_success_all)
  360. {
  361. canvas_draw_str(canvas, 0, 20, "Processing...");
  362. // success
  363. // check status
  364. if (fhttp.state == ISSUE || fhttp.received_data == NULL)
  365. {
  366. flip_library_request_error(canvas);
  367. FURI_LOG_E(TAG, "HTTP request failed or received data is NULL");
  368. return;
  369. }
  370. // parse json to find the text key
  371. char *definition = flip_library_parse_dictionary();
  372. if (definition == NULL)
  373. {
  374. flip_library_request_error(canvas);
  375. fhttp.state = ISSUE;
  376. return;
  377. }
  378. // Mark success
  379. random_fact_request_success_all = true;
  380. // draw random facts
  381. flip_library_draw_fact(definition, &app_instance->widget_dictionary);
  382. // go to random facts widget
  383. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewDictionaryWidget);
  384. }
  385. // likely redundant but just in case
  386. else if (fhttp.state == IDLE && random_fact_request_success_all && random_fact != NULL)
  387. {
  388. // draw random facts
  389. flip_library_draw_fact(random_fact, &app_instance->widget_dictionary);
  390. // go to random facts widget
  391. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewDictionaryWidget);
  392. }
  393. else // handle weird scenarios
  394. {
  395. // if received data isnt NULL
  396. if (fhttp.received_data != NULL)
  397. {
  398. // parse json to find the text key
  399. char *definition = flip_library_parse_dictionary();
  400. if (definition == NULL)
  401. {
  402. flip_library_request_error(canvas);
  403. fhttp.state = ISSUE;
  404. return;
  405. }
  406. // draw random facts
  407. flip_library_draw_fact(definition, &app_instance->widget_dictionary);
  408. // go to random facts widget
  409. view_dispatcher_switch_to_view(app_instance->view_dispatcher, FlipLibraryViewDictionaryWidget);
  410. free(definition);
  411. return;
  412. }
  413. }
  414. }
  415. }
  416. // Input callback for the view (async input handling)
  417. bool view_input_callback_random_facts(InputEvent *event, void *context)
  418. {
  419. if (!event || !context)
  420. {
  421. return false;
  422. }
  423. FlipLibraryApp *app = (FlipLibraryApp *)context;
  424. if (event->type == InputTypePress && event->key == InputKeyBack)
  425. {
  426. // Exit the app when the back button is pressed
  427. view_dispatcher_stop(app->view_dispatcher);
  428. return true;
  429. }
  430. return false;
  431. }
  432. static void callback_submenu_choices(void *context, uint32_t index)
  433. {
  434. FlipLibraryApp *app = (FlipLibraryApp *)context;
  435. if (!app)
  436. {
  437. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  438. return;
  439. }
  440. switch (index)
  441. {
  442. case FlipLibrarySubmenuIndexRandomFacts:
  443. random_facts_index = 0;
  444. sent_random_fact_request = false;
  445. random_fact = NULL;
  446. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewRandomFacts);
  447. break;
  448. case FlipLibrarySubmenuIndexAbout:
  449. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewAbout);
  450. break;
  451. case FlipLibrarySubmenuIndexSettings:
  452. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewSettings);
  453. break;
  454. case FlipLibrarySubmenuIndexDictionary:
  455. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewDictionaryTextInput);
  456. break;
  457. case FlipLibrarySubmenuIndexRandomFactsCats:
  458. random_facts_index = FlipLibrarySubmenuIndexRandomFactsCats;
  459. sent_random_fact_request = false;
  460. random_fact = NULL;
  461. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewRandomFactsRun);
  462. break;
  463. case FlipLibrarySubmenuIndexRandomFactsAll:
  464. random_facts_index = FlipLibrarySubmenuIndexRandomFactsAll;
  465. sent_random_fact_request = false;
  466. random_fact = NULL;
  467. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewRandomFactsRun);
  468. break;
  469. default:
  470. break;
  471. }
  472. }
  473. static void text_updated_ssid(void *context)
  474. {
  475. FlipLibraryApp *app = (FlipLibraryApp *)context;
  476. if (!app)
  477. {
  478. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  479. return;
  480. }
  481. // store the entered text
  482. strncpy(app->uart_text_input_buffer_ssid, app->uart_text_input_temp_buffer_ssid, app->uart_text_input_buffer_size_ssid);
  483. // Ensure null-termination
  484. app->uart_text_input_buffer_ssid[app->uart_text_input_buffer_size_ssid - 1] = '\0';
  485. // update the variable item text
  486. if (app->variable_item_ssid)
  487. {
  488. variable_item_set_current_value_text(app->variable_item_ssid, app->uart_text_input_buffer_ssid);
  489. }
  490. // save settings
  491. save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
  492. // save wifi settings to devboard
  493. if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
  494. {
  495. if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
  496. {
  497. FURI_LOG_E(TAG, "Failed to save wifi settings");
  498. }
  499. }
  500. // switch to the settings view
  501. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewSettings);
  502. }
  503. static void text_updated_password(void *context)
  504. {
  505. FlipLibraryApp *app = (FlipLibraryApp *)context;
  506. if (!app)
  507. {
  508. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  509. return;
  510. }
  511. // store the entered text
  512. strncpy(app->uart_text_input_buffer_password, app->uart_text_input_temp_buffer_password, app->uart_text_input_buffer_size_password);
  513. // Ensure null-termination
  514. app->uart_text_input_buffer_password[app->uart_text_input_buffer_size_password - 1] = '\0';
  515. // update the variable item text
  516. if (app->variable_item_password)
  517. {
  518. variable_item_set_current_value_text(app->variable_item_password, app->uart_text_input_buffer_password);
  519. }
  520. // save settings
  521. save_settings(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password);
  522. // save wifi settings to devboard
  523. if (strlen(app->uart_text_input_buffer_ssid) > 0 && strlen(app->uart_text_input_buffer_password) > 0)
  524. {
  525. if (!flipper_http_save_wifi(app->uart_text_input_buffer_ssid, app->uart_text_input_buffer_password))
  526. {
  527. FURI_LOG_E(TAG, "Failed to save wifi settings");
  528. }
  529. }
  530. // switch to the settings view
  531. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewSettings);
  532. }
  533. static void text_updated_dictionary(void *context)
  534. {
  535. FlipLibraryApp *app = (FlipLibraryApp *)context;
  536. if (!app)
  537. {
  538. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  539. return;
  540. }
  541. // store the entered text
  542. strncpy(app->uart_text_input_buffer_dictionary, app->uart_text_input_temp_buffer_dictionary, app->uart_text_input_buffer_size_dictionary);
  543. // Ensure null-termination
  544. app->uart_text_input_buffer_dictionary[app->uart_text_input_buffer_size_dictionary - 1] = '\0';
  545. // switch to the dictionary view
  546. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewDictionaryRun);
  547. }
  548. static uint32_t callback_to_submenu(void *context)
  549. {
  550. if (!context)
  551. {
  552. FURI_LOG_E(TAG, "Context is NULL");
  553. return VIEW_NONE;
  554. }
  555. UNUSED(context);
  556. random_facts_index = 0;
  557. sent_random_fact_request = false;
  558. random_fact_request_success = false;
  559. random_fact_request_success_all = false;
  560. random_fact = NULL;
  561. return FlipLibraryViewSubmenuMain;
  562. }
  563. static uint32_t callback_to_wifi_settings(void *context)
  564. {
  565. if (!context)
  566. {
  567. FURI_LOG_E(TAG, "Context is NULL");
  568. return VIEW_NONE;
  569. }
  570. UNUSED(context);
  571. return FlipLibraryViewSettings;
  572. }
  573. static uint32_t callback_to_random_facts(void *context)
  574. {
  575. if (!context)
  576. {
  577. FURI_LOG_E(TAG, "Context is NULL");
  578. return VIEW_NONE;
  579. }
  580. UNUSED(context);
  581. return FlipLibraryViewRandomFacts;
  582. }
  583. static void settings_item_selected(void *context, uint32_t index)
  584. {
  585. FlipLibraryApp *app = (FlipLibraryApp *)context;
  586. if (!app)
  587. {
  588. FURI_LOG_E(TAG, "FlipLibraryApp is NULL");
  589. return;
  590. }
  591. switch (index)
  592. {
  593. case 0: // Input SSID
  594. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewTextInputSSID);
  595. break;
  596. case 1: // Input Password
  597. view_dispatcher_switch_to_view(app->view_dispatcher, FlipLibraryViewTextInputPassword);
  598. break;
  599. default:
  600. FURI_LOG_E(TAG, "Unknown configuration item index");
  601. break;
  602. }
  603. }
  604. /**
  605. * @brief Navigation callback for exiting the application
  606. * @param context The context - unused
  607. * @return next view id (VIEW_NONE to exit the app)
  608. */
  609. static uint32_t callback_exit_app(void *context)
  610. {
  611. // Exit the application
  612. if (!context)
  613. {
  614. FURI_LOG_E(TAG, "Context is NULL");
  615. return VIEW_NONE;
  616. }
  617. UNUSED(context);
  618. return VIEW_NONE; // Return VIEW_NONE to exit the app
  619. }
  620. #endif // FLIP_LIBRARY_CALLBACK_H