Display.h 5.2 KB

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