Display.h 5.3 KB

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