MenuFunctions.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #include "MenuFunctions.h"
  2. MenuFunctions::MenuFunctions()
  3. {
  4. }
  5. // Function to check menu input
  6. void MenuFunctions::main()
  7. {
  8. // This is code from bodmer's keypad example
  9. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  10. // Get the display buffer out of the way
  11. if (wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF)
  12. display_obj.displayBuffer();
  13. // Pressed will be set true is there is a valid touch on the screen
  14. boolean pressed = display_obj.tft.getTouch(&t_x, &t_y);
  15. //boolean pressed = false;
  16. // This is if there are scans going on
  17. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (pressed))
  18. //if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) && (x != -1) && (y != -1))
  19. {
  20. // Stop the current scan
  21. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  22. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  23. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ST) ||
  24. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  25. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  26. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  27. {
  28. Serial.println("Stopping scan...");
  29. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  30. // If we don't do this, the text and button coordinates will be off
  31. display_obj.tft.init();
  32. // Take us back to the menu
  33. changeMenu(current_menu);
  34. }
  35. x = -1;
  36. y = -1;
  37. return;
  38. }
  39. // / Check if any key coordinate boxes contain the touch coordinates
  40. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  41. if (pressed && key[b].contains(t_x, t_y)) {
  42. key[b].press(true); // tell the button it is pressed
  43. } else {
  44. key[b].press(false); // tell the button it is NOT pressed
  45. }
  46. }
  47. // Check if any key has changed state
  48. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  49. display_obj.tft.setFreeFont(MENU_FONT);
  50. if (key[b].justPressed()) {
  51. key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  52. }
  53. // If button was just release, execute the button's function
  54. if (key[b].justReleased())
  55. {
  56. key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  57. current_menu->list->get(b).callable();
  58. }
  59. display_obj.tft.setFreeFont(NULL);
  60. }
  61. x = -1;
  62. y = -1;
  63. }
  64. // Function to build the menus
  65. void MenuFunctions::RunSetup()
  66. {
  67. // Main menu stuff
  68. mainMenu.list = new SimpleList<MenuNode>(); // Get list in first menu ready
  69. wifiMenu.list = new SimpleList<MenuNode>(); // Get list in second menu ready
  70. bluetoothMenu.list = new SimpleList<MenuNode>(); // Get list in third menu ready
  71. // WiFi menu stuff
  72. wifiSnifferMenu.list = new SimpleList<MenuNode>();
  73. wifiScannerMenu.list = new SimpleList<MenuNode>();
  74. wifiAttackMenu.list = new SimpleList<MenuNode>();
  75. // Bluetooth menu stuff
  76. bluetoothSnifferMenu.list = new SimpleList<MenuNode>();
  77. bluetoothScannerMenu.list = new SimpleList<MenuNode>();
  78. // Work menu names
  79. mainMenu.name = " ESP32 Marauder ";
  80. wifiMenu.name = " WiFi ";
  81. bluetoothMenu.name = " Bluetooth ";
  82. wifiSnifferMenu.name = " WiFi Sniffers ";
  83. wifiScannerMenu.name = " WiFi Scanners";
  84. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  85. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  86. // Build Main Menu
  87. mainMenu.parentMenu = NULL;
  88. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, 0, [this](){changeMenu(&wifiMenu);});
  89. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, 1, [this](){changeMenu(&bluetoothMenu);});
  90. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, 2, [](){ESP.restart();});
  91. // Build WiFi Menu
  92. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  93. addNodes(&wifiMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiMenu.parentMenu);});
  94. addNodes(&wifiMenu, "Sniffers", TFT_LIGHTGREY, NULL, 1, [this](){changeMenu(&wifiSnifferMenu);});
  95. addNodes(&wifiMenu, "Scanners", TFT_YELLOW, NULL, 1, [this](){Serial.println("Coming soon...");});
  96. addNodes(&wifiMenu, "Attacks", TFT_ORANGE, NULL, 1, [this](){Serial.println("Coming soon...");});
  97. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  98. addNodes(&wifiSnifferMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(wifiSnifferMenu.parentMenu);});
  99. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, 2, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);});
  100. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, 3, [this](){wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);});
  101. // Build Bluetooth Menu
  102. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  103. addNodes(&bluetoothMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothMenu.parentMenu);});
  104. addNodes(&bluetoothMenu, "Sniffers", TFT_LIGHTGREY, NULL, 1, [this](){changeMenu(&bluetoothSnifferMenu);});
  105. addNodes(&bluetoothMenu, "Scanners", TFT_YELLOW, NULL, 1, [this](){changeMenu(&bluetoothScannerMenu);});
  106. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  107. addNodes(&bluetoothSnifferMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothSnifferMenu.parentMenu);});
  108. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, 1, [this](){wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);});
  109. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  110. addNodes(&bluetoothScannerMenu, "Back", TFT_RED, NULL, 0, [this](){changeMenu(bluetoothScannerMenu.parentMenu);});
  111. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, 2, [this](){wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);});
  112. // Set the current menu to the mainMenu
  113. changeMenu(&mainMenu);
  114. }
  115. // Function to change menu
  116. void MenuFunctions::changeMenu(Menu* menu)
  117. {
  118. display_obj.initScrollValues();
  119. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  120. display_obj.tft.init();
  121. current_menu = menu;
  122. buildButtons(menu);
  123. displayCurrentMenu();
  124. }
  125. // Function to show all MenuNodes in a Menu
  126. void MenuFunctions::showMenuList(Menu* menu, int layer)
  127. {
  128. // Iterate through all of the menu nodes in the menu
  129. for (int i = 0; i < menu->list->size(); i++)
  130. {
  131. // Depending on layer, indent
  132. for (int x = 0; x < layer * 4; x++)
  133. Serial.print(" ");
  134. Serial.print("Node: ");
  135. Serial.println(menu->list->get(i).name);
  136. // If the current menu node points to another menu, list that menu
  137. if (menu->list->get(i).childMenu != NULL)
  138. showMenuList(menu->list->get(i).childMenu, layer+1);
  139. }
  140. Serial.println();
  141. }
  142. // Function to add MenuNodes to a menu
  143. void MenuFunctions::addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable)
  144. {
  145. TFT_eSPI_Button new_button;
  146. menu->list->add(MenuNode{name, color, child, &new_button, callable});
  147. }
  148. void MenuFunctions::buildButtons(Menu* menu)
  149. {
  150. Serial.println("Bulding buttons...");
  151. if (menu->list != NULL)
  152. {
  153. for (int i = 0; i < menu->list->size(); i++)
  154. {
  155. TFT_eSPI_Button new_button;
  156. char buf[menu->list->get(i).name.length() + 1] = {};
  157. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  158. key[i].initButton(&display_obj.tft,
  159. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  160. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  161. KEY_W,
  162. KEY_H,
  163. TFT_BLACK, // Outline
  164. TFT_BLACK, // Fill
  165. menu->list->get(i).color, // Text
  166. buf,
  167. KEY_TEXTSIZE);
  168. }
  169. }
  170. }
  171. void MenuFunctions::displayCurrentMenu()
  172. {
  173. Serial.println("Displaying current menu...");
  174. display_obj.clearScreen();
  175. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  176. display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  177. display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  178. //String current_name = &current_menu->parentMenu->name;
  179. //display_obj.tft.drawCentreString(current_name,120,0,2);
  180. if (current_menu->list != NULL)
  181. {
  182. display_obj.tft.setFreeFont(MENU_FONT);
  183. for (int i = 0; i < current_menu->list->size(); i++)
  184. {
  185. key[i].drawButton2(current_menu->list->get(i).name);
  186. }
  187. display_obj.tft.setFreeFont(NULL);
  188. }
  189. }