MenuFunctions.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. #include "MenuFunctions.h"
  2. #include "lang_var.h"
  3. //#include "icons.h"
  4. #ifdef HAS_SCREEN
  5. extern const unsigned char menu_icons[][66];
  6. PROGMEM lv_obj_t * slider_label;
  7. PROGMEM lv_obj_t * ta1;
  8. PROGMEM lv_obj_t * ta2;
  9. PROGMEM lv_obj_t * save_name;
  10. MenuFunctions::MenuFunctions()
  11. {
  12. }
  13. // LVGL Stuff
  14. /* Interrupt driven periodic handler */
  15. #ifdef HAS_ILI9341
  16. void MenuFunctions::lv_tick_handler()
  17. {
  18. lv_tick_inc(LVGL_TICK_PERIOD);
  19. }
  20. /* Display flushing */
  21. void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  22. {
  23. extern Display display_obj;
  24. uint16_t c;
  25. display_obj.tft.startWrite();
  26. display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
  27. for (int y = area->y1; y <= area->y2; y++) {
  28. for (int x = area->x1; x <= area->x2; x++) {
  29. c = color_p->full;
  30. display_obj.tft.writeColor(c, 1);
  31. color_p++;
  32. }
  33. }
  34. display_obj.tft.endWrite();
  35. lv_disp_flush_ready(disp);
  36. }
  37. bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  38. {
  39. extern Display display_obj;
  40. uint16_t touchX, touchY;
  41. bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
  42. if(!touched)
  43. {
  44. return false;
  45. }
  46. if(touchX>WIDTH_1 || touchY > HEIGHT_1)
  47. {
  48. Serial.println("Y or y outside of expected parameters..");
  49. Serial.print("y:");
  50. Serial.print(touchX);
  51. Serial.print(" x:");
  52. Serial.print(touchY);
  53. }
  54. else
  55. {
  56. data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  57. data->point.x = touchX;
  58. data->point.y = touchY;
  59. }
  60. return false;
  61. }
  62. void MenuFunctions::initLVGL() {
  63. tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
  64. lv_init();
  65. lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  66. lv_disp_drv_t disp_drv;
  67. lv_disp_drv_init(&disp_drv);
  68. disp_drv.hor_res = WIDTH_1;
  69. disp_drv.ver_res = HEIGHT_1;
  70. disp_drv.flush_cb = my_disp_flush;
  71. disp_drv.buffer = &disp_buf;
  72. lv_disp_drv_register(&disp_drv);
  73. lv_indev_drv_t indev_drv;
  74. lv_indev_drv_init(&indev_drv);
  75. indev_drv.type = LV_INDEV_TYPE_POINTER;
  76. indev_drv.read_cb = my_touchpad_read;
  77. lv_indev_drv_register(&indev_drv);
  78. }
  79. void MenuFunctions::deinitLVGL() {
  80. Serial.println(F("Deinit LVGL"));
  81. //lv_deinit();
  82. }
  83. // Event handler for settings drop down menus
  84. void setting_dropdown_cb(lv_obj_t * obj, lv_event_t event) {
  85. }
  86. // GFX Function to build a list showing all Stations scanned
  87. void MenuFunctions::addStationGFX(){
  88. extern LinkedList<Station>* stations;
  89. extern LinkedList<AccessPoint>* access_points;
  90. extern WiFiScan wifi_scan_obj;
  91. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  92. lv_obj_set_size(list1, 160, 200);
  93. lv_obj_set_width(list1, LV_HOR_RES);
  94. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  95. lv_obj_t * list_btn;
  96. lv_obj_t * label;
  97. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
  98. lv_obj_set_event_cb(list_btn, station_list_cb);
  99. char addr[] = "00:00:00:00:00:00";
  100. for (int x = 0; x < access_points->size(); x++) {
  101. AccessPoint cur_ap = access_points->get(x);
  102. // Add non clickable button for AP
  103. String full_label = "AP: " + cur_ap.essid;
  104. char buf[full_label.length() + 1] = {};
  105. full_label.toCharArray(buf, full_label.length() + 1);
  106. list_btn = lv_list_add_btn(list1, NULL, buf);
  107. lv_btn_set_checkable(list_btn, false);
  108. int cur_ap_sta_len = access_points->get(x).stations->size();
  109. for (int y = 0; y < cur_ap_sta_len; y++) {
  110. Station cur_sta = stations->get(cur_ap.stations->get(y));
  111. // Convert uint8_t MAC to char array
  112. wifi_scan_obj.getMAC(addr, cur_sta.mac, 0);
  113. list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, addr);
  114. lv_btn_set_checkable(list_btn, true);
  115. lv_obj_set_event_cb(list_btn, station_list_cb);
  116. if (cur_sta.selected)
  117. lv_btn_toggle(list_btn);
  118. }
  119. }
  120. }
  121. // Function to work with list of Stations
  122. void station_list_cb(lv_obj_t * btn, lv_event_t event) {
  123. extern LinkedList<Station>* stations;
  124. extern MenuFunctions menu_function_obj;
  125. extern WiFiScan wifi_scan_obj;
  126. String btn_text = lv_list_get_btn_text(btn);
  127. String display_string = "";
  128. char addr[] = "00:00:00:00:00:00";
  129. if (event == LV_EVENT_CLICKED) {
  130. if (btn_text != text09) {
  131. }
  132. else {
  133. Serial.println("Exiting...");
  134. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  135. for (int i = 0; i < stations->size(); i++) {
  136. if (stations->get(i).selected) {
  137. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  138. Serial.print("Selected: ");
  139. Serial.println(addr);
  140. }
  141. }
  142. printf("LV_EVENT_CANCEL\n");
  143. menu_function_obj.deinitLVGL();
  144. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  145. display_obj.exit_draw = true; // set everything back to normal
  146. }
  147. }
  148. if (event == LV_EVENT_VALUE_CHANGED) {
  149. if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
  150. for (int i = 0; i < stations->size(); i++) {
  151. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  152. if (strcmp(addr, btn_text.c_str()) == 0) {
  153. Serial.print("Adding Station: ");
  154. Serial.println(addr);
  155. Station sta = stations->get(i);
  156. sta.selected = true;
  157. stations->set(i, sta);
  158. }
  159. }
  160. }
  161. else {
  162. for (int i = 0; i < stations->size(); i++) {
  163. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  164. if (strcmp(addr, btn_text.c_str()) == 0) {
  165. Serial.print("Removing Station: ");
  166. Serial.println(addr);
  167. Station sta = stations->get(i);
  168. sta.selected = false;
  169. stations->set(i, sta);
  170. }
  171. }
  172. }
  173. }
  174. }
  175. // GFX Function to build a list showing all APs scanned
  176. void MenuFunctions::addAPGFX(){
  177. extern LinkedList<AccessPoint>* access_points;
  178. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  179. lv_obj_set_size(list1, 160, 200);
  180. lv_obj_set_width(list1, LV_HOR_RES);
  181. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  182. lv_obj_t * list_btn;
  183. lv_obj_t * label;
  184. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
  185. lv_obj_set_event_cb(list_btn, ap_list_cb);
  186. for (int i = 0; i < access_points->size(); i++) {
  187. char buf[access_points->get(i).essid.length() + 1] = {};
  188. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  189. list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, buf);
  190. lv_btn_set_checkable(list_btn, true);
  191. lv_obj_set_event_cb(list_btn, ap_list_cb);
  192. if (access_points->get(i).selected)
  193. lv_btn_toggle(list_btn);
  194. }
  195. }
  196. void ap_list_cb(lv_obj_t * btn, lv_event_t event) {
  197. extern LinkedList<AccessPoint>* access_points;
  198. extern MenuFunctions menu_function_obj;
  199. String btn_text = lv_list_get_btn_text(btn);
  200. String display_string = "";
  201. if (event == LV_EVENT_CLICKED) {
  202. if (btn_text != text09) {
  203. }
  204. else {
  205. Serial.println("Exiting...");
  206. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  207. for (int i = 0; i < access_points->size(); i++) {
  208. if (access_points->get(i).selected) {
  209. Serial.println("Selected: " + (String)access_points->get(i).essid);
  210. }
  211. }
  212. printf("LV_EVENT_CANCEL\n");
  213. menu_function_obj.deinitLVGL();
  214. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  215. display_obj.exit_draw = true; // set everything back to normal
  216. }
  217. }
  218. if (event == LV_EVENT_VALUE_CHANGED) {
  219. if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
  220. for (int i = 0; i < access_points->size(); i++) {
  221. if (access_points->get(i).essid == btn_text) {
  222. Serial.println("Adding AP: " + (String)access_points->get(i).essid);
  223. AccessPoint ap = access_points->get(i);
  224. ap.selected = true;
  225. access_points->set(i, ap);
  226. }
  227. }
  228. }
  229. else {
  230. for (int i = 0; i < access_points->size(); i++) {
  231. if (access_points->get(i).essid == btn_text) {
  232. Serial.println("Removing AP: " + (String)access_points->get(i).essid);
  233. AccessPoint ap = access_points->get(i);
  234. ap.selected = false;
  235. access_points->set(i, ap);
  236. }
  237. }
  238. }
  239. }
  240. }
  241. void MenuFunctions::addSSIDGFX(){
  242. extern LinkedList<ssid>* ssids;
  243. String display_string = "";
  244. // Create a keyboard and apply the styles
  245. kb = lv_keyboard_create(lv_scr_act(), NULL);
  246. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  247. lv_obj_set_event_cb(kb, add_ssid_keyboard_event_cb);
  248. // Create one text area
  249. // Store all SSIDs
  250. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  251. lv_textarea_set_one_line(ta1, false);
  252. lv_obj_set_width(ta1, LV_HOR_RES);
  253. lv_obj_set_height(ta1, (LV_VER_RES / 2) - 35);
  254. lv_obj_set_pos(ta1, 5, 20);
  255. lv_textarea_set_cursor_hidden(ta1, true);
  256. lv_obj_align(ta1, NULL, LV_ALIGN_IN_TOP_MID, NULL, NULL);
  257. lv_textarea_set_placeholder_text(ta1, text_table1[0]);
  258. // Create second text area
  259. // Add SSIDs
  260. ta2 = lv_textarea_create(lv_scr_act(), ta1);
  261. lv_textarea_set_cursor_hidden(ta2, false);
  262. lv_textarea_set_one_line(ta2, true);
  263. lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35);
  264. lv_textarea_set_text(ta2, "");
  265. lv_textarea_set_placeholder_text(ta2, text_table1[1]);
  266. // After generating text areas, add text to first text box
  267. for (int i = 0; i < ssids->size(); i++)
  268. display_string.concat((String)ssids->get(i).essid + "\n");
  269. lv_textarea_set_text(ta1, display_string.c_str());
  270. // Focus it on one of the text areas to start
  271. lv_keyboard_set_textarea(kb, ta2);
  272. lv_keyboard_set_cursor_manage(kb, true);
  273. }
  274. // Keyboard callback dedicated to joining wifi
  275. void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
  276. extern Display display_obj;
  277. extern MenuFunctions menu_function_obj;
  278. extern WiFiScan wifi_scan_obj;
  279. extern LinkedList<ssid>* ssids;
  280. lv_keyboard_def_event_cb(kb, event);
  281. // User has applied text box
  282. if(event == LV_EVENT_APPLY){
  283. String display_string = "";
  284. printf("LV_EVENT_APPLY\n");
  285. // Get text from SSID text box
  286. String ta2_text = lv_textarea_get_text(ta2);
  287. Serial.println(ta2_text);
  288. // Add text box text to list of SSIDs
  289. wifi_scan_obj.addSSID(ta2_text);
  290. // Update large text box with ssid
  291. for (int i = 0; i < ssids->size(); i++)
  292. display_string.concat((String)ssids->get(i).essid + "\n");
  293. lv_textarea_set_text(ta1, display_string.c_str());
  294. lv_textarea_set_text(ta2, "");
  295. }else if(event == LV_EVENT_CANCEL){
  296. printf("LV_EVENT_CANCEL\n");
  297. menu_function_obj.deinitLVGL();
  298. display_obj.exit_draw = true; // set everything back to normal
  299. }
  300. }
  301. void ta_event_cb(lv_obj_t * ta, lv_event_t event)
  302. {
  303. if(event == LV_EVENT_CLICKED) {
  304. if(kb != NULL)
  305. lv_keyboard_set_textarea(kb, ta);
  306. }
  307. }
  308. #endif
  309. //// END LV_ARDUINO STUFF
  310. void MenuFunctions::buttonNotSelected(uint8_t b) {
  311. display_obj.tft.setFreeFont(NULL);
  312. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  313. }
  314. void MenuFunctions::buttonSelected(uint8_t b) {
  315. display_obj.tft.setFreeFont(NULL);
  316. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  317. }
  318. // Function to check menu input
  319. void MenuFunctions::main(uint32_t currentTime)
  320. {
  321. // Some function exited and we need to go back to normal
  322. if (display_obj.exit_draw) {
  323. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  324. display_obj.exit_draw = false;
  325. this->orientDisplay();
  326. }
  327. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  328. (wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
  329. (wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
  330. (wifi_scan_obj.currentScanMode == SHOW_INFO) ||
  331. (wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_DATA)) {
  332. if (wifi_scan_obj.orient_display) {
  333. this->orientDisplay();
  334. wifi_scan_obj.orient_display = false;
  335. }
  336. /*#ifdef HAS_ILI9341
  337. if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
  338. (wifi_scan_obj.currentScanMode != LV_ADD_SSID))
  339. display_obj.updateBanner(current_menu->name);
  340. #endif*/
  341. }
  342. if (currentTime != 0) {
  343. if (currentTime - initTime >= BANNER_TIME) {
  344. this->initTime = millis();
  345. if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
  346. (wifi_scan_obj.currentScanMode != LV_ADD_SSID))
  347. this->updateStatusBar();
  348. //#if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  349. // display_obj.updateBanner(current_menu->name);
  350. //#endif
  351. }
  352. }
  353. boolean pressed = false;
  354. // This is code from bodmer's keypad example
  355. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  356. // Get the display buffer out of the way
  357. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  358. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  359. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
  360. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
  361. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
  362. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
  363. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_TARGETED) &&
  364. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
  365. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  366. display_obj.displayBuffer();
  367. // Pressed will be set true is there is a valid touch on the screen
  368. int pre_getTouch = millis();
  369. // getTouch causes a 10ms delay which makes beacon spam less effective
  370. #ifdef HAS_ILI9341
  371. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  372. #endif
  373. // This is if there are scans/attacks going on
  374. #ifdef HAS_ILI9341
  375. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  376. (pressed) &&
  377. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  378. (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
  379. (wifi_scan_obj.currentScanMode != SHOW_INFO) &&
  380. (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA))
  381. {
  382. // Stop the current scan
  383. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  384. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  385. (wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION) ||
  386. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  387. (wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) ||
  388. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EVIL_PORTAL) ||
  389. (wifi_scan_obj.currentScanMode == WIFI_SCAN_SIG_STREN) ||
  390. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  391. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  392. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  393. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  394. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  395. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  396. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  397. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  398. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  399. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  400. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  401. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_TARGETED) ||
  402. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  403. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  404. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  405. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  406. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  407. {
  408. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  409. // If we don't do this, the text and button coordinates will be off
  410. display_obj.tft.init();
  411. // Take us back to the menu
  412. changeMenu(current_menu);
  413. }
  414. x = -1;
  415. y = -1;
  416. return;
  417. }
  418. #endif
  419. #ifdef HAS_BUTTONS
  420. bool c_btn_press = c_btn.justPressed();
  421. if ((c_btn_press) &&
  422. (wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  423. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  424. (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
  425. (wifi_scan_obj.currentScanMode != SHOW_INFO) &&
  426. (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA))
  427. {
  428. // Stop the current scan
  429. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  430. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  431. (wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION) ||
  432. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  433. (wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) ||
  434. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EVIL_PORTAL) ||
  435. (wifi_scan_obj.currentScanMode == WIFI_SCAN_SIG_STREN) ||
  436. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  437. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  438. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  439. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  440. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  441. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  442. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  443. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  444. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  445. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  446. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  447. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_TARGETED) ||
  448. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  449. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  450. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  451. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  452. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS) ||
  453. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL) ||
  454. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
  455. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) ||
  456. (wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR))
  457. {
  458. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  459. // If we don't do this, the text and button coordinates will be off
  460. display_obj.tft.init();
  461. // Take us back to the menu
  462. changeMenu(current_menu);
  463. }
  464. x = -1;
  465. y = -1;
  466. return;
  467. }
  468. #endif
  469. // Check if any key coordinate boxes contain the touch coordinates
  470. // This is for when on a menu
  471. #ifdef HAS_ILI9341
  472. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  473. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
  474. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
  475. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
  476. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
  477. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_TARGETED) &&
  478. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
  479. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  480. {
  481. // Need this to set all keys to false
  482. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  483. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  484. display_obj.key[b].press(true); // tell the button it is pressed
  485. } else {
  486. display_obj.key[b].press(false); // tell the button it is NOT pressed
  487. }
  488. }
  489. // Check if any key has changed state
  490. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  491. display_obj.tft.setFreeFont(MENU_FONT);
  492. if (display_obj.key[b].justPressed()) {
  493. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  494. if (current_menu->list->get(b).name != text09)
  495. display_obj.tft.drawXBitmap(0,
  496. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  497. menu_icons[current_menu->list->get(b).icon],
  498. ICON_W,
  499. ICON_H,
  500. current_menu->list->get(b).color,
  501. TFT_BLACK);
  502. }
  503. // If button was just release, execute the button's function
  504. if ((display_obj.key[b].justReleased()) && (!pressed))
  505. {
  506. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  507. current_menu->list->get(b).callable();
  508. }
  509. // This
  510. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  511. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  512. if (current_menu->list->get(b).name != text09)
  513. display_obj.tft.drawXBitmap(0,
  514. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  515. menu_icons[current_menu->list->get(b).icon],
  516. ICON_W,
  517. ICON_H,
  518. TFT_BLACK,
  519. current_menu->list->get(b).color);
  520. }
  521. display_obj.tft.setFreeFont(NULL);
  522. }
  523. }
  524. x = -1;
  525. y = -1;
  526. #endif
  527. #ifdef HAS_BUTTONS
  528. #ifndef MARAUDER_M5STICKC
  529. if (u_btn.justPressed()){
  530. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  531. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  532. if (current_menu->selected > 0) {
  533. current_menu->selected--;
  534. this->buttonSelected(current_menu->selected);
  535. if (!current_menu->list->get(current_menu->selected + 1).selected)
  536. this->buttonNotSelected(current_menu->selected + 1);
  537. }
  538. }
  539. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  540. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  541. if (wifi_scan_obj.set_channel < 14)
  542. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel + 1);
  543. }
  544. }
  545. #endif
  546. if (d_btn.justPressed()){
  547. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  548. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  549. if (current_menu->selected < current_menu->list->size() - 1) {
  550. current_menu->selected++;
  551. this->buttonSelected(current_menu->selected);
  552. if (!current_menu->list->get(current_menu->selected - 1).selected)
  553. this->buttonNotSelected(current_menu->selected - 1);
  554. }
  555. else {
  556. current_menu->selected = 0;
  557. this->buttonSelected(current_menu->selected);
  558. if (!current_menu->list->get(current_menu->list->size() - 1).selected)
  559. this->buttonNotSelected(current_menu->list->size() - 1);
  560. }
  561. }
  562. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  563. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  564. if (wifi_scan_obj.set_channel > 1)
  565. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel - 1);
  566. }
  567. }
  568. if(c_btn_press){
  569. current_menu->list->get(current_menu->selected).callable();
  570. }
  571. #endif
  572. }
  573. #if BATTERY_ANALOG_ON == 1
  574. byte battery_analog_array[10];
  575. byte battery_count = 0;
  576. byte battery_analog_last = 101;
  577. #define BATTERY_CHECK 50
  578. uint16_t battery_analog = 0;
  579. void MenuFunctions::battery(bool initial)
  580. {
  581. if (BATTERY_ANALOG_ON) {
  582. uint8_t n = 0;
  583. byte battery_analog_sample[10];
  584. byte deviation;
  585. if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
  586. else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
  587. if (battery_count == 0) {
  588. battery_analog = 0;
  589. for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
  590. for (n = 0; n < 10; n++) {
  591. battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
  592. if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
  593. else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
  594. battery_analog += battery_analog_sample[n];
  595. }
  596. battery_analog = battery_analog / 10;
  597. for (n = 0; n < 10; n++) {
  598. deviation = abs(battery_analog - battery_analog_sample[n]);
  599. if (deviation >= 10) battery_analog_sample[n] = battery_analog;
  600. }
  601. battery_analog = 0;
  602. for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
  603. battery_analog = battery_analog / 10;
  604. battery_analog_array[0] = battery_analog;
  605. if (battery_analog_array[9] > 0 ) {
  606. battery_analog = 0;
  607. for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
  608. battery_analog = battery_analog / 10;
  609. }
  610. battery_count ++;
  611. }
  612. else if (battery_count < BATTERY_CHECK) battery_count++;
  613. else if (battery_count >= BATTERY_CHECK) battery_count = 0;
  614. if (battery_analog_last != battery_analog) {
  615. battery_analog_last = battery_analog;
  616. MenuFunctions::battery2();
  617. }
  618. }
  619. }
  620. void MenuFunctions::battery2(bool initial)
  621. {
  622. uint16_t the_color;
  623. if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
  624. else if (battery_analog < 20) the_color = TFT_RED;
  625. else if (battery_analog < 40) the_color = TFT_YELLOW;
  626. else the_color = TFT_GREEN;
  627. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  628. display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  629. display_obj.tft.drawXBitmap(186,
  630. 0,
  631. menu_icons[STATUS_BAT],
  632. 16,
  633. 16,
  634. STATUSBAR_COLOR,
  635. the_color);
  636. display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
  637. }
  638. #else
  639. void MenuFunctions::battery(bool initial)
  640. {
  641. uint16_t the_color;
  642. if (battery_obj.i2c_supported)
  643. {
  644. // Could use int compare maybe idk
  645. if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
  646. the_color = TFT_GREEN;
  647. else
  648. the_color = TFT_RED;
  649. if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
  650. battery_obj.old_level = battery_obj.battery_level;
  651. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  652. display_obj.tft.setCursor(0, 1);
  653. display_obj.tft.drawXBitmap(186,
  654. 0,
  655. menu_icons[STATUS_BAT],
  656. 16,
  657. 16,
  658. STATUSBAR_COLOR,
  659. the_color);
  660. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  661. }
  662. }
  663. }
  664. void MenuFunctions::battery2(bool initial)
  665. {
  666. MenuFunctions::battery(initial);
  667. }
  668. #endif
  669. void MenuFunctions::updateStatusBar()
  670. {
  671. display_obj.tft.setTextSize(1);
  672. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  673. display_obj.tft.setFreeFont(NULL);
  674. #endif
  675. uint16_t the_color;
  676. // GPS Stuff
  677. #ifdef HAS_GPS
  678. if (gps_obj.getGpsModuleStatus()) {
  679. if (gps_obj.getFixStatus())
  680. the_color = TFT_GREEN;
  681. else
  682. the_color = TFT_RED;
  683. #ifdef HAS_ILI9341
  684. display_obj.tft.drawXBitmap(4,
  685. 0,
  686. menu_icons[STATUS_GPS],
  687. 16,
  688. 16,
  689. STATUSBAR_COLOR,
  690. the_color);
  691. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  692. display_obj.tft.drawString(gps_obj.getNumSatsString(), 22, 0, 2);
  693. #endif
  694. }
  695. #endif
  696. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  697. // WiFi Channel Stuff
  698. if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) {
  699. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  700. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  701. #ifdef HAS_ILI9341
  702. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  703. #endif
  704. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  705. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  706. #endif
  707. }
  708. // RAM Stuff
  709. wifi_scan_obj.freeRAM();
  710. if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) {
  711. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  712. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  713. #ifdef HAS_ILI9341
  714. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  715. #endif
  716. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  717. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  718. #endif
  719. }
  720. // Draw battery info
  721. MenuFunctions::battery(false);
  722. // Draw SD info
  723. #ifndef WRITE_PACKETS_SERIAL
  724. if (sd_obj.supported)
  725. the_color = TFT_GREEN;
  726. else
  727. the_color = TFT_RED;
  728. #else
  729. the_color = TFT_RED;
  730. #endif
  731. #ifdef HAS_ILI9341
  732. display_obj.tft.drawXBitmap(170,
  733. 0,
  734. menu_icons[STATUS_SD],
  735. 16,
  736. 16,
  737. STATUSBAR_COLOR,
  738. the_color);
  739. #endif
  740. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  741. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  742. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  743. #endif
  744. }
  745. void MenuFunctions::drawStatusBar()
  746. {
  747. display_obj.tft.setTextSize(1);
  748. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  749. display_obj.tft.setFreeFont(NULL);
  750. #endif
  751. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  752. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  753. uint16_t the_color;
  754. // GPS Stuff
  755. #ifdef HAS_GPS
  756. if (gps_obj.getGpsModuleStatus()) {
  757. if (gps_obj.getFixStatus())
  758. the_color = TFT_GREEN;
  759. else
  760. the_color = TFT_RED;
  761. #ifdef HAS_ILI9341
  762. display_obj.tft.drawXBitmap(4,
  763. 0,
  764. menu_icons[STATUS_GPS],
  765. 16,
  766. 16,
  767. STATUSBAR_COLOR,
  768. the_color);
  769. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  770. display_obj.tft.drawString(gps_obj.getNumSatsString(), 22, 0, 2);
  771. #endif
  772. }
  773. #endif
  774. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  775. // WiFi Channel Stuff
  776. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  777. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  778. #ifdef HAS_ILI9341
  779. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  780. #endif
  781. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  782. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  783. #endif
  784. // RAM Stuff
  785. wifi_scan_obj.freeRAM();
  786. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  787. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  788. #ifdef HAS_ILI9341
  789. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  790. #endif
  791. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  792. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  793. #endif
  794. MenuFunctions::battery2(true);
  795. // Draw SD info
  796. #ifndef WRITE_PACKETS_SERIAL
  797. if (sd_obj.supported)
  798. the_color = TFT_GREEN;
  799. else
  800. the_color = TFT_RED;
  801. #else
  802. the_color = TFT_RED;
  803. #endif
  804. #ifdef HAS_ILI9341
  805. display_obj.tft.drawXBitmap(170,
  806. 0,
  807. menu_icons[STATUS_SD],
  808. 16,
  809. 16,
  810. STATUSBAR_COLOR,
  811. the_color);
  812. #endif
  813. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  814. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  815. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  816. #endif
  817. }
  818. void MenuFunctions::orientDisplay()
  819. {
  820. display_obj.tft.init();
  821. display_obj.tft.setRotation(0); // Portrait
  822. display_obj.tft.setCursor(0, 0);
  823. #ifdef HAS_ILI9341
  824. #ifdef TFT_SHIELD
  825. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  826. #else if defined(TFT_DIY)
  827. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  828. #endif
  829. display_obj.tft.setTouch(calData);
  830. #endif
  831. changeMenu(current_menu);
  832. }
  833. void MenuFunctions::runBoolSetting(String key) {
  834. display_obj.tftDrawRedOnOffButton();
  835. }
  836. String MenuFunctions::callSetting(String key) {
  837. specSettingMenu.name = key;
  838. String setting_type = settings_obj.getSettingType(key);
  839. if (setting_type == "bool") {
  840. return "bool";
  841. }
  842. }
  843. void MenuFunctions::displaySetting(String key, Menu* menu, int index) {
  844. specSettingMenu.name = key;
  845. bool setting_value = settings_obj.loadSetting<bool>(key);
  846. // Make a local copy of menu node
  847. MenuNode node = menu->list->get(index);
  848. display_obj.tft.setTextWrap(false);
  849. display_obj.tft.setFreeFont(NULL);
  850. display_obj.tft.setCursor(0, 100);
  851. display_obj.tft.setTextSize(1);
  852. // Set local copy value
  853. if (!setting_value) {
  854. display_obj.tft.setTextColor(TFT_RED);
  855. display_obj.tft.println(F(text_table1[4]));
  856. node.selected = false;
  857. }
  858. else {
  859. display_obj.tft.setTextColor(TFT_GREEN);
  860. display_obj.tft.println(F(text_table1[5]));
  861. node.selected = true;
  862. }
  863. // Put local copy back into menu
  864. menu->list->set(index, node);
  865. }
  866. // Function to build the menus
  867. void MenuFunctions::RunSetup()
  868. {
  869. extern LinkedList<AccessPoint>* access_points;
  870. #ifdef HAS_ILI9341
  871. this->initLVGL();
  872. #endif
  873. // root menu stuff
  874. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  875. // Main menu stuff
  876. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  877. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  878. deviceMenu.list = new LinkedList<MenuNode>();
  879. #ifdef HAS_GPS
  880. if (gps_obj.getGpsModuleStatus()) {
  881. gpsInfoMenu.list = new LinkedList<MenuNode>();
  882. }
  883. #endif
  884. // Device menu stuff
  885. failedUpdateMenu.list = new LinkedList<MenuNode>();
  886. whichUpdateMenu.list = new LinkedList<MenuNode>();
  887. confirmMenu.list = new LinkedList<MenuNode>();
  888. updateMenu.list = new LinkedList<MenuNode>();
  889. settingsMenu.list = new LinkedList<MenuNode>();
  890. specSettingMenu.list = new LinkedList<MenuNode>();
  891. infoMenu.list = new LinkedList<MenuNode>();
  892. languageMenu.list = new LinkedList<MenuNode>();
  893. // WiFi menu stuff
  894. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  895. wifiAttackMenu.list = new LinkedList<MenuNode>();
  896. wifiGeneralMenu.list = new LinkedList<MenuNode>();
  897. wifiAPMenu.list = new LinkedList<MenuNode>();
  898. // Bluetooth menu stuff
  899. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  900. // Settings stuff
  901. generateSSIDsMenu.list = new LinkedList<MenuNode>();
  902. clearSSIDsMenu.list = new LinkedList<MenuNode>();
  903. clearAPsMenu.list = new LinkedList<MenuNode>();
  904. // Work menu names
  905. mainMenu.name = text_table1[6];
  906. wifiMenu.name = text_table1[7];
  907. deviceMenu.name = text_table1[9];
  908. failedUpdateMenu.name = text_table1[11];
  909. whichUpdateMenu.name = text_table1[12];
  910. confirmMenu.name = text_table1[13];
  911. updateMenu.name = text_table1[15];
  912. languageMenu.name = text_table1[16];
  913. infoMenu.name = text_table1[17];
  914. settingsMenu.name = text_table1[18];
  915. bluetoothMenu.name = text_table1[19];
  916. wifiSnifferMenu.name = text_table1[20];
  917. wifiAttackMenu.name = text_table1[21];
  918. wifiGeneralMenu.name = text_table1[22];
  919. bluetoothSnifferMenu.name = text_table1[23];
  920. generateSSIDsMenu.name = text_table1[27];
  921. clearSSIDsMenu.name = text_table1[28];
  922. clearAPsMenu.name = text_table1[29];
  923. wifiAPMenu.name = "Access Points";
  924. #ifdef HAS_GPS
  925. gpsInfoMenu.name = "GPS Data";
  926. #endif
  927. // Build Main Menu
  928. mainMenu.parentMenu = NULL;
  929. this->addNodes(&mainMenu, text_table1[7], TFT_GREEN, NULL, WIFI, [this]() {
  930. this->changeMenu(&wifiMenu);
  931. });
  932. this->addNodes(&mainMenu, text_table1[19], TFT_CYAN, NULL, BLUETOOTH, [this]() {
  933. this->changeMenu(&bluetoothMenu);
  934. });
  935. this->addNodes(&mainMenu, text_table1[9], TFT_BLUE, NULL, DEVICE, [this]() {
  936. this->changeMenu(&deviceMenu);
  937. });
  938. this->addNodes(&mainMenu, text_table1[30], TFT_LIGHTGREY, NULL, REBOOT, []() {
  939. ESP.restart();
  940. });
  941. // Build WiFi Menu
  942. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  943. this->addNodes(&wifiMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  944. this->changeMenu(wifiMenu.parentMenu);
  945. });
  946. this->addNodes(&wifiMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  947. this->changeMenu(&wifiSnifferMenu);
  948. });
  949. this->addNodes(&wifiMenu, text_table1[32], TFT_RED, NULL, ATTACKS, [this]() {
  950. this->changeMenu(&wifiAttackMenu);
  951. });
  952. this->addNodes(&wifiMenu, text_table1[33], TFT_PURPLE, NULL, GENERAL_APPS, [this]() {
  953. this->changeMenu(&wifiGeneralMenu);
  954. });
  955. // Build WiFi sniffer Menu
  956. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  957. this->addNodes(&wifiSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  958. this->changeMenu(wifiSnifferMenu.parentMenu);
  959. });
  960. this->addNodes(&wifiSnifferMenu, text_table1[42], TFT_CYAN, NULL, PROBE_SNIFF, [this]() {
  961. display_obj.clearScreen();
  962. this->drawStatusBar();
  963. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);
  964. });
  965. this->addNodes(&wifiSnifferMenu, text_table1[43], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  966. display_obj.clearScreen();
  967. this->drawStatusBar();
  968. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  969. });
  970. this->addNodes(&wifiSnifferMenu, text_table1[44], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  971. display_obj.clearScreen();
  972. this->drawStatusBar();
  973. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  974. });
  975. #ifdef HAS_ILI9341
  976. this->addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  977. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  978. });
  979. this->addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  980. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  981. });
  982. #else
  983. this->addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  984. display_obj.clearScreen();
  985. this->drawStatusBar();
  986. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  987. });
  988. this->addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  989. display_obj.clearScreen();
  990. this->drawStatusBar();
  991. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  992. });
  993. #endif
  994. this->addNodes(&wifiSnifferMenu, text_table1[47], TFT_RED, NULL, PWNAGOTCHI, [this]() {
  995. display_obj.clearScreen();
  996. this->drawStatusBar();
  997. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_RED);
  998. });
  999. this->addNodes(&wifiSnifferMenu, text_table1[49], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  1000. display_obj.clearScreen();
  1001. this->drawStatusBar();
  1002. wifi_scan_obj.StartScan(WIFI_SCAN_TARGET_AP, TFT_MAGENTA);
  1003. });
  1004. this->addNodes(&wifiSnifferMenu, text_table1[58], TFT_WHITE, NULL, PACKET_MONITOR, [this]() {
  1005. display_obj.clearScreen();
  1006. this->drawStatusBar();
  1007. wifi_scan_obj.StartScan(WIFI_SCAN_RAW_CAPTURE, TFT_WHITE);
  1008. });
  1009. this->addNodes(&wifiSnifferMenu, text_table1[59], TFT_ORANGE, NULL, PACKET_MONITOR, [this]() {
  1010. display_obj.clearScreen();
  1011. this->drawStatusBar();
  1012. wifi_scan_obj.StartScan(WIFI_SCAN_STATION, TFT_WHITE);
  1013. });
  1014. #ifdef HAS_ILI9341
  1015. this->addNodes(&wifiSnifferMenu, "Signal Monitor", TFT_CYAN, NULL, PACKET_MONITOR, [this]() {
  1016. display_obj.clearScreen();
  1017. this->drawStatusBar();
  1018. wifi_scan_obj.StartScan(WIFI_SCAN_SIG_STREN, TFT_CYAN);
  1019. });
  1020. #endif
  1021. #ifdef HAS_GPS
  1022. if (gps_obj.getGpsModuleStatus()) {
  1023. this->addNodes(&wifiSnifferMenu, "Wardrive", TFT_GREEN, NULL, BEACON_SNIFF, [this]() {
  1024. display_obj.clearScreen();
  1025. this->drawStatusBar();
  1026. wifi_scan_obj.StartScan(WIFI_SCAN_WAR_DRIVE, TFT_GREEN);
  1027. });
  1028. }
  1029. #endif
  1030. // Build WiFi attack menu
  1031. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  1032. this->addNodes(&wifiAttackMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1033. this->changeMenu(wifiAttackMenu.parentMenu);
  1034. });
  1035. this->addNodes(&wifiAttackMenu, text_table1[50], TFT_RED, NULL, BEACON_LIST, [this]() {
  1036. display_obj.clearScreen();
  1037. this->drawStatusBar();
  1038. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_LIST, TFT_RED);
  1039. });
  1040. this->addNodes(&wifiAttackMenu, text_table1[51], TFT_ORANGE, NULL, BEACON_SPAM, [this]() {
  1041. display_obj.clearScreen();
  1042. this->drawStatusBar();
  1043. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  1044. });
  1045. this->addNodes(&wifiAttackMenu, text_table1[52], TFT_YELLOW, NULL, RICK_ROLL, [this]() {
  1046. display_obj.clearScreen();
  1047. this->drawStatusBar();
  1048. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  1049. });
  1050. this->addNodes(&wifiAttackMenu, text_table1[53], TFT_RED, NULL, PROBE_SNIFF, [this]() {
  1051. display_obj.clearScreen();
  1052. this->drawStatusBar();
  1053. wifi_scan_obj.StartScan(WIFI_ATTACK_AUTH, TFT_RED);
  1054. });
  1055. this->addNodes(&wifiAttackMenu, "Evil Portal", TFT_ORANGE, NULL, BEACON_SNIFF, [this]() {
  1056. display_obj.clearScreen();
  1057. this->drawStatusBar();
  1058. wifi_scan_obj.StartScan(WIFI_SCAN_EVIL_PORTAL, TFT_ORANGE);
  1059. });
  1060. this->addNodes(&wifiAttackMenu, text_table1[54], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1061. display_obj.clearScreen();
  1062. this->drawStatusBar();
  1063. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH, TFT_RED);
  1064. });
  1065. this->addNodes(&wifiAttackMenu, text_table1[57], TFT_MAGENTA, NULL, BEACON_LIST, [this]() {
  1066. display_obj.clearScreen();
  1067. this->drawStatusBar();
  1068. wifi_scan_obj.StartScan(WIFI_ATTACK_AP_SPAM, TFT_MAGENTA);
  1069. });
  1070. this->addNodes(&wifiAttackMenu, text_table1[62], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1071. display_obj.clearScreen();
  1072. this->drawStatusBar();
  1073. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH_TARGETED, TFT_ORANGE);
  1074. });
  1075. // Build WiFi General menu
  1076. wifiGeneralMenu.parentMenu = &wifiMenu;
  1077. this->addNodes(&wifiGeneralMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1078. this->changeMenu(wifiGeneralMenu.parentMenu);
  1079. });
  1080. this->addNodes(&wifiGeneralMenu, text_table1[27], TFT_SKYBLUE, NULL, GENERATE, [this]() {
  1081. this->changeMenu(&generateSSIDsMenu);
  1082. wifi_scan_obj.RunGenerateSSIDs();
  1083. });
  1084. #ifdef HAS_ILI9341
  1085. this->addNodes(&wifiGeneralMenu, text_table1[1], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1086. display_obj.clearScreen();
  1087. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_YELLOW);
  1088. addSSIDGFX();
  1089. });
  1090. #endif
  1091. this->addNodes(&wifiGeneralMenu, text_table1[28], TFT_SILVER, NULL, CLEAR_ICO, [this]() {
  1092. this->changeMenu(&clearSSIDsMenu);
  1093. wifi_scan_obj.RunClearSSIDs();
  1094. });
  1095. this->addNodes(&wifiGeneralMenu, text_table1[29], TFT_DARKGREY, NULL, CLEAR_ICO, [this]() {
  1096. this->changeMenu(&clearAPsMenu);
  1097. wifi_scan_obj.RunClearAPs();
  1098. });
  1099. this->addNodes(&wifiGeneralMenu, text_table1[60], TFT_BLUE, NULL, CLEAR_ICO, [this]() {
  1100. this->changeMenu(&clearAPsMenu);
  1101. wifi_scan_obj.RunClearStations();
  1102. });
  1103. #ifdef HAS_ILI9341
  1104. // Select APs on OG
  1105. this->addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1106. display_obj.clearScreen();
  1107. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1108. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1109. addAPGFX();
  1110. });
  1111. this->addNodes(&wifiGeneralMenu, text_table1[61], TFT_LIGHTGREY, NULL, KEYBOARD_ICO, [this](){
  1112. display_obj.clearScreen();
  1113. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1114. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1115. addStationGFX();
  1116. });
  1117. #else
  1118. // Select APs on Mini
  1119. this->addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1120. wifiAPMenu.list->clear();
  1121. this->addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1122. this->changeMenu(wifiAPMenu.parentMenu);
  1123. });
  1124. int menu_limit;
  1125. if (access_points->size() <= BUTTON_ARRAY_LEN)
  1126. menu_limit = access_points->size();
  1127. else
  1128. menu_limit = BUTTON_ARRAY_LEN;
  1129. for (int i = 0; i < menu_limit - 1; i++) {
  1130. this->addNodes(&wifiAPMenu, access_points->get(i).essid, TFT_CYAN, NULL, KEYBOARD_ICO, [this, i](){
  1131. AccessPoint new_ap = access_points->get(i);
  1132. new_ap.selected = !access_points->get(i).selected;
  1133. // Change selection status of menu node
  1134. MenuNode new_node = current_menu->list->get(i + 1);
  1135. new_node.selected = !current_menu->list->get(i + 1).selected;
  1136. current_menu->list->set(i + 1, new_node);
  1137. // Change selection status of button key
  1138. if (new_ap.selected) {
  1139. this->buttonSelected(i + 1);
  1140. } else {
  1141. this->buttonNotSelected(i + 1);
  1142. }
  1143. access_points->set(i, new_ap);
  1144. }, access_points->get(i).selected);
  1145. }
  1146. this->changeMenu(&wifiAPMenu);
  1147. });
  1148. wifiAPMenu.parentMenu = &wifiGeneralMenu;
  1149. this->addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1150. this->changeMenu(wifiAPMenu.parentMenu);
  1151. });
  1152. #endif
  1153. // Build generate ssids menu
  1154. generateSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1155. this->addNodes(&generateSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1156. this->changeMenu(generateSSIDsMenu.parentMenu);
  1157. });
  1158. // Build clear ssids menu
  1159. clearSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1160. this->addNodes(&clearSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1161. this->changeMenu(clearSSIDsMenu.parentMenu);
  1162. });
  1163. clearAPsMenu.parentMenu = &wifiGeneralMenu;
  1164. this->addNodes(&clearAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1165. this->changeMenu(clearAPsMenu.parentMenu);
  1166. });
  1167. // Build Bluetooth Menu
  1168. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  1169. this->addNodes(&bluetoothMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1170. this->changeMenu(bluetoothMenu.parentMenu);
  1171. });
  1172. this->addNodes(&bluetoothMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  1173. this->changeMenu(&bluetoothSnifferMenu);
  1174. });
  1175. // Build bluetooth sniffer Menu
  1176. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  1177. this->addNodes(&bluetoothSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1178. this->changeMenu(bluetoothSnifferMenu.parentMenu);
  1179. });
  1180. this->addNodes(&bluetoothSnifferMenu, text_table1[34], TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this]() {
  1181. display_obj.clearScreen();
  1182. this->drawStatusBar();
  1183. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  1184. });
  1185. this->addNodes(&bluetoothSnifferMenu, text_table1[35], TFT_MAGENTA, NULL, CC_SKIMMERS, [this]() {
  1186. display_obj.clearScreen();
  1187. this->drawStatusBar();
  1188. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  1189. });
  1190. // Device menu
  1191. deviceMenu.parentMenu = &mainMenu;
  1192. this->addNodes(&deviceMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1193. this->changeMenu(deviceMenu.parentMenu);
  1194. });
  1195. this->addNodes(&deviceMenu, text_table1[15], TFT_ORANGE, NULL, UPDATE, [this]() {
  1196. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1197. this->changeMenu(&whichUpdateMenu);
  1198. });
  1199. this->addNodes(&deviceMenu, text_table1[16], TFT_GREEN, NULL, LANGUAGE, [this]() {
  1200. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1201. this->changeMenu(&languageMenu);
  1202. });
  1203. this->addNodes(&deviceMenu, text_table1[17], TFT_WHITE, NULL, DEVICE_INFO, [this]() {
  1204. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1205. this->changeMenu(&infoMenu);
  1206. wifi_scan_obj.RunInfo();
  1207. });
  1208. this->addNodes(&deviceMenu, text08, TFT_NAVY, NULL, KEYBOARD_ICO, [this]() {
  1209. this->changeMenu(&settingsMenu);
  1210. });
  1211. // GPS Menu
  1212. #ifdef HAS_GPS
  1213. if (gps_obj.getGpsModuleStatus()) {
  1214. this->addNodes(&deviceMenu, "GPS Data", TFT_RED, NULL, GPS_MENU, [this]() {
  1215. wifi_scan_obj.currentScanMode = WIFI_SCAN_GPS_DATA;
  1216. this->changeMenu(&gpsInfoMenu);
  1217. wifi_scan_obj.StartScan(WIFI_SCAN_GPS_DATA, TFT_CYAN);
  1218. });
  1219. // GPS Info Menu
  1220. gpsInfoMenu.parentMenu = &deviceMenu;
  1221. this->addNodes(&gpsInfoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1222. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1223. this->changeMenu(gpsInfoMenu.parentMenu);
  1224. });
  1225. }
  1226. #endif
  1227. // Settings menu
  1228. // Device menu
  1229. settingsMenu.parentMenu = &deviceMenu;
  1230. this->addNodes(&settingsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1231. changeMenu(settingsMenu.parentMenu);
  1232. });
  1233. for (int i = 0; i < settings_obj.getNumberSettings(); i++) {
  1234. if (this->callSetting(settings_obj.setting_index_to_name(i)) == "bool")
  1235. this->addNodes(&settingsMenu, settings_obj.setting_index_to_name(i), TFT_LIGHTGREY, NULL, 0, [this, i]() {
  1236. settings_obj.toggleSetting(settings_obj.setting_index_to_name(i));
  1237. this->changeMenu(&specSettingMenu);
  1238. this->displaySetting(settings_obj.setting_index_to_name(i), &settingsMenu, i + 1);
  1239. }, settings_obj.loadSetting<bool>(settings_obj.setting_index_to_name(i)));
  1240. }
  1241. // Specific setting menu
  1242. specSettingMenu.parentMenu = &settingsMenu;
  1243. addNodes(&specSettingMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1244. this->changeMenu(specSettingMenu.parentMenu);
  1245. });
  1246. // Select update
  1247. whichUpdateMenu.parentMenu = &deviceMenu;
  1248. this->addNodes(&whichUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1249. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1250. this->changeMenu(whichUpdateMenu.parentMenu);
  1251. });
  1252. #ifndef WRITE_PACKETS_SERIAL
  1253. if (sd_obj.supported) addNodes(&whichUpdateMenu, text_table1[40], TFT_MAGENTA, NULL, SD_UPDATE, [this]() {
  1254. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1255. this->changeMenu(&confirmMenu);
  1256. });
  1257. #endif
  1258. // Confirm SD update menu
  1259. confirmMenu.parentMenu = &whichUpdateMenu;
  1260. this->addNodes(&confirmMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1261. this->changeMenu(confirmMenu.parentMenu);
  1262. });
  1263. this->addNodes(&confirmMenu, text14, TFT_ORANGE, NULL, UPDATE, [this]() {
  1264. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1265. this->changeMenu(&failedUpdateMenu);
  1266. sd_obj.runUpdate();
  1267. });
  1268. // Web Update
  1269. updateMenu.parentMenu = &deviceMenu;
  1270. // Failed update menu
  1271. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  1272. this->addNodes(&failedUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1273. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1274. this->changeMenu(failedUpdateMenu.parentMenu);
  1275. });
  1276. // Device info menu
  1277. infoMenu.parentMenu = &deviceMenu;
  1278. this->addNodes(&infoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1279. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1280. this->changeMenu(infoMenu.parentMenu);
  1281. });
  1282. //language info menu
  1283. languageMenu.parentMenu = &deviceMenu;
  1284. this->addNodes(&languageMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1285. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1286. this->changeMenu(infoMenu.parentMenu);
  1287. });
  1288. // Set the current menu to the mainMenu
  1289. this->changeMenu(&mainMenu);
  1290. this->initTime = millis();
  1291. }
  1292. // Function to change menu
  1293. void MenuFunctions::changeMenu(Menu * menu)
  1294. {
  1295. display_obj.initScrollValues();
  1296. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  1297. display_obj.tft.init();
  1298. current_menu = menu;
  1299. buildButtons(menu);
  1300. displayCurrentMenu();
  1301. }
  1302. // Function to show all MenuNodes in a Menu
  1303. void MenuFunctions::showMenuList(Menu * menu, int layer)
  1304. {
  1305. // Iterate through all of the menu nodes in the menu
  1306. for (uint8_t i = 0; i < menu->list->size(); i++)
  1307. {
  1308. // Depending on layer, indent
  1309. for (uint8_t x = 0; x < layer * 4; x++)
  1310. Serial.print(" ");
  1311. Serial.print("Node: ");
  1312. Serial.println(menu->list->get(i).name);
  1313. }
  1314. Serial.println();
  1315. }
  1316. // Function to add MenuNodes to a menu
  1317. void MenuFunctions::addNodes(Menu * menu, String name, uint16_t color, Menu * child, int place, std::function<void()> callable, bool selected, String command)
  1318. {
  1319. TFT_eSPI_Button new_button;
  1320. menu->list->add(MenuNode{name, false, color, place, &new_button, selected, callable});
  1321. }
  1322. void MenuFunctions::buildButtons(Menu * menu, int starting_index)
  1323. {
  1324. if (menu->list != NULL)
  1325. {
  1326. for (uint8_t i = 0; i < menu->list->size(); i++)
  1327. {
  1328. TFT_eSPI_Button new_button;
  1329. char buf[menu->list->get(starting_index + i).name.length() + 1] = {};
  1330. menu->list->get(starting_index + i).name.toCharArray(buf, menu->list->get(starting_index + i).name.length() + 1);
  1331. display_obj.key[i].initButton(&display_obj.tft,
  1332. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  1333. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  1334. KEY_W,
  1335. KEY_H,
  1336. TFT_BLACK, // Outline
  1337. TFT_BLACK, // Fill
  1338. menu->list->get(starting_index + i).color, // Text
  1339. buf,
  1340. KEY_TEXTSIZE);
  1341. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W / 2), 2, ML_DATUM);
  1342. }
  1343. }
  1344. }
  1345. void MenuFunctions::displayCurrentMenu()
  1346. {
  1347. //Serial.println(F("Displaying current menu..."));
  1348. display_obj.clearScreen();
  1349. display_obj.updateBanner(current_menu->name);
  1350. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  1351. this->drawStatusBar();
  1352. if (current_menu->list != NULL)
  1353. {
  1354. #ifdef HAS_ILI9341
  1355. display_obj.tft.setFreeFont(MENU_FONT);
  1356. #endif
  1357. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  1358. display_obj.tft.setFreeFont(NULL);
  1359. display_obj.tft.setTextSize(1);
  1360. #endif
  1361. for (uint8_t i = 0; i < current_menu->list->size(); i++)
  1362. {
  1363. #ifdef HAS_ILI9341
  1364. if (!current_menu->list->get(i).selected)
  1365. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1366. else
  1367. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1368. if (current_menu->list->get(i).name != text09)
  1369. display_obj.tft.drawXBitmap(0,
  1370. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  1371. menu_icons[current_menu->list->get(i).icon],
  1372. ICON_W,
  1373. ICON_H,
  1374. TFT_BLACK,
  1375. current_menu->list->get(i).color);
  1376. #endif
  1377. #if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC)
  1378. if ((current_menu->selected == i) || (current_menu->list->get(i).selected))
  1379. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1380. else
  1381. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1382. #endif
  1383. }
  1384. display_obj.tft.setFreeFont(NULL);
  1385. }
  1386. }
  1387. #endif