Display.h 5.0 KB

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