MenuFunctions.cpp 74 KB

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