MenuFunctions.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. #include "MenuFunctions.h"
  2. //#include "icons.h"
  3. extern const unsigned char menu_icons[][66];
  4. PROGMEM lv_obj_t * slider_label;
  5. PROGMEM lv_obj_t * ta1;
  6. PROGMEM lv_obj_t * ta2;
  7. MenuFunctions::MenuFunctions()
  8. {
  9. }
  10. // LVGL Stuff
  11. /* Interrupt driven periodic handler */
  12. void MenuFunctions::lv_tick_handler()
  13. {
  14. lv_tick_inc(LVGL_TICK_PERIOD);
  15. }
  16. /* Display flushing */
  17. void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  18. {
  19. extern Display display_obj;
  20. uint16_t c;
  21. display_obj.tft.startWrite();
  22. display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
  23. for (int y = area->y1; y <= area->y2; y++) {
  24. for (int x = area->x1; x <= area->x2; x++) {
  25. c = color_p->full;
  26. display_obj.tft.writeColor(c, 1);
  27. color_p++;
  28. }
  29. }
  30. display_obj.tft.endWrite();
  31. lv_disp_flush_ready(disp);
  32. }
  33. bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  34. {
  35. extern Display display_obj;
  36. uint16_t touchX, touchY;
  37. bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
  38. if(!touched)
  39. {
  40. return false;
  41. }
  42. if(touchX>WIDTH_1 || touchY > HEIGHT_1)
  43. {
  44. Serial.println("Y or y outside of expected parameters..");
  45. Serial.print("y:");
  46. Serial.print(touchX);
  47. Serial.print(" x:");
  48. Serial.print(touchY);
  49. }
  50. else
  51. {
  52. data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  53. //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
  54. data->point.x = touchX;
  55. data->point.y = touchY;
  56. Serial.print("Data x");
  57. Serial.println(touchX);
  58. Serial.print("Data y");
  59. Serial.println(touchY);
  60. }
  61. return false;
  62. }
  63. void MenuFunctions::initLVGL() {
  64. tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
  65. lv_init();
  66. lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  67. lv_disp_drv_t disp_drv;
  68. lv_disp_drv_init(&disp_drv);
  69. disp_drv.hor_res = WIDTH_1;
  70. disp_drv.ver_res = HEIGHT_1;
  71. disp_drv.flush_cb = my_disp_flush;
  72. disp_drv.buffer = &disp_buf;
  73. lv_disp_drv_register(&disp_drv);
  74. lv_indev_drv_t indev_drv;
  75. lv_indev_drv_init(&indev_drv);
  76. indev_drv.type = LV_INDEV_TYPE_POINTER;
  77. indev_drv.read_cb = my_touchpad_read;
  78. lv_indev_drv_register(&indev_drv);
  79. }
  80. void MenuFunctions::deinitLVGL() {
  81. Serial.println(F("Deinit LVGL"));
  82. //lv_deinit();
  83. }
  84. void MenuFunctions::joinWiFiGFX(){
  85. // Create one text area
  86. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  87. lv_textarea_set_one_line(ta1, true);
  88. lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
  89. lv_obj_set_pos(ta1, 5, 20);
  90. //lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
  91. lv_textarea_set_text(ta1, "");
  92. lv_obj_set_event_cb(ta1, ta_event_cb);
  93. // Create first label
  94. lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL);
  95. lv_label_set_text(ssid_label, "SSID:");
  96. lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  97. // Create second text area
  98. ta2 = lv_textarea_create(lv_scr_act(), ta1);
  99. //lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
  100. //lv_textarea_set_pwd_show_time(ta2, 1000);
  101. lv_textarea_set_cursor_hidden(ta2, true);
  102. lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
  103. // Create second label
  104. lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL);
  105. lv_label_set_text(pw_label, "Password:");
  106. lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  107. // Create a keyboard and apply the styles
  108. kb = lv_keyboard_create(lv_scr_act(), NULL);
  109. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  110. lv_obj_set_event_cb(kb, keyboard_event_cb);
  111. // Focus it on one of the text areas to start
  112. lv_keyboard_set_textarea(kb, ta1);
  113. lv_keyboard_set_cursor_manage(kb, true);
  114. }
  115. void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
  116. extern Display display_obj;
  117. extern MenuFunctions menu_function_obj;
  118. extern WiFiScan wifi_scan_obj;
  119. lv_keyboard_def_event_cb(kb, event);
  120. if(event == LV_EVENT_APPLY){
  121. printf("LV_EVENT_APPLY\n");
  122. //String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
  123. String ta1_text = lv_textarea_get_text(ta1);
  124. String ta2_text = lv_textarea_get_text(ta2);
  125. Serial.println(ta1_text);
  126. Serial.println(ta2_text);
  127. wifi_scan_obj.joinWiFi(ta1_text, ta2_text);
  128. }else if(event == LV_EVENT_CANCEL){
  129. printf("LV_EVENT_CANCEL\n");
  130. //lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
  131. menu_function_obj.deinitLVGL();
  132. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  133. display_obj.exit_draw = true; // set everything back to normal
  134. }
  135. }
  136. void ta_event_cb(lv_obj_t * ta, lv_event_t event)
  137. {
  138. if(event == LV_EVENT_CLICKED) {
  139. if(kb != NULL)
  140. lv_keyboard_set_textarea(kb, ta);
  141. }
  142. //else if(event == LV_EVENT_INSERT) {
  143. // const char * str = lv_event_get_data();
  144. // if(str[0] == '\n') {
  145. // printf("Ready\n");
  146. // }
  147. //}
  148. }
  149. // Function to check menu input
  150. void MenuFunctions::main(uint32_t currentTime)
  151. {
  152. // Some function exited and we need to go back to normal
  153. if (display_obj.exit_draw) {
  154. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  155. display_obj.exit_draw = false;
  156. this->orientDisplay();
  157. //changeMenu(current_menu);
  158. }
  159. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
  160. (wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
  161. (wifi_scan_obj.currentScanMode == SHOW_INFO)) {
  162. if (wifi_scan_obj.orient_display) {
  163. this->orientDisplay();
  164. wifi_scan_obj.orient_display = false;
  165. }
  166. //if ((display_obj.current_banner_pos <= 0) || (display_obj.current_banner_pos == SCREEN_WIDTH))
  167. //{
  168. // this->drawStatusBar();
  169. //}
  170. if (wifi_scan_obj.currentScanMode != LV_JOIN_WIFI)
  171. display_obj.updateBanner(current_menu->name);
  172. }
  173. if (currentTime != 0) {
  174. if (currentTime - initTime >= 100) {
  175. this->initTime = millis();
  176. if (wifi_scan_obj.currentScanMode != LV_JOIN_WIFI)
  177. this->updateStatusBar();
  178. }
  179. }
  180. //this->displayCurrentMenu();
  181. boolean pressed = false;
  182. // This is code from bodmer's keypad example
  183. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  184. // Get the display buffer out of the way
  185. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
  186. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  187. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  188. display_obj.displayBuffer();
  189. //Serial.println(wifi_scan_obj.freeRAM());
  190. // Pressed will be set true is there is a valid touch on the screen
  191. int pre_getTouch = millis();
  192. // getTouch causes a 10ms delay which makes beacon spam less effective
  193. //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
  194. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  195. //if (pressed)
  196. // Serial.println("Pressed, son");
  197. //boolean pressed = false;
  198. //Serial.print("getTouch: ");
  199. //Serial.print(millis() - pre_getTouch);
  200. //Serial.println("ms");
  201. // This is if there are scans/attacks going on
  202. if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
  203. (pressed) &&
  204. (wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
  205. (wifi_scan_obj.currentScanMode != SHOW_INFO))
  206. {
  207. // Stop the current scan
  208. if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
  209. (wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
  210. (wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
  211. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  212. (wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
  213. (wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
  214. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  215. (wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  216. (wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
  217. (wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
  218. {
  219. Serial.println("Stopping scan...");
  220. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  221. // If we don't do this, the text and button coordinates will be off
  222. display_obj.tft.init();
  223. // Take us back to the menu
  224. changeMenu(current_menu);
  225. }
  226. x = -1;
  227. y = -1;
  228. return;
  229. }
  230. // Check if any key coordinate boxes contain the touch coordinates
  231. // This is for when on a menu
  232. if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
  233. (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
  234. {
  235. // Need this to set all keys to false
  236. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
  237. if (pressed && display_obj.key[b].contains(t_x, t_y)) {
  238. display_obj.key[b].press(true); // tell the button it is pressed
  239. } else {
  240. display_obj.key[b].press(false); // tell the button it is NOT pressed
  241. }
  242. }
  243. // Check if any key has changed state
  244. for (uint8_t b = 0; b < current_menu->list->size(); b++) {
  245. display_obj.tft.setFreeFont(MENU_FONT);
  246. if (display_obj.key[b].justPressed()) {
  247. //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert
  248. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true);
  249. display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
  250. if (current_menu->list->get(b).name != "Back")
  251. display_obj.tft.drawXBitmap(0,
  252. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  253. menu_icons[current_menu->list->get(b).icon],
  254. ICON_W,
  255. ICON_H,
  256. current_menu->list->get(b).color,
  257. TFT_BLACK);
  258. }
  259. //else if (pressed)
  260. // display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  261. // If button was just release, execute the button's function
  262. if ((display_obj.key[b].justReleased()) && (!pressed))
  263. {
  264. //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal
  265. //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name);
  266. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  267. current_menu->list->get(b).callable();
  268. }
  269. // This
  270. else if ((display_obj.key[b].justReleased()) && (pressed)) {
  271. display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
  272. if (current_menu->list->get(b).name != "Back")
  273. display_obj.tft.drawXBitmap(0,
  274. KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  275. menu_icons[current_menu->list->get(b).icon],
  276. ICON_W,
  277. ICON_H,
  278. TFT_BLACK,
  279. current_menu->list->get(b).color);
  280. }
  281. display_obj.tft.setFreeFont(NULL);
  282. }
  283. }
  284. x = -1;
  285. y = -1;
  286. }
  287. #if BATTERY_ANALOG_ON == 1
  288. byte battery_analog_array[10];
  289. byte battery_count = 0;
  290. byte battery_analog_last = 101;
  291. #define BATTERY_CHECK 50
  292. uint16_t battery_analog = 0;
  293. void MenuFunctions::battery(bool initial)
  294. {
  295. if (BATTERY_ANALOG_ON) {
  296. uint8_t n = 0;
  297. byte battery_analog_sample[10];
  298. byte deviation;
  299. if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
  300. else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
  301. if (battery_count == 0) {
  302. battery_analog = 0;
  303. for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
  304. for (n = 0; n < 10; n++) {
  305. battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
  306. if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
  307. else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
  308. battery_analog += battery_analog_sample[n];
  309. }
  310. battery_analog = battery_analog / 10;
  311. for (n = 0; n < 10; n++) {
  312. deviation = abs(battery_analog - battery_analog_sample[n]);
  313. if (deviation >= 10) battery_analog_sample[n] = battery_analog;
  314. }
  315. battery_analog = 0;
  316. for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
  317. battery_analog = battery_analog / 10;
  318. battery_analog_array[0] = battery_analog;
  319. if (battery_analog_array[9] > 0 ) {
  320. battery_analog = 0;
  321. for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
  322. battery_analog = battery_analog / 10;
  323. }
  324. battery_count ++;
  325. }
  326. else if (battery_count < BATTERY_CHECK) battery_count++;
  327. else if (battery_count >= BATTERY_CHECK) battery_count = 0;
  328. if (battery_analog_last != battery_analog) {
  329. battery_analog_last = battery_analog;
  330. MenuFunctions::battery2();
  331. }
  332. }
  333. }
  334. void MenuFunctions::battery2(bool initial)
  335. {
  336. uint16_t the_color;
  337. if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
  338. else if (battery_analog < 20) the_color = TFT_RED;
  339. else if (battery_analog < 40) the_color = TFT_YELLOW;
  340. else the_color = TFT_GREEN;
  341. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  342. display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  343. display_obj.tft.drawXBitmap(186,
  344. 0,
  345. menu_icons[STATUS_BAT],
  346. 16,
  347. 16,
  348. STATUSBAR_COLOR,
  349. the_color);
  350. display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
  351. }
  352. #else
  353. void MenuFunctions::battery(bool initial)
  354. {
  355. uint16_t the_color;
  356. if (battery_obj.i2c_supported)
  357. {
  358. // Could use int compare maybe idk
  359. if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
  360. the_color = TFT_GREEN;
  361. else
  362. the_color = TFT_RED;
  363. if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
  364. battery_obj.old_level = battery_obj.battery_level;
  365. display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  366. display_obj.tft.setCursor(0, 1);
  367. display_obj.tft.drawXBitmap(186,
  368. 0,
  369. menu_icons[STATUS_BAT],
  370. 16,
  371. 16,
  372. STATUSBAR_COLOR,
  373. the_color);
  374. display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
  375. }
  376. }
  377. }
  378. void MenuFunctions::battery2(bool initial)
  379. {
  380. MenuFunctions::battery(initial);
  381. }
  382. #endif
  383. void MenuFunctions::updateStatusBar()
  384. {
  385. display_obj.tft.setTextSize(1);
  386. uint16_t the_color;
  387. // Draw temp info
  388. if (temp_obj.current_temp < 70)
  389. the_color = TFT_GREEN;
  390. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  391. the_color = TFT_YELLOW;
  392. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  393. the_color = TFT_ORANGE;
  394. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  395. the_color = TFT_RED;
  396. else
  397. the_color = TFT_MAROON;
  398. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  399. if (temp_obj.current_temp != temp_obj.old_temp) {
  400. temp_obj.old_temp = temp_obj.current_temp;
  401. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  402. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  403. }
  404. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  405. // WiFi Channel Stuff
  406. if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) {
  407. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  408. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  409. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  410. }
  411. // RAM Stuff
  412. wifi_scan_obj.freeRAM();
  413. if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) {
  414. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  415. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  416. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  417. }
  418. // Draw battery info
  419. MenuFunctions::battery(false);
  420. // Draw SD info
  421. if (sd_obj.supported)
  422. the_color = TFT_GREEN;
  423. else
  424. the_color = TFT_RED;
  425. display_obj.tft.drawXBitmap(170,
  426. 0,
  427. menu_icons[STATUS_SD],
  428. 16,
  429. 16,
  430. STATUSBAR_COLOR,
  431. the_color);
  432. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  433. }
  434. void MenuFunctions::drawStatusBar()
  435. {
  436. display_obj.tft.setTextSize(1);
  437. display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  438. //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY);
  439. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  440. //display_obj.tft.setTextSize(2);
  441. uint16_t the_color;
  442. // Draw temp info
  443. if (temp_obj.current_temp < 70)
  444. the_color = TFT_GREEN;
  445. else if ((temp_obj.current_temp >= 70) && (temp_obj.current_temp < 80))
  446. the_color = TFT_YELLOW;
  447. else if ((temp_obj.current_temp >= 80) && (temp_obj.current_temp < 90))
  448. the_color = TFT_ORANGE;
  449. else if ((temp_obj.current_temp >= 90) && (temp_obj.current_temp < 100))
  450. the_color = TFT_RED;
  451. else
  452. the_color = TFT_MAROON;
  453. display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
  454. temp_obj.old_temp = temp_obj.current_temp;
  455. display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  456. display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2);
  457. display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
  458. // WiFi Channel Stuff
  459. wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
  460. display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  461. display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
  462. // RAM Stuff
  463. wifi_scan_obj.freeRAM();
  464. wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
  465. display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
  466. display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
  467. MenuFunctions::battery2(true);
  468. // Draw SD info
  469. if (sd_obj.supported)
  470. the_color = TFT_GREEN;
  471. else
  472. the_color = TFT_RED;
  473. display_obj.tft.drawXBitmap(170,
  474. 0,
  475. menu_icons[STATUS_SD],
  476. 16,
  477. 16,
  478. STATUSBAR_COLOR,
  479. the_color);
  480. //display_obj.tft.print((String)battery_obj.battery_level + "%");
  481. }
  482. void MenuFunctions::orientDisplay()
  483. {
  484. Serial.println(F("orientDisplay()"));
  485. display_obj.tft.init();
  486. display_obj.tft.setRotation(0); // Portrait
  487. display_obj.tft.setCursor(0, 0);
  488. //uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
  489. //uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  490. #ifdef TFT_SHIELD
  491. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  492. Serial.println("Using TFT Shield");
  493. #else if defined(TFT_DIY)
  494. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  495. Serial.println("Using TFT DIY");
  496. #endif
  497. display_obj.tft.setTouch(calData);
  498. //display_obj.clearScreen();
  499. changeMenu(current_menu);
  500. }
  501. // Function to build the menus
  502. void MenuFunctions::RunSetup()
  503. {
  504. this->initLVGL();
  505. // root menu stuff
  506. mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
  507. // Main menu stuff
  508. wifiMenu.list = new LinkedList<MenuNode>(); // Get list in second menu ready
  509. bluetoothMenu.list = new LinkedList<MenuNode>(); // Get list in third menu ready
  510. generalMenu.list = new LinkedList<MenuNode>();
  511. deviceMenu.list = new LinkedList<MenuNode>();
  512. // Device menu stuff
  513. failedUpdateMenu.list = new LinkedList<MenuNode>();
  514. whichUpdateMenu.list = new LinkedList<MenuNode>();
  515. confirmMenu.list = new LinkedList<MenuNode>();
  516. updateMenu.list = new LinkedList<MenuNode>();
  517. infoMenu.list = new LinkedList<MenuNode>();
  518. // WiFi menu stuff
  519. wifiSnifferMenu.list = new LinkedList<MenuNode>();
  520. wifiScannerMenu.list = new LinkedList<MenuNode>();
  521. wifiAttackMenu.list = new LinkedList<MenuNode>();
  522. // Bluetooth menu stuff
  523. bluetoothSnifferMenu.list = new LinkedList<MenuNode>();
  524. bluetoothScannerMenu.list = new LinkedList<MenuNode>();
  525. // Work menu names
  526. mainMenu.name = " ESP32 Marauder ";
  527. wifiMenu.name = " WiFi ";
  528. deviceMenu.name = " Device ";
  529. generalMenu.name = " General Apps ";
  530. failedUpdateMenu.name = " Updating... ";
  531. whichUpdateMenu.name = "Select Method ";
  532. confirmMenu.name = " Confirm Update ";
  533. updateMenu.name = " Update Firmware ";
  534. infoMenu.name = " Device Info ";
  535. bluetoothMenu.name = " Bluetooth ";
  536. wifiSnifferMenu.name = " WiFi Sniffers ";
  537. wifiScannerMenu.name = " WiFi Scanners";
  538. wifiAttackMenu.name = " WiFi Attacks ";
  539. bluetoothSnifferMenu.name = " Bluetooth Sniffers ";
  540. bluetoothScannerMenu.name = " Bluetooth Scanners ";
  541. // Build Main Menu
  542. mainMenu.parentMenu = NULL;
  543. addNodes(&mainMenu, "WiFi", TFT_GREEN, NULL, WIFI, [this]() {
  544. changeMenu(&wifiMenu);
  545. });
  546. addNodes(&mainMenu, "Bluetooth", TFT_CYAN, NULL, BLUETOOTH, [this]() {
  547. changeMenu(&bluetoothMenu);
  548. });
  549. addNodes(&mainMenu, "General Apps", TFT_MAGENTA, NULL, GENERAL_APPS, [this]() {
  550. changeMenu(&generalMenu);
  551. });
  552. addNodes(&mainMenu, "Device", TFT_BLUE, NULL, DEVICE, [this]() {
  553. changeMenu(&deviceMenu);
  554. });
  555. addNodes(&mainMenu, "Reboot", TFT_LIGHTGREY, NULL, REBOOT, []() {
  556. ESP.restart();
  557. });
  558. // Build WiFi Menu
  559. wifiMenu.parentMenu = &mainMenu; // Main Menu is second menu parent
  560. addNodes(&wifiMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  561. changeMenu(wifiMenu.parentMenu);
  562. });
  563. addNodes(&wifiMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this]() {
  564. changeMenu(&wifiSnifferMenu);
  565. });
  566. addNodes(&wifiMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  567. changeMenu(&wifiScannerMenu);
  568. });
  569. addNodes(&wifiMenu, "Attacks", TFT_RED, NULL, ATTACKS, [this]() {
  570. changeMenu(&wifiAttackMenu);
  571. });
  572. // Build WiFi sniffer Menu
  573. wifiSnifferMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  574. addNodes(&wifiSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  575. changeMenu(wifiSnifferMenu.parentMenu);
  576. });
  577. addNodes(&wifiSnifferMenu, "Probe Request Sniff", TFT_CYAN, NULL, PROBE_SNIFF, [this]() {
  578. display_obj.clearScreen();
  579. this->drawStatusBar();
  580. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_CYAN);
  581. });
  582. addNodes(&wifiSnifferMenu, "Beacon Sniff", TFT_MAGENTA, NULL, BEACON_SNIFF, [this]() {
  583. display_obj.clearScreen();
  584. this->drawStatusBar();
  585. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  586. });
  587. addNodes(&wifiSnifferMenu, "Deauth Sniff", TFT_RED, NULL, DEAUTH_SNIFF, [this]() {
  588. display_obj.clearScreen();
  589. this->drawStatusBar();
  590. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  591. });
  592. // Build WiFi scanner Menu
  593. wifiScannerMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  594. addNodes(&wifiScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  595. changeMenu(wifiScannerMenu.parentMenu);
  596. });
  597. addNodes(&wifiScannerMenu, "Packet Monitor", TFT_BLUE, NULL, PACKET_MONITOR, [this]() {
  598. wifi_scan_obj.StartScan(WIFI_PACKET_MONITOR, TFT_BLUE);
  599. });
  600. addNodes(&wifiScannerMenu, "EAPOL/PMKID Scan", TFT_VIOLET, NULL, EAPOL, [this]() {
  601. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  602. });
  603. addNodes(&wifiScannerMenu, "Detect Pwnagotchi", TFT_RED, NULL, PWNAGOTCHI, [this]() {
  604. display_obj.clearScreen();
  605. this->drawStatusBar();
  606. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_RED);
  607. });
  608. addNodes(&wifiScannerMenu, "Detect Espressif", TFT_ORANGE, NULL, ESPRESSIF, [this]() {
  609. display_obj.clearScreen();
  610. this->drawStatusBar();
  611. wifi_scan_obj.StartScan(WIFI_SCAN_ESPRESSIF, TFT_ORANGE);
  612. });
  613. // Build WiFi attack menu
  614. wifiAttackMenu.parentMenu = &wifiMenu; // Main Menu is second menu parent
  615. addNodes(&wifiAttackMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  616. changeMenu(wifiAttackMenu.parentMenu);
  617. });
  618. addNodes(&wifiAttackMenu, "Beacon Spam Random", TFT_ORANGE, NULL, BEACON_SPAM, [this]() {
  619. display_obj.clearScreen();
  620. this->drawStatusBar();
  621. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  622. });
  623. addNodes(&wifiAttackMenu, "Rick Roll Beacon", TFT_YELLOW, NULL, RICK_ROLL, [this]() {
  624. display_obj.clearScreen();
  625. this->drawStatusBar();
  626. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  627. });
  628. addNodes(&wifiAttackMenu, "Join WiFi", TFT_DARKCYAN, NULL, SNIFFERS, [this](){
  629. display_obj.clearScreen();
  630. wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
  631. wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
  632. joinWiFiGFX();
  633. });
  634. // Build Bluetooth Menu
  635. bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
  636. addNodes(&bluetoothMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  637. changeMenu(bluetoothMenu.parentMenu);
  638. });
  639. addNodes(&bluetoothMenu, "Sniffers", TFT_YELLOW, NULL, SNIFFERS, [this]() {
  640. changeMenu(&bluetoothSnifferMenu);
  641. });
  642. addNodes(&bluetoothMenu, "Scanners", TFT_ORANGE, NULL, SCANNERS, [this]() {
  643. changeMenu(&bluetoothScannerMenu);
  644. });
  645. // Build bluetooth sniffer Menu
  646. bluetoothSnifferMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  647. addNodes(&bluetoothSnifferMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  648. changeMenu(bluetoothSnifferMenu.parentMenu);
  649. });
  650. addNodes(&bluetoothSnifferMenu, "Bluetooth Sniffer", TFT_GREEN, NULL, BLUETOOTH_SNIFF, [this]() {
  651. display_obj.clearScreen();
  652. this->drawStatusBar();
  653. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  654. });
  655. // Build bluetooth scanner Menu
  656. bluetoothScannerMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent
  657. addNodes(&bluetoothScannerMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  658. changeMenu(bluetoothScannerMenu.parentMenu);
  659. });
  660. addNodes(&bluetoothScannerMenu, "Detect Card Skimmers", TFT_MAGENTA, NULL, CC_SKIMMERS, [this]() {
  661. display_obj.clearScreen();
  662. this->drawStatusBar();
  663. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  664. });
  665. // General apps menu
  666. generalMenu.parentMenu = &mainMenu;
  667. addNodes(&generalMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  668. display_obj.draw_tft = false;
  669. changeMenu(generalMenu.parentMenu);
  670. });
  671. addNodes(&generalMenu, "Draw", TFT_WHITE, NULL, DRAW, [this]() {
  672. display_obj.clearScreen();
  673. display_obj.setupDraw();
  674. display_obj.draw_tft = true;
  675. });
  676. // Device menu
  677. deviceMenu.parentMenu = &mainMenu;
  678. addNodes(&deviceMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  679. changeMenu(deviceMenu.parentMenu);
  680. });
  681. //addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); web_obj.setupOTAupdate();});
  682. addNodes(&deviceMenu, "Update Firmware", TFT_ORANGE, NULL, UPDATE, [this]() {
  683. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  684. changeMenu(&whichUpdateMenu);
  685. });
  686. addNodes(&deviceMenu, "Device Info", TFT_WHITE, NULL, DEVICE_INFO, [this]() {
  687. wifi_scan_obj.currentScanMode = SHOW_INFO;
  688. changeMenu(&infoMenu);
  689. wifi_scan_obj.RunInfo();
  690. });
  691. // Select update
  692. whichUpdateMenu.parentMenu = &deviceMenu;
  693. addNodes(&whichUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  694. changeMenu(whichUpdateMenu.parentMenu);
  695. });
  696. addNodes(&whichUpdateMenu, "Web Update", TFT_GREEN, NULL, WEB_UPDATE, [this]() {
  697. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  698. changeMenu(&updateMenu);
  699. web_obj.setupOTAupdate();
  700. });
  701. if (sd_obj.supported) addNodes(&whichUpdateMenu, "SD Update", TFT_MAGENTA, NULL, SD_UPDATE, [this]() {
  702. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  703. changeMenu(&confirmMenu);
  704. });
  705. // Confirm SD update menu
  706. confirmMenu.parentMenu = &whichUpdateMenu;
  707. addNodes(&confirmMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  708. changeMenu(confirmMenu.parentMenu);
  709. });
  710. //addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this](){wifi_scan_obj.currentScanMode = OTA_UPDATE; changeMenu(&updateMenu); sd_obj.runUpdate();});
  711. addNodes(&confirmMenu, "Yes", TFT_ORANGE, NULL, UPDATE, [this]() {
  712. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  713. changeMenu(&failedUpdateMenu);
  714. sd_obj.runUpdate();
  715. });
  716. // Web Update
  717. updateMenu.parentMenu = &deviceMenu;
  718. addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  719. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  720. changeMenu(updateMenu.parentMenu);
  721. WiFi.softAPdisconnect(true);
  722. web_obj.shutdownServer();
  723. });
  724. //addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
  725. // Failed update menu
  726. failedUpdateMenu.parentMenu = &whichUpdateMenu;
  727. addNodes(&failedUpdateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  728. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  729. changeMenu(failedUpdateMenu.parentMenu);
  730. });
  731. // Device info menu
  732. infoMenu.parentMenu = &deviceMenu;
  733. addNodes(&infoMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this]() {
  734. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  735. changeMenu(infoMenu.parentMenu);
  736. });
  737. // Set the current menu to the mainMenu
  738. changeMenu(&mainMenu);
  739. this->initTime = millis();
  740. }
  741. // Function to change menu
  742. void MenuFunctions::changeMenu(Menu * menu)
  743. {
  744. display_obj.initScrollValues();
  745. display_obj.setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
  746. display_obj.tft.init();
  747. current_menu = menu;
  748. buildButtons(menu);
  749. displayCurrentMenu();
  750. }
  751. // Function to show all MenuNodes in a Menu
  752. void MenuFunctions::showMenuList(Menu * menu, int layer)
  753. {
  754. // Iterate through all of the menu nodes in the menu
  755. for (uint8_t i = 0; i < menu->list->size(); i++)
  756. {
  757. // Depending on layer, indent
  758. for (uint8_t x = 0; x < layer * 4; x++)
  759. Serial.print(" ");
  760. Serial.print("Node: ");
  761. Serial.println(menu->list->get(i).name);
  762. // If the current menu node points to another menu, list that menu
  763. //if (menu->list->get(i).childMenu != NULL)
  764. // showMenuList(menu->list->get(i).childMenu, layer+1);
  765. }
  766. Serial.println();
  767. }
  768. // Function to add MenuNodes to a menu
  769. void MenuFunctions::addNodes(Menu * menu, String name, uint16_t color, Menu * child, int place, std::function<void()> callable)
  770. {
  771. TFT_eSPI_Button new_button;
  772. menu->list->add(MenuNode{name, color, place, &new_button, callable});
  773. //strcpy(menu->list->get(-1).icon, bluetooth_icon);
  774. }
  775. void MenuFunctions::buildButtons(Menu * menu)
  776. {
  777. Serial.println("Bulding buttons...");
  778. if (menu->list != NULL)
  779. {
  780. //for (int i = 0; i < sizeof(key); i++)
  781. // key[i] = NULL;
  782. for (uint8_t i = 0; i < menu->list->size(); i++)
  783. {
  784. TFT_eSPI_Button new_button;
  785. char buf[menu->list->get(i).name.length() + 1] = {};
  786. menu->list->get(i).name.toCharArray(buf, menu->list->get(i).name.length() + 1);
  787. display_obj.key[i].initButton(&display_obj.tft,
  788. KEY_X + 0 * (KEY_W + KEY_SPACING_X),
  789. KEY_Y + i * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
  790. KEY_W,
  791. KEY_H,
  792. TFT_BLACK, // Outline
  793. TFT_BLACK, // Fill
  794. menu->list->get(i).color, // Text
  795. buf,
  796. KEY_TEXTSIZE);
  797. display_obj.key[i].setLabelDatum(BUTTON_PADDING - (KEY_W / 2), 2, ML_DATUM);
  798. }
  799. }
  800. }
  801. void MenuFunctions::displayCurrentMenu()
  802. {
  803. Serial.println(F("Displaying current menu..."));
  804. display_obj.clearScreen();
  805. display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY);
  806. this->drawStatusBar();
  807. //display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY);
  808. //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2);
  809. //Serial.println("Getting size...");
  810. //char buf[&current_menu->parentMenu->name.length() + 1] = {};
  811. //Serial.println("Got size...");
  812. //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1);
  813. //String current_name = &current_menu->parentMenu->name;
  814. //Serial.println("gottem");
  815. //display_obj.tft.drawCentreString(current_menu->name,120,0,2);
  816. if (current_menu->list != NULL)
  817. {
  818. display_obj.tft.setFreeFont(MENU_FONT);
  819. for (uint8_t i = 0; i < current_menu->list->size(); i++)
  820. {
  821. //display_obj.key[i].drawButton2(current_menu->list->get(i).name);
  822. //display_obj.key[i].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(i).name);
  823. //display_obj.key[i].drawButton(true);
  824. display_obj.key[i].drawButton(false, current_menu->list->get(i).name);
  825. if (current_menu->list->get(i).name != "Back")
  826. display_obj.tft.drawXBitmap(0,
  827. KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
  828. menu_icons[current_menu->list->get(i).icon],
  829. ICON_W,
  830. ICON_H,
  831. TFT_BLACK,
  832. current_menu->list->get(i).color);
  833. }
  834. display_obj.tft.setFreeFont(NULL);
  835. }
  836. }