Display.h 5.0 KB

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