callback.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. #include <callback/callback.h>
  2. static void frame_cb(GameEngine *engine, Canvas *canvas, InputState input, void *context)
  3. {
  4. UNUSED(engine);
  5. GameManager *game_manager = context;
  6. game_manager_input_set(game_manager, input);
  7. game_manager_update(game_manager);
  8. game_manager_render(game_manager, canvas);
  9. }
  10. static int32_t game_app(void *p)
  11. {
  12. UNUSED(p);
  13. GameManager *game_manager = game_manager_alloc();
  14. if (!game_manager)
  15. {
  16. FURI_LOG_E("Game", "Failed to allocate game manager");
  17. return -1;
  18. }
  19. GameEngineSettings settings = game_engine_settings_init();
  20. settings.target_fps = game.target_fps;
  21. settings.show_fps = game.show_fps;
  22. settings.always_backlight = game.always_backlight;
  23. settings.frame_callback = frame_cb;
  24. settings.context = game_manager;
  25. GameEngine *engine = game_engine_alloc(settings);
  26. if (!engine)
  27. {
  28. FURI_LOG_E("Game", "Failed to allocate game engine");
  29. game_manager_free(game_manager);
  30. return -1;
  31. }
  32. game_manager_engine_set(game_manager, engine);
  33. void *game_context = NULL;
  34. if (game.context_size > 0)
  35. {
  36. game_context = malloc(game.context_size);
  37. game_manager_game_context_set(game_manager, game_context);
  38. }
  39. game.start(game_manager, game_context);
  40. game_engine_run(engine);
  41. game_engine_free(engine);
  42. game_manager_free(game_manager);
  43. game.stop(game_context);
  44. if (game_context)
  45. {
  46. free(game_context);
  47. }
  48. int32_t entities = entities_get_count();
  49. if (entities != 0)
  50. {
  51. FURI_LOG_E("Game", "Memory leak detected: %ld entities still allocated", entities);
  52. return -1;
  53. }
  54. return 0;
  55. }
  56. static bool alloc_about_view(void *context);
  57. static bool alloc_text_input_view(void *context, char *title);
  58. static bool alloc_variable_item_list(void *context, uint32_t view_id);
  59. //
  60. static void wifi_settings_item_selected(void *context, uint32_t index);
  61. static void text_updated_ssid(void *context);
  62. static void text_updated_pass(void *context);
  63. //
  64. static void flip_world_game_fps_change(VariableItem *item);
  65. static void game_settings_item_selected(void *context, uint32_t index);
  66. uint32_t callback_to_submenu(void *context)
  67. {
  68. UNUSED(context);
  69. return FlipWorldViewSubmenu;
  70. }
  71. static uint32_t callback_to_wifi_settings(void *context)
  72. {
  73. UNUSED(context);
  74. return FlipWorldViewVariableItemList;
  75. }
  76. static uint32_t callback_to_settings(void *context)
  77. {
  78. UNUSED(context);
  79. return FlipWorldViewSettings;
  80. }
  81. static void flip_world_view_about_draw_callback(Canvas *canvas, void *model)
  82. {
  83. UNUSED(model);
  84. canvas_clear(canvas);
  85. canvas_set_font_custom(canvas, FONT_SIZE_XLARGE);
  86. canvas_draw_str(canvas, 0, 10, VERSION_TAG);
  87. canvas_set_font_custom(canvas, FONT_SIZE_MEDIUM);
  88. canvas_draw_str(canvas, 0, 20, "- @JBlanked @codeallnight");
  89. canvas_set_font_custom(canvas, FONT_SIZE_SMALL);
  90. canvas_draw_str(canvas, 0, 30, "- github.com/JBlanked/FlipWorld");
  91. canvas_draw_str_multi(canvas, 0, 55, "The first open world multiplayer\ngame on the Flipper Zero.");
  92. }
  93. // alloc
  94. static bool alloc_about_view(void *context)
  95. {
  96. FlipWorldApp *app = (FlipWorldApp *)context;
  97. if (!app)
  98. {
  99. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  100. return false;
  101. }
  102. if (!app->view_about)
  103. {
  104. if (!easy_flipper_set_view(&app->view_about, FlipWorldViewAbout, flip_world_view_about_draw_callback, NULL, callback_to_submenu, &app->view_dispatcher, app))
  105. {
  106. return false;
  107. }
  108. if (!app->view_about)
  109. {
  110. return false;
  111. }
  112. }
  113. return true;
  114. }
  115. static bool alloc_text_input_view(void *context, char *title)
  116. {
  117. FlipWorldApp *app = (FlipWorldApp *)context;
  118. if (!app)
  119. {
  120. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  121. return false;
  122. }
  123. if (!title)
  124. {
  125. FURI_LOG_E(TAG, "Title is NULL");
  126. return false;
  127. }
  128. app->text_input_buffer_size = 64;
  129. if (!app->text_input_buffer)
  130. {
  131. if (!easy_flipper_set_buffer(&app->text_input_buffer, app->text_input_buffer_size))
  132. {
  133. return false;
  134. }
  135. }
  136. if (!app->text_input_temp_buffer)
  137. {
  138. if (!easy_flipper_set_buffer(&app->text_input_temp_buffer, app->text_input_buffer_size))
  139. {
  140. return false;
  141. }
  142. }
  143. if (!app->text_input)
  144. {
  145. if (!easy_flipper_set_uart_text_input(
  146. &app->text_input,
  147. FlipWorldViewTextInput,
  148. title,
  149. app->text_input_temp_buffer,
  150. app->text_input_buffer_size,
  151. strcmp(title, "SSID") == 0 ? text_updated_ssid : text_updated_pass,
  152. callback_to_wifi_settings,
  153. &app->view_dispatcher,
  154. app))
  155. {
  156. return false;
  157. }
  158. if (!app->text_input)
  159. {
  160. return false;
  161. }
  162. char ssid[64];
  163. char pass[64];
  164. if (load_settings(ssid, sizeof(ssid), pass, sizeof(pass)))
  165. {
  166. if (strcmp(title, "SSID") == 0)
  167. {
  168. strncpy(app->text_input_temp_buffer, ssid, app->text_input_buffer_size);
  169. }
  170. else
  171. {
  172. strncpy(app->text_input_temp_buffer, pass, app->text_input_buffer_size);
  173. }
  174. }
  175. }
  176. return true;
  177. }
  178. static bool alloc_variable_item_list(void *context, uint32_t view_id)
  179. {
  180. FlipWorldApp *app = (FlipWorldApp *)context;
  181. if (!app)
  182. {
  183. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  184. return false;
  185. }
  186. if (!app->variable_item_list)
  187. {
  188. switch (view_id)
  189. {
  190. case FlipWorldSubmenuIndexWiFiSettings:
  191. if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipWorldViewVariableItemList, wifi_settings_item_selected, callback_to_settings, &app->view_dispatcher, app))
  192. {
  193. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  194. return false;
  195. }
  196. if (!app->variable_item_list)
  197. {
  198. FURI_LOG_E(TAG, "Variable item list is NULL");
  199. return false;
  200. }
  201. if (!app->variable_item_wifi_ssid)
  202. {
  203. app->variable_item_wifi_ssid = variable_item_list_add(app->variable_item_list, "SSID", 0, NULL, NULL);
  204. variable_item_set_current_value_text(app->variable_item_wifi_ssid, "");
  205. }
  206. if (!app->variable_item_wifi_pass)
  207. {
  208. app->variable_item_wifi_pass = variable_item_list_add(app->variable_item_list, "Password", 0, NULL, NULL);
  209. variable_item_set_current_value_text(app->variable_item_wifi_pass, "");
  210. }
  211. char ssid[64];
  212. char pass[64];
  213. if (load_settings(ssid, sizeof(ssid), pass, sizeof(pass)))
  214. {
  215. variable_item_set_current_value_text(app->variable_item_wifi_ssid, ssid);
  216. // variable_item_set_current_value_text(app->variable_item_wifi_pass, pass);
  217. save_char("WiFi-SSID", ssid);
  218. save_char("WiFi-Password", pass);
  219. }
  220. break;
  221. case FlipWorldSubmenuIndexGameSettings:
  222. if (!easy_flipper_set_variable_item_list(&app->variable_item_list, FlipWorldViewVariableItemList, game_settings_item_selected, callback_to_settings, &app->view_dispatcher, app))
  223. {
  224. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  225. return false;
  226. }
  227. if (!app->variable_item_list)
  228. {
  229. FURI_LOG_E(TAG, "Variable item list is NULL");
  230. return false;
  231. }
  232. if (!app->variable_item_game_fps)
  233. {
  234. app->variable_item_game_fps = variable_item_list_add(app->variable_item_list, "FPS", 4, flip_world_game_fps_change, NULL);
  235. variable_item_set_current_value_index(app->variable_item_game_fps, 0);
  236. variable_item_set_current_value_text(app->variable_item_game_fps, game_fps_choices[0]);
  237. }
  238. char _game_fps[8];
  239. if (load_char("Game-FPS", _game_fps, sizeof(_game_fps)))
  240. {
  241. int index = strcmp(_game_fps, "30") == 0 ? 0 : strcmp(_game_fps, "60") == 0 ? 1
  242. : strcmp(_game_fps, "120") == 0 ? 2
  243. : strcmp(_game_fps, "240") == 0 ? 3
  244. : 0;
  245. variable_item_set_current_value_text(app->variable_item_game_fps, game_fps_choices[index]);
  246. variable_item_set_current_value_index(app->variable_item_game_fps, index);
  247. snprintf(game_fps, 8, "%s", _game_fps);
  248. }
  249. break;
  250. }
  251. }
  252. return true;
  253. }
  254. static bool alloc_submenu_settings(void *context)
  255. {
  256. FlipWorldApp *app = (FlipWorldApp *)context;
  257. if (!app)
  258. {
  259. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  260. return false;
  261. }
  262. if (!app->submenu_settings)
  263. {
  264. if (!easy_flipper_set_submenu(&app->submenu_settings, FlipWorldViewSettings, "Settings", callback_to_submenu, &app->view_dispatcher))
  265. {
  266. return NULL;
  267. }
  268. if (!app->submenu_settings)
  269. {
  270. return false;
  271. }
  272. submenu_add_item(app->submenu_settings, "WiFi", FlipWorldSubmenuIndexWiFiSettings, callback_submenu_choices, app);
  273. submenu_add_item(app->submenu_settings, "Game", FlipWorldSubmenuIndexGameSettings, callback_submenu_choices, app);
  274. submenu_add_item(app->submenu_settings, "User", FlipWorldSubmenuIndexUserSettings, callback_submenu_choices, app);
  275. }
  276. return true;
  277. }
  278. // free
  279. static void free_about_view(void *context)
  280. {
  281. FlipWorldApp *app = (FlipWorldApp *)context;
  282. if (!app)
  283. {
  284. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  285. return;
  286. }
  287. if (app->view_about)
  288. {
  289. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewAbout);
  290. view_free(app->view_about);
  291. app->view_about = NULL;
  292. }
  293. }
  294. static void free_main_view(void *context)
  295. {
  296. FlipWorldApp *app = (FlipWorldApp *)context;
  297. if (!app)
  298. {
  299. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  300. return;
  301. }
  302. if (app->view_main)
  303. {
  304. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewMain);
  305. view_free(app->view_main);
  306. app->view_main = NULL;
  307. }
  308. }
  309. static void free_text_input_view(void *context)
  310. {
  311. FlipWorldApp *app = (FlipWorldApp *)context;
  312. if (!app)
  313. {
  314. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  315. return;
  316. }
  317. if (app->text_input)
  318. {
  319. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewTextInput);
  320. uart_text_input_free(app->text_input);
  321. app->text_input = NULL;
  322. }
  323. if (app->text_input_buffer)
  324. {
  325. free(app->text_input_buffer);
  326. app->text_input_buffer = NULL;
  327. }
  328. if (app->text_input_temp_buffer)
  329. {
  330. free(app->text_input_temp_buffer);
  331. app->text_input_temp_buffer = NULL;
  332. }
  333. }
  334. static void free_variable_item_list(void *context)
  335. {
  336. FlipWorldApp *app = (FlipWorldApp *)context;
  337. if (!app)
  338. {
  339. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  340. return;
  341. }
  342. if (app->variable_item_list)
  343. {
  344. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  345. variable_item_list_free(app->variable_item_list);
  346. app->variable_item_list = NULL;
  347. }
  348. if (app->variable_item_wifi_ssid)
  349. {
  350. free(app->variable_item_wifi_ssid);
  351. app->variable_item_wifi_ssid = NULL;
  352. }
  353. if (app->variable_item_wifi_pass)
  354. {
  355. free(app->variable_item_wifi_pass);
  356. app->variable_item_wifi_pass = NULL;
  357. }
  358. if (app->variable_item_game_fps)
  359. {
  360. free(app->variable_item_game_fps);
  361. app->variable_item_game_fps = NULL;
  362. }
  363. if (app->variable_item_user_username)
  364. {
  365. free(app->variable_item_user_username);
  366. app->variable_item_user_username = NULL;
  367. }
  368. if (app->variable_item_user_password)
  369. {
  370. free(app->variable_item_user_password);
  371. app->variable_item_user_password = NULL;
  372. }
  373. }
  374. static void free_submenu_settings(void *context)
  375. {
  376. FlipWorldApp *app = (FlipWorldApp *)context;
  377. if (!app)
  378. {
  379. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  380. return;
  381. }
  382. if (app->submenu_settings)
  383. {
  384. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewSettings);
  385. submenu_free(app->submenu_settings);
  386. app->submenu_settings = NULL;
  387. }
  388. }
  389. static FuriThreadId thread_id;
  390. static bool game_thread_running = false;
  391. void free_all_views(void *context, bool should_free_variable_item_list, bool should_free_submenu_settings)
  392. {
  393. FlipWorldApp *app = (FlipWorldApp *)context;
  394. if (!app)
  395. {
  396. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  397. return;
  398. }
  399. if (should_free_variable_item_list)
  400. {
  401. free_variable_item_list(app);
  402. }
  403. free_about_view(app);
  404. free_main_view(app);
  405. free_text_input_view(app);
  406. if (app->view_main)
  407. {
  408. view_free(app->view_main);
  409. view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewMain);
  410. app->view_main = NULL;
  411. }
  412. // free game thread
  413. if (game_thread_running)
  414. {
  415. game_thread_running = false;
  416. furi_thread_flags_set(thread_id, WorkerEvtStop);
  417. furi_thread_free(thread_id);
  418. }
  419. if (should_free_submenu_settings)
  420. free_submenu_settings(app);
  421. }
  422. void callback_submenu_choices(void *context, uint32_t index)
  423. {
  424. FlipWorldApp *app = (FlipWorldApp *)context;
  425. if (!app)
  426. {
  427. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  428. return;
  429. }
  430. switch (index)
  431. {
  432. case FlipWorldSubmenuIndexRun:
  433. // free game thread
  434. if (game_thread_running)
  435. {
  436. game_thread_running = false;
  437. furi_thread_flags_set(thread_id, WorkerEvtStop);
  438. furi_thread_free(thread_id);
  439. }
  440. free_all_views(app, true, true);
  441. if (!app->view_main)
  442. {
  443. if (!easy_flipper_set_view(&app->view_main, FlipWorldViewMain, NULL, NULL, callback_to_submenu, &app->view_dispatcher, app))
  444. {
  445. return;
  446. }
  447. if (!app->view_main)
  448. {
  449. return;
  450. }
  451. }
  452. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewMain);
  453. FuriThread *thread = furi_thread_alloc_ex("game", 4096, game_app, app);
  454. if (!thread)
  455. {
  456. FURI_LOG_E(TAG, "Failed to allocate game thread");
  457. return;
  458. }
  459. furi_thread_start(thread);
  460. thread_id = furi_thread_get_id(thread);
  461. game_thread_running = true;
  462. break;
  463. case FlipWorldSubmenuIndexAbout:
  464. free_all_views(app, true, true);
  465. if (!alloc_about_view(app))
  466. {
  467. FURI_LOG_E(TAG, "Failed to allocate about view");
  468. return;
  469. }
  470. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewAbout);
  471. break;
  472. case FlipWorldSubmenuIndexSettings:
  473. free_all_views(app, true, true);
  474. if (!alloc_submenu_settings(app))
  475. {
  476. FURI_LOG_E(TAG, "Failed to allocate settings view");
  477. return;
  478. }
  479. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSettings);
  480. break;
  481. case FlipWorldSubmenuIndexWiFiSettings:
  482. free_all_views(app, true, false);
  483. if (!alloc_variable_item_list(app, FlipWorldSubmenuIndexWiFiSettings))
  484. {
  485. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  486. return;
  487. }
  488. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  489. break;
  490. case FlipWorldSubmenuIndexGameSettings:
  491. free_all_views(app, true, false);
  492. if (!alloc_variable_item_list(app, FlipWorldSubmenuIndexGameSettings))
  493. {
  494. FURI_LOG_E(TAG, "Failed to allocate variable item list");
  495. return;
  496. }
  497. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  498. break;
  499. case FlipWorldSubmenuIndexUserSettings:
  500. easy_flipper_dialog("User Settings", "Coming soon...");
  501. break;
  502. default:
  503. break;
  504. }
  505. }
  506. static void text_updated_ssid(void *context)
  507. {
  508. FlipWorldApp *app = (FlipWorldApp *)context;
  509. if (!app)
  510. {
  511. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  512. return;
  513. }
  514. // store the entered text
  515. strncpy(app->text_input_buffer, app->text_input_temp_buffer, app->text_input_buffer_size);
  516. // Ensure null-termination
  517. app->text_input_buffer[app->text_input_buffer_size - 1] = '\0';
  518. // save the setting
  519. save_char("WiFi-SSID", app->text_input_buffer);
  520. // update the variable item text
  521. if (app->variable_item_wifi_ssid)
  522. {
  523. variable_item_set_current_value_text(app->variable_item_wifi_ssid, app->text_input_buffer);
  524. // get value of password
  525. char pass[64];
  526. if (load_char("WiFi-Password", pass, sizeof(pass)))
  527. {
  528. if (strlen(pass) > 0 && strlen(app->text_input_buffer) > 0)
  529. {
  530. // save the settings
  531. save_settings(app->text_input_buffer, pass);
  532. // initialize the http
  533. if (flipper_http_init(flipper_http_rx_callback, app))
  534. {
  535. // save the wifi if the device is connected
  536. if (!flipper_http_save_wifi(app->text_input_buffer, pass))
  537. {
  538. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  539. }
  540. // free the resources
  541. flipper_http_deinit();
  542. }
  543. else
  544. {
  545. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  546. }
  547. }
  548. }
  549. }
  550. // switch to the settings view
  551. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  552. }
  553. static void text_updated_pass(void *context)
  554. {
  555. FlipWorldApp *app = (FlipWorldApp *)context;
  556. if (!app)
  557. {
  558. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  559. return;
  560. }
  561. // store the entered text
  562. strncpy(app->text_input_buffer, app->text_input_temp_buffer, app->text_input_buffer_size);
  563. // Ensure null-termination
  564. app->text_input_buffer[app->text_input_buffer_size - 1] = '\0';
  565. // save the setting
  566. save_char("WiFi-Password", app->text_input_buffer);
  567. // update the variable item text
  568. if (app->variable_item_wifi_pass)
  569. {
  570. // variable_item_set_current_value_text(app->variable_item_wifi_pass, app->text_input_buffer);
  571. }
  572. // get value of ssid
  573. char ssid[64];
  574. if (load_char("WiFi-SSID", ssid, sizeof(ssid)))
  575. {
  576. if (strlen(ssid) > 0 && strlen(app->text_input_buffer) > 0)
  577. {
  578. // save the settings
  579. save_settings(ssid, app->text_input_buffer);
  580. // initialize the http
  581. if (flipper_http_init(flipper_http_rx_callback, app))
  582. {
  583. // save the wifi if the device is connected
  584. if (!flipper_http_save_wifi(ssid, app->text_input_buffer))
  585. {
  586. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  587. }
  588. // free the resources
  589. flipper_http_deinit();
  590. }
  591. else
  592. {
  593. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  594. }
  595. }
  596. }
  597. // switch to the settings view
  598. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
  599. }
  600. static void wifi_settings_item_selected(void *context, uint32_t index)
  601. {
  602. FlipWorldApp *app = (FlipWorldApp *)context;
  603. if (!app)
  604. {
  605. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  606. return;
  607. }
  608. char ssid[64];
  609. char pass[64];
  610. switch (index)
  611. {
  612. case 0: // Input SSID
  613. free_all_views(app, false, false);
  614. if (!alloc_text_input_view(app, "SSID"))
  615. {
  616. FURI_LOG_E(TAG, "Failed to allocate text input view");
  617. return;
  618. }
  619. // load SSID
  620. if (load_settings(ssid, sizeof(ssid), pass, sizeof(pass)))
  621. {
  622. strncpy(app->text_input_temp_buffer, ssid, app->text_input_buffer_size - 1);
  623. app->text_input_temp_buffer[app->text_input_buffer_size - 1] = '\0';
  624. }
  625. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewTextInput);
  626. break;
  627. case 1: // Input Password
  628. free_all_views(app, false, false);
  629. if (!alloc_text_input_view(app, "Password"))
  630. {
  631. FURI_LOG_E(TAG, "Failed to allocate text input view");
  632. return;
  633. }
  634. // load password
  635. if (load_settings(ssid, sizeof(ssid), pass, sizeof(pass)))
  636. {
  637. strncpy(app->text_input_temp_buffer, pass, app->text_input_buffer_size - 1);
  638. app->text_input_temp_buffer[app->text_input_buffer_size - 1] = '\0';
  639. }
  640. view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewTextInput);
  641. break;
  642. default:
  643. FURI_LOG_E(TAG, "Unknown configuration item index");
  644. break;
  645. }
  646. }
  647. static void flip_world_game_fps_change(VariableItem *item)
  648. {
  649. uint8_t index = variable_item_get_current_value_index(item);
  650. variable_item_set_current_value_text(item, game_fps_choices[index]);
  651. // save the fps
  652. snprintf(game_fps, 8, "%s", game_fps_choices[index]);
  653. save_char("Game-FPS", game_fps);
  654. }
  655. static void game_settings_item_selected(void *context, uint32_t index)
  656. {
  657. FlipWorldApp *app = (FlipWorldApp *)context;
  658. if (!app)
  659. {
  660. FURI_LOG_E(TAG, "FlipWorldApp is NULL");
  661. return;
  662. }
  663. switch (index)
  664. {
  665. case 0: // Game FPS
  666. break; // handled by flip_world_game_fps_change
  667. }
  668. }