MenuFunctions.cpp 76 KB

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