Display.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 FRAME_X 100
  65. #define FRAME_Y 64
  66. #define FRAME_W 120
  67. #define FRAME_H 50
  68. // Red zone size
  69. #define REDBUTTON_X FRAME_X
  70. #define REDBUTTON_Y FRAME_Y
  71. #define REDBUTTON_W (FRAME_W/2)
  72. #define REDBUTTON_H FRAME_H
  73. // Green zone size
  74. #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
  75. #define GREENBUTTON_Y FRAME_Y
  76. #define GREENBUTTON_W (FRAME_W/2)
  77. #define GREENBUTTON_H FRAME_H
  78. #define STATUSBAR_COLOR 0x4A49
  79. #define KIT_LED_BUILTIN 13
  80. /*
  81. PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
  82. PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
  83. PROGMEM static lv_disp_buf_t disp_buf;
  84. PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
  85. PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
  86. PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
  87. // lvgl stuff
  88. PROGMEM static lv_obj_t *kb;
  89. */
  90. class Display
  91. {
  92. private:
  93. bool SwitchOn = false;
  94. bool run_setup = true;
  95. // For the byte we read from the serial port
  96. byte data = 0;
  97. // A few test variables used during debugging
  98. boolean change_colour = 1;
  99. boolean selected = 1;
  100. void drawFrame();
  101. //void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
  102. //void changeMenu(Menu* menu);
  103. //void showMenuList(Menu* menu, int layer);
  104. //static void lv_tick_handler();
  105. public:
  106. Display();
  107. //Ticker tick;
  108. TFT_eSPI tft = TFT_eSPI();
  109. TFT_eSprite img = TFT_eSprite(&tft);
  110. TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
  111. const String PROGMEM version_number = "v0.9.5";
  112. bool printing = false;
  113. bool loading = false;
  114. bool tteBar = false;
  115. bool draw_tft = false;
  116. bool exit_draw = false;
  117. int TOP_FIXED_AREA_2 = 48;
  118. int print_delay_1, print_delay_2 = 10;
  119. int current_banner_pos = SCREEN_WIDTH;
  120. //Menu* current_menu;
  121. //Menu mainMenu;
  122. //Menu wifiMenu;
  123. //Menu bluetoothMenu;
  124. LinkedList<String>* display_buffer;
  125. // The initial y coordinate of the top of the bottom text line
  126. uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
  127. // Keep track of the drawing x coordinate
  128. uint16_t xPos = 0;
  129. // The initial y coordinate of the top of the scrolling area
  130. uint16_t yStart = TOP_FIXED_AREA_2;
  131. // yArea must be a integral multiple of TEXT_HEIGHT
  132. uint16_t yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
  133. // We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
  134. // for a full width line, meanwhile the serial buffer may be filling... and overflowing
  135. // We can speed up scrolling of short text lines by just blanking the character we drew
  136. int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
  137. //void initLVGL();
  138. //void deinitLVGL();
  139. //void joinWiFiGFX();
  140. void tftDrawRedOnOffButton();
  141. void tftDrawGreenOnOffButton();
  142. void tftDrawGraphObjects(byte x_scale);
  143. void tftDrawEapolColorKey();
  144. void tftDrawColorKey();
  145. void tftDrawXScaleButtons(byte x_scale);
  146. void tftDrawYScaleButtons(byte y_scale);
  147. void tftDrawChannelScaleButtons(int set_channel);
  148. void tftDrawExitScaleButtons();
  149. void buildBanner(String msg, int xpos);
  150. void clearScreen();
  151. void displayBuffer(bool do_clear = false);
  152. void drawJpeg(const char *filename, int xpos, int ypos);
  153. void setupDraw();
  154. void drawStylus();
  155. void getTouchWhileFunction(bool pressed);
  156. void initScrollValues(bool tte = false);
  157. void jpegInfo();
  158. void jpegRender(int xpos, int ypos);
  159. void listDir(fs::FS &fs, const char * dirname, uint8_t levels);
  160. void listFiles();
  161. void main(uint8_t scan_mode);
  162. void RunSetup();
  163. void scrollAddress(uint16_t vsp);
  164. int scroll_line(uint32_t color);
  165. void setupScrollArea(uint16_t tfa, uint16_t bfa);
  166. void showCenterText(String text, int y);
  167. void touchToExit();
  168. void twoPartDisplay(String center_text);
  169. void updateBanner(String msg);
  170. };
  171. #endif