MenuFunctions.cpp 23 KB

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