MenuFunctions.cpp 74 KB

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