Display.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. #include "Display.h"
  2. /*
  3. Big thanks to bodmer for having great TFT and JPEG libraries
  4. https://github.com/bodmer
  5. */
  6. Display::Display()
  7. {
  8. }
  9. // Function to prepare the display and the menus
  10. void Display::RunSetup()
  11. {
  12. run_setup = false;
  13. // Need to declare new
  14. display_buffer = new LinkedList<String>();
  15. tft.init();
  16. tft.setRotation(0); // Portrait
  17. tft.setCursor(0, 0);
  18. //tft.setFreeFont(&FreeMonoBold9pt7b);
  19. // Calibration data
  20. //uint16_t calData[5] = { 390, 3516, 253, 3520, 7 }; tft.setRotation(1); // Portrait
  21. #ifdef TFT_SHIELD
  22. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  23. Serial.println("Using TFT Shield");
  24. #else if defined(TFT_DIY)
  25. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  26. Serial.println("Using TFT DIY");
  27. #endif
  28. tft.setTouch(calData);
  29. //tft.fillScreen(TFT_BLACK);
  30. clearScreen();
  31. Serial.println("SPI_FREQUENCY: " + (String)SPI_FREQUENCY);
  32. Serial.println("SPI_READ_FREQUENCY: " + (String)SPI_READ_FREQUENCY);
  33. Serial.println("SPI_TOUCH_FREQUENCY: " + (String)SPI_TOUCH_FREQUENCY);
  34. // Initialize file system
  35. // This should probably have its own class
  36. if (!SPIFFS.begin()) {
  37. Serial.println("SPIFFS initialisation failed!");
  38. while (1) yield(); // Stay here twiddling thumbs waiting
  39. }
  40. // Draw the title screen
  41. drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image
  42. //showCenterText(version_number, 250);
  43. tft.drawCentreString(version_number, 120, 250, 2);
  44. digitalWrite(TFT_BL, HIGH);
  45. delay(5000);
  46. }
  47. void Display::tftDrawGraphObjects(byte x_scale)
  48. {
  49. //draw the graph objects
  50. tft.fillRect(11, 5, x_scale+1, 120, TFT_BLACK); // positive start point
  51. tft.fillRect(11, 121, x_scale+1, 119, TFT_BLACK); // negative start point
  52. tft.drawFastVLine(10, 5, 230, TFT_WHITE); // y axis
  53. tft.drawFastHLine(10, HEIGHT_1 - 1, 310, TFT_WHITE); // x axis
  54. tft.setTextColor(TFT_YELLOW); tft.setTextSize(1); // set parameters for y axis labels
  55. //tft.setCursor(3, 116); tft.print(midway); // "0" at center of ya axis
  56. tft.setCursor(3, 6); tft.print("+"); // "+' at top of y axis
  57. tft.setCursor(3, 228); tft.print("0"); // "-" at bottom of y axis
  58. }
  59. void Display::tftDrawEapolColorKey()
  60. {
  61. //Display color key
  62. tft.setTextSize(1); tft.setTextColor(TFT_WHITE);
  63. tft.fillRect(14, 0, 15, 8, TFT_CYAN); tft.setCursor(30, 0); tft.print(" - EAPOL");
  64. }
  65. void Display::tftDrawColorKey()
  66. {
  67. //Display color key
  68. tft.setTextSize(1); tft.setTextColor(TFT_WHITE);
  69. tft.fillRect(14, 0, 15, 8, TFT_GREEN); tft.setCursor(30, 0); tft.print(" - Beacons");
  70. tft.fillRect(14, 8, 15, 8, TFT_RED); tft.setCursor(30, 8); tft.print(" - Deauths");
  71. tft.fillRect(14, 16, 15, 8, TFT_BLUE); tft.setCursor(30, 16); tft.print(" - Probes");
  72. }
  73. void Display::tftDrawXScaleButtons(byte x_scale)
  74. {
  75. tft.drawFastVLine(234, 0, 20, TFT_WHITE);
  76. tft.setCursor(208, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("X Scale:"); tft.print(x_scale);
  77. key[0].initButton(&tft, // x - box
  78. 220,
  79. 10, // x, y, w, h, outline, fill, text
  80. 20,
  81. 20,
  82. TFT_BLACK, // Outline
  83. TFT_CYAN, // Fill
  84. TFT_BLACK, // Text
  85. "-",
  86. 2);
  87. key[1].initButton(&tft, // x + box
  88. 249,
  89. 10, // x, y, w, h, outline, fill, text
  90. 20,
  91. 20,
  92. TFT_BLACK, // Outline
  93. TFT_CYAN, // Fill
  94. TFT_BLACK, // Text
  95. "+",
  96. 2);
  97. key[0].setLabelDatum(1, 5, MC_DATUM);
  98. key[1].setLabelDatum(1, 5, MC_DATUM);
  99. key[0].drawButton();
  100. key[1].drawButton();
  101. }
  102. void Display::tftDrawYScaleButtons(byte y_scale)
  103. {
  104. tft.drawFastVLine(290, 0, 20, TFT_WHITE);
  105. tft.setCursor(265, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Y Scale:"); tft.print(y_scale);
  106. key[2].initButton(&tft, // y - box
  107. 276,
  108. 10, // x, y, w, h, outline, fill, text
  109. 20,
  110. 20,
  111. TFT_BLACK, // Outline
  112. TFT_MAGENTA, // Fill
  113. TFT_BLACK, // Text
  114. "-",
  115. 2);
  116. key[3].initButton(&tft, // y + box
  117. 305,
  118. 10, // x, y, w, h, outline, fill, text
  119. 20,
  120. 20,
  121. TFT_BLACK, // Outline
  122. TFT_MAGENTA, // Fill
  123. TFT_BLACK, // Text
  124. "+",
  125. 2);
  126. key[2].setLabelDatum(1, 5, MC_DATUM);
  127. key[3].setLabelDatum(1, 5, MC_DATUM);
  128. key[2].drawButton();
  129. key[3].drawButton();
  130. }
  131. void Display::tftDrawChannelScaleButtons(int set_channel)
  132. {
  133. tft.drawFastVLine(178, 0, 20, TFT_WHITE);
  134. tft.setCursor(145, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Channel:"); tft.print(set_channel);
  135. key[4].initButton(&tft, // channel - box
  136. 164,
  137. 10, // x, y, w, h, outline, fill, text
  138. 20,
  139. 20,
  140. TFT_BLACK, // Outline
  141. TFT_BLUE, // Fill
  142. TFT_BLACK, // Text
  143. "-",
  144. 2);
  145. key[5].initButton(&tft, // channel + box
  146. 193,
  147. 10, // x, y, w, h, outline, fill, text
  148. 20,
  149. 20,
  150. TFT_BLACK, // Outline
  151. TFT_BLUE, // Fill
  152. TFT_BLACK, // Text
  153. "+",
  154. 2);
  155. key[4].setLabelDatum(1, 5, MC_DATUM);
  156. key[5].setLabelDatum(1, 5, MC_DATUM);
  157. key[4].drawButton();
  158. key[5].drawButton();
  159. }
  160. void Display::tftDrawExitScaleButtons()
  161. {
  162. //tft.drawFastVLine(178, 0, 20, TFT_WHITE);
  163. //tft.setCursor(145, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Channel:"); tft.print(set_channel);
  164. key[6].initButton(&tft, // Exit box
  165. 137,
  166. 10, // x, y, w, h, outline, fill, text
  167. 20,
  168. 20,
  169. TFT_ORANGE, // Outline
  170. TFT_RED, // Fill
  171. TFT_BLACK, // Text
  172. "X",
  173. 2);
  174. key[6].setLabelDatum(1, 5, MC_DATUM);
  175. key[6].drawButton();
  176. }
  177. void Display::twoPartDisplay(String center_text)
  178. {
  179. tft.setTextColor(TFT_BLACK, TFT_YELLOW);
  180. tft.fillRect(0,16,HEIGHT_1,144, TFT_YELLOW);
  181. //tft.drawCentreString(center_text,120,82,1);
  182. tft.setTextWrap(true);
  183. tft.setFreeFont(NULL);
  184. //showCenterText(center_text, 82);
  185. //tft.drawCentreString(center_text,120,82,1);
  186. tft.setCursor(0, 82);
  187. tft.println(center_text);
  188. tft.setFreeFont(MENU_FONT);
  189. tft.setTextWrap(false);
  190. }
  191. void Display::touchToExit()
  192. {
  193. tft.setTextColor(TFT_BLACK, TFT_LIGHTGREY);
  194. tft.fillRect(0,32,HEIGHT_1,16, TFT_LIGHTGREY);
  195. tft.drawCentreString("Touch screen to exit",120,32,2);
  196. }
  197. // Function to just draw the screen black
  198. void Display::clearScreen()
  199. {
  200. Serial.println("clearScreen()");
  201. tft.fillScreen(TFT_BLACK);
  202. tft.setCursor(0, 0);
  203. }
  204. void Display::displayBuffer(bool do_clear)
  205. {
  206. if (this->display_buffer->size() > 0)
  207. {
  208. delay(1);
  209. while (display_buffer->size() > 0)
  210. {
  211. xPos = 0;
  212. if ((display_buffer->size() > 0) && (!loading))
  213. {
  214. printing = true;
  215. delay(print_delay_1);
  216. yDraw = scroll_line(TFT_RED);
  217. tft.setCursor(xPos, yDraw);
  218. tft.setTextColor(TFT_GREEN, TFT_BLACK);
  219. tft.print(display_buffer->shift());
  220. printing = false;
  221. delay(print_delay_2);
  222. }
  223. if (!tteBar)
  224. blank[(18+(yStart - TOP_FIXED_AREA) / TEXT_HEIGHT)%19] = xPos;
  225. else
  226. blank[(18+(yStart - TOP_FIXED_AREA_2) / TEXT_HEIGHT)%19] = xPos;
  227. }
  228. }
  229. }
  230. void Display::showCenterText(String text, int y)
  231. {
  232. tft.setCursor((SCREEN_WIDTH - (text.length() * 6)) / 2, y);
  233. tft.println(text);
  234. }
  235. void Display::initScrollValues(bool tte)
  236. {
  237. Serial.println("initScrollValues()");
  238. yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
  239. xPos = 0;
  240. if (!tte)
  241. {
  242. yStart = TOP_FIXED_AREA;
  243. yArea = YMAX - TOP_FIXED_AREA - BOT_FIXED_AREA;
  244. }
  245. else
  246. {
  247. yStart = TOP_FIXED_AREA_2;
  248. yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
  249. }
  250. for(int i = 0; i < 18; i++) blank[i] = 0;
  251. }
  252. // Function to execute hardware scroll for TFT screen
  253. int Display::scroll_line(uint32_t color) {
  254. //Serial.println("scroll_line()");
  255. int yTemp = yStart; // Store the old yStart, this is where we draw the next line
  256. // Use the record of line lengths to optimise the rectangle size we need to erase the top line
  257. // Check if we have the "touch to exit bar"
  258. if (!tteBar)
  259. {
  260. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  261. // Change the top of the scroll area
  262. yStart+=TEXT_HEIGHT;
  263. // The value must wrap around as the screen memory is a circular buffer
  264. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA);
  265. }
  266. else
  267. {
  268. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA_2)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  269. // Change the top of the scroll area
  270. yStart+=TEXT_HEIGHT;
  271. // The value must wrap around as the screen memory is a circular buffer
  272. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA_2 + (yStart - YMAX + BOT_FIXED_AREA);
  273. }
  274. // Now we can scroll the display
  275. scrollAddress(yStart);
  276. return yTemp;
  277. }
  278. // Function to setup hardware scroll for TFT screen
  279. void Display::setupScrollArea(uint16_t tfa, uint16_t bfa) {
  280. Serial.println("setupScrollArea()");
  281. Serial.println(" tfa: " + (String)tfa);
  282. Serial.println(" bfa: " + (String)bfa);
  283. Serial.println("yStart: " + (String)this->yStart);
  284. tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
  285. tft.writedata(tfa >> 8); // Top Fixed Area line count
  286. tft.writedata(tfa);
  287. tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count
  288. tft.writedata(YMAX-tfa-bfa);
  289. tft.writedata(bfa >> 8); // Bottom Fixed Area line count
  290. tft.writedata(bfa);
  291. }
  292. void Display::scrollAddress(uint16_t vsp) {
  293. tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
  294. tft.writedata(vsp>>8);
  295. tft.writedata(vsp);
  296. }
  297. // JPEG_functions
  298. void Display::drawJpeg(const char *filename, int xpos, int ypos) {
  299. // Open the named file (the Jpeg decoder library will close it after rendering image)
  300. fs::File jpegFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  301. //ESP32 always seems to return 1 for jpegFile so this null trap does not work
  302. if ( !jpegFile ) {
  303. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  304. return;
  305. }
  306. // Use one of the three following methods to initialise the decoder,
  307. // the filename can be a String or character array type:
  308. boolean decoded = JpegDec.decodeFsFile(filename); // or pass the filename (leading / distinguishes SPIFFS files)
  309. if (decoded) {
  310. // print information about the image to the serial port
  311. jpegInfo();
  312. // render the image onto the screen at given coordinates
  313. jpegRender(xpos, ypos);
  314. }
  315. else {
  316. Serial.println("Jpeg file format not supported!");
  317. }
  318. }
  319. void Display::drawStylus()
  320. {
  321. uint16_t x = 0, y = 0; // To store the touch coordinates
  322. // Pressed will be set true is there is a valid touch on the screen
  323. boolean pressed = tft.getTouch(&x, &y);
  324. // Draw a white spot at the detected coordinates
  325. if (pressed) {
  326. tft.fillCircle(x, y, 2, TFT_WHITE);
  327. //Serial.print("x,y = ");
  328. //Serial.print(x);
  329. //Serial.print(",");
  330. //Serial.println(y);
  331. }
  332. }
  333. //====================================================================================
  334. // Decode and render the Jpeg image onto the TFT screen
  335. //====================================================================================
  336. void Display::jpegRender(int xpos, int ypos) {
  337. // retrieve infomration about the image
  338. uint16_t *pImg;
  339. int16_t mcu_w = JpegDec.MCUWidth;
  340. int16_t mcu_h = JpegDec.MCUHeight;
  341. int32_t max_x = JpegDec.width;
  342. int32_t max_y = JpegDec.height;
  343. // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
  344. // Typically these MCUs are 16x16 pixel blocks
  345. // Determine the width and height of the right and bottom edge image blocks
  346. int32_t min_w = minimum(mcu_w, max_x % mcu_w);
  347. int32_t min_h = minimum(mcu_h, max_y % mcu_h);
  348. // save the current image block size
  349. int32_t win_w = mcu_w;
  350. int32_t win_h = mcu_h;
  351. // record the current time so we can measure how long it takes to draw an image
  352. uint32_t drawTime = millis();
  353. // save the coordinate of the right and bottom edges to assist image cropping
  354. // to the screen size
  355. max_x += xpos;
  356. max_y += ypos;
  357. // read each MCU block until there are no more
  358. while ( JpegDec.readSwappedBytes()) { // Swapped byte order read
  359. // save a pointer to the image block
  360. pImg = JpegDec.pImage;
  361. // calculate where the image block should be drawn on the screen
  362. int mcu_x = JpegDec.MCUx * mcu_w + xpos; // Calculate coordinates of top left corner of current MCU
  363. int mcu_y = JpegDec.MCUy * mcu_h + ypos;
  364. // check if the image block size needs to be changed for the right edge
  365. if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
  366. else win_w = min_w;
  367. // check if the image block size needs to be changed for the bottom edge
  368. if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
  369. else win_h = min_h;
  370. // copy pixels into a contiguous block
  371. if (win_w != mcu_w)
  372. {
  373. for (int h = 1; h < win_h-1; h++)
  374. {
  375. memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
  376. }
  377. }
  378. // draw image MCU block only if it will fit on the screen
  379. if ( mcu_x < tft.width() && mcu_y < tft.height())
  380. {
  381. // Now push the image block to the screen
  382. tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
  383. }
  384. else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();
  385. }
  386. // calculate how long it took to draw the image
  387. drawTime = millis() - drawTime; // Calculate the time it took
  388. }
  389. //====================================================================================
  390. // Print information decoded from the Jpeg image
  391. //====================================================================================
  392. void Display::jpegInfo() {
  393. /*
  394. Serial.println("===============");
  395. Serial.println("JPEG image info");
  396. Serial.println("===============");
  397. Serial.print ("Width :"); Serial.println(JpegDec.width);
  398. Serial.print ("Height :"); Serial.println(JpegDec.height);
  399. Serial.print ("Components :"); Serial.println(JpegDec.comps);
  400. Serial.print ("MCU / row :"); Serial.println(JpegDec.MCUSPerRow);
  401. Serial.print ("MCU / col :"); Serial.println(JpegDec.MCUSPerCol);
  402. Serial.print ("Scan type :"); Serial.println(JpegDec.scanType);
  403. Serial.print ("MCU width :"); Serial.println(JpegDec.MCUWidth);
  404. Serial.print ("MCU height :"); Serial.println(JpegDec.MCUHeight);
  405. Serial.println("===============");
  406. Serial.println("");
  407. */
  408. }
  409. //====================================================================================
  410. // Open a Jpeg file and send it to the Serial port in a C array compatible format
  411. //====================================================================================
  412. void createArray(const char *filename) {
  413. // Open the named file
  414. fs::File jpgFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  415. // File jpgFile = SD.open( filename, FILE_READ); // or, file handle reference for SD library
  416. if ( !jpgFile ) {
  417. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  418. return;
  419. }
  420. uint8_t data;
  421. byte line_len = 0;
  422. Serial.println("");
  423. Serial.println("// Generated by a JPEGDecoder library example sketch:");
  424. Serial.println("// https://github.com/Bodmer/JPEGDecoder");
  425. Serial.println("");
  426. Serial.println("#if defined(__AVR__)");
  427. Serial.println(" #include <avr/pgmspace.h>");
  428. Serial.println("#endif");
  429. Serial.println("");
  430. Serial.print ("const uint8_t ");
  431. while (*filename != '.') Serial.print(*filename++);
  432. Serial.println("[] PROGMEM = {"); // PROGMEM added for AVR processors, it is ignored by Due
  433. while ( jpgFile.available()) {
  434. data = jpgFile.read();
  435. Serial.print("0x"); if (abs(data) < 16) Serial.print("0");
  436. Serial.print(data, HEX); Serial.print(",");// Add value and comma
  437. line_len++;
  438. if ( line_len >= 32) {
  439. line_len = 0;
  440. Serial.println();
  441. }
  442. }
  443. Serial.println("};\r\n");
  444. jpgFile.close();
  445. }
  446. // End JPEG_functions
  447. // SPIFFS_functions
  448. #ifdef ESP8266
  449. void Display::listFiles(void) {
  450. Serial.println();
  451. Serial.println("SPIFFS files found:");
  452. fs::Dir dir = SPIFFS.openDir("/"); // Root directory
  453. String line = "=====================================";
  454. Serial.println(line);
  455. Serial.println(" File name Size");
  456. Serial.println(line);
  457. while (dir.next()) {
  458. String fileName = dir.fileName();
  459. Serial.print(fileName);
  460. int spaces = 21 - fileName.length(); // Tabulate nicely
  461. while (spaces--) Serial.print(" ");
  462. fs::File f = dir.openFile("r");
  463. String fileSize = (String) f.size();
  464. spaces = 10 - fileSize.length(); // Tabulate nicely
  465. while (spaces--) Serial.print(" ");
  466. Serial.println(fileSize + " bytes");
  467. }
  468. Serial.println(line);
  469. Serial.println();
  470. delay(1000);
  471. }
  472. #endif
  473. //====================================================================================
  474. #ifdef ESP32
  475. void Display::listFiles(void) {
  476. listDir(SPIFFS, "/", 0);
  477. }
  478. void Display::listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
  479. Serial.println();
  480. Serial.println("SPIFFS files found:");
  481. Serial.printf("Listing directory: %s\n", "/");
  482. String line = "=====================================";
  483. Serial.println(line);
  484. Serial.println(" File name Size");
  485. Serial.println(line);
  486. fs::File root = fs.open(dirname);
  487. if (!root) {
  488. Serial.println("Failed to open directory");
  489. return;
  490. }
  491. if (!root.isDirectory()) {
  492. Serial.println("Not a directory");
  493. return;
  494. }
  495. fs::File file = root.openNextFile();
  496. while (file) {
  497. if (file.isDirectory()) {
  498. Serial.print("DIR : ");
  499. String fileName = file.name();
  500. Serial.print(fileName);
  501. if (levels) {
  502. listDir(fs, file.name(), levels - 1);
  503. }
  504. } else {
  505. String fileName = file.name();
  506. Serial.print(" " + fileName);
  507. int spaces = 20 - fileName.length(); // Tabulate nicely
  508. while (spaces--) Serial.print(" ");
  509. String fileSize = (String) file.size();
  510. spaces = 10 - fileSize.length(); // Tabulate nicely
  511. while (spaces--) Serial.print(" ");
  512. Serial.println(fileSize + " bytes");
  513. }
  514. file = root.openNextFile();
  515. }
  516. Serial.println(line);
  517. Serial.println();
  518. delay(1000);
  519. }
  520. #endif
  521. void Display::updateBanner(String msg)
  522. {
  523. this->img.deleteSprite();
  524. this->img.setColorDepth(8);
  525. this->img.createSprite(SCREEN_WIDTH, TEXT_HEIGHT);
  526. this->buildBanner(msg, current_banner_pos);
  527. this->img.pushSprite(0, STATUS_BAR_WIDTH);
  528. current_banner_pos--;
  529. if (current_banner_pos <= 0)
  530. current_banner_pos = SCREEN_WIDTH + 2;
  531. }
  532. void Display::buildBanner(String msg, int xpos)
  533. {
  534. int h = TEXT_HEIGHT;
  535. // We could just use fillSprite(color) but lets be a bit more creative...
  536. // Fill with rainbow stripes
  537. //while (h--) img.drawFastHLine(0, h, SCREEN_WIDTH, 255);
  538. // Draw some graphics, the text will apear to scroll over these
  539. //img.fillRect (SCREEN_WIDTH / 2 - 20, TEXT_HEIGHT / 2 - 10, 40, 20, TFT_YELLOW);
  540. //img.fillCircle(SCREEN_WIDTH / 2, TEXT_HEIGHT / 2, 10, TFT_ORANGE);
  541. // Now print text on top of the graphics
  542. img.setTextSize(2); // Font size scaling is x1
  543. img.setTextFont(0); // Font 4 selected
  544. img.setTextColor(TFT_WHITE); // Black text, no background colour
  545. img.setTextWrap(false); // Turn of wrap so we can print past end of sprite
  546. // Need to print twice so text appears to wrap around at left and right edges
  547. img.setCursor(xpos, 2); // Print text at xpos
  548. img.print(msg);
  549. img.setCursor(xpos - SCREEN_WIDTH, 2); // Print text at xpos - sprite width
  550. img.print(msg);
  551. }
  552. void Display::main()
  553. {
  554. return;
  555. }
  556. // End SPIFFS_functions