Display.h 4.5 KB

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