Display.h 3.1 KB

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