forked from justcallmekoko/ESP32Marauder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuFunctions.cpp
2398 lines (2090 loc) · 88.7 KB
/
MenuFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "MenuFunctions.h"
#include "lang_var.h"
//#include "icons.h"
#ifdef HAS_SCREEN
extern const unsigned char menu_icons[][66];
PROGMEM lv_obj_t * slider_label;
PROGMEM lv_obj_t * ta1;
PROGMEM lv_obj_t * ta2;
PROGMEM lv_obj_t * save_name;
MenuFunctions::MenuFunctions()
{
}
// LVGL Stuff
/* Interrupt driven periodic handler */
#ifdef HAS_ILI9341
uint8_t MenuFunctions::updateTouch(uint16_t *x, uint16_t *y, uint16_t threshold) {
if (!display_obj.headless_mode)
return display_obj.tft.getTouch(x, y, threshold);
else
return !display_obj.headless_mode;
}
void MenuFunctions::lv_tick_handler()
{
lv_tick_inc(LVGL_TICK_PERIOD);
}
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
extern Display display_obj;
uint16_t c;
display_obj.tft.startWrite();
display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
for (int y = area->y1; y <= area->y2; y++) {
for (int x = area->x1; x <= area->x2; x++) {
c = color_p->full;
display_obj.tft.writeColor(c, 1);
color_p++;
}
}
display_obj.tft.endWrite();
lv_disp_flush_ready(disp);
}
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
extern Display display_obj;
uint16_t touchX, touchY;
bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
if(!touched)
{
return false;
}
if(touchX>WIDTH_1 || touchY > HEIGHT_1)
{
Serial.println("Y or y outside of expected parameters..");
Serial.print("y:");
Serial.print(touchX);
Serial.print(" x:");
Serial.print(touchY);
}
else
{
data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->point.x = touchX;
data->point.y = touchY;
}
return false;
}
void MenuFunctions::initLVGL() {
tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
lv_init();
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = WIDTH_1;
disp_drv.ver_res = HEIGHT_1;
disp_drv.flush_cb = my_disp_flush;
disp_drv.buffer = &disp_buf;
lv_disp_drv_register(&disp_drv);
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
void MenuFunctions::deinitLVGL() {
Serial.println(F("Deinit LVGL"));
//lv_deinit();
}
// Event handler for settings drop down menus
void setting_dropdown_cb(lv_obj_t * obj, lv_event_t event) {
}
// GFX Function to build a list showing all Stations scanned
void MenuFunctions::addStationGFX(){
extern LinkedList<Station>* stations;
extern LinkedList<AccessPoint>* access_points;
extern WiFiScan wifi_scan_obj;
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_size(list1, 160, 200);
lv_obj_set_width(list1, LV_HOR_RES);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * list_btn;
lv_obj_t * label;
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
lv_obj_set_event_cb(list_btn, station_list_cb);
char addr[] = "00:00:00:00:00:00";
for (int x = 0; x < access_points->size(); x++) {
AccessPoint cur_ap = access_points->get(x);
// Add non clickable button for AP
String full_label = "AP: " + cur_ap.essid;
char buf[full_label.length() + 1] = {};
full_label.toCharArray(buf, full_label.length() + 1);
list_btn = lv_list_add_btn(list1, NULL, buf);
lv_btn_set_checkable(list_btn, false);
int cur_ap_sta_len = access_points->get(x).stations->size();
for (int y = 0; y < cur_ap_sta_len; y++) {
Station cur_sta = stations->get(cur_ap.stations->get(y));
// Convert uint8_t MAC to char array
wifi_scan_obj.getMAC(addr, cur_sta.mac, 0);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, addr);
lv_btn_set_checkable(list_btn, true);
lv_obj_set_event_cb(list_btn, station_list_cb);
if (cur_sta.selected)
lv_btn_toggle(list_btn);
}
}
}
// Function to work with list of Stations
void station_list_cb(lv_obj_t * btn, lv_event_t event) {
extern LinkedList<Station>* stations;
extern MenuFunctions menu_function_obj;
extern WiFiScan wifi_scan_obj;
String btn_text = lv_list_get_btn_text(btn);
String display_string = "";
char addr[] = "00:00:00:00:00:00";
if (event == LV_EVENT_CLICKED) {
if (btn_text != text09) {
}
else {
Serial.println("Exiting...");
lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
for (int i = 0; i < stations->size(); i++) {
if (stations->get(i).selected) {
wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
Serial.print("Selected: ");
Serial.println(addr);
}
}
printf("LV_EVENT_CANCEL\n");
menu_function_obj.deinitLVGL();
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
display_obj.exit_draw = true; // set everything back to normal
}
}
if (event == LV_EVENT_VALUE_CHANGED) {
if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
for (int i = 0; i < stations->size(); i++) {
wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
if (strcmp(addr, btn_text.c_str()) == 0) {
Serial.print("Adding Station: ");
Serial.println(addr);
Station sta = stations->get(i);
sta.selected = true;
stations->set(i, sta);
}
}
}
else {
for (int i = 0; i < stations->size(); i++) {
wifi_scan_obj.getMAC(addr, stations->get(i).mac, 0);
if (strcmp(addr, btn_text.c_str()) == 0) {
Serial.print("Removing Station: ");
Serial.println(addr);
Station sta = stations->get(i);
sta.selected = false;
stations->set(i, sta);
}
}
}
}
}
// GFX Function to build a list showing all EP HTML Files
void MenuFunctions::selectEPHTMLGFX() {
extern EvilPortal evil_portal_obj;
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_size(list1, 160, 200);
lv_obj_set_width(list1, LV_HOR_RES);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * list_btn;
lv_obj_t * label;
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
lv_obj_set_event_cb(list_btn, html_list_cb);
for (int i = 1; i < evil_portal_obj.html_files->size(); i++) {
char buf[evil_portal_obj.html_files->get(i).length() + 1] = {};
evil_portal_obj.html_files->get(i).toCharArray(buf, evil_portal_obj.html_files->get(i).length() + 1);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, buf);
lv_btn_set_checkable(list_btn, true);
lv_obj_set_event_cb(list_btn, html_list_cb);
if (i == evil_portal_obj.selected_html_index)
lv_btn_toggle(list_btn);
}
}
void html_list_cb(lv_obj_t * btn, lv_event_t event) {
extern EvilPortal evil_portal_obj;
extern MenuFunctions menu_function_obj;
String btn_text = lv_list_get_btn_text(btn);
String display_string = "";
if (event == LV_EVENT_CLICKED) {
if (btn_text != text09) {
}
else {
Serial.println("Exiting...");
lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
for (int i = 1; i < evil_portal_obj.html_files->size(); i++) {
if (i == evil_portal_obj.selected_html_index) {
Serial.println("Selected: " + (String)evil_portal_obj.html_files->get(i));
}
}
printf("LV_EVENT_CANCEL\n");
menu_function_obj.deinitLVGL();
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
display_obj.exit_draw = true; // set everything back to normal
}
}
if (event == LV_EVENT_VALUE_CHANGED) {
if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
for (int i = 1; i < evil_portal_obj.html_files->size(); i++) {
if (evil_portal_obj.html_files->get(i) == btn_text) {
Serial.println("Setting HTML: " + (String)evil_portal_obj.html_files->get(i));
evil_portal_obj.selected_html_index = i;
evil_portal_obj.target_html_name = (String)evil_portal_obj.html_files->get(i);
}
}
// Deselect buttons that were previously selected
lv_obj_t * list = lv_obj_get_parent(btn);
lv_obj_t * next_btn = lv_obj_get_child(list, NULL);
while (next_btn != NULL) {
if (next_btn != btn) {
lv_btn_set_state(next_btn, LV_BTN_STATE_RELEASED);
}
next_btn = lv_obj_get_child(list, next_btn);
}
}
}
}
// GFX Function to build a list showing all APs scanned
void MenuFunctions::addAPGFX(){
extern LinkedList<AccessPoint>* access_points;
lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
lv_obj_set_size(list1, 160, 200);
lv_obj_set_width(list1, LV_HOR_RES);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * list_btn;
lv_obj_t * label;
list_btn = lv_list_add_btn(list1, LV_SYMBOL_CLOSE, text09);
lv_obj_set_event_cb(list_btn, ap_list_cb);
for (int i = 0; i < access_points->size(); i++) {
char buf[access_points->get(i).essid.length() + 1] = {};
access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
list_btn = lv_list_add_btn(list1, LV_SYMBOL_WIFI, buf);
lv_btn_set_checkable(list_btn, true);
lv_obj_set_event_cb(list_btn, ap_list_cb);
if (access_points->get(i).selected)
lv_btn_toggle(list_btn);
}
}
void ap_list_cb(lv_obj_t * btn, lv_event_t event) {
extern LinkedList<AccessPoint>* access_points;
extern MenuFunctions menu_function_obj;
String btn_text = lv_list_get_btn_text(btn);
String display_string = "";
if (event == LV_EVENT_CLICKED) {
if (btn_text != text09) {
}
else {
Serial.println("Exiting...");
lv_obj_del_async(lv_obj_get_parent(lv_obj_get_parent(btn)));
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).selected) {
Serial.println("Selected: " + (String)access_points->get(i).essid);
}
}
printf("LV_EVENT_CANCEL\n");
menu_function_obj.deinitLVGL();
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
display_obj.exit_draw = true; // set everything back to normal
}
}
if (event == LV_EVENT_VALUE_CHANGED) {
if (lv_btn_get_state(btn) == LV_BTN_STATE_CHECKED_RELEASED) {
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).essid == btn_text) {
Serial.println("Adding AP: " + (String)access_points->get(i).essid);
AccessPoint ap = access_points->get(i);
ap.selected = true;
access_points->set(i, ap);
}
}
}
else {
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).essid == btn_text) {
Serial.println("Removing AP: " + (String)access_points->get(i).essid);
AccessPoint ap = access_points->get(i);
ap.selected = false;
access_points->set(i, ap);
}
}
}
}
}
void MenuFunctions::addSSIDGFX(){
extern LinkedList<ssid>* ssids;
String display_string = "";
// Create a keyboard and apply the styles
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_set_event_cb(kb, add_ssid_keyboard_event_cb);
// Create one text area
// Store all SSIDs
ta1 = lv_textarea_create(lv_scr_act(), NULL);
lv_textarea_set_one_line(ta1, false);
lv_obj_set_width(ta1, LV_HOR_RES);
lv_obj_set_height(ta1, (LV_VER_RES / 2) - 35);
lv_obj_set_pos(ta1, 5, 20);
lv_textarea_set_cursor_hidden(ta1, true);
lv_obj_align(ta1, NULL, LV_ALIGN_IN_TOP_MID, NULL, NULL);
lv_textarea_set_placeholder_text(ta1, text_table1[0]);
// Create second text area
// Add SSIDs
ta2 = lv_textarea_create(lv_scr_act(), ta1);
lv_textarea_set_cursor_hidden(ta2, false);
lv_textarea_set_one_line(ta2, true);
lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_MID, NULL, (LV_VER_RES / 2) - 35);
lv_textarea_set_text(ta2, "");
lv_textarea_set_placeholder_text(ta2, text_table1[1]);
// After generating text areas, add text to first text box
for (int i = 0; i < ssids->size(); i++)
display_string.concat((String)ssids->get(i).essid + "\n");
lv_textarea_set_text(ta1, display_string.c_str());
// Focus it on one of the text areas to start
lv_keyboard_set_textarea(kb, ta2);
lv_keyboard_set_cursor_manage(kb, true);
}
// Keyboard callback dedicated to joining wifi
void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
extern Display display_obj;
extern MenuFunctions menu_function_obj;
extern WiFiScan wifi_scan_obj;
extern LinkedList<ssid>* ssids;
lv_keyboard_def_event_cb(kb, event);
// User has applied text box
if(event == LV_EVENT_APPLY){
String display_string = "";
printf("LV_EVENT_APPLY\n");
// Get text from SSID text box
String ta2_text = lv_textarea_get_text(ta2);
Serial.println(ta2_text);
// Add text box text to list of SSIDs
wifi_scan_obj.addSSID(ta2_text);
// Update large text box with ssid
for (int i = 0; i < ssids->size(); i++)
display_string.concat((String)ssids->get(i).essid + "\n");
lv_textarea_set_text(ta1, display_string.c_str());
lv_textarea_set_text(ta2, "");
}else if(event == LV_EVENT_CANCEL){
printf("LV_EVENT_CANCEL\n");
menu_function_obj.deinitLVGL();
display_obj.exit_draw = true; // set everything back to normal
}
}
void ta_event_cb(lv_obj_t * ta, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
if(kb != NULL)
lv_keyboard_set_textarea(kb, ta);
}
}
#endif
//// END LV_ARDUINO STUFF
void MenuFunctions::buttonNotSelected(uint8_t b, int8_t x) {
if (x == -1)
x = b;
display_obj.tft.setFreeFont(NULL);
display_obj.key[b].drawButton(false, current_menu->list->get(x).name);
}
void MenuFunctions::buttonSelected(uint8_t b, int8_t x) {
if (x == -1)
x = b;
display_obj.tft.setFreeFont(NULL);
display_obj.key[b].drawButton(true, current_menu->list->get(x).name);
}
// Function to check menu input
void MenuFunctions::main(uint32_t currentTime)
{
// Some function exited and we need to go back to normal
if (display_obj.exit_draw) {
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
display_obj.exit_draw = false;
this->orientDisplay();
}
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
(wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
(wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
(wifi_scan_obj.currentScanMode == SHOW_INFO) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_DATA) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_NMEA)) {
if (wifi_scan_obj.orient_display) {
this->orientDisplay();
wifi_scan_obj.orient_display = false;
}
/*#ifdef HAS_ILI9341
if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
(wifi_scan_obj.currentScanMode != LV_ADD_SSID))
display_obj.updateBanner(current_menu->name);
#endif*/
}
if (currentTime != 0) {
if (currentTime - initTime >= BANNER_TIME) {
this->initTime = millis();
if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
(wifi_scan_obj.currentScanMode != LV_ADD_SSID))
this->updateStatusBar();
}
}
boolean pressed = false;
// This is code from bodmer's keypad example
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
// Get the display buffer out of the way
if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_TARGETED) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
display_obj.displayBuffer();
// Pressed will be set true is there is a valid touch on the screen
int pre_getTouch = millis();
// getTouch causes a 10ms delay which makes beacon spam less effective
#ifdef HAS_ILI9341
if (!this->disable_touch)
pressed = this->updateTouch(&t_x, &t_y);
#endif
// This is if there are scans/attacks going on
#ifdef HAS_ILI9341
if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
(pressed) &&
(wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
(wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
(wifi_scan_obj.currentScanMode != SHOW_INFO) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA))
{
// Stop the current scan
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_EVIL_PORTAL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_SIG_STREN) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_TARGETED) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SOUR_APPLE) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SWIFTPAIR_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SPAM_ALL) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SAMSUNG_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_GOOGLE_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_WAR_DRIVE_CONT) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS))
{
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
// If we don't do this, the text and button coordinates will be off
display_obj.tft.init();
// Take us back to the menu
changeMenu(current_menu);
}
x = -1;
y = -1;
return;
}
#endif
#ifdef HAS_BUTTONS
bool c_btn_press = c_btn.justPressed();
#ifndef HAS_ILI9341
if ((c_btn_press) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
(wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
(wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
(wifi_scan_obj.currentScanMode != SHOW_INFO) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA))
{
// Stop the current scan
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_PROBE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_AP) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_EVIL_PORTAL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_SIG_STREN) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_PWN) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ESPRESSIF) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ALL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_DEAUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_AP_SPAM) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_AUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_DEAUTH_TARGETED) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_MIMIC) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
(wifi_scan_obj.currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_ALL) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SOUR_APPLE) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SWIFTPAIR_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SPAM_ALL) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_SAMSUNG_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_ATTACK_GOOGLE_SPAM) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_WAR_DRIVE) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_WAR_DRIVE_CONT) ||
(wifi_scan_obj.currentScanMode == BT_SCAN_SKIMMERS) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) ||
(wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR))
{
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
// If we don't do this, the text and button coordinates will be off
display_obj.tft.init();
// Take us back to the menu
changeMenu(current_menu);
}
x = -1;
y = -1;
return;
}
#endif
#endif
// Check if any key coordinate boxes contain the touch coordinates
// This is for when on a menu
#ifdef HAS_ILI9341
if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_MANUAL) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH_TARGETED) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) &&
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
{
// Need this to set all keys to false
for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) {
if (pressed && display_obj.key[b].contains(t_x, t_y)) {
display_obj.key[b].press(true); // tell the button it is pressed
} else {
display_obj.key[b].press(false); // tell the button it is NOT pressed
}
}
// Check if any key has changed state
for (uint8_t b = 0; b < current_menu->list->size(); b++) {
display_obj.tft.setFreeFont(MENU_FONT);
if (display_obj.key[b].justPressed()) {
display_obj.key[b].drawButton(true, current_menu->list->get(b).name);
if (current_menu->list->get(b).name != text09)
display_obj.tft.drawXBitmap(0,
KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
menu_icons[current_menu->list->get(b).icon],
ICON_W,
ICON_H,
current_menu->list->get(b).color,
TFT_BLACK);
}
// If button was just release, execute the button's function
if ((display_obj.key[b].justReleased()) && (!pressed))
{
display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
current_menu->list->get(b).callable();
}
// This
else if ((display_obj.key[b].justReleased()) && (pressed)) {
display_obj.key[b].drawButton(false, current_menu->list->get(b).name);
if (current_menu->list->get(b).name != text09)
display_obj.tft.drawXBitmap(0,
KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2),
menu_icons[current_menu->list->get(b).icon],
ICON_W,
ICON_H,
TFT_BLACK,
current_menu->list->get(b).color);
}
display_obj.tft.setFreeFont(NULL);
}
}
x = -1;
y = -1;
#endif
#ifdef HAS_BUTTONS
#if !(defined(MARAUDER_V6) || defined(MARAUDER_V6_1))
#ifndef MARAUDER_M5STICKC
if (u_btn.justPressed()){
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
if (current_menu->selected > 0) {
current_menu->selected--;
// Page up
if (current_menu->selected < this->menu_start_index) {
this->buildButtons(current_menu, current_menu->selected);
this->displayCurrentMenu(current_menu->selected);
}
this->buttonSelected(current_menu->selected - this->menu_start_index, current_menu->selected);
if (!current_menu->list->get(current_menu->selected + 1).selected)
this->buttonNotSelected(current_menu->selected + 1 - this->menu_start_index, current_menu->selected + 1);
}
// Loop to end
else {
current_menu->selected = current_menu->list->size() - 1;
if (current_menu->selected >= BUTTON_SCREEN_LIMIT) {
this->buildButtons(current_menu, current_menu->selected + 1 - BUTTON_SCREEN_LIMIT);
this->displayCurrentMenu(current_menu->selected + 1 - BUTTON_SCREEN_LIMIT);
}
this->buttonSelected(current_menu->selected, current_menu->selected);
if (!current_menu->list->get(0).selected)
this->buttonNotSelected(0, this->menu_start_index);
}
}
else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
if (wifi_scan_obj.set_channel < 14)
wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel + 1);
else
wifi_scan_obj.changeChannel(1);
}
}
#endif
if (d_btn.justPressed()){
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
if (current_menu->selected < current_menu->list->size() - 1) {
current_menu->selected++;
this->buttonSelected(current_menu->selected - this->menu_start_index, current_menu->selected);
if (!current_menu->list->get(current_menu->selected - 1).selected)
this->buttonNotSelected(current_menu->selected - 1 - this->menu_start_index, current_menu->selected - 1);
// Page down
if (current_menu->selected - this->menu_start_index >= BUTTON_SCREEN_LIMIT) {
this->buildButtons(current_menu, current_menu->selected + 1 - BUTTON_SCREEN_LIMIT);
this->displayCurrentMenu(current_menu->selected + 1 - BUTTON_SCREEN_LIMIT);
}
}
// Loop to beginning
else {
if (current_menu->selected >= BUTTON_SCREEN_LIMIT) {
this->buildButtons(current_menu);
this->displayCurrentMenu();
}
current_menu->selected = 0;
this->buttonSelected(current_menu->selected);
if (!current_menu->list->get(current_menu->list->size() - 1).selected)
this->buttonNotSelected(current_menu->list->size() - 1);
}
}
else if ((wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_EAPOL)) {
if (wifi_scan_obj.set_channel > 1)
wifi_scan_obj.changeChannel(wifi_scan_obj.set_channel - 1);
else
wifi_scan_obj.changeChannel(14);
}
}
if(c_btn_press){
current_menu->list->get(current_menu->selected).callable();
}
#endif
#endif
}
#if BATTERY_ANALOG_ON == 1
byte battery_analog_array[10];
byte battery_count = 0;
byte battery_analog_last = 101;
#define BATTERY_CHECK 50
uint16_t battery_analog = 0;
void MenuFunctions::battery(bool initial)
{
if (BATTERY_ANALOG_ON) {
uint8_t n = 0;
byte battery_analog_sample[10];
byte deviation;
if (battery_count == BATTERY_CHECK - 5) digitalWrite(BATTERY_PIN, HIGH);
else if (battery_count == 5) digitalWrite(BATTERY_PIN, LOW);
if (battery_count == 0) {
battery_analog = 0;
for (n = 9; n > 0; n--)battery_analog_array[n] = battery_analog_array[n - 1];
for (n = 0; n < 10; n++) {
battery_analog_sample[n] = map((analogRead(ANALOG_PIN) * 5), 2400, 4200, 0, 100);
if (battery_analog_sample[n] > 100) battery_analog_sample[n] = 100;
else if (battery_analog_sample[n] < 0) battery_analog_sample[n] = 0;
battery_analog += battery_analog_sample[n];
}
battery_analog = battery_analog / 10;
for (n = 0; n < 10; n++) {
deviation = abs(battery_analog - battery_analog_sample[n]);
if (deviation >= 10) battery_analog_sample[n] = battery_analog;
}
battery_analog = 0;
for (n = 0; n < 10; n++) battery_analog += battery_analog_sample[n];
battery_analog = battery_analog / 10;
battery_analog_array[0] = battery_analog;
if (battery_analog_array[9] > 0 ) {
battery_analog = 0;
for (n = 0; n < 10; n++) battery_analog += battery_analog_array[n];
battery_analog = battery_analog / 10;
}
battery_count ++;
}
else if (battery_count < BATTERY_CHECK) battery_count++;
else if (battery_count >= BATTERY_CHECK) battery_count = 0;
if (battery_analog_last != battery_analog) {
battery_analog_last = battery_analog;
MenuFunctions::battery2();
}
}
}
void MenuFunctions::battery2(bool initial)
{
uint16_t the_color;
if ( digitalRead(CHARGING_PIN) == 1) the_color = TFT_BLUE;
else if (battery_analog < 20) the_color = TFT_RED;
else if (battery_analog < 40) the_color = TFT_YELLOW;
else the_color = TFT_GREEN;
display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
display_obj.tft.fillRect(186, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
display_obj.tft.drawXBitmap(186,
0,
menu_icons[STATUS_BAT],
16,
16,
STATUSBAR_COLOR,
the_color);
display_obj.tft.drawString((String) battery_analog + "%", 204, 0, 2);
}
#else
void MenuFunctions::battery(bool initial)
{
#ifdef HAS_BATTERY
uint16_t the_color;
if (battery_obj.i2c_supported)
{
// Could use int compare maybe idk
if (((String)battery_obj.battery_level != "25") && ((String)battery_obj.battery_level != "0"))
the_color = TFT_GREEN;
else
the_color = TFT_RED;
if ((battery_obj.battery_level != battery_obj.old_level) || (initial)) {
battery_obj.old_level = battery_obj.battery_level;
display_obj.tft.fillRect(204, 0, SCREEN_WIDTH, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
display_obj.tft.setCursor(0, 1);
display_obj.tft.drawXBitmap(186,
0,
menu_icons[STATUS_BAT],
16,
16,
STATUSBAR_COLOR,
the_color);
display_obj.tft.drawString((String)battery_obj.battery_level + "%", 204, 0, 2);
}
}
#endif
}
void MenuFunctions::battery2(bool initial)
{
MenuFunctions::battery(initial);
}
#endif
void MenuFunctions::updateStatusBar()
{
display_obj.tft.setTextSize(1);
bool status_changed = false;
#if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC) || defined(MARAUDER_REV_FEATHER)
display_obj.tft.setFreeFont(NULL);
#endif
uint16_t the_color;
if (this->old_gps_sat_count != gps_obj.getNumSats()) {
this->old_gps_sat_count = gps_obj.getNumSats();
display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
status_changed = true;
}
// GPS Stuff
#ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) {
if (gps_obj.getFixStatus())
the_color = TFT_GREEN;
else
the_color = TFT_RED;
#ifdef HAS_ILI9341
display_obj.tft.drawXBitmap(4,
0,
menu_icons[STATUS_GPS],
16,
16,
STATUSBAR_COLOR,
the_color);
display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
display_obj.tft.drawString(gps_obj.getNumSatsString(), 22, 0, 2);
#elif defined(HAS_SCREEN)
display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR);
display_obj.tft.drawString("GPS", 0, 0, 1);
#endif
}
#endif
display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR);
// WiFi Channel Stuff
if ((wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) || (status_changed)) {
wifi_scan_obj.old_channel = wifi_scan_obj.set_channel;
#if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC) || defined(MARAUDER_REV_FEATHER)
display_obj.tft.fillRect(43, 0, TFT_WIDTH * 0.21, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
#else
display_obj.tft.fillRect(50, 0, TFT_WIDTH * 0.21, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
#endif
#ifdef HAS_ILI9341
display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2);
#endif
#if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC) || defined(MARAUDER_REV_FEATHER)
display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1);
#endif
}
// RAM Stuff
wifi_scan_obj.freeRAM();
if ((wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) || (status_changed)) {
wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram;
display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR);
#ifdef HAS_ILI9341
display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2);
#endif
#if defined(MARAUDER_MINI) || defined(MARAUDER_M5STICKC) || defined(MARAUDER_REV_FEATHER)
display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1);