Display.h 3.8 KB

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