MenuFunctions.cpp 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  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. #ifndef MARAUDER_MINI
  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. //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
  58. data->point.x = touchX;
  59. data->point.y = touchY;
  60. //Serial.print("Data x");
  61. //Serial.println(touchX);
  62. //Serial.print("Data y");
  63. //Serial.println(touchY);
  64. }
  65. return false;
  66. }
  67. void MenuFunctions::initLVGL() {
  68. tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
  69. lv_init();
  70. lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  71. lv_disp_drv_t disp_drv;
  72. lv_disp_drv_init(&disp_drv);
  73. disp_drv.hor_res = WIDTH_1;
  74. disp_drv.ver_res = HEIGHT_1;
  75. disp_drv.flush_cb = my_disp_flush;
  76. disp_drv.buffer = &disp_buf;
  77. lv_disp_drv_register(&disp_drv);
  78. lv_indev_drv_t indev_drv;
  79. lv_indev_drv_init(&indev_drv);
  80. indev_drv.type = LV_INDEV_TYPE_POINTER;
  81. indev_drv.read_cb = my_touchpad_read;
  82. lv_indev_drv_register(&indev_drv);
  83. }
  84. void MenuFunctions::deinitLVGL() {
  85. Serial.println(F("Deinit LVGL"));
  86. //lv_deinit();
  87. }
  88. void MenuFunctions::writeBadUSB(){
  89. // Create a keyboard and apply the styles
  90. kb = lv_keyboard_create(lv_scr_act(), NULL);
  91. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  92. lv_obj_set_event_cb(kb, write_bad_usb_keyboard_event_cb);
  93. // Create one text area
  94. // Store all SSIDs
  95. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  96. lv_textarea_set_cursor_hidden(ta1, false);
  97. lv_textarea_set_one_line(ta1, false);
  98. lv_obj_set_width(ta1, LV_HOR_RES);
  99. lv_obj_set_height(ta1, (LV_VER_RES / 2) - 35);
  100. lv_obj_set_pos(ta1, 5, 20);
  101. lv_textarea_set_cursor_hidden(ta1, true);
  102. lv_obj_align(ta1, NULL, LV_ALIGN_IN_TOP_MID, NULL, NULL);
  103. lv_textarea_set_text(ta1, "");
  104. lv_textarea_set_placeholder_text(ta1, "Ducky script");
  105. if (sd_obj.supported) {
  106. // Create load button
  107. lv_obj_t * label;
  108. lv_obj_t * load_btn = lv_btn_create(lv_scr_act(), NULL);
  109. lv_obj_set_event_cb(load_btn, load_btn_cb);
  110. lv_obj_set_height(load_btn, 35);
  111. lv_obj_set_width(load_btn, LV_HOR_RES / 3);
  112. lv_obj_align(load_btn, ta1, LV_ALIGN_IN_TOP_RIGHT, NULL, (LV_VER_RES / 2) - 35); // align to text area
  113. label = lv_label_create(load_btn, NULL);
  114. lv_label_set_text(label, text05);
  115. // Create Save As button
  116. lv_obj_t * label2;
  117. lv_obj_t * save_as_btn = lv_btn_create(lv_scr_act(), NULL);
  118. lv_obj_set_event_cb(save_as_btn, load_btn_cb);
  119. lv_obj_set_height(save_as_btn, 35);
  120. lv_obj_set_width(save_as_btn, LV_HOR_RES / 3);
  121. lv_obj_align(save_as_btn, ta1, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35); // align to text area
  122. label2 = lv_label_create(save_as_btn, NULL);
  123. lv_label_set_text(label2, text06);
  124. }
  125. // Focus it on one of the text areas to start
  126. lv_keyboard_set_textarea(kb, ta1);
  127. lv_keyboard_set_cursor_manage(kb, true);
  128. }
  129. // Event handler for settings drop down menus
  130. void setting_dropdown_cb(lv_obj_t * obj, lv_event_t event) {
  131. //lv_event_code_t code = lv_event_get_code(event);
  132. //lv_obj_t * obj = lv_event_get_target(event);
  133. //lv_obj_t * list1 = lv_obj_get_parent(lv_obj_get_parent(obj));
  134. //if(event == LV_EVENT_CLICKED) {
  135. // LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list1, obj));
  136. //}
  137. }
  138. void settings_list_cb(lv_obj_t * btn, lv_event_t event) {
  139. extern Settings settings_obj;
  140. extern MenuFunctions menu_function_obj;
  141. String btn_text = lv_list_get_btn_text(btn);
  142. String display_string = "";
  143. if (event == LV_EVENT_CLICKED) {
  144. if (btn_text == text07) {
  145. Serial.println("Exiting...");
  146. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  147. printf("LV_EVENT_CANCEL\n");
  148. Serial.println("Potato");
  149. //menu_function_obj.deinitLVGL();
  150. //wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  151. //display_obj.exit_draw = true; // set everything back to normal
  152. }
  153. else {
  154. // Build base obj to host buttons
  155. Serial.println("Creating base object...");
  156. lv_obj_t * obj;
  157. obj = lv_obj_create(lv_scr_act(), NULL);
  158. lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
  159. lv_obj_t * exit_btn;
  160. lv_obj_t * label;
  161. // Build the generic Exit button
  162. exit_btn = lv_btn_create(obj, NULL);
  163. lv_obj_set_event_cb(exit_btn, settings_list_cb);
  164. lv_label_set_text(label, text07);
  165. //lv_obj_center(label);
  166. label = lv_label_create(exit_btn, NULL);
  167. // Create the type specific device
  168. if (settings_obj.getSettingType(btn_text) == "bool") {
  169. lv_obj_t * sw = lv_switch_create(obj, NULL);
  170. lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 0);
  171. }
  172. }
  173. }
  174. }
  175. void MenuFunctions::displaySettingsGFX(){
  176. extern Settings settings_obj;
  177. DynamicJsonDocument json(1024); // ArduinoJson v6
  178. if (deserializeJson(json, settings_obj.getSettingsString())) {
  179. Serial.println("\nCould not parse json");
  180. }
  181. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  182. lv_obj_set_size(list1, 160, 200);
  183. lv_obj_set_width(list1, LV_HOR_RES);
  184. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  185. lv_obj_t * list_btn;
  186. lv_obj_t * label;
  187. lv_obj_t * sw;
  188. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text07);
  189. lv_obj_set_event_cb(list_btn, ap_list_cb);
  190. for (int i = 0; i < json[text09].size(); i++) {
  191. char buf[json[text08][i]["name"].as<String>().length() + 1] = {};
  192. json[text08][i]["name"].as<String>().toCharArray(buf, json[text08][i]["name"].as<String>().length() + 1);
  193. list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, buf);
  194. lv_btn_set_checkable(list_btn, false);
  195. lv_obj_set_event_cb(list_btn, settings_list_cb);
  196. }
  197. }
  198. // GFX Function to build a list showing all Stations scanned
  199. void MenuFunctions::addStationGFX(){
  200. extern LinkedList<Station>* stations;
  201. extern LinkedList<AccessPoint>* access_points;
  202. extern WiFiScan wifi_scan_obj;
  203. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  204. lv_obj_set_size(list1, 160, 200);
  205. lv_obj_set_width(list1, LV_HOR_RES);
  206. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  207. lv_obj_t * list_btn;
  208. lv_obj_t * label;
  209. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
  210. lv_obj_set_event_cb(list_btn, station_list_cb);
  211. char addr[] = "00:00:00:00:00:00";
  212. for (int x = 0; x < access_points->size(); x++) {
  213. AccessPoint cur_ap = access_points->get(x);
  214. // Add non clickable button for AP
  215. String full_label = "AP: " + cur_ap.essid;
  216. char buf[full_label.length() + 1] = {};
  217. full_label.toCharArray(buf, full_label.length() + 1);
  218. list_btn = lv_list_add_btn(list1, NULL, buf);
  219. lv_btn_set_checkable(list_btn, false);
  220. int cur_ap_sta_len = access_points->get(x).stations->size();
  221. for (int y = 0; y < cur_ap_sta_len; y++) {
  222. Station cur_sta = stations->get(cur_ap.stations->get(y));
  223. // Convert uint8_t MAC to char array
  224. wifi_scan_obj.getMAC(addr, cur_sta.mac, 0);
  225. //char buf[stations->get(i).mac.length() + 1] = {};
  226. //stations->get(i).mac.toCharArray(buf, stations->get(i).mac.length() + 1);
  227. list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, addr);
  228. lv_btn_set_checkable(list_btn, true);
  229. lv_obj_set_event_cb(list_btn, station_list_cb);
  230. if (cur_sta.selected)
  231. lv_btn_toggle(list_btn);
  232. }
  233. }
  234. }
  235. // Function to work with list of Stations
  236. void station_list_cb(lv_obj_t * btn, lv_event_t event) {
  237. extern LinkedList<Station>* stations;
  238. extern MenuFunctions menu_function_obj;
  239. extern WiFiScan wifi_scan_obj;
  240. String btn_text = lv_list_get_btn_text(btn);
  241. String display_string = "";
  242. char addr[] = "00:00:00:00:00:00";
  243. if (event == LV_EVENT_CLICKED) {
  244. if (btn_text != text09) {
  245. //lv_list_focus_btn(lv_obj_get_parent(lv_obj_get_parent(btn)), btn);
  246. }
  247. else {
  248. Serial.println("Exiting...");
  249. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  250. for (int i = 0; i < stations->size(); i++) {
  251. if (stations->get(i).selected) {
  252. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  253. Serial.print("Selected: ");
  254. Serial.println(addr);
  255. }
  256. }
  257. printf("LV_EVENT_CANCEL\n");
  258. menu_function_obj.deinitLVGL();
  259. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  260. display_obj.exit_draw = true; // set everything back to normal
  261. }
  262. }
  263. if (event == LV_EVENT_VALUE_CHANGED) {
  264. if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
  265. //Serial.print("Toggle on: ");
  266. //Serial.println(btn_text);
  267. for (int i = 0; i < stations->size(); i++) {
  268. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  269. if (strcmp(addr, btn_text.c_str()) == 0) {
  270. Serial.print("Adding Station: ");
  271. Serial.println(addr);
  272. Station sta = stations->get(i);
  273. sta.selected = true;
  274. stations->set(i, sta);
  275. }
  276. }
  277. }
  278. else {
  279. //Serial.print("Toggle off: ");
  280. //Serial.println(btn_text);
  281. for (int i = 0; i < stations->size(); i++) {
  282. wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
  283. if (strcmp(addr, btn_text.c_str()) == 0) {
  284. Serial.print("Removing Station: ");
  285. Serial.println(addr);
  286. Station sta = stations->get(i);
  287. sta.selected = false;
  288. stations->set(i, sta);
  289. }
  290. }
  291. }
  292. }
  293. }
  294. // GFX Function to build a list showing all APs scanned
  295. void MenuFunctions::addAPGFX(){
  296. extern LinkedList<AccessPoint>* access_points;
  297. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  298. lv_obj_set_size(list1, 160, 200);
  299. lv_obj_set_width(list1, LV_HOR_RES);
  300. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  301. lv_obj_t * list_btn;
  302. lv_obj_t * label;
  303. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
  304. lv_obj_set_event_cb(list_btn, ap_list_cb);
  305. for (int i = 0; i < access_points->size(); i++) {
  306. char buf[access_points->get(i).essid.length() + 1] = {};
  307. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  308. list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, buf);
  309. lv_btn_set_checkable(list_btn, true);
  310. lv_obj_set_event_cb(list_btn, ap_list_cb);
  311. if (access_points->get(i).selected)
  312. lv_btn_toggle(list_btn);
  313. }
  314. }
  315. void ap_list_cb(lv_obj_t * btn, lv_event_t event) {
  316. extern LinkedList<AccessPoint>* access_points;
  317. extern MenuFunctions menu_function_obj;
  318. String btn_text = lv_list_get_btn_text(btn);
  319. String display_string = "";
  320. if (event == LV_EVENT_CLICKED) {
  321. if (btn_text != text09) {
  322. //lv_list_focus_btn(lv_obj_get_parent(lv_obj_get_parent(btn)), btn);
  323. }
  324. else {
  325. Serial.println("Exiting...");
  326. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  327. for (int i = 0; i < access_points->size(); i++) {
  328. if (access_points->get(i).selected) {
  329. Serial.println("Selected: " + (String)access_points->get(i).essid);
  330. }
  331. }
  332. printf("LV_EVENT_CANCEL\n");
  333. menu_function_obj.deinitLVGL();
  334. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  335. display_obj.exit_draw = true; // set everything back to normal
  336. }
  337. }
  338. if (event == LV_EVENT_VALUE_CHANGED) {
  339. if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
  340. //Serial.print("Toggle on: ");
  341. //Serial.println(btn_text);
  342. for (int i = 0; i < access_points->size(); i++) {
  343. if (access_points->get(i).essid == btn_text) {
  344. Serial.println("Adding AP: " + (String)access_points->get(i).essid);
  345. AccessPoint ap = access_points->get(i);
  346. ap.selected = true;
  347. access_points->set(i, ap);
  348. }
  349. }
  350. }
  351. else {
  352. //Serial.print("Toggle off: ");
  353. //Serial.println(btn_text);
  354. for (int i = 0; i < access_points->size(); i++) {
  355. if (access_points->get(i).essid == btn_text) {
  356. Serial.println("Removing AP: " + (String)access_points->get(i).essid);
  357. AccessPoint ap = access_points->get(i);
  358. ap.selected = false;
  359. access_points->set(i, ap);
  360. }
  361. }
  362. }
  363. }
  364. }
  365. void MenuFunctions::addSSIDGFX(){
  366. extern LinkedList<ssid>* ssids;
  367. String display_string = "";
  368. // Create a keyboard and apply the styles
  369. kb = lv_keyboard_create(lv_scr_act(), NULL);
  370. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  371. lv_obj_set_event_cb(kb, add_ssid_keyboard_event_cb);
  372. // Create one text area
  373. // Store all SSIDs
  374. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  375. lv_textarea_set_one_line(ta1, false);
  376. lv_obj_set_width(ta1, LV_HOR_RES);
  377. lv_obj_set_height(ta1, (LV_VER_RES / 2) - 35);
  378. lv_obj_set_pos(ta1, 5, 20);
  379. lv_textarea_set_cursor_hidden(ta1, true);
  380. lv_obj_align(ta1, NULL, LV_ALIGN_IN_TOP_MID, NULL, NULL);
  381. lv_textarea_set_placeholder_text(ta1, text_table1[0]);
  382. // Create second text area
  383. // Add SSIDs
  384. ta2 = lv_textarea_create(lv_scr_act(), ta1);
  385. lv_textarea_set_cursor_hidden(ta2, false);
  386. lv_textarea_set_one_line(ta2, true);
  387. lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35);
  388. lv_textarea_set_text(ta2, "");
  389. lv_textarea_set_placeholder_text(ta2, text_table1[1]);
  390. // After generating text areas, add text to first text box
  391. for (int i = 0; i < ssids->size(); i++)
  392. display_string.concat((String)ssids->get(i).essid + "\n");
  393. lv_textarea_set_text(ta1, display_string.c_str());
  394. // Focus it on one of the text areas to start
  395. lv_keyboard_set_textarea(kb, ta2);
  396. lv_keyboard_set_cursor_manage(kb, true);
  397. }
  398. void MenuFunctions::joinWiFiGFX(){
  399. // Create one text area
  400. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  401. lv_textarea_set_one_line(ta1, true);
  402. lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
  403. lv_obj_set_pos(ta1, 5, 20);
  404. //lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
  405. lv_textarea_set_text(ta1, "");
  406. lv_obj_set_event_cb(ta1, ta_event_cb);
  407. // Create first label
  408. lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL);
  409. lv_label_set_text(ssid_label, text_table1[2]);
  410. lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  411. // Create second text area
  412. ta2 = lv_textarea_create(lv_scr_act(), ta1);
  413. //lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
  414. //lv_textarea_set_pwd_show_time(ta2, 1000);
  415. lv_textarea_set_cursor_hidden(ta2, true);
  416. lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
  417. // Create second label
  418. lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL);
  419. lv_label_set_text(pw_label, text_table1[3]);
  420. lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  421. // Create a keyboard and apply the styles
  422. kb = lv_keyboard_create(lv_scr_act(), NULL);
  423. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  424. lv_obj_set_event_cb(kb, join_wifi_keyboard_event_cb);
  425. // Focus it on one of the text areas to start
  426. lv_keyboard_set_textarea(kb, ta1);
  427. lv_keyboard_set_cursor_manage(kb, true);
  428. }
  429. // Function to create keyboard for saving file name
  430. void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event) {
  431. extern MenuFunctions menu_function_obj;
  432. lv_keyboard_def_event_cb(save_as_kb, event);
  433. // User canceled so we will get rid of the keyboard and text box
  434. if (event == LV_EVENT_CANCEL) {
  435. lv_obj_del_async(save_as_kb);
  436. lv_obj_del_async(save_name);
  437. }
  438. // Save content from ta1 to file name in save_name
  439. else if(event == LV_EVENT_APPLY){
  440. String display_string = "";
  441. printf("LV_EVENT_APPLY\n");
  442. // Get ducky script
  443. String content = lv_textarea_get_text(ta1);
  444. String target_file_name = "/SCRIPTS/" + (String)lv_textarea_get_text(save_name);
  445. Serial.println("Writing to target file: " + (String)target_file_name);
  446. // Open file with the given name
  447. File script = SD.open(target_file_name, FILE_WRITE);
  448. if (script) {
  449. menu_function_obj.loaded_file = target_file_name;
  450. Serial.println("Writing content: ");
  451. Serial.println(content);
  452. script.print(content);
  453. script.close();
  454. }
  455. lv_obj_del_async(save_as_kb);
  456. lv_obj_del_async(save_name);
  457. // Create Save button
  458. lv_obj_t * save_label;
  459. lv_obj_t * save_btn = lv_btn_create(lv_scr_act(), NULL);
  460. lv_obj_set_event_cb(save_btn, load_btn_cb);
  461. lv_obj_set_height(save_btn, 35);
  462. lv_obj_set_width(save_btn, LV_HOR_RES / 3);
  463. lv_obj_align(save_btn, ta1, LV_ALIGN_IN_TOP_LEFT, NULL, (LV_VER_RES / 2) - 35); // align to text area
  464. save_label = lv_label_create(save_btn, NULL);
  465. lv_label_set_text(save_label, text13);
  466. }
  467. }
  468. void test_btn_cb(lv_obj_t * btn, lv_event_t event) {
  469. extern MenuFunctions menu_function_obj;
  470. if (event == LV_EVENT_CLICKED) {
  471. String btn_text = lv_list_get_btn_text(btn);
  472. String display_string = "";
  473. //printf("Clicked: %s\n", btn_text);
  474. Serial.print("Clicked: ");
  475. Serial.println(btn_text);
  476. // Get file content and send to text area
  477. if (btn_text != text12) {
  478. File script = SD.open(btn_text);
  479. if (script) {
  480. while (script.available()) {
  481. display_string.concat((char)script.read());
  482. }
  483. script.close();
  484. Serial.println(display_string);
  485. char buf[display_string.length() + 1] = {};
  486. display_string.toCharArray(buf, display_string.length() + 1);
  487. lv_textarea_set_text(ta1, buf);
  488. // Create Save button
  489. lv_obj_t * save_label;
  490. lv_obj_t * save_btn = lv_btn_create(lv_scr_act(), NULL);
  491. lv_obj_set_event_cb(save_btn, load_btn_cb);
  492. lv_obj_set_height(save_btn, 35);
  493. lv_obj_set_width(save_btn, LV_HOR_RES / 3);
  494. lv_obj_align(save_btn, ta1, LV_ALIGN_IN_TOP_LEFT, NULL, (LV_VER_RES / 2) - 35); // align to text area
  495. save_label = lv_label_create(save_btn, NULL);
  496. lv_label_set_text(save_label, text13);
  497. }
  498. }
  499. // Delete the file list obj
  500. lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
  501. menu_function_obj.loaded_file = btn_text;
  502. }
  503. }
  504. void load_btn_cb(lv_obj_t * load_btn, lv_event_t event) {
  505. extern SDInterface sd_obj;
  506. extern MenuFunctions menu_function_obj;
  507. String btn_text = lv_list_get_btn_text(load_btn);
  508. if (btn_text == "Load") {
  509. if (event == LV_EVENT_CLICKED)
  510. Serial.println("Load button pressed");
  511. else if (event == LV_EVENT_RELEASED) {
  512. Serial.println("Load button released");
  513. /*Create a list*/
  514. lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
  515. lv_obj_set_size(list1, 160, 200);
  516. lv_obj_set_width(list1, LV_HOR_RES);
  517. lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
  518. //lv_list_set_anim_time(list1, 0);
  519. // Load file names into buttons
  520. File scripts = SD.open("/SCRIPTS");
  521. // Build list of files from the SD card
  522. lv_obj_t * list_btn;
  523. list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text12);
  524. lv_obj_set_event_cb(list_btn, test_btn_cb);
  525. while (true) {
  526. File entity = scripts.openNextFile();
  527. if (!entity)
  528. break;
  529. if (!entity.isDirectory()) {
  530. String file_name = entity.name();
  531. // Fancy button text time
  532. char buf[file_name.length() + 1] = {};
  533. file_name.toCharArray(buf, file_name.length() + 1);
  534. list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, buf);
  535. lv_obj_set_event_cb(list_btn, test_btn_cb);
  536. }
  537. entity.close();
  538. }
  539. scripts.close();
  540. }
  541. }
  542. // Save current text bod content to new file
  543. else if (btn_text == text06) {
  544. if (event == LV_EVENT_CLICKED)
  545. Serial.println("Save button pressed");
  546. else if (event == LV_EVENT_RELEASED) {
  547. Serial.println("Save button released");
  548. save_name = lv_textarea_create(lv_scr_act(), ta2);
  549. lv_textarea_set_cursor_hidden(save_name, false);
  550. lv_textarea_set_one_line(save_name, true);
  551. lv_obj_align(save_name, NULL, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35);
  552. lv_textarea_set_text(save_name, "");
  553. lv_textarea_set_placeholder_text(save_name, "File Name");
  554. // Create a keyboard and apply the styles
  555. save_as_kb = lv_keyboard_create(lv_scr_act(), NULL);
  556. lv_obj_set_size(save_as_kb, LV_HOR_RES, LV_VER_RES / 2);
  557. lv_obj_set_event_cb(save_as_kb, save_as_keyboard_event_cb);
  558. lv_keyboard_set_textarea(save_as_kb, save_name);
  559. lv_keyboard_set_cursor_manage(save_as_kb, true);
  560. }
  561. }
  562. // Save current text box content to current loaded file
  563. else if (btn_text == text13) {
  564. if (event == LV_EVENT_CLICKED)
  565. Serial.println("Save button pressed");
  566. else if (event == LV_EVENT_RELEASED) {
  567. Serial.println("Save button released");
  568. Serial.println("Writing to file: " + (String)menu_function_obj.loaded_file);
  569. File script = SD.open(menu_function_obj.loaded_file, FILE_WRITE);
  570. // Write data to file
  571. if (script) {
  572. String content = lv_textarea_get_text(ta1);
  573. Serial.println("Writing content:");
  574. Serial.println(content);
  575. Serial.println("to file: " + (String)menu_function_obj.loaded_file);
  576. script.print(lv_textarea_get_text(ta1));
  577. script.close();
  578. }
  579. }
  580. }
  581. }
  582. void write_bad_usb_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event) {
  583. extern Display display_obj;
  584. extern MenuFunctions menu_function_obj;
  585. extern A32u4Interface a32u4_obj;
  586. extern WiFiScan wifi_scan_obj;
  587. lv_keyboard_def_event_cb(kb, event);
  588. if(event == LV_EVENT_APPLY){
  589. String display_string = "";
  590. printf("LV_EVENT_APPLY\n");
  591. String ta1_text = lv_textarea_get_text(ta1);
  592. Serial.println(ta1_text);
  593. a32u4_obj.runScript(ta1_text);
  594. }
  595. else if(event == LV_EVENT_CANCEL) {
  596. printf("LV_EVENT_CANCEL\n");
  597. menu_function_obj.deinitLVGL();
  598. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  599. display_obj.exit_draw = true; // set everything back to normal
  600. }
  601. }
  602. // Keyboard callback dedicated to joining wifi
  603. void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
  604. extern Display display_obj;
  605. extern MenuFunctions menu_function_obj;
  606. extern WiFiScan wifi_scan_obj;
  607. extern LinkedList<ssid>* ssids;
  608. lv_keyboard_def_event_cb(kb, event);
  609. // User has applied text box
  610. if(event == LV_EVENT_APPLY){
  611. String display_string = "";
  612. printf("LV_EVENT_APPLY\n");
  613. // Get text from SSID text box
  614. String ta2_text = lv_textarea_get_text(ta2);
  615. //Serial.println(ta1_text);
  616. Serial.println(ta2_text);
  617. // Add text box text to list of SSIDs
  618. wifi_scan_obj.addSSID(ta2_text);
  619. // Update large text box with ssid
  620. for (int i = 0; i < ssids->size(); i++)
  621. display_string.concat((String)ssids->get(i).essid + "\n");
  622. lv_textarea_set_text(ta1, display_string.c_str());
  623. lv_textarea_set_text(ta2, "");
  624. }else if(event == LV_EVENT_CANCEL){
  625. printf("LV_EVENT_CANCEL\n");
  626. //lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
  627. menu_function_obj.deinitLVGL();
  628. //wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  629. display_obj.exit_draw = true; // set everything back to normal
  630. }
  631. }
  632. // Keyboard callback dedicated to joining wifi
  633. void join_wifi_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
  634. extern Display display_obj;
  635. extern MenuFunctions menu_function_obj;
  636. extern WiFiScan wifi_scan_obj;
  637. lv_keyboard_def_event_cb(kb, event);
  638. if(event == LV_EVENT_APPLY){
  639. printf("LV_EVENT_APPLY\n");
  640. //String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
  641. String ta1_text = lv_textarea_get_text(ta1);
  642. String ta2_text = lv_textarea_get_text(ta2);
  643. Serial.println(ta1_text);
  644. Serial.println(ta2_text);
  645. wifi_scan_obj.joinWiFi(ta1_text, ta2_text);
  646. }else if(event == LV_EVENT_CANCEL){
  647. printf("LV_EVENT_CANCEL\n");
  648. //lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
  649. menu_function_obj.deinitLVGL();
  650. //wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  651. display_obj.exit_draw = true; // set everything back to normal
  652. }
  653. }
  654. void ta_event_cb(lv_obj_t * ta, lv_event_t event)
  655. {
  656. if(event == LV_EVENT_CLICKED) {
  657. if(kb != NULL)
  658. lv_keyboard_set_textarea(kb, ta);
  659. }
  660. //else if(event == LV_EVENT_INSERT) {
  661. // const char * str = lv_event_get_data();
  662. // if(str[0] == '\n') {
  663. // printf("Ready\n");
  664. // }
  665. //}
  666. }
  667. #endif
  668. //// END LV_ARDUINO STUFF
  669. void MenuFunctions::buttonNotSelected(uint8_t b) {
  670. display_obj.tft.setFreeFont(NULL);
  671. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  672. }
  673. void MenuFunctions::buttonSelected(uint8_t b) {
  674. display_obj.tft.setFreeFont(NULL);
  675. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  676. }
  677. // Function to check menu input
  678. void MenuFunctions::main(uint32_t currentTime)
  679. {
  680. // Some function exited and we need to go back to normal
  681. if (display_obj.exit_draw) {
  682. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  683. display_obj.exit_draw = false;
  684. this->orientDisplay();
  685. }
  686. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  687. (wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
  688. (wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
  689. (wifi_scan_obj.currentScanMode == SHOW_INFO)) {
  690. if (wifi_scan_obj.orient_display) {
  691. this->orientDisplay();
  692. wifi_scan_obj.orient_display = false;
  693. }
  694. #ifndef MARAUDER_MINI
  695. if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
  696. (wifi_scan_obj.currentScanMode != LV_ADD_SSID))
  697. display_obj.updateBanner(current_menu->name);
  698. #endif
  699. }
  700. if (currentTime != 0) {
  701. if (currentTime - initTime >= BANNER_TIME) {
  702. this->initTime = millis();
  703. if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
  704. (wifi_scan_obj.currentScanMode != LV_ADD_SSID))
  705. this->updateStatusBar();
  706. #ifdef MARAUDER_MINI
  707. display_obj.updateBanner(current_menu->name);
  708. #endif
  709. }
  710. }
  711. boolean pressed = false;
  712. // This is code from bodmer's keypad example
  713. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  714. // Get the display buffer out of the way
  715. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  716. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  717. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
  718. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
  719. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
  720. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
  721. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
  722. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  723. display_obj.displayBuffer();
  724. // Pressed will be set true is there is a valid touch on the screen
  725. int pre_getTouch = millis();
  726. // getTouch causes a 10ms delay which makes beacon spam less effective
  727. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  728. #ifndef MARAUDER_MINI
  729. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  730. #endif
  731. // This is if there are scans/attacks going on
  732. #ifndef MARAUDER_MINI
  733. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  734. (pressed) &&
  735. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  736. (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
  737. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  738. {
  739. // Stop the current scan
  740. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  741. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  742. (wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION) ||
  743. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  744. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  745. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  746. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  747. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  748. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  749. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  750. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  751. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  752. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  753. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  754. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  755. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  756. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  757. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  758. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  759. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  760. {
  761. //Serial.println("Stopping scan...");
  762. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  763. // If we don't do this, the text and button coordinates will be off
  764. display_obj.tft.init();
  765. // Take us back to the menu
  766. changeMenu(current_menu);
  767. }
  768. x = -1;
  769. y = -1;
  770. return;
  771. }
  772. #endif
  773. #ifdef MARAUDER_MINI
  774. bool c_btn_press = c_btn.justPressed();
  775. if ((c_btn_press) &&
  776. (wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  777. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  778. (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
  779. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  780. {
  781. // Stop the current scan
  782. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  783. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  784. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  785. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  786. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  787. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  788. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  789. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  790. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  791. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  792. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  793. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  794. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  795. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  796. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  797. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  798. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  799. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  800. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  801. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS) ||
  802. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL) ||
  803. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
  804. (wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR))
  805. {
  806. //Serial.println("Stopping scan...");
  807. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  808. // If we don't do this, the text and button coordinates will be off
  809. display_obj.tft.init();
  810. // Take us back to the menu
  811. changeMenu(current_menu);
  812. }
  813. x = -1;
  814. y = -1;
  815. return;
  816. }
  817. #endif
  818. // Check if any key coordinate boxes contain the touch coordinates
  819. // This is for when on a menu
  820. #ifndef MARAUDER_MINI
  821. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  822. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
  823. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
  824. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
  825. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
  826. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
  827. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  828. //(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_LIST))
  829. {
  830. // Need this to set all keys to false
  831. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  832. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  833. display_obj.key[b].press(true); // tell the button it is pressed
  834. } else {
  835. display_obj.key[b].press(false); // tell the button it is NOT pressed
  836. }
  837. }
  838. // Check if any key has changed state
  839. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  840. display_obj.tft.setFreeFont(MENU_FONT);
  841. if (display_obj.key[b].justPressed()) {
  842. //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  843. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true);
  844. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  845. if (current_menu->list->get(b).name != text09)
  846. display_obj.tft.drawXBitmap(0,
  847. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  848. menu_icons[current_menu->list->get(b).icon],
  849. ICON_W,
  850. ICON_H,
  851. current_menu->list->get(b).color,
  852. TFT_BLACK);
  853. }
  854. //else if (pressed)
  855. // display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  856. // If button was just release, execute the button's function
  857. if ((display_obj.key[b].justReleased()) && (!pressed))
  858. {
  859. //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  860. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name);
  861. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  862. current_menu->list->get(b).callable();
  863. }
  864. // This
  865. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  866. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  867. if (current_menu->list->get(b).name != text09)
  868. display_obj.tft.drawXBitmap(0,
  869. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  870. menu_icons[current_menu->list->get(b).icon],
  871. ICON_W,
  872. ICON_H,
  873. TFT_BLACK,
  874. current_menu->list->get(b).color);
  875. }
  876. display_obj.tft.setFreeFont(NULL);
  877. }
  878. }
  879. x = -1;
  880. y = -1;
  881. #endif
  882. #ifdef MARAUDER_MINI
  883. if (u_btn.justPressed()){
  884. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  885. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  886. if (current_menu->selected > 0) {
  887. current_menu->selected--;
  888. this->buttonSelected(current_menu->selected);
  889. if (!current_menu->list->get(current_menu->selected + 1).selected)
  890. this->buttonNotSelected(current_menu->selected + 1);
  891. }
  892. }
  893. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  894. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  895. if (wifi_scan_obj.set_channel < 14)
  896. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel + 1);
  897. }
  898. }
  899. if (d_btn.justPressed()){
  900. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  901. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  902. if (current_menu->selected < current_menu->list->size() - 1) {
  903. current_menu->selected++;
  904. this->buttonSelected(current_menu->selected);
  905. if (!current_menu->list->get(current_menu->selected - 1).selected)
  906. this->buttonNotSelected(current_menu->selected - 1);
  907. }
  908. }
  909. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  910. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  911. if (wifi_scan_obj.set_channel > 1)
  912. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel - 1);
  913. }
  914. }
  915. if(c_btn_press){
  916. current_menu->list->get(current_menu->selected).callable();
  917. }
  918. #endif
  919. }
  920. #if BATTERY_ANALOG_ON == 1
  921. byte battery_analog_array[10];
  922. byte battery_count = 0;
  923. byte battery_analog_last = 101;
  924. #define BATTERY_CHECK 50
  925. uint16_t battery_analog = 0;
  926. void MenuFunctions::battery(bool initial)
  927. {
  928. if (BATTERY_ANALOG_ON) {
  929. uint8_t n = 0;
  930. byte battery_analog_sample[10];
  931. byte deviation;
  932. if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
  933. else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
  934. if (battery_count == 0) {
  935. battery_analog = 0;
  936. for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
  937. for (n = 0; n < 10; n++) {
  938. battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
  939. if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
  940. else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
  941. battery_analog += battery_analog_sample[n];
  942. }
  943. battery_analog = battery_analog / 10;
  944. for (n = 0; n < 10; n++) {
  945. deviation = abs(battery_analog - battery_analog_sample[n]);
  946. if (deviation >= 10) battery_analog_sample[n] = battery_analog;
  947. }
  948. battery_analog = 0;
  949. for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
  950. battery_analog = battery_analog / 10;
  951. battery_analog_array[0] = battery_analog;
  952. if (battery_analog_array[9] > 0 ) {
  953. battery_analog = 0;
  954. for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
  955. battery_analog = battery_analog / 10;
  956. }
  957. battery_count ++;
  958. }
  959. else if (battery_count < BATTERY_CHECK) battery_count++;
  960. else if (battery_count >= BATTERY_CHECK) battery_count = 0;
  961. if (battery_analog_last != battery_analog) {
  962. battery_analog_last = battery_analog;
  963. MenuFunctions::battery2();
  964. }
  965. }
  966. }
  967. void MenuFunctions::battery2(bool initial)
  968. {
  969. uint16_t the_color;
  970. if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
  971. else if (battery_analog < 20) the_color = TFT_RED;
  972. else if (battery_analog < 40) the_color = TFT_YELLOW;
  973. else the_color = TFT_GREEN;
  974. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  975. display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  976. display_obj.tft.drawXBitmap(186,
  977. 0,
  978. menu_icons[STATUS_BAT],
  979. 16,
  980. 16,
  981. STATUSBAR_COLOR,
  982. the_color);
  983. display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
  984. }
  985. #else
  986. void MenuFunctions::battery(bool initial)
  987. {
  988. uint16_t the_color;
  989. if (battery_obj.i2c_supported)
  990. {
  991. // Could use int compare maybe idk
  992. if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
  993. the_color = TFT_GREEN;
  994. else
  995. the_color = TFT_RED;
  996. if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
  997. battery_obj.old_level = battery_obj.battery_level;
  998. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  999. display_obj.tft.setCursor(0, 1);
  1000. display_obj.tft.drawXBitmap(186,
  1001. 0,
  1002. menu_icons[STATUS_BAT],
  1003. 16,
  1004. 16,
  1005. STATUSBAR_COLOR,
  1006. the_color);
  1007. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  1008. }
  1009. }
  1010. }
  1011. void MenuFunctions::battery2(bool initial)
  1012. {
  1013. MenuFunctions::battery(initial);
  1014. }
  1015. #endif
  1016. void MenuFunctions::updateStatusBar()
  1017. {
  1018. display_obj.tft.setTextSize(1);
  1019. #ifdef MARAUDER_MINI
  1020. display_obj.tft.setFreeFont(NULL);
  1021. #endif
  1022. uint16_t the_color;
  1023. // Draw temp info
  1024. if (temp_obj.current_temp < 70)
  1025. the_color = TFT_GREEN;
  1026. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  1027. the_color = TFT_YELLOW;
  1028. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  1029. the_color = TFT_ORANGE;
  1030. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  1031. the_color = TFT_RED;
  1032. else
  1033. the_color = TFT_MAROON;
  1034. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1035. if (temp_obj.current_temp != temp_obj.old_temp) {
  1036. temp_obj.old_temp = temp_obj.current_temp;
  1037. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1038. #ifndef MARAUDER_MINI
  1039. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  1040. #endif
  1041. #ifdef MARAUDER_MINI
  1042. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1);
  1043. #endif
  1044. }
  1045. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1046. // WiFi Channel Stuff
  1047. if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) {
  1048. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  1049. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1050. #ifndef MARAUDER_MINI
  1051. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  1052. #endif
  1053. #ifdef MARAUDER_MINI
  1054. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  1055. #endif
  1056. }
  1057. // RAM Stuff
  1058. wifi_scan_obj.freeRAM();
  1059. if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) {
  1060. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  1061. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1062. #ifndef MARAUDER_MINI
  1063. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  1064. #endif
  1065. #ifdef MARAUDER_MINI
  1066. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  1067. #endif
  1068. }
  1069. // Draw battery info
  1070. MenuFunctions::battery(false);
  1071. // Draw SD info
  1072. if (sd_obj.supported)
  1073. the_color = TFT_GREEN;
  1074. else
  1075. the_color = TFT_RED;
  1076. #ifndef MARAUDER_MINI
  1077. display_obj.tft.drawXBitmap(170,
  1078. 0,
  1079. menu_icons[STATUS_SD],
  1080. 16,
  1081. 16,
  1082. STATUSBAR_COLOR,
  1083. the_color);
  1084. #endif
  1085. #ifdef MARAUDER_MINI
  1086. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1087. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  1088. #endif
  1089. }
  1090. void MenuFunctions::drawStatusBar()
  1091. {
  1092. display_obj.tft.setTextSize(1);
  1093. #ifdef MARAUDER_MINI
  1094. display_obj.tft.setFreeFont(NULL);
  1095. #endif
  1096. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1097. //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY);
  1098. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1099. //display_obj.tft.setTextSize(2);
  1100. uint16_t the_color;
  1101. // Draw temp info
  1102. if (temp_obj.current_temp < 70)
  1103. the_color = TFT_GREEN;
  1104. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  1105. the_color = TFT_YELLOW;
  1106. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  1107. the_color = TFT_ORANGE;
  1108. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  1109. the_color = TFT_RED;
  1110. else
  1111. the_color = TFT_MAROON;
  1112. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1113. temp_obj.old_temp = temp_obj.current_temp;
  1114. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1115. #ifndef MARAUDER_MINI
  1116. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  1117. #endif
  1118. #ifdef MARAUDER_MINI
  1119. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1);
  1120. #endif
  1121. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1122. // WiFi Channel Stuff
  1123. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  1124. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1125. #ifndef MARAUDER_MINI
  1126. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  1127. #endif
  1128. #ifdef MARAUDER_MINI
  1129. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  1130. #endif
  1131. // RAM Stuff
  1132. wifi_scan_obj.freeRAM();
  1133. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  1134. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1135. #ifndef MARAUDER_MINI
  1136. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  1137. #endif
  1138. #ifdef MARAUDER_MINI
  1139. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  1140. #endif
  1141. MenuFunctions::battery2(true);
  1142. // Draw SD info
  1143. if (sd_obj.supported)
  1144. the_color = TFT_GREEN;
  1145. else
  1146. the_color = TFT_RED;
  1147. #ifndef MARAUDER_MINI
  1148. display_obj.tft.drawXBitmap(170,
  1149. 0,
  1150. menu_icons[STATUS_SD],
  1151. 16,
  1152. 16,
  1153. STATUSBAR_COLOR,
  1154. the_color);
  1155. #endif
  1156. #ifdef MARAUDER_MINI
  1157. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1158. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  1159. #endif
  1160. }
  1161. void MenuFunctions::orientDisplay()
  1162. {
  1163. display_obj.tft.init();
  1164. display_obj.tft.setRotation(0); // Portrait
  1165. display_obj.tft.setCursor(0, 0);
  1166. #ifndef MARAUDER_MINI
  1167. #ifdef TFT_SHIELD
  1168. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  1169. //Serial.println("Using TFT Shield");
  1170. #else if defined(TFT_DIY)
  1171. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  1172. //Serial.println("Using TFT DIY");
  1173. #endif
  1174. display_obj.tft.setTouch(calData);
  1175. #endif
  1176. changeMenu(current_menu);
  1177. }
  1178. void MenuFunctions::runBoolSetting(String key) {
  1179. //Serial.println("Building bool setting screen...");
  1180. display_obj.tftDrawRedOnOffButton();
  1181. //display_obj.tftDrawGreenOnOffButton();
  1182. }
  1183. String MenuFunctions::callSetting(String key) {
  1184. specSettingMenu.name = key;
  1185. String setting_type = settings_obj.getSettingType(key);
  1186. if (setting_type == "bool") {
  1187. return "bool";
  1188. }
  1189. }
  1190. void MenuFunctions::displaySetting(String key, Menu* menu, int index) {
  1191. specSettingMenu.name = key;
  1192. bool setting_value = settings_obj.loadSetting<bool>(key);
  1193. // Make a local copy of menu node
  1194. MenuNode node = menu->list->get(index);
  1195. display_obj.tft.setTextWrap(false);
  1196. display_obj.tft.setFreeFont(NULL);
  1197. display_obj.tft.setCursor(0, 100);
  1198. display_obj.tft.setTextSize(1);
  1199. // Set local copy value
  1200. if (!setting_value) {
  1201. display_obj.tft.setTextColor(TFT_RED);
  1202. display_obj.tft.println(F(text_table1[4]));
  1203. node.selected = false;
  1204. }
  1205. else {
  1206. display_obj.tft.setTextColor(TFT_GREEN);
  1207. display_obj.tft.println(F(text_table1[5]));
  1208. node.selected = true;
  1209. }
  1210. // Put local copy back into menu
  1211. menu->list->set(index, node);
  1212. }
  1213. // Function to build the menus
  1214. void MenuFunctions::RunSetup()
  1215. {
  1216. extern LinkedList<AccessPoint>* access_points;
  1217. #ifndef MARAUDER_MINI
  1218. this->initLVGL();
  1219. #endif
  1220. // root menu stuff
  1221. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  1222. // Main menu stuff
  1223. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  1224. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  1225. badusbMenu.list = new LinkedList<MenuNode>();
  1226. generalMenu.list = new LinkedList<MenuNode>();
  1227. deviceMenu.list = new LinkedList<MenuNode>();
  1228. // Device menu stuff
  1229. failedUpdateMenu.list = new LinkedList<MenuNode>();
  1230. whichUpdateMenu.list = new LinkedList<MenuNode>();
  1231. confirmMenu.list = new LinkedList<MenuNode>();
  1232. espUpdateMenu.list = new LinkedList<MenuNode>();
  1233. updateMenu.list = new LinkedList<MenuNode>();
  1234. settingsMenu.list = new LinkedList<MenuNode>();
  1235. specSettingMenu.list = new LinkedList<MenuNode>();
  1236. infoMenu.list = new LinkedList<MenuNode>();
  1237. languageMenu.list = new LinkedList<MenuNode>();
  1238. // WiFi menu stuff
  1239. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  1240. wifiAttackMenu.list = new LinkedList<MenuNode>();
  1241. wifiGeneralMenu.list = new LinkedList<MenuNode>();
  1242. wifiAPMenu.list = new LinkedList<MenuNode>();
  1243. // Bluetooth menu stuff
  1244. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  1245. bluetoothGeneralMenu.list = new LinkedList<MenuNode>();
  1246. // Settings stuff
  1247. shutdownWiFiMenu.list = new LinkedList<MenuNode>();
  1248. shutdownBLEMenu.list = new LinkedList<MenuNode>();
  1249. generateSSIDsMenu.list = new LinkedList<MenuNode>();
  1250. clearSSIDsMenu.list = new LinkedList<MenuNode>();
  1251. clearAPsMenu.list = new LinkedList<MenuNode>();
  1252. // Work menu names
  1253. mainMenu.name = text_table1[6];
  1254. wifiMenu.name = text_table1[7];
  1255. badusbMenu.name = text_table1[8];
  1256. deviceMenu.name = text_table1[9];
  1257. generalMenu.name = text_table1[10];
  1258. failedUpdateMenu.name = text_table1[11];
  1259. whichUpdateMenu.name = text_table1[12];
  1260. confirmMenu.name = text_table1[13];
  1261. espUpdateMenu.name = text_table1[14];
  1262. updateMenu.name = text_table1[15];
  1263. languageMenu.name = text_table1[16];
  1264. infoMenu.name = text_table1[17];
  1265. settingsMenu.name = text_table1[18];
  1266. bluetoothMenu.name = text_table1[19];
  1267. wifiSnifferMenu.name = text_table1[20];
  1268. wifiAttackMenu.name = text_table1[21];
  1269. wifiGeneralMenu.name = text_table1[22];
  1270. bluetoothSnifferMenu.name = text_table1[23];
  1271. bluetoothGeneralMenu.name = text_table1[24];
  1272. shutdownWiFiMenu.name = text_table1[25];
  1273. shutdownBLEMenu.name = text_table1[26];
  1274. generateSSIDsMenu.name = text_table1[27];
  1275. clearSSIDsMenu.name = text_table1[28];
  1276. clearAPsMenu.name = text_table1[29];
  1277. wifiAPMenu.name = "Access Points";
  1278. // Build Main Menu
  1279. mainMenu.parentMenu = NULL;
  1280. addNodes(&mainMenu, text_table1[7], TFT_GREEN, NULL, WIFI, [this]() {
  1281. changeMenu(&wifiMenu);
  1282. });
  1283. addNodes(&mainMenu, text_table1[19], TFT_CYAN, NULL, BLUETOOTH, [this]() {
  1284. changeMenu(&bluetoothMenu);
  1285. });
  1286. if (a32u4_obj.supported) addNodes(&mainMenu, text_table1[8], TFT_RED, NULL, BAD_USB_ICO, [this]() {
  1287. changeMenu(&badusbMenu);
  1288. });
  1289. addNodes(&mainMenu, text_table1[10], TFT_MAGENTA, NULL, GENERAL_APPS, [this]() {
  1290. changeMenu(&generalMenu);
  1291. });
  1292. addNodes(&mainMenu, text_table1[9], TFT_BLUE, NULL, DEVICE, [this]() {
  1293. changeMenu(&deviceMenu);
  1294. });
  1295. addNodes(&mainMenu, text_table1[30], TFT_LIGHTGREY, NULL, REBOOT, []() {
  1296. ESP.restart();
  1297. });
  1298. // Build WiFi Menu
  1299. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  1300. addNodes(&wifiMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1301. changeMenu(wifiMenu.parentMenu);
  1302. });
  1303. addNodes(&wifiMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  1304. changeMenu(&wifiSnifferMenu);
  1305. });
  1306. //addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  1307. // changeMenu(&wifiScannerMenu);
  1308. //});
  1309. addNodes(&wifiMenu, text_table1[32], TFT_RED, NULL, ATTACKS, [this]() {
  1310. changeMenu(&wifiAttackMenu);
  1311. });
  1312. addNodes(&wifiMenu, text_table1[33], TFT_PURPLE, NULL, GENERAL_APPS, [this]() {
  1313. changeMenu(&wifiGeneralMenu);
  1314. });
  1315. // Build WiFi sniffer Menu
  1316. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  1317. addNodes(&wifiSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1318. changeMenu(wifiSnifferMenu.parentMenu);
  1319. });
  1320. addNodes(&wifiSnifferMenu, text_table1[42], TFT_CYAN, NULL, PROBE_SNIFF, [this]() {
  1321. display_obj.clearScreen();
  1322. this->drawStatusBar();
  1323. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);
  1324. });
  1325. addNodes(&wifiSnifferMenu, text_table1[43], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  1326. display_obj.clearScreen();
  1327. this->drawStatusBar();
  1328. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  1329. });
  1330. addNodes(&wifiSnifferMenu, text_table1[44], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1331. display_obj.clearScreen();
  1332. this->drawStatusBar();
  1333. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  1334. });
  1335. #ifndef MARAUDER_MINI
  1336. addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  1337. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  1338. });
  1339. addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  1340. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  1341. });
  1342. #else
  1343. addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  1344. display_obj.clearScreen();
  1345. this->drawStatusBar();
  1346. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  1347. });
  1348. addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  1349. display_obj.clearScreen();
  1350. this->drawStatusBar();
  1351. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  1352. });
  1353. #endif
  1354. addNodes(&wifiSnifferMenu, text_table1[47], TFT_RED, NULL, PWNAGOTCHI, [this]() {
  1355. display_obj.clearScreen();
  1356. this->drawStatusBar();
  1357. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_RED);
  1358. });
  1359. /*addNodes(&wifiSnifferMenu, text_table1[48], TFT_ORANGE, NULL, ESPRESSIF, [this]() {
  1360. display_obj.clearScreen();
  1361. this->drawStatusBar();
  1362. wifi_scan_obj.StartScan(WIFI_SCAN_ESPRESSIF, TFT_ORANGE);
  1363. });*/
  1364. addNodes(&wifiSnifferMenu, text_table1[49], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  1365. display_obj.clearScreen();
  1366. this->drawStatusBar();
  1367. wifi_scan_obj.StartScan(WIFI_SCAN_TARGET_AP, TFT_MAGENTA);
  1368. });
  1369. addNodes(&wifiSnifferMenu, text_table1[58], TFT_WHITE, NULL, PACKET_MONITOR, [this]() {
  1370. display_obj.clearScreen();
  1371. this->drawStatusBar();
  1372. wifi_scan_obj.StartScan(WIFI_SCAN_RAW_CAPTURE, TFT_WHITE);
  1373. });
  1374. addNodes(&wifiSnifferMenu, text_table1[59], TFT_ORANGE, NULL, PACKET_MONITOR, [this]() {
  1375. display_obj.clearScreen();
  1376. this->drawStatusBar();
  1377. wifi_scan_obj.StartScan(WIFI_SCAN_STATION, TFT_WHITE);
  1378. });
  1379. // Build WiFi attack menu
  1380. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  1381. addNodes(&wifiAttackMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1382. changeMenu(wifiAttackMenu.parentMenu);
  1383. });
  1384. addNodes(&wifiAttackMenu, text_table1[50], TFT_RED, NULL, BEACON_LIST, [this]() {
  1385. display_obj.clearScreen();
  1386. this->drawStatusBar();
  1387. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_LIST, TFT_RED);
  1388. });
  1389. addNodes(&wifiAttackMenu, text_table1[51], TFT_ORANGE, NULL, BEACON_SPAM, [this]() {
  1390. display_obj.clearScreen();
  1391. this->drawStatusBar();
  1392. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  1393. });
  1394. addNodes(&wifiAttackMenu, text_table1[52], TFT_YELLOW, NULL, RICK_ROLL, [this]() {
  1395. display_obj.clearScreen();
  1396. this->drawStatusBar();
  1397. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  1398. });
  1399. addNodes(&wifiAttackMenu, text_table1[53], TFT_RED, NULL, PROBE_SNIFF, [this]() {
  1400. display_obj.clearScreen();
  1401. this->drawStatusBar();
  1402. wifi_scan_obj.StartScan(WIFI_ATTACK_AUTH, TFT_RED);
  1403. });
  1404. addNodes(&wifiAttackMenu, text_table1[54], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1405. display_obj.clearScreen();
  1406. this->drawStatusBar();
  1407. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH, TFT_RED);
  1408. });
  1409. addNodes(&wifiAttackMenu, text_table1[57], TFT_MAGENTA, NULL, BEACON_LIST, [this]() {
  1410. display_obj.clearScreen();
  1411. this->drawStatusBar();
  1412. wifi_scan_obj.StartScan(WIFI_ATTACK_AP_SPAM, TFT_MAGENTA);
  1413. });
  1414. //addNodes(&wifiAttackMenu, "AP Mimic Flood", TFT_PURPLE, NULL, DEAUTH_SNIFF, [this]() {
  1415. // display_obj.clearScreen();
  1416. // this->drawStatusBar();
  1417. // wifi_scan_obj.StartScan(WIFI_ATTACK_MIMIC, TFT_PURPLE);
  1418. //});
  1419. // Build WiFi General menu
  1420. wifiGeneralMenu.parentMenu = &wifiMenu;
  1421. addNodes(&wifiGeneralMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1422. changeMenu(wifiGeneralMenu.parentMenu);
  1423. });
  1424. #ifndef MARAUDER_MINI
  1425. addNodes(&wifiGeneralMenu, text_table1[55], TFT_DARKCYAN, NULL, JOIN_WIFI, [this](){
  1426. display_obj.clearScreen();
  1427. wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
  1428. wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
  1429. joinWiFiGFX();
  1430. });
  1431. #endif
  1432. addNodes(&wifiGeneralMenu, text_table1[25], TFT_CYAN, NULL, SHUTDOWN, [this]() {
  1433. changeMenu(&shutdownWiFiMenu);
  1434. wifi_scan_obj.RunShutdownWiFi();
  1435. });
  1436. addNodes(&wifiGeneralMenu, text_table1[27], TFT_SKYBLUE, NULL, GENERATE, [this]() {
  1437. changeMenu(&generateSSIDsMenu);
  1438. wifi_scan_obj.RunGenerateSSIDs();
  1439. });
  1440. #ifndef MARAUDER_MINI
  1441. addNodes(&wifiGeneralMenu, text_table1[1], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1442. display_obj.clearScreen();
  1443. //wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1444. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_YELLOW);
  1445. addSSIDGFX();
  1446. });
  1447. #endif
  1448. addNodes(&wifiGeneralMenu, text_table1[28], TFT_SILVER, NULL, CLEAR_ICO, [this]() {
  1449. changeMenu(&clearSSIDsMenu);
  1450. wifi_scan_obj.RunClearSSIDs();
  1451. });
  1452. addNodes(&wifiGeneralMenu, text_table1[29], TFT_DARKGREY, NULL, CLEAR_ICO, [this]() {
  1453. changeMenu(&clearAPsMenu);
  1454. wifi_scan_obj.RunClearAPs();
  1455. });
  1456. addNodes(&wifiGeneralMenu, text_table1[60], TFT_BLUE, NULL, CLEAR_ICO, [this]() {
  1457. changeMenu(&clearAPsMenu);
  1458. wifi_scan_obj.RunClearStations();
  1459. });
  1460. #ifndef MARAUDER_MINI
  1461. // Select APs on OG
  1462. addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1463. display_obj.clearScreen();
  1464. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1465. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1466. addAPGFX();
  1467. });
  1468. addNodes(&wifiGeneralMenu, text_table1[61], TFT_LIGHTGREY, NULL, KEYBOARD_ICO, [this](){
  1469. display_obj.clearScreen();
  1470. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1471. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1472. addStationGFX();
  1473. });
  1474. #else
  1475. // Select APs on Mini
  1476. addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1477. wifiAPMenu.list->clear();
  1478. addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1479. changeMenu(wifiAPMenu.parentMenu);
  1480. });
  1481. int menu_limit;
  1482. if (access_points->size() <= BUTTON_ARRAY_LEN)
  1483. menu_limit = access_points->size();
  1484. else
  1485. menu_limit = BUTTON_ARRAY_LEN;
  1486. for (int i = 0; i < menu_limit - 1; i++) {
  1487. addNodes(&wifiAPMenu, access_points->get(i).essid, TFT_CYAN, NULL, KEYBOARD_ICO, [this, i](){
  1488. AccessPoint new_ap = access_points->get(i);
  1489. new_ap.selected = !access_points->get(i).selected;
  1490. // Change selection status of menu node
  1491. MenuNode new_node = current_menu->list->get(i + 1);
  1492. new_node.selected = !current_menu->list->get(i + 1).selected;
  1493. current_menu->list->set(i + 1, new_node);
  1494. // Change selection status of button key
  1495. if (new_ap.selected) {
  1496. this->buttonSelected(i + 1);
  1497. //changeMenu(current_menu);
  1498. } else {
  1499. this->buttonNotSelected(i + 1);
  1500. //changeMenu(current_menu);
  1501. }
  1502. access_points->set(i, new_ap);
  1503. //changeMenu(wifiAPMenu.parentMenu);
  1504. }, access_points->get(i).selected);
  1505. }
  1506. changeMenu(&wifiAPMenu);
  1507. });
  1508. wifiAPMenu.parentMenu = &wifiGeneralMenu;
  1509. addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1510. changeMenu(wifiAPMenu.parentMenu);
  1511. });
  1512. #endif
  1513. // Build shutdown wifi menu
  1514. shutdownWiFiMenu.parentMenu = &wifiGeneralMenu;
  1515. addNodes(&shutdownWiFiMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1516. changeMenu(shutdownWiFiMenu.parentMenu);
  1517. });
  1518. // Build generate ssids menu
  1519. generateSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1520. addNodes(&generateSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1521. changeMenu(generateSSIDsMenu.parentMenu);
  1522. });
  1523. // Build clear ssids menu
  1524. clearSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1525. addNodes(&clearSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1526. changeMenu(clearSSIDsMenu.parentMenu);
  1527. });
  1528. clearAPsMenu.parentMenu = &wifiGeneralMenu;
  1529. addNodes(&clearAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1530. changeMenu(clearAPsMenu.parentMenu);
  1531. });
  1532. // Build Bluetooth Menu
  1533. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  1534. addNodes(&bluetoothMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1535. changeMenu(bluetoothMenu.parentMenu);
  1536. });
  1537. addNodes(&bluetoothMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  1538. changeMenu(&bluetoothSnifferMenu);
  1539. });
  1540. //addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  1541. // changeMenu(&bluetoothScannerMenu);
  1542. //});
  1543. addNodes(&bluetoothMenu, text_table1[33], TFT_PURPLE, NULL, GENERAL_APPS, [this]() {
  1544. changeMenu(&bluetoothGeneralMenu);
  1545. });
  1546. // Build bluetooth sniffer Menu
  1547. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  1548. addNodes(&bluetoothSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1549. changeMenu(bluetoothSnifferMenu.parentMenu);
  1550. });
  1551. addNodes(&bluetoothSnifferMenu, text_table1[34], TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this]() {
  1552. display_obj.clearScreen();
  1553. this->drawStatusBar();
  1554. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  1555. });
  1556. addNodes(&bluetoothSnifferMenu, text_table1[35], TFT_MAGENTA, NULL, CC_SKIMMERS, [this]() {
  1557. display_obj.clearScreen();
  1558. this->drawStatusBar();
  1559. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  1560. });
  1561. // Build bluetooth scanner Menu
  1562. //bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  1563. //addNodes(&bluetoothScannerMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1564. // changeMenu(bluetoothScannerMenu.parentMenu);
  1565. //});
  1566. // Build bluetooth general menu
  1567. bluetoothGeneralMenu.parentMenu = &bluetoothMenu;
  1568. addNodes(&bluetoothGeneralMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1569. changeMenu(bluetoothGeneralMenu.parentMenu);
  1570. });
  1571. addNodes(&bluetoothGeneralMenu, text_table1[26], TFT_ORANGE, NULL, SHUTDOWN, [this]() {
  1572. changeMenu(&shutdownBLEMenu);
  1573. wifi_scan_obj.RunShutdownBLE();
  1574. });
  1575. // Build shutdown BLE menu
  1576. shutdownBLEMenu.parentMenu = &bluetoothGeneralMenu;
  1577. addNodes(&shutdownBLEMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1578. changeMenu(shutdownBLEMenu.parentMenu);
  1579. });
  1580. // Bad USB Menu
  1581. badusbMenu.parentMenu = &mainMenu;
  1582. addNodes(&badusbMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1583. changeMenu(badusbMenu.parentMenu);
  1584. });
  1585. addNodes(&badusbMenu, text_table1[36], TFT_PURPLE, NULL, TEST_BAD_USB_ICO, [this]() {
  1586. a32u4_obj.test();
  1587. });
  1588. #ifndef MARAUDER_MINI
  1589. addNodes(&badusbMenu, text_table1[37], TFT_RED, NULL, BAD_USB_ICO, [this](){
  1590. display_obj.clearScreen();
  1591. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1592. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1593. writeBadUSB();
  1594. });
  1595. #endif
  1596. // General apps menu
  1597. generalMenu.parentMenu = &mainMenu;
  1598. addNodes(&generalMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1599. display_obj.draw_tft = false;
  1600. changeMenu(generalMenu.parentMenu);
  1601. });
  1602. addNodes(&generalMenu, text_table1[38], TFT_WHITE, NULL, DRAW, [this]() {
  1603. display_obj.clearScreen();
  1604. display_obj.setupDraw();
  1605. display_obj.draw_tft = true;
  1606. });
  1607. // Device menu
  1608. deviceMenu.parentMenu = &mainMenu;
  1609. addNodes(&deviceMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1610. changeMenu(deviceMenu.parentMenu);
  1611. });
  1612. //addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  1613. addNodes(&deviceMenu, text_table1[15], TFT_ORANGE, NULL, UPDATE, [this]() {
  1614. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1615. changeMenu(&whichUpdateMenu);
  1616. });
  1617. addNodes(&deviceMenu, text_table1[16], TFT_GREEN, NULL, LANGUAGE, [this]() {
  1618. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1619. changeMenu(&languageMenu);
  1620. });
  1621. addNodes(&deviceMenu, text_table1[17], TFT_WHITE, NULL, DEVICE_INFO, [this]() {
  1622. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1623. changeMenu(&infoMenu);
  1624. wifi_scan_obj.RunInfo();
  1625. });
  1626. addNodes(&deviceMenu, text08, TFT_NAVY, NULL, KEYBOARD_ICO, [this]() {
  1627. changeMenu(&settingsMenu);
  1628. });
  1629. /*addNodes(&deviceMenu, text08, TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1630. display_obj.clearScreen();
  1631. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1632. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1633. displaySettingsGFX();
  1634. });*/
  1635. // Settings menu
  1636. // Device menu
  1637. settingsMenu.parentMenu = &deviceMenu;
  1638. addNodes(&settingsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1639. changeMenu(settingsMenu.parentMenu);
  1640. });
  1641. for (int i = 0; i < settings_obj.getNumberSettings(); i++) {
  1642. if (this->callSetting(settings_obj.setting_index_to_name(i)) == "bool")
  1643. addNodes(&settingsMenu, settings_obj.setting_index_to_name(i), TFT_LIGHTGREY, NULL, 0, [this, i]() {
  1644. settings_obj.toggleSetting(settings_obj.setting_index_to_name(i));
  1645. changeMenu(&specSettingMenu);
  1646. //this->callSetting(settings_obj.setting_index_to_name(i));
  1647. this->displaySetting(settings_obj.setting_index_to_name(i), &settingsMenu, i + 1);
  1648. }, settings_obj.loadSetting<bool>(settings_obj.setting_index_to_name(i)));
  1649. }
  1650. // Specific setting menu
  1651. specSettingMenu.parentMenu = &settingsMenu;
  1652. addNodes(&specSettingMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1653. changeMenu(specSettingMenu.parentMenu);
  1654. });
  1655. // Select update
  1656. whichUpdateMenu.parentMenu = &deviceMenu;
  1657. addNodes(&whichUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1658. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1659. changeMenu(whichUpdateMenu.parentMenu);
  1660. });
  1661. addNodes(&whichUpdateMenu, text_table1[39], TFT_GREEN, NULL, WEB_UPDATE, [this]() {
  1662. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1663. changeMenu(&updateMenu);
  1664. web_obj.setupOTAupdate();
  1665. });
  1666. if (sd_obj.supported) addNodes(&whichUpdateMenu, text_table1[40], TFT_MAGENTA, NULL, SD_UPDATE, [this]() {
  1667. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1668. changeMenu(&confirmMenu);
  1669. });
  1670. addNodes(&whichUpdateMenu, text_table1[41], TFT_RED, NULL, ESP_UPDATE_ICO, [this]() {
  1671. wifi_scan_obj.currentScanMode = ESP_UPDATE;
  1672. changeMenu(&espUpdateMenu);
  1673. esp_obj.RunUpdate();
  1674. });
  1675. // ESP Update Menu
  1676. espUpdateMenu.parentMenu = &whichUpdateMenu;
  1677. addNodes(&espUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1678. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1679. esp_obj.bootRunMode();
  1680. changeMenu(espUpdateMenu.parentMenu);
  1681. });
  1682. // Confirm SD update menu
  1683. confirmMenu.parentMenu = &whichUpdateMenu;
  1684. addNodes(&confirmMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1685. changeMenu(confirmMenu.parentMenu);
  1686. });
  1687. //addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); sd_obj.runUpdate();});
  1688. addNodes(&confirmMenu, text14, TFT_ORANGE, NULL, UPDATE, [this]() {
  1689. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1690. changeMenu(&failedUpdateMenu);
  1691. sd_obj.runUpdate();
  1692. });
  1693. // Web Update
  1694. updateMenu.parentMenu = &deviceMenu;
  1695. addNodes(&updateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1696. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1697. changeMenu(updateMenu.parentMenu);
  1698. WiFi.softAPdisconnect(true);
  1699. web_obj.shutdownServer();
  1700. });
  1701. //addNodes(&updateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
  1702. // Failed update menu
  1703. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  1704. addNodes(&failedUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1705. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1706. changeMenu(failedUpdateMenu.parentMenu);
  1707. });
  1708. // Device info menu
  1709. infoMenu.parentMenu = &deviceMenu;
  1710. addNodes(&infoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1711. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1712. changeMenu(infoMenu.parentMenu);
  1713. });
  1714. //language info menu
  1715. languageMenu.parentMenu = &deviceMenu;
  1716. addNodes(&languageMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1717. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1718. changeMenu(infoMenu.parentMenu);
  1719. });
  1720. // Set the current menu to the mainMenu
  1721. changeMenu(&mainMenu);
  1722. this->initTime = millis();
  1723. }
  1724. // Function to change menu
  1725. void MenuFunctions::changeMenu(Menu * menu)
  1726. {
  1727. display_obj.initScrollValues();
  1728. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  1729. display_obj.tft.init();
  1730. current_menu = menu;
  1731. buildButtons(menu);
  1732. displayCurrentMenu();
  1733. }
  1734. // Function to show all MenuNodes in a Menu
  1735. void MenuFunctions::showMenuList(Menu * menu, int layer)
  1736. {
  1737. // Iterate through all of the menu nodes in the menu
  1738. for (uint8_t i = 0; i < menu->list->size(); i++)
  1739. {
  1740. // Depending on layer, indent
  1741. for (uint8_t x = 0; x < layer * 4; x++)
  1742. Serial.print(" ");
  1743. Serial.print("Node: ");
  1744. Serial.println(menu->list->get(i).name);
  1745. }
  1746. Serial.println();
  1747. }
  1748. // Function to add MenuNodes to a menu
  1749. void MenuFunctions::addNodes(Menu * menu, String name, uint16_t color, Menu * child, int place, std::function<void()> callable, bool selected, String command)
  1750. {
  1751. TFT_eSPI_Button new_button;
  1752. menu->list->add(MenuNode{name, command, color, place, &new_button, selected, callable});
  1753. //menu->list->add(MenuNode{name, color, place, callable});
  1754. }
  1755. void MenuFunctions::buildButtons(Menu * menu, int starting_index)
  1756. {
  1757. //Serial.println("Bulding buttons...");
  1758. if (menu->list != NULL)
  1759. {
  1760. //for (int i = 0; i < sizeof(key); i++)
  1761. // key[i] = NULL;
  1762. for (uint8_t i = 0; i < menu->list->size(); i++)
  1763. {
  1764. TFT_eSPI_Button new_button;
  1765. char buf[menu->list->get(starting_index + i).name.length() + 1] = {};
  1766. menu->list->get(starting_index + i).name.toCharArray(buf, menu->list->get(starting_index + i).name.length() + 1);
  1767. display_obj.key[i].initButton(&display_obj.tft,
  1768. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  1769. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  1770. KEY_W,
  1771. KEY_H,
  1772. TFT_BLACK, // Outline
  1773. TFT_BLACK, // Fill
  1774. menu->list->get(starting_index + i).color, // Text
  1775. buf,
  1776. KEY_TEXTSIZE);
  1777. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W / 2), 2, ML_DATUM);
  1778. }
  1779. }
  1780. }
  1781. void MenuFunctions::displayCurrentMenu()
  1782. {
  1783. //Serial.println(F("Displaying current menu..."));
  1784. display_obj.clearScreen();
  1785. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  1786. this->drawStatusBar();
  1787. if (current_menu->list != NULL)
  1788. {
  1789. #ifndef MARAUDER_MINI
  1790. display_obj.tft.setFreeFont(MENU_FONT);
  1791. #endif
  1792. #ifdef MARAUDER_MINI
  1793. display_obj.tft.setFreeFont(NULL);
  1794. display_obj.tft.setTextSize(1);
  1795. #endif
  1796. for (uint8_t i = 0; i < current_menu->list->size(); i++)
  1797. {
  1798. #ifndef MARAUDER_MINI
  1799. if (!current_menu->list->get(i).selected)
  1800. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1801. else
  1802. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1803. if (current_menu->list->get(i).name != text09)
  1804. display_obj.tft.drawXBitmap(0,
  1805. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  1806. menu_icons[current_menu->list->get(i).icon],
  1807. ICON_W,
  1808. ICON_H,
  1809. TFT_BLACK,
  1810. current_menu->list->get(i).color);
  1811. #endif
  1812. #ifdef MARAUDER_MINI
  1813. if ((current_menu->selected == i) || (current_menu->list->get(i).selected))
  1814. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1815. else
  1816. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1817. #endif
  1818. }
  1819. display_obj.tft.setFreeFont(NULL);
  1820. }
  1821. }
  1822. #endif