MenuFunctions.cpp 75 KB

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