MenuFunctions.cpp 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060
  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_AP) ||
  704. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  705. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  706. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  707. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  708. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  709. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  710. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  711. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  712. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  713. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  714. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  715. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  716. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  717. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  718. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  719. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  720. {
  721. //Serial.println("Stopping scan...");
  722. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  723. // If we don't do this, the text and button coordinates will be off
  724. display_obj.tft.init();
  725. // Take us back to the menu
  726. changeMenu(current_menu);
  727. }
  728. x = -1;
  729. y = -1;
  730. return;
  731. }
  732. #endif
  733. #ifdef MARAUDER_MINI
  734. bool c_btn_press = c_btn.justPressed();
  735. if ((c_btn_press) &&
  736. (wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  737. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  738. (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
  739. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  740. {
  741. // Stop the current scan
  742. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  743. (wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  744. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  745. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
  746. (wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  747. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  748. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  749. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  750. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  751. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  752. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
  753. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
  754. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
  755. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  756. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
  757. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  758. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  759. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  760. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS) ||
  761. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL) ||
  762. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
  763. (wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR))
  764. {
  765. //Serial.println("Stopping scan...");
  766. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  767. // If we don't do this, the text and button coordinates will be off
  768. display_obj.tft.init();
  769. // Take us back to the menu
  770. changeMenu(current_menu);
  771. }
  772. x = -1;
  773. y = -1;
  774. return;
  775. }
  776. #endif
  777. // Check if any key coordinate boxes contain the touch coordinates
  778. // This is for when on a menu
  779. #ifndef MARAUDER_MINI
  780. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  781. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
  782. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
  783. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
  784. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
  785. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
  786. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  787. //(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_LIST))
  788. {
  789. // Need this to set all keys to false
  790. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  791. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  792. display_obj.key[b].press(true); // tell the button it is pressed
  793. } else {
  794. display_obj.key[b].press(false); // tell the button it is NOT pressed
  795. }
  796. }
  797. // Check if any key has changed state
  798. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  799. display_obj.tft.setFreeFont(MENU_FONT);
  800. if (display_obj.key[b].justPressed()) {
  801. //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  802. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true);
  803. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  804. if (current_menu->list->get(b).name != text09)
  805. display_obj.tft.drawXBitmap(0,
  806. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  807. menu_icons[current_menu->list->get(b).icon],
  808. ICON_W,
  809. ICON_H,
  810. current_menu->list->get(b).color,
  811. TFT_BLACK);
  812. }
  813. //else if (pressed)
  814. // display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  815. // If button was just release, execute the button's function
  816. if ((display_obj.key[b].justReleased()) && (!pressed))
  817. {
  818. //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  819. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name);
  820. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  821. current_menu->list->get(b).callable();
  822. }
  823. // This
  824. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  825. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  826. if (current_menu->list->get(b).name != text09)
  827. display_obj.tft.drawXBitmap(0,
  828. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  829. menu_icons[current_menu->list->get(b).icon],
  830. ICON_W,
  831. ICON_H,
  832. TFT_BLACK,
  833. current_menu->list->get(b).color);
  834. }
  835. display_obj.tft.setFreeFont(NULL);
  836. }
  837. }
  838. x = -1;
  839. y = -1;
  840. #endif
  841. #ifdef MARAUDER_MINI
  842. if (u_btn.justPressed()){
  843. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  844. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  845. if (current_menu->selected > 0) {
  846. current_menu->selected--;
  847. this->buttonSelected(current_menu->selected);
  848. if (!current_menu->list->get(current_menu->selected + 1).selected)
  849. this->buttonNotSelected(current_menu->selected + 1);
  850. }
  851. }
  852. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  853. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  854. if (wifi_scan_obj.set_channel < 14)
  855. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel + 1);
  856. }
  857. }
  858. if (d_btn.justPressed()){
  859. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  860. (wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
  861. if (current_menu->selected < current_menu->list->size() - 1) {
  862. current_menu->selected++;
  863. this->buttonSelected(current_menu->selected);
  864. if (!current_menu->list->get(current_menu->selected - 1).selected)
  865. this->buttonNotSelected(current_menu->selected - 1);
  866. }
  867. }
  868. else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
  869. (wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
  870. if (wifi_scan_obj.set_channel > 1)
  871. wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel - 1);
  872. }
  873. }
  874. if(c_btn_press){
  875. current_menu->list->get(current_menu->selected).callable();
  876. }
  877. #endif
  878. }
  879. #if BATTERY_ANALOG_ON == 1
  880. byte battery_analog_array[10];
  881. byte battery_count = 0;
  882. byte battery_analog_last = 101;
  883. #define BATTERY_CHECK 50
  884. uint16_t battery_analog = 0;
  885. void MenuFunctions::battery(bool initial)
  886. {
  887. if (BATTERY_ANALOG_ON) {
  888. uint8_t n = 0;
  889. byte battery_analog_sample[10];
  890. byte deviation;
  891. if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
  892. else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
  893. if (battery_count == 0) {
  894. battery_analog = 0;
  895. for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
  896. for (n = 0; n < 10; n++) {
  897. battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
  898. if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
  899. else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
  900. battery_analog += battery_analog_sample[n];
  901. }
  902. battery_analog = battery_analog / 10;
  903. for (n = 0; n < 10; n++) {
  904. deviation = abs(battery_analog - battery_analog_sample[n]);
  905. if (deviation >= 10) battery_analog_sample[n] = battery_analog;
  906. }
  907. battery_analog = 0;
  908. for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
  909. battery_analog = battery_analog / 10;
  910. battery_analog_array[0] = battery_analog;
  911. if (battery_analog_array[9] > 0 ) {
  912. battery_analog = 0;
  913. for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
  914. battery_analog = battery_analog / 10;
  915. }
  916. battery_count ++;
  917. }
  918. else if (battery_count < BATTERY_CHECK) battery_count++;
  919. else if (battery_count >= BATTERY_CHECK) battery_count = 0;
  920. if (battery_analog_last != battery_analog) {
  921. battery_analog_last = battery_analog;
  922. MenuFunctions::battery2();
  923. }
  924. }
  925. }
  926. void MenuFunctions::battery2(bool initial)
  927. {
  928. uint16_t the_color;
  929. if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
  930. else if (battery_analog < 20) the_color = TFT_RED;
  931. else if (battery_analog < 40) the_color = TFT_YELLOW;
  932. else the_color = TFT_GREEN;
  933. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  934. display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  935. display_obj.tft.drawXBitmap(186,
  936. 0,
  937. menu_icons[STATUS_BAT],
  938. 16,
  939. 16,
  940. STATUSBAR_COLOR,
  941. the_color);
  942. display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
  943. }
  944. #else
  945. void MenuFunctions::battery(bool initial)
  946. {
  947. uint16_t the_color;
  948. if (battery_obj.i2c_supported)
  949. {
  950. // Could use int compare maybe idk
  951. if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
  952. the_color = TFT_GREEN;
  953. else
  954. the_color = TFT_RED;
  955. if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
  956. battery_obj.old_level = battery_obj.battery_level;
  957. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  958. display_obj.tft.setCursor(0, 1);
  959. display_obj.tft.drawXBitmap(186,
  960. 0,
  961. menu_icons[STATUS_BAT],
  962. 16,
  963. 16,
  964. STATUSBAR_COLOR,
  965. the_color);
  966. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  967. }
  968. }
  969. }
  970. void MenuFunctions::battery2(bool initial)
  971. {
  972. MenuFunctions::battery(initial);
  973. }
  974. #endif
  975. void MenuFunctions::updateStatusBar()
  976. {
  977. display_obj.tft.setTextSize(1);
  978. #ifdef MARAUDER_MINI
  979. display_obj.tft.setFreeFont(NULL);
  980. #endif
  981. uint16_t the_color;
  982. // Draw temp info
  983. if (temp_obj.current_temp < 70)
  984. the_color = TFT_GREEN;
  985. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  986. the_color = TFT_YELLOW;
  987. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  988. the_color = TFT_ORANGE;
  989. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  990. the_color = TFT_RED;
  991. else
  992. the_color = TFT_MAROON;
  993. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  994. if (temp_obj.current_temp != temp_obj.old_temp) {
  995. temp_obj.old_temp = temp_obj.current_temp;
  996. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  997. #ifndef MARAUDER_MINI
  998. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  999. #endif
  1000. #ifdef MARAUDER_MINI
  1001. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1);
  1002. #endif
  1003. }
  1004. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1005. // WiFi Channel Stuff
  1006. if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) {
  1007. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  1008. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1009. #ifndef MARAUDER_MINI
  1010. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  1011. #endif
  1012. #ifdef MARAUDER_MINI
  1013. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  1014. #endif
  1015. }
  1016. // RAM Stuff
  1017. wifi_scan_obj.freeRAM();
  1018. if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) {
  1019. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  1020. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1021. #ifndef MARAUDER_MINI
  1022. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  1023. #endif
  1024. #ifdef MARAUDER_MINI
  1025. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  1026. #endif
  1027. }
  1028. // Draw battery info
  1029. MenuFunctions::battery(false);
  1030. // Draw SD info
  1031. if (sd_obj.supported)
  1032. the_color = TFT_GREEN;
  1033. else
  1034. the_color = TFT_RED;
  1035. #ifndef MARAUDER_MINI
  1036. display_obj.tft.drawXBitmap(170,
  1037. 0,
  1038. menu_icons[STATUS_SD],
  1039. 16,
  1040. 16,
  1041. STATUSBAR_COLOR,
  1042. the_color);
  1043. #endif
  1044. #ifdef MARAUDER_MINI
  1045. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1046. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  1047. #endif
  1048. }
  1049. void MenuFunctions::drawStatusBar()
  1050. {
  1051. display_obj.tft.setTextSize(1);
  1052. #ifdef MARAUDER_MINI
  1053. display_obj.tft.setFreeFont(NULL);
  1054. #endif
  1055. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1056. //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY);
  1057. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1058. //display_obj.tft.setTextSize(2);
  1059. uint16_t the_color;
  1060. // Draw temp info
  1061. if (temp_obj.current_temp < 70)
  1062. the_color = TFT_GREEN;
  1063. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  1064. the_color = TFT_YELLOW;
  1065. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  1066. the_color = TFT_ORANGE;
  1067. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  1068. the_color = TFT_RED;
  1069. else
  1070. the_color = TFT_MAROON;
  1071. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1072. temp_obj.old_temp = temp_obj.current_temp;
  1073. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1074. #ifndef MARAUDER_MINI
  1075. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  1076. #endif
  1077. #ifdef MARAUDER_MINI
  1078. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1);
  1079. #endif
  1080. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  1081. // WiFi Channel Stuff
  1082. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  1083. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1084. #ifndef MARAUDER_MINI
  1085. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  1086. #endif
  1087. #ifdef MARAUDER_MINI
  1088. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
  1089. #endif
  1090. // RAM Stuff
  1091. wifi_scan_obj.freeRAM();
  1092. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  1093. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  1094. #ifndef MARAUDER_MINI
  1095. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  1096. #endif
  1097. #ifdef MARAUDER_MINI
  1098. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);
  1099. #endif
  1100. MenuFunctions::battery2(true);
  1101. // Draw SD info
  1102. if (sd_obj.supported)
  1103. the_color = TFT_GREEN;
  1104. else
  1105. the_color = TFT_RED;
  1106. #ifndef MARAUDER_MINI
  1107. display_obj.tft.drawXBitmap(170,
  1108. 0,
  1109. menu_icons[STATUS_SD],
  1110. 16,
  1111. 16,
  1112. STATUSBAR_COLOR,
  1113. the_color);
  1114. #endif
  1115. #ifdef MARAUDER_MINI
  1116. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  1117. display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1);
  1118. #endif
  1119. }
  1120. void MenuFunctions::orientDisplay()
  1121. {
  1122. display_obj.tft.init();
  1123. display_obj.tft.setRotation(0); // Portrait
  1124. display_obj.tft.setCursor(0, 0);
  1125. #ifndef MARAUDER_MINI
  1126. #ifdef TFT_SHIELD
  1127. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  1128. //Serial.println("Using TFT Shield");
  1129. #else if defined(TFT_DIY)
  1130. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  1131. //Serial.println("Using TFT DIY");
  1132. #endif
  1133. display_obj.tft.setTouch(calData);
  1134. #endif
  1135. changeMenu(current_menu);
  1136. }
  1137. void MenuFunctions::runBoolSetting(String key) {
  1138. //Serial.println("Building bool setting screen...");
  1139. display_obj.tftDrawRedOnOffButton();
  1140. //display_obj.tftDrawGreenOnOffButton();
  1141. }
  1142. String MenuFunctions::callSetting(String key) {
  1143. specSettingMenu.name = key;
  1144. String setting_type = settings_obj.getSettingType(key);
  1145. if (setting_type == "bool") {
  1146. return "bool";
  1147. }
  1148. }
  1149. void MenuFunctions::displaySetting(String key, Menu* menu, int index) {
  1150. specSettingMenu.name = key;
  1151. bool setting_value = settings_obj.loadSetting<bool>(key);
  1152. // Make a local copy of menu node
  1153. MenuNode node = menu->list->get(index);
  1154. display_obj.tft.setTextWrap(false);
  1155. display_obj.tft.setFreeFont(NULL);
  1156. display_obj.tft.setCursor(0, 100);
  1157. display_obj.tft.setTextSize(1);
  1158. // Set local copy value
  1159. if (!setting_value) {
  1160. display_obj.tft.setTextColor(TFT_RED);
  1161. display_obj.tft.println(F(text_table1[4]));
  1162. node.selected = false;
  1163. }
  1164. else {
  1165. display_obj.tft.setTextColor(TFT_GREEN);
  1166. display_obj.tft.println(F(text_table1[5]));
  1167. node.selected = true;
  1168. }
  1169. // Put local copy back into menu
  1170. menu->list->set(index, node);
  1171. }
  1172. // Function to build the menus
  1173. void MenuFunctions::RunSetup()
  1174. {
  1175. extern LinkedList<AccessPoint>* access_points;
  1176. #ifndef MARAUDER_MINI
  1177. this->initLVGL();
  1178. #endif
  1179. // root menu stuff
  1180. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  1181. // Main menu stuff
  1182. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  1183. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  1184. badusbMenu.list = new LinkedList<MenuNode>();
  1185. generalMenu.list = new LinkedList<MenuNode>();
  1186. deviceMenu.list = new LinkedList<MenuNode>();
  1187. // Device menu stuff
  1188. failedUpdateMenu.list = new LinkedList<MenuNode>();
  1189. whichUpdateMenu.list = new LinkedList<MenuNode>();
  1190. confirmMenu.list = new LinkedList<MenuNode>();
  1191. espUpdateMenu.list = new LinkedList<MenuNode>();
  1192. updateMenu.list = new LinkedList<MenuNode>();
  1193. settingsMenu.list = new LinkedList<MenuNode>();
  1194. specSettingMenu.list = new LinkedList<MenuNode>();
  1195. infoMenu.list = new LinkedList<MenuNode>();
  1196. languageMenu.list = new LinkedList<MenuNode>();
  1197. // WiFi menu stuff
  1198. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  1199. wifiAttackMenu.list = new LinkedList<MenuNode>();
  1200. wifiGeneralMenu.list = new LinkedList<MenuNode>();
  1201. wifiAPMenu.list = new LinkedList<MenuNode>();
  1202. // Bluetooth menu stuff
  1203. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  1204. bluetoothGeneralMenu.list = new LinkedList<MenuNode>();
  1205. // Settings stuff
  1206. shutdownWiFiMenu.list = new LinkedList<MenuNode>();
  1207. shutdownBLEMenu.list = new LinkedList<MenuNode>();
  1208. generateSSIDsMenu.list = new LinkedList<MenuNode>();
  1209. clearSSIDsMenu.list = new LinkedList<MenuNode>();
  1210. clearAPsMenu.list = new LinkedList<MenuNode>();
  1211. // Work menu names
  1212. mainMenu.name = text_table1[6];
  1213. wifiMenu.name = text_table1[7];
  1214. badusbMenu.name = text_table1[8];
  1215. deviceMenu.name = text_table1[9];
  1216. generalMenu.name = text_table1[10];
  1217. failedUpdateMenu.name = text_table1[11];
  1218. whichUpdateMenu.name = text_table1[12];
  1219. confirmMenu.name = text_table1[13];
  1220. espUpdateMenu.name = text_table1[14];
  1221. updateMenu.name = text_table1[15];
  1222. languageMenu.name = text_table1[16];
  1223. infoMenu.name = text_table1[17];
  1224. settingsMenu.name = text_table1[18];
  1225. bluetoothMenu.name = text_table1[19];
  1226. wifiSnifferMenu.name = text_table1[20];
  1227. wifiAttackMenu.name = text_table1[21];
  1228. wifiGeneralMenu.name = text_table1[22];
  1229. bluetoothSnifferMenu.name = text_table1[23];
  1230. bluetoothGeneralMenu.name = text_table1[24];
  1231. shutdownWiFiMenu.name = text_table1[25];
  1232. shutdownBLEMenu.name = text_table1[26];
  1233. generateSSIDsMenu.name = text_table1[27];
  1234. clearSSIDsMenu.name = text_table1[28];
  1235. clearAPsMenu.name = text_table1[29];
  1236. wifiAPMenu.name = "Access Points";
  1237. // Build Main Menu
  1238. mainMenu.parentMenu = NULL;
  1239. addNodes(&mainMenu, text_table1[7], TFT_GREEN, NULL, WIFI, [this]() {
  1240. changeMenu(&wifiMenu);
  1241. });
  1242. addNodes(&mainMenu, text_table1[19], TFT_CYAN, NULL, BLUETOOTH, [this]() {
  1243. changeMenu(&bluetoothMenu);
  1244. });
  1245. if (a32u4_obj.supported) addNodes(&mainMenu, text_table1[8], TFT_RED, NULL, BAD_USB_ICO, [this]() {
  1246. changeMenu(&badusbMenu);
  1247. });
  1248. addNodes(&mainMenu, text_table1[10], TFT_MAGENTA, NULL, GENERAL_APPS, [this]() {
  1249. changeMenu(&generalMenu);
  1250. });
  1251. addNodes(&mainMenu, text_table1[9], TFT_BLUE, NULL, DEVICE, [this]() {
  1252. changeMenu(&deviceMenu);
  1253. });
  1254. addNodes(&mainMenu, text_table1[30], TFT_LIGHTGREY, NULL, REBOOT, []() {
  1255. ESP.restart();
  1256. });
  1257. // Build WiFi Menu
  1258. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  1259. addNodes(&wifiMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1260. changeMenu(wifiMenu.parentMenu);
  1261. });
  1262. addNodes(&wifiMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  1263. changeMenu(&wifiSnifferMenu);
  1264. });
  1265. //addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  1266. // changeMenu(&wifiScannerMenu);
  1267. //});
  1268. addNodes(&wifiMenu, text_table1[32], TFT_RED, NULL, ATTACKS, [this]() {
  1269. changeMenu(&wifiAttackMenu);
  1270. });
  1271. addNodes(&wifiMenu, text_table1[33], TFT_PURPLE, NULL, GENERAL_APPS, [this]() {
  1272. changeMenu(&wifiGeneralMenu);
  1273. });
  1274. // Build WiFi sniffer Menu
  1275. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  1276. addNodes(&wifiSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1277. changeMenu(wifiSnifferMenu.parentMenu);
  1278. });
  1279. addNodes(&wifiSnifferMenu, text_table1[42], TFT_CYAN, NULL, PROBE_SNIFF, [this]() {
  1280. display_obj.clearScreen();
  1281. this->drawStatusBar();
  1282. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);
  1283. });
  1284. addNodes(&wifiSnifferMenu, text_table1[43], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  1285. display_obj.clearScreen();
  1286. this->drawStatusBar();
  1287. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  1288. });
  1289. addNodes(&wifiSnifferMenu, text_table1[44], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1290. display_obj.clearScreen();
  1291. this->drawStatusBar();
  1292. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  1293. });
  1294. #ifndef MARAUDER_MINI
  1295. addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  1296. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  1297. });
  1298. addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  1299. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  1300. });
  1301. #else
  1302. addNodes(&wifiSnifferMenu, text_table1[46], TFT_VIOLET, NULL, EAPOL, [this]() {
  1303. display_obj.clearScreen();
  1304. this->drawStatusBar();
  1305. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  1306. });
  1307. addNodes(&wifiSnifferMenu, text_table1[45], TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  1308. display_obj.clearScreen();
  1309. this->drawStatusBar();
  1310. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  1311. });
  1312. #endif
  1313. addNodes(&wifiSnifferMenu, text_table1[47], TFT_RED, NULL, PWNAGOTCHI, [this]() {
  1314. display_obj.clearScreen();
  1315. this->drawStatusBar();
  1316. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_RED);
  1317. });
  1318. addNodes(&wifiSnifferMenu, text_table1[48], TFT_ORANGE, NULL, ESPRESSIF, [this]() {
  1319. display_obj.clearScreen();
  1320. this->drawStatusBar();
  1321. wifi_scan_obj.StartScan(WIFI_SCAN_ESPRESSIF, TFT_ORANGE);
  1322. });
  1323. addNodes(&wifiSnifferMenu, text_table1[49], TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  1324. display_obj.clearScreen();
  1325. this->drawStatusBar();
  1326. wifi_scan_obj.StartScan(WIFI_SCAN_TARGET_AP, TFT_MAGENTA);
  1327. });
  1328. addNodes(&wifiSnifferMenu, text_table1[58], TFT_WHITE, NULL, PACKET_MONITOR, [this]() {
  1329. display_obj.clearScreen();
  1330. this->drawStatusBar();
  1331. wifi_scan_obj.StartScan(WIFI_SCAN_RAW_CAPTURE, TFT_WHITE);
  1332. });
  1333. // Build WiFi attack menu
  1334. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  1335. addNodes(&wifiAttackMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1336. changeMenu(wifiAttackMenu.parentMenu);
  1337. });
  1338. addNodes(&wifiAttackMenu, text_table1[50], TFT_RED, NULL, BEACON_LIST, [this]() {
  1339. display_obj.clearScreen();
  1340. this->drawStatusBar();
  1341. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_LIST, TFT_RED);
  1342. });
  1343. addNodes(&wifiAttackMenu, text_table1[51], TFT_ORANGE, NULL, BEACON_SPAM, [this]() {
  1344. display_obj.clearScreen();
  1345. this->drawStatusBar();
  1346. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  1347. });
  1348. addNodes(&wifiAttackMenu, text_table1[52], TFT_YELLOW, NULL, RICK_ROLL, [this]() {
  1349. display_obj.clearScreen();
  1350. this->drawStatusBar();
  1351. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  1352. });
  1353. addNodes(&wifiAttackMenu, text_table1[53], TFT_RED, NULL, PROBE_SNIFF, [this]() {
  1354. display_obj.clearScreen();
  1355. this->drawStatusBar();
  1356. wifi_scan_obj.StartScan(WIFI_ATTACK_AUTH, TFT_RED);
  1357. });
  1358. addNodes(&wifiAttackMenu, text_table1[54], TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  1359. display_obj.clearScreen();
  1360. this->drawStatusBar();
  1361. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH, TFT_RED);
  1362. });
  1363. addNodes(&wifiAttackMenu, text_table1[57], TFT_MAGENTA, NULL, BEACON_LIST, [this]() {
  1364. display_obj.clearScreen();
  1365. this->drawStatusBar();
  1366. wifi_scan_obj.StartScan(WIFI_ATTACK_AP_SPAM, TFT_MAGENTA);
  1367. });
  1368. //addNodes(&wifiAttackMenu, "AP Mimic Flood", TFT_PURPLE, NULL, DEAUTH_SNIFF, [this]() {
  1369. // display_obj.clearScreen();
  1370. // this->drawStatusBar();
  1371. // wifi_scan_obj.StartScan(WIFI_ATTACK_MIMIC, TFT_PURPLE);
  1372. //});
  1373. // Build WiFi General menu
  1374. wifiGeneralMenu.parentMenu = &wifiMenu;
  1375. addNodes(&wifiGeneralMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1376. changeMenu(wifiGeneralMenu.parentMenu);
  1377. });
  1378. #ifndef MARAUDER_MINI
  1379. addNodes(&wifiGeneralMenu, text_table1[55], TFT_DARKCYAN, NULL, JOIN_WIFI, [this](){
  1380. display_obj.clearScreen();
  1381. wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
  1382. wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
  1383. joinWiFiGFX();
  1384. });
  1385. #endif
  1386. addNodes(&wifiGeneralMenu, text_table1[25], TFT_CYAN, NULL, SHUTDOWN, [this]() {
  1387. changeMenu(&shutdownWiFiMenu);
  1388. wifi_scan_obj.RunShutdownWiFi();
  1389. });
  1390. addNodes(&wifiGeneralMenu, text_table1[27], TFT_SKYBLUE, NULL, GENERATE, [this]() {
  1391. changeMenu(&generateSSIDsMenu);
  1392. wifi_scan_obj.RunGenerateSSIDs();
  1393. });
  1394. #ifndef MARAUDER_MINI
  1395. addNodes(&wifiGeneralMenu, text_table1[1], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1396. display_obj.clearScreen();
  1397. //wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1398. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_YELLOW);
  1399. addSSIDGFX();
  1400. });
  1401. #endif
  1402. addNodes(&wifiGeneralMenu, text_table1[28], TFT_SILVER, NULL, CLEAR_ICO, [this]() {
  1403. changeMenu(&clearSSIDsMenu);
  1404. wifi_scan_obj.RunClearSSIDs();
  1405. });
  1406. addNodes(&wifiGeneralMenu, text_table1[29], TFT_DARKGREY, NULL, CLEAR_ICO, [this]() {
  1407. changeMenu(&clearAPsMenu);
  1408. wifi_scan_obj.RunClearAPs();
  1409. });
  1410. #ifndef MARAUDER_MINI
  1411. // Select APs on OG
  1412. addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1413. display_obj.clearScreen();
  1414. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1415. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1416. addAPGFX();
  1417. });
  1418. #else
  1419. // Select APs on Mini
  1420. addNodes(&wifiGeneralMenu, text_table1[56], TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1421. wifiAPMenu.list->clear();
  1422. addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1423. changeMenu(wifiAPMenu.parentMenu);
  1424. });
  1425. int menu_limit;
  1426. if (access_points->size() <= BUTTON_ARRAY_LEN)
  1427. menu_limit = access_points->size();
  1428. else
  1429. menu_limit = BUTTON_ARRAY_LEN;
  1430. for (int i = 0; i < menu_limit - 1; i++) {
  1431. addNodes(&wifiAPMenu, access_points->get(i).essid, TFT_CYAN, NULL, KEYBOARD_ICO, [this, i](){
  1432. AccessPoint new_ap = access_points->get(i);
  1433. new_ap.selected = !access_points->get(i).selected;
  1434. // Change selection status of menu node
  1435. MenuNode new_node = current_menu->list->get(i + 1);
  1436. new_node.selected = !current_menu->list->get(i + 1).selected;
  1437. current_menu->list->set(i + 1, new_node);
  1438. // Change selection status of button key
  1439. if (new_ap.selected) {
  1440. this->buttonSelected(i + 1);
  1441. //changeMenu(current_menu);
  1442. } else {
  1443. this->buttonNotSelected(i + 1);
  1444. //changeMenu(current_menu);
  1445. }
  1446. access_points->set(i, new_ap);
  1447. //changeMenu(wifiAPMenu.parentMenu);
  1448. }, access_points->get(i).selected);
  1449. }
  1450. changeMenu(&wifiAPMenu);
  1451. });
  1452. wifiAPMenu.parentMenu = &wifiGeneralMenu;
  1453. addNodes(&wifiAPMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1454. changeMenu(wifiAPMenu.parentMenu);
  1455. });
  1456. #endif
  1457. // Build shutdown wifi menu
  1458. shutdownWiFiMenu.parentMenu = &wifiGeneralMenu;
  1459. addNodes(&shutdownWiFiMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1460. changeMenu(shutdownWiFiMenu.parentMenu);
  1461. });
  1462. // Build generate ssids menu
  1463. generateSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1464. addNodes(&generateSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1465. changeMenu(generateSSIDsMenu.parentMenu);
  1466. });
  1467. // Build clear ssids menu
  1468. clearSSIDsMenu.parentMenu = &wifiGeneralMenu;
  1469. addNodes(&clearSSIDsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1470. changeMenu(clearSSIDsMenu.parentMenu);
  1471. });
  1472. clearAPsMenu.parentMenu = &wifiGeneralMenu;
  1473. addNodes(&clearAPsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1474. changeMenu(clearAPsMenu.parentMenu);
  1475. });
  1476. // Build Bluetooth Menu
  1477. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  1478. addNodes(&bluetoothMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1479. changeMenu(bluetoothMenu.parentMenu);
  1480. });
  1481. addNodes(&bluetoothMenu, text_table1[31], TFT_YELLOW, NULL, SNIFFERS, [this]() {
  1482. changeMenu(&bluetoothSnifferMenu);
  1483. });
  1484. //addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  1485. // changeMenu(&bluetoothScannerMenu);
  1486. //});
  1487. addNodes(&bluetoothMenu, text_table1[33], TFT_PURPLE, NULL, GENERAL_APPS, [this]() {
  1488. changeMenu(&bluetoothGeneralMenu);
  1489. });
  1490. // Build bluetooth sniffer Menu
  1491. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  1492. addNodes(&bluetoothSnifferMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1493. changeMenu(bluetoothSnifferMenu.parentMenu);
  1494. });
  1495. addNodes(&bluetoothSnifferMenu, text_table1[34], TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this]() {
  1496. display_obj.clearScreen();
  1497. this->drawStatusBar();
  1498. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  1499. });
  1500. addNodes(&bluetoothSnifferMenu, text_table1[35], TFT_MAGENTA, NULL, CC_SKIMMERS, [this]() {
  1501. display_obj.clearScreen();
  1502. this->drawStatusBar();
  1503. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  1504. });
  1505. // Build bluetooth scanner Menu
  1506. //bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  1507. //addNodes(&bluetoothScannerMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1508. // changeMenu(bluetoothScannerMenu.parentMenu);
  1509. //});
  1510. // Build bluetooth general menu
  1511. bluetoothGeneralMenu.parentMenu = &bluetoothMenu;
  1512. addNodes(&bluetoothGeneralMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1513. changeMenu(bluetoothGeneralMenu.parentMenu);
  1514. });
  1515. addNodes(&bluetoothGeneralMenu, text_table1[26], TFT_ORANGE, NULL, SHUTDOWN, [this]() {
  1516. changeMenu(&shutdownBLEMenu);
  1517. wifi_scan_obj.RunShutdownBLE();
  1518. });
  1519. // Build shutdown BLE menu
  1520. shutdownBLEMenu.parentMenu = &bluetoothGeneralMenu;
  1521. addNodes(&shutdownBLEMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1522. changeMenu(shutdownBLEMenu.parentMenu);
  1523. });
  1524. // Bad USB Menu
  1525. badusbMenu.parentMenu = &mainMenu;
  1526. addNodes(&badusbMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1527. changeMenu(badusbMenu.parentMenu);
  1528. });
  1529. addNodes(&badusbMenu, text_table1[36], TFT_PURPLE, NULL, TEST_BAD_USB_ICO, [this]() {
  1530. a32u4_obj.test();
  1531. });
  1532. #ifndef MARAUDER_MINI
  1533. addNodes(&badusbMenu, text_table1[37], TFT_RED, NULL, BAD_USB_ICO, [this](){
  1534. display_obj.clearScreen();
  1535. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1536. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1537. writeBadUSB();
  1538. });
  1539. #endif
  1540. // General apps menu
  1541. generalMenu.parentMenu = &mainMenu;
  1542. addNodes(&generalMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1543. display_obj.draw_tft = false;
  1544. changeMenu(generalMenu.parentMenu);
  1545. });
  1546. addNodes(&generalMenu, text_table1[38], TFT_WHITE, NULL, DRAW, [this]() {
  1547. display_obj.clearScreen();
  1548. display_obj.setupDraw();
  1549. display_obj.draw_tft = true;
  1550. });
  1551. // Device menu
  1552. deviceMenu.parentMenu = &mainMenu;
  1553. addNodes(&deviceMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1554. changeMenu(deviceMenu.parentMenu);
  1555. });
  1556. //addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  1557. addNodes(&deviceMenu, text_table1[15], TFT_ORANGE, NULL, UPDATE, [this]() {
  1558. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1559. changeMenu(&whichUpdateMenu);
  1560. });
  1561. addNodes(&deviceMenu, text_table1[16], TFT_GREEN, NULL, LANGUAGE, [this]() {
  1562. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1563. changeMenu(&languageMenu);
  1564. });
  1565. addNodes(&deviceMenu, text_table1[17], TFT_WHITE, NULL, DEVICE_INFO, [this]() {
  1566. wifi_scan_obj.currentScanMode = SHOW_INFO;
  1567. changeMenu(&infoMenu);
  1568. wifi_scan_obj.RunInfo();
  1569. });
  1570. addNodes(&deviceMenu, text08, TFT_NAVY, NULL, KEYBOARD_ICO, [this]() {
  1571. changeMenu(&settingsMenu);
  1572. });
  1573. /*addNodes(&deviceMenu, text08, TFT_NAVY, NULL, KEYBOARD_ICO, [this](){
  1574. display_obj.clearScreen();
  1575. wifi_scan_obj.currentScanMode = LV_ADD_SSID;
  1576. wifi_scan_obj.StartScan(LV_ADD_SSID, TFT_RED);
  1577. displaySettingsGFX();
  1578. });*/
  1579. // Settings menu
  1580. // Device menu
  1581. settingsMenu.parentMenu = &deviceMenu;
  1582. addNodes(&settingsMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1583. changeMenu(settingsMenu.parentMenu);
  1584. });
  1585. for (int i = 0; i < settings_obj.getNumberSettings(); i++) {
  1586. if (this->callSetting(settings_obj.setting_index_to_name(i)) == "bool")
  1587. addNodes(&settingsMenu, settings_obj.setting_index_to_name(i), TFT_LIGHTGREY, NULL, 0, [this, i]() {
  1588. settings_obj.toggleSetting(settings_obj.setting_index_to_name(i));
  1589. changeMenu(&specSettingMenu);
  1590. //this->callSetting(settings_obj.setting_index_to_name(i));
  1591. this->displaySetting(settings_obj.setting_index_to_name(i), &settingsMenu, i + 1);
  1592. }, settings_obj.loadSetting<bool>(settings_obj.setting_index_to_name(i)));
  1593. }
  1594. // Specific setting menu
  1595. specSettingMenu.parentMenu = &settingsMenu;
  1596. addNodes(&specSettingMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1597. changeMenu(specSettingMenu.parentMenu);
  1598. });
  1599. // Select update
  1600. whichUpdateMenu.parentMenu = &deviceMenu;
  1601. addNodes(&whichUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1602. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1603. changeMenu(whichUpdateMenu.parentMenu);
  1604. });
  1605. addNodes(&whichUpdateMenu, text_table1[39], TFT_GREEN, NULL, WEB_UPDATE, [this]() {
  1606. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1607. changeMenu(&updateMenu);
  1608. web_obj.setupOTAupdate();
  1609. });
  1610. if (sd_obj.supported) addNodes(&whichUpdateMenu, text_table1[40], TFT_MAGENTA, NULL, SD_UPDATE, [this]() {
  1611. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1612. changeMenu(&confirmMenu);
  1613. });
  1614. addNodes(&whichUpdateMenu, text_table1[41], TFT_RED, NULL, ESP_UPDATE_ICO, [this]() {
  1615. wifi_scan_obj.currentScanMode = ESP_UPDATE;
  1616. changeMenu(&espUpdateMenu);
  1617. esp_obj.RunUpdate();
  1618. });
  1619. // ESP Update Menu
  1620. espUpdateMenu.parentMenu = &whichUpdateMenu;
  1621. addNodes(&espUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1622. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1623. esp_obj.bootRunMode();
  1624. changeMenu(espUpdateMenu.parentMenu);
  1625. });
  1626. // Confirm SD update menu
  1627. confirmMenu.parentMenu = &whichUpdateMenu;
  1628. addNodes(&confirmMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1629. changeMenu(confirmMenu.parentMenu);
  1630. });
  1631. //addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); sd_obj.runUpdate();});
  1632. addNodes(&confirmMenu, text14, TFT_ORANGE, NULL, UPDATE, [this]() {
  1633. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  1634. changeMenu(&failedUpdateMenu);
  1635. sd_obj.runUpdate();
  1636. });
  1637. // Web Update
  1638. updateMenu.parentMenu = &deviceMenu;
  1639. addNodes(&updateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1640. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1641. changeMenu(updateMenu.parentMenu);
  1642. WiFi.softAPdisconnect(true);
  1643. web_obj.shutdownServer();
  1644. });
  1645. //addNodes(&updateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
  1646. // Failed update menu
  1647. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  1648. addNodes(&failedUpdateMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1649. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1650. changeMenu(failedUpdateMenu.parentMenu);
  1651. });
  1652. // Device info menu
  1653. infoMenu.parentMenu = &deviceMenu;
  1654. addNodes(&infoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1655. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1656. changeMenu(infoMenu.parentMenu);
  1657. });
  1658. //language info menu
  1659. languageMenu.parentMenu = &deviceMenu;
  1660. addNodes(&languageMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() {
  1661. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  1662. changeMenu(infoMenu.parentMenu);
  1663. });
  1664. // Set the current menu to the mainMenu
  1665. changeMenu(&mainMenu);
  1666. this->initTime = millis();
  1667. }
  1668. // Function to change menu
  1669. void MenuFunctions::changeMenu(Menu * menu)
  1670. {
  1671. display_obj.initScrollValues();
  1672. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  1673. display_obj.tft.init();
  1674. current_menu = menu;
  1675. buildButtons(menu);
  1676. displayCurrentMenu();
  1677. }
  1678. // Function to show all MenuNodes in a Menu
  1679. void MenuFunctions::showMenuList(Menu * menu, int layer)
  1680. {
  1681. // Iterate through all of the menu nodes in the menu
  1682. for (uint8_t i = 0; i < menu->list->size(); i++)
  1683. {
  1684. // Depending on layer, indent
  1685. for (uint8_t x = 0; x < layer * 4; x++)
  1686. Serial.print(" ");
  1687. Serial.print("Node: ");
  1688. Serial.println(menu->list->get(i).name);
  1689. }
  1690. Serial.println();
  1691. }
  1692. // Function to add MenuNodes to a menu
  1693. void MenuFunctions::addNodes(Menu * menu, String name, uint16_t color, Menu * child, int place, std::function<void()> callable, bool selected, String command)
  1694. {
  1695. TFT_eSPI_Button new_button;
  1696. menu->list->add(MenuNode{name, command, color, place, &new_button, selected, callable});
  1697. //menu->list->add(MenuNode{name, color, place, callable});
  1698. }
  1699. void MenuFunctions::buildButtons(Menu * menu, int starting_index)
  1700. {
  1701. //Serial.println("Bulding buttons...");
  1702. if (menu->list != NULL)
  1703. {
  1704. //for (int i = 0; i < sizeof(key); i++)
  1705. // key[i] = NULL;
  1706. for (uint8_t i = 0; i < menu->list->size(); i++)
  1707. {
  1708. TFT_eSPI_Button new_button;
  1709. char buf[menu->list->get(starting_index + i).name.length() + 1] = {};
  1710. menu->list->get(starting_index + i).name.toCharArray(buf, menu->list->get(starting_index + i).name.length() + 1);
  1711. display_obj.key[i].initButton(&display_obj.tft,
  1712. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  1713. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  1714. KEY_W,
  1715. KEY_H,
  1716. TFT_BLACK, // Outline
  1717. TFT_BLACK, // Fill
  1718. menu->list->get(starting_index + i).color, // Text
  1719. buf,
  1720. KEY_TEXTSIZE);
  1721. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W / 2), 2, ML_DATUM);
  1722. }
  1723. }
  1724. }
  1725. void MenuFunctions::displayCurrentMenu()
  1726. {
  1727. //Serial.println(F("Displaying current menu..."));
  1728. display_obj.clearScreen();
  1729. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  1730. this->drawStatusBar();
  1731. if (current_menu->list != NULL)
  1732. {
  1733. #ifndef MARAUDER_MINI
  1734. display_obj.tft.setFreeFont(MENU_FONT);
  1735. #endif
  1736. #ifdef MARAUDER_MINI
  1737. display_obj.tft.setFreeFont(NULL);
  1738. display_obj.tft.setTextSize(1);
  1739. #endif
  1740. for (uint8_t i = 0; i < current_menu->list->size(); i++)
  1741. {
  1742. #ifndef MARAUDER_MINI
  1743. if (!current_menu->list->get(i).selected)
  1744. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1745. else
  1746. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1747. if (current_menu->list->get(i).name != text09)
  1748. display_obj.tft.drawXBitmap(0,
  1749. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  1750. menu_icons[current_menu->list->get(i).icon],
  1751. ICON_W,
  1752. ICON_H,
  1753. TFT_BLACK,
  1754. current_menu->list->get(i).color);
  1755. #endif
  1756. #ifdef MARAUDER_MINI
  1757. if ((current_menu->selected == i) || (current_menu->list->get(i).selected))
  1758. display_obj.key[i].drawButton(true, current_menu->list->get(i).name);
  1759. else
  1760. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  1761. #endif
  1762. }
  1763. display_obj.tft.setFreeFont(NULL);
  1764. }
  1765. }
  1766. #endif