Display.h 3.7 KB

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