Display.h 3.7 KB

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