MenuFunctions.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. #include "MenuFunctions.h"
  2. //#include "icons.h"
  3. extern const unsigned char menu_icons[][66];
  4. MenuFunctions::MenuFunctions()
  5. {
  6. }
  7. // Function to check menu input
  8. void MenuFunctions::main(uint32_t currentTime)
  9. {
  10. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  11. (wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
  12. (wifi_scan_obj.currentScanMode == SHOW_INFO)) {
  13. if (wifi_scan_obj.orient_display) {
  14. this->orientDisplay();
  15. wifi_scan_obj.orient_display = false;
  16. }
  17. //if ((display_obj.current_banner_pos <= 0) || (display_obj.current_banner_pos == SCREEN_WIDTH))
  18. //{
  19. // this->drawStatusBar();
  20. //}
  21. display_obj.updateBanner(current_menu->name);
  22. }
  23. if (currentTime != 0) {
  24. if (currentTime - initTime >= 100) {
  25. this->initTime = millis();
  26. this->updateStatusBar();
  27. }
  28. }
  29. //this->displayCurrentMenu();
  30. boolean pressed = false;
  31. // This is code from bodmer's keypad example
  32. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  33. // Get the display buffer out of the way
  34. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  35. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  36. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  37. display_obj.displayBuffer();
  38. //Serial.println(wifi_scan_obj.freeRAM());
  39. // Pressed will be set true is there is a valid touch on the screen
  40. int pre_getTouch = millis();
  41. // getTouch causes a 10ms delay which makes beacon spam less effective
  42. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  43. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  44. //if (pressed)
  45. // Serial.println("Pressed, son");
  46. //boolean pressed = false;
  47. //Serial.print("getTouch: ");
  48. //Serial.print(millis() - pre_getTouch);
  49. //Serial.println("ms");
  50. // This is if there are scans/attacks going on
  51. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  52. (pressed) &&
  53. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  54. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  55. {
  56. // Stop the current scan
  57. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  58. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  59. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  60. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  61. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  62. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  63. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  64. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  65. {
  66. Serial.println("Stopping scan...");
  67. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  68. // If we don't do this, the text and button coordinates will be off
  69. display_obj.tft.init();
  70. // Take us back to the menu
  71. changeMenu(current_menu);
  72. }
  73. x = -1;
  74. y = -1;
  75. return;
  76. }
  77. // Check if any key coordinate boxes contain the touch coordinates
  78. // This is for when on a menu
  79. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  80. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  81. {
  82. // Need this to set all keys to false
  83. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  84. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  85. display_obj.key[b].press(true); // tell the button it is pressed
  86. } else {
  87. display_obj.key[b].press(false); // tell the button it is NOT pressed
  88. }
  89. }
  90. // Check if any key has changed state
  91. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  92. display_obj.tft.setFreeFont(MENU_FONT);
  93. if (display_obj.key[b].justPressed()) {
  94. //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  95. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true);
  96. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  97. if (current_menu->list->get(b).name != "Back")
  98. display_obj.tft.drawXBitmap(0,
  99. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  100. menu_icons[current_menu->list->get(b).icon],
  101. ICON_W,
  102. ICON_H,
  103. current_menu->list->get(b).color,
  104. TFT_BLACK);
  105. }
  106. //else if (pressed)
  107. // display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  108. // If button was just release, execute the button's function
  109. if ((display_obj.key[b].justReleased()) && (!pressed))
  110. {
  111. //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  112. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name);
  113. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  114. current_menu->list->get(b).callable();
  115. }
  116. // This
  117. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  118. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  119. if (current_menu->list->get(b).name != "Back")
  120. display_obj.tft.drawXBitmap(0,
  121. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  122. menu_icons[current_menu->list->get(b).icon],
  123. ICON_W,
  124. ICON_H,
  125. TFT_BLACK,
  126. current_menu->list->get(b).color);
  127. }
  128. display_obj.tft.setFreeFont(NULL);
  129. }
  130. }
  131. x = -1;
  132. y = -1;
  133. }
  134. void MenuFunctions::updateStatusBar()
  135. {
  136. uint16_t the_color;
  137. // Draw temp info
  138. if (temp_obj.current_temp < 70)
  139. the_color = TFT_GREEN;
  140. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  141. the_color = TFT_YELLOW;
  142. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  143. the_color = TFT_ORANGE;
  144. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  145. the_color = TFT_RED;
  146. else
  147. the_color = TFT_MAROON;
  148. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  149. if (temp_obj.current_temp != temp_obj.old_temp) {
  150. temp_obj.old_temp = temp_obj.current_temp;
  151. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  152. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  153. }
  154. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  155. // Draw battery info
  156. if (battery_obj.i2c_supported)
  157. {
  158. if ((String)battery_obj.battery_level != "25")
  159. the_color = TFT_GREEN;
  160. else
  161. the_color = TFT_RED;
  162. if (battery_obj.battery_level != battery_obj.old_level) {
  163. battery_obj.old_level = battery_obj.battery_level;
  164. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  165. display_obj.tft.setCursor(0, 1);
  166. display_obj.tft.drawXBitmap(186,
  167. 0,
  168. menu_icons[STATUS_BAT],
  169. 16,
  170. 16,
  171. STATUSBAR_COLOR,
  172. the_color);
  173. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  174. }
  175. }
  176. // Draw SD info
  177. if (sd_obj.supported)
  178. the_color = TFT_GREEN;
  179. else
  180. the_color = TFT_RED;
  181. display_obj.tft.drawXBitmap(170,
  182. 0,
  183. menu_icons[STATUS_SD],
  184. 16,
  185. 16,
  186. STATUSBAR_COLOR,
  187. the_color);
  188. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  189. }
  190. void MenuFunctions::drawStatusBar()
  191. {
  192. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  193. //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY);
  194. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  195. //display_obj.tft.setTextSize(2);
  196. uint16_t the_color;
  197. // Draw temp info
  198. if (temp_obj.current_temp < 70)
  199. the_color = TFT_GREEN;
  200. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  201. the_color = TFT_YELLOW;
  202. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  203. the_color = TFT_ORANGE;
  204. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  205. the_color = TFT_RED;
  206. else
  207. the_color = TFT_MAROON;
  208. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  209. temp_obj.old_temp = temp_obj.current_temp;
  210. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  211. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  212. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  213. // Draw battery info
  214. if (battery_obj.i2c_supported)
  215. {
  216. if ((String)battery_obj.battery_level != "25")
  217. the_color = TFT_GREEN;
  218. else
  219. the_color = TFT_RED;
  220. battery_obj.old_level = battery_obj.battery_level;
  221. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  222. display_obj.tft.setCursor(0, 1);
  223. display_obj.tft.drawXBitmap(186,
  224. 0,
  225. menu_icons[STATUS_BAT],
  226. 16,
  227. 16,
  228. STATUSBAR_COLOR,
  229. the_color);
  230. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  231. }
  232. // Draw SD info
  233. if (sd_obj.supported)
  234. the_color = TFT_GREEN;
  235. else
  236. the_color = TFT_RED;
  237. display_obj.tft.drawXBitmap(170,
  238. 0,
  239. menu_icons[STATUS_SD],
  240. 16,
  241. 16,
  242. STATUSBAR_COLOR,
  243. the_color);
  244. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  245. }
  246. void MenuFunctions::orientDisplay()
  247. {
  248. display_obj.tft.init();
  249. display_obj.tft.setRotation(0); // Portrait
  250. display_obj.tft.setCursor(0, 0);
  251. //uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
  252. //uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  253. #ifdef TFT_SHIELD
  254. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  255. Serial.println("Using TFT Shield");
  256. #else if defined(TFT_DIY)
  257. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  258. Serial.println("Using TFT DIY");
  259. #endif
  260. display_obj.tft.setTouch(calData);
  261. //display_obj.clearScreen();
  262. changeMenu(current_menu);
  263. }
  264. // Function to build the menus
  265. void MenuFunctions::RunSetup()
  266. {
  267. // root menu stuff
  268. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  269. // Main menu stuff
  270. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  271. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  272. generalMenu.list = new LinkedList<MenuNode>();
  273. deviceMenu.list = new LinkedList<MenuNode>();
  274. // Device menu stuff
  275. failedUpdateMenu.list = new LinkedList<MenuNode>();
  276. whichUpdateMenu.list = new LinkedList<MenuNode>();
  277. confirmMenu.list = new LinkedList<MenuNode>();
  278. updateMenu.list = new LinkedList<MenuNode>();
  279. infoMenu.list = new LinkedList<MenuNode>();
  280. // WiFi menu stuff
  281. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  282. wifiScannerMenu.list = new LinkedList<MenuNode>();
  283. wifiAttackMenu.list = new LinkedList<MenuNode>();
  284. // Bluetooth menu stuff
  285. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  286. bluetoothScannerMenu.list = new LinkedList<MenuNode>();
  287. // Work menu names
  288. mainMenu.name = " ESP32 Marauder ";
  289. wifiMenu.name = " WiFi ";
  290. deviceMenu.name = " Device ";
  291. generalMenu.name = " General Apps ";
  292. failedUpdateMenu.name = " Updating... ";
  293. whichUpdateMenu.name = "Select Method ";
  294. confirmMenu.name = " Confirm Update ";
  295. updateMenu.name = " Update Firmware ";
  296. infoMenu.name = " Device Info ";
  297. bluetoothMenu.name = " Bluetooth ";
  298. wifiSnifferMenu.name = " WiFi Sniffers ";
  299. wifiScannerMenu.name = " WiFi Scanners";
  300. wifiAttackMenu.name = " WiFi Attacks ";
  301. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  302. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  303. // Build Main Menu
  304. mainMenu.parentMenu = NULL;
  305. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, WIFI, [this](){changeMenu(&wifiMenu);});
  306. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, BLUETOOTH, [this](){changeMenu(&bluetoothMenu);});
  307. addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, GENERAL_APPS, [this](){changeMenu(&generalMenu);});
  308. addNodes(&mainMenu, "Device", TFT_BLUE, NULL, DEVICE, [this](){changeMenu(&deviceMenu);});
  309. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, REBOOT, [](){ESP.restart();});
  310. // Build WiFi Menu
  311. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  312. addNodes(&wifiMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiMenu.parentMenu);});
  313. addNodes(&wifiMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this](){changeMenu(&wifiSnifferMenu);});
  314. addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this](){changeMenu(&wifiScannerMenu);});
  315. addNodes(&wifiMenu, "Attacks", TFT_RED, NULL, ATTACKS, [this](){changeMenu(&wifiAttackMenu);});
  316. // Build WiFi sniffer Menu
  317. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  318. addNodes(&wifiSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiSnifferMenu.parentMenu);});
  319. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, PROBE_SNIFF, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);});
  320. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, BEACON_SNIFF, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);});
  321. addNodes(&wifiSnifferMenu, "Deauth Sniff", TFT_RED, NULL, DEAUTH_SNIFF, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);});
  322. // Build WiFi scanner Menu
  323. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  324. addNodes(&wifiScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiScannerMenu.parentMenu);});
  325. addNodes(&wifiScannerMenu, "Packet Monitor", TFT_BLUE, NULL, PACKET_MONITOR, [this](){wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);});
  326. addNodes(&wifiScannerMenu, "EAPOL/PMKID Scan", TFT_VIOLET, NULL, EAPOL, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);});
  327. // Build WiFi attack menu
  328. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  329. addNodes(&wifiAttackMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(wifiAttackMenu.parentMenu);});
  330. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, BEACON_SPAM, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);});
  331. addNodes(&wifiAttackMenu, "Rick Roll Beacon", TFT_YELLOW, NULL, RICK_ROLL, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);});
  332. // Build Bluetooth Menu
  333. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  334. addNodes(&bluetoothMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothMenu.parentMenu);});
  335. addNodes(&bluetoothMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this](){changeMenu(&bluetoothSnifferMenu);});
  336. addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this](){changeMenu(&bluetoothScannerMenu);});
  337. // Build bluetooth sniffer Menu
  338. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  339. addNodes(&bluetoothSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothSnifferMenu.parentMenu);});
  340. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);});
  341. // Build bluetooth scanner Menu
  342. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  343. addNodes(&bluetoothScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(bluetoothScannerMenu.parentMenu);});
  344. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, CC_SKIMMERS, [this](){display_obj.clearScreen(); this->drawStatusBar(); wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);});
  345. // General apps menu
  346. generalMenu.parentMenu = &mainMenu;
  347. addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){display_obj.draw_tft = false; changeMenu(generalMenu.parentMenu);});
  348. addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, DRAW, [this](){display_obj.clearScreen(); display_obj.draw_tft = true;});
  349. // Device menu
  350. deviceMenu.parentMenu = &mainMenu;
  351. addNodes(&deviceMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(deviceMenu.parentMenu);});
  352. //addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  353. addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&whichUpdateMenu);});
  354. addNodes(&deviceMenu, "Device Info", TFT_WHITE, NULL, DEVICE_INFO, [this](){wifi_scan_obj.currentScanMode = SHOW_INFO; changeMenu(&infoMenu); wifi_scan_obj.RunInfo();});
  355. // Select update
  356. whichUpdateMenu.parentMenu = &deviceMenu;
  357. addNodes(&whichUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(whichUpdateMenu.parentMenu);});
  358. addNodes(&whichUpdateMenu, "Web Update", TFT_GREEN, NULL, WEB_UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  359. if (sd_obj.supported) addNodes(&whichUpdateMenu, "SD Update", TFT_MAGENTA, NULL, SD_UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&confirmMenu);});
  360. // Confirm SD update menu
  361. confirmMenu.parentMenu = &whichUpdateMenu;
  362. addNodes(&confirmMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){changeMenu(confirmMenu.parentMenu);});
  363. //addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); sd_obj.runUpdate();});
  364. addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&failedUpdateMenu); sd_obj.runUpdate();});
  365. // Web Update
  366. updateMenu.parentMenu = &deviceMenu;
  367. addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu); WiFi.softAPdisconnect(true); web_obj.shutdownServer();});
  368. //addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
  369. // Failed update menu
  370. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  371. addNodes(&failedUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(failedUpdateMenu.parentMenu);});
  372. // Device info menu
  373. infoMenu.parentMenu = &deviceMenu;
  374. addNodes(&infoMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(infoMenu.parentMenu);});
  375. // Set the current menu to the mainMenu
  376. changeMenu(&mainMenu);
  377. this->initTime = millis();
  378. }
  379. // Function to change menu
  380. void MenuFunctions::changeMenu(Menu* menu)
  381. {
  382. display_obj.initScrollValues();
  383. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  384. display_obj.tft.init();
  385. current_menu = menu;
  386. buildButtons(menu);
  387. displayCurrentMenu();
  388. }
  389. // Function to show all MenuNodes in a Menu
  390. void MenuFunctions::showMenuList(Menu* menu, int layer)
  391. {
  392. // Iterate through all of the menu nodes in the menu
  393. for (int i = 0; i < menu->list->size(); i++)
  394. {
  395. // Depending on layer, indent
  396. for (int x = 0; x < layer * 4; x++)
  397. Serial.print(" ");
  398. Serial.print("Node: ");
  399. Serial.println(menu->list->get(i).name);
  400. // If the current menu node points to another menu, list that menu
  401. //if (menu->list->get(i).childMenu != NULL)
  402. // showMenuList(menu->list->get(i).childMenu, layer+1);
  403. }
  404. Serial.println();
  405. }
  406. // Function to add MenuNodes to a menu
  407. void MenuFunctions::addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable)
  408. {
  409. TFT_eSPI_Button new_button;
  410. menu->list->add(MenuNode{name, color, place, &new_button, callable});
  411. //strcpy(menu->list->get(-1).icon, bluetooth_icon);
  412. }
  413. void MenuFunctions::buildButtons(Menu* menu)
  414. {
  415. Serial.println("Bulding buttons...");
  416. if (menu->list != NULL)
  417. {
  418. //for (int i = 0; i < sizeof(key); i++)
  419. // key[i] = NULL;
  420. for (int i = 0; i < menu->list->size(); i++)
  421. {
  422. TFT_eSPI_Button new_button;
  423. char buf[menu->list->get(i).name.length() + 1] = {};
  424. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  425. display_obj.key[i].initButton(&display_obj.tft,
  426. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  427. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  428. KEY_W,
  429. KEY_H,
  430. TFT_BLACK, // Outline
  431. TFT_BLACK, // Fill
  432. menu->list->get(i).color, // Text
  433. buf,
  434. KEY_TEXTSIZE);
  435. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W/2), 2, ML_DATUM);
  436. }
  437. }
  438. }
  439. void MenuFunctions::displayCurrentMenu()
  440. {
  441. Serial.println("Displaying current menu...");
  442. display_obj.clearScreen();
  443. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  444. this->drawStatusBar();
  445. //display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  446. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  447. //Serial.println("Getting size...");
  448. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  449. //Serial.println("Got size...");
  450. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  451. //String current_name = &current_menu->parentMenu->name;
  452. //Serial.println("gottem");
  453. //display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  454. if (current_menu->list != NULL)
  455. {
  456. display_obj.tft.setFreeFont(MENU_FONT);
  457. for (int i = 0; i < current_menu->list->size(); i++)
  458. {
  459. //display_obj.key[i].drawButton2(current_menu->list->get(i).name);
  460. //display_obj.key[i].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(i).name);
  461. //display_obj.key[i].drawButton(true);
  462. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  463. if (current_menu->list->get(i).name != "Back")
  464. display_obj.tft.drawXBitmap(0,
  465. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  466. menu_icons[current_menu->list->get(i).icon],
  467. ICON_W,
  468. ICON_H,
  469. TFT_BLACK,
  470. current_menu->list->get(i).color);
  471. }
  472. display_obj.tft.setFreeFont(NULL);
  473. }
  474. }