Display.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef Display_h
  2. #define Display_h
  3. #include <FS.h>
  4. #include <functional>
  5. #include <JPEGDecoder.h>
  6. //#include <SimpleList.h>
  7. #include <LinkedList.h>
  8. #include <SPI.h>
  9. #include <lvgl.h>
  10. #include <Ticker.h>
  11. //#include <M5Stack.h>
  12. #include "SPIFFS.h"
  13. #include "Assets.h"
  14. #include <TFT_eSPI.h>
  15. // WiFi stuff
  16. #define OTA_UPDATE 100
  17. #define SHOW_INFO 101
  18. #define WIFI_SCAN_OFF 0
  19. #define WIFI_SCAN_PROBE 1
  20. #define WIFI_SCAN_AP 2
  21. #define WIFI_SCAN_PWN 3
  22. #define WIFI_SCAN_EAPOL 4
  23. #define WIFI_SCAN_DEAUTH 5
  24. #define WIFI_SCAN_ALL 6
  25. #define WIFI_PACKET_MONITOR 7
  26. #define WIFI_ATTACK_BEACON_SPAM 8
  27. #define WIFI_ATTACK_RICK_ROLL 9
  28. #define BT_SCAN_ALL 10
  29. #define BT_SCAN_SKIMMERS 11
  30. #define WIFI_SCAN_ESPRESSIF 12
  31. #define LV_JOIN_WIFI 13
  32. #define LV_ADD_SSID 14
  33. #define WIFI_ATTACK_BEACON_LIST 15
  34. #define TFT_SHIELD
  35. //#define TFT_DIY
  36. #define SCREEN_WIDTH 240
  37. #define SCREEN_HEIGHT 320
  38. #define HEIGHT_1 240
  39. #define WIDTH_1 320
  40. #define STANDARD_FONT_CHAR_LIMIT 40 // number of characters on a single line with normal font
  41. #define TEXT_HEIGHT 16 // Height of text to be printed and scrolled
  42. #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
  43. #define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen)
  44. #define YMAX 320 // Bottom of screen area
  45. #define minimum(a,b) (((a) < (b)) ? (a) : (b))
  46. //#define MENU_FONT NULL
  47. #define MENU_FONT &FreeMono9pt7b // Winner
  48. //#define MENU_FONT &FreeMonoBold9pt7b
  49. //#define MENU_FONT &FreeSans9pt7b
  50. //#define MENU_FONT &FreeSansBold9pt7b
  51. #define BUTTON_ARRAY_LEN 7
  52. #define STATUS_BAR_WIDTH 16
  53. #define LVGL_TICK_PERIOD 6
  54. #define STATUSBAR_COLOR 0x4A49
  55. /*
  56. PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
  57. PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
  58. PROGMEM static lv_disp_buf_t disp_buf;
  59. PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
  60. PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
  61. PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
  62. // lvgl stuff
  63. PROGMEM static lv_obj_t *kb;
  64. */
  65. class Display
  66. {
  67. private:
  68. bool run_setup = true;
  69. // For the byte we read from the serial port
  70. byte data = 0;
  71. // A few test variables used during debugging
  72. boolean change_colour = 1;
  73. boolean selected = 1;
  74. //void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
  75. //void changeMenu(Menu* menu);
  76. //void showMenuList(Menu* menu, int layer);
  77. //static void lv_tick_handler();
  78. public:
  79. Display();
  80. //Ticker tick;
  81. TFT_eSPI tft = TFT_eSPI();
  82. TFT_eSprite img = TFT_eSprite(&tft);
  83. TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
  84. const String PROGMEM version_number = "v0.8.0";
  85. bool printing = false;
  86. bool loading = false;
  87. bool tteBar = false;
  88. bool draw_tft = false;
  89. bool exit_draw = false;
  90. int TOP_FIXED_AREA_2 = 48;
  91. int print_delay_1, print_delay_2 = 10;
  92. int current_banner_pos = SCREEN_WIDTH;
  93. //Menu* current_menu;
  94. //Menu mainMenu;
  95. //Menu wifiMenu;
  96. //Menu bluetoothMenu;
  97. LinkedList<String>* display_buffer;
  98. // The initial y coordinate of the top of the bottom text line
  99. uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
  100. // Keep track of the drawing x coordinate
  101. uint16_t xPos = 0;
  102. // The initial y coordinate of the top of the scrolling area
  103. uint16_t yStart = TOP_FIXED_AREA_2;
  104. // yArea must be a integral multiple of TEXT_HEIGHT
  105. uint16_t yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
  106. // We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
  107. // for a full width line, meanwhile the serial buffer may be filling... and overflowing
  108. // We can speed up scrolling of short text lines by just blanking the character we drew
  109. int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
  110. //void initLVGL();
  111. //void deinitLVGL();
  112. //void joinWiFiGFX();
  113. void tftDrawGraphObjects(byte x_scale);
  114. void tftDrawEapolColorKey();
  115. void tftDrawColorKey();
  116. void tftDrawXScaleButtons(byte x_scale);
  117. void tftDrawYScaleButtons(byte y_scale);
  118. void tftDrawChannelScaleButtons(int set_channel);
  119. void tftDrawExitScaleButtons();
  120. void buildBanner(String msg, int xpos);
  121. void clearScreen();
  122. void displayBuffer(bool do_clear = false);
  123. void drawJpeg(const char *filename, int xpos, int ypos);
  124. void setupDraw();
  125. void drawStylus();
  126. void getTouchWhileFunction(bool pressed);
  127. void initScrollValues(bool tte = false);
  128. void jpegInfo();
  129. void jpegRender(int xpos, int ypos);
  130. void listDir(fs::FS &fs, const char * dirname, uint8_t levels);
  131. void listFiles();
  132. void main(uint8_t scan_mode);
  133. void RunSetup();
  134. void scrollAddress(uint16_t vsp);
  135. int scroll_line(uint32_t color);
  136. void setupScrollArea(uint16_t tfa, uint16_t bfa);
  137. void showCenterText(String text, int y);
  138. void touchToExit();
  139. void twoPartDisplay(String center_text);
  140. void updateBanner(String msg);
  141. };
  142. #endif