Display.h 2.9 KB

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