flip_trader.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <flip_trader.h>
  2. void flip_trader_loader_free_model(View* view);
  3. void asset_names_free(char** names) {
  4. if(names) {
  5. for(int i = 0; i < ASSET_COUNT; i++) {
  6. free(names[i]);
  7. }
  8. free(names);
  9. }
  10. }
  11. char** asset_names_alloc() {
  12. // Allocate memory for an array of 42 string pointers
  13. char** names = malloc(ASSET_COUNT * sizeof(char*));
  14. if(!names) {
  15. FURI_LOG_E(TAG, "Failed to allocate memory for asset names");
  16. return NULL;
  17. }
  18. // Assign each asset name to the array
  19. names[0] = strdup("ETHUSD");
  20. names[1] = strdup("BTCUSD");
  21. names[2] = strdup("AAPL");
  22. names[3] = strdup("AMZN");
  23. names[4] = strdup("GOOGL");
  24. names[5] = strdup("MSFT");
  25. names[6] = strdup("TSLA");
  26. names[7] = strdup("NFLX");
  27. names[8] = strdup("META");
  28. names[9] = strdup("NVDA");
  29. names[10] = strdup("AMD");
  30. names[11] = strdup("INTC");
  31. names[12] = strdup("PLTR");
  32. names[13] = strdup("EURUSD");
  33. names[14] = strdup("GBPUSD");
  34. names[15] = strdup("AUDUSD");
  35. names[16] = strdup("NZDUSD");
  36. names[17] = strdup("XAUUSD");
  37. names[18] = strdup("USDJPY");
  38. names[19] = strdup("USDCHF");
  39. names[20] = strdup("USDCAD");
  40. names[21] = strdup("EURJPY");
  41. names[22] = strdup("EURGBP");
  42. names[23] = strdup("EURCHF");
  43. names[24] = strdup("EURCAD");
  44. names[25] = strdup("EURAUD");
  45. names[26] = strdup("EURNZD");
  46. names[27] = strdup("AUDJPY");
  47. names[28] = strdup("AUDCHF");
  48. names[29] = strdup("AUDCAD");
  49. names[30] = strdup("NZDJPY");
  50. names[31] = strdup("NZDCHF");
  51. names[32] = strdup("NZDCAD");
  52. names[33] = strdup("GBPJPY");
  53. names[34] = strdup("GBPCHF");
  54. names[35] = strdup("GBPCAD");
  55. names[36] = strdup("CHFJPY");
  56. names[37] = strdup("CADJPY");
  57. names[38] = strdup("CADCHF");
  58. names[39] = strdup("GBPAUD");
  59. names[40] = strdup("GBPNZD");
  60. names[41] = strdup("AUDNZD");
  61. return names;
  62. }
  63. char** asset_names = NULL;
  64. // index
  65. uint32_t asset_index = 0;
  66. FlipTraderApp* app_instance = NULL;
  67. // Function to free the resources used by FlipTraderApp
  68. void flip_trader_app_free(FlipTraderApp* app) {
  69. if(!app) {
  70. FURI_LOG_E(TAG, "FlipTraderApp is NULL");
  71. return;
  72. }
  73. // Free View(s)
  74. if(app->view_loader) {
  75. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewLoader);
  76. flip_trader_loader_free_model(app->view_loader);
  77. view_free(app->view_loader);
  78. }
  79. // Free Submenu(s)
  80. if(app->submenu_main) {
  81. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewMainSubmenu);
  82. submenu_free(app->submenu_main);
  83. }
  84. if(app->submenu_assets) {
  85. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAssetsSubmenu);
  86. submenu_free(app->submenu_assets);
  87. }
  88. // Free Widget(s)
  89. if(app->widget_about) {
  90. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAbout);
  91. widget_free(app->widget_about);
  92. }
  93. if(app->widget_result) {
  94. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewWidgetResult);
  95. widget_free(app->widget_result);
  96. }
  97. // Free Variable Item List(s)
  98. if(app->variable_item_list_wifi) {
  99. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewWiFiSettings);
  100. variable_item_list_free(app->variable_item_list_wifi);
  101. }
  102. // Free Text Input(s)
  103. if(app->uart_text_input_ssid) {
  104. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputSSID);
  105. text_input_free(app->uart_text_input_ssid);
  106. }
  107. if(app->uart_text_input_password) {
  108. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputPassword);
  109. text_input_free(app->uart_text_input_password);
  110. }
  111. asset_names_free(asset_names);
  112. // deinitalize flipper http
  113. flipper_http_deinit();
  114. // free the view dispatcher
  115. view_dispatcher_free(app->view_dispatcher);
  116. // close the gui
  117. furi_record_close(RECORD_GUI);
  118. // free the app
  119. free(app);
  120. }