Display.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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,16,HEIGHT_1,16, TFT_LIGHTGREY);
  195. tft.drawCentreString("Touch screen to exit",120,16,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.print(display_buffer->shift());
  219. printing = false;
  220. delay(print_delay_2);
  221. }
  222. if (!tteBar)
  223. blank[(18+(yStart - TOP_FIXED_AREA) / TEXT_HEIGHT)%19] = xPos;
  224. else
  225. blank[(18+(yStart - TOP_FIXED_AREA_2) / TEXT_HEIGHT)%19] = xPos;
  226. }
  227. }
  228. }
  229. void Display::showCenterText(String text, int y)
  230. {
  231. tft.setCursor((SCREEN_WIDTH - (text.length() * 6)) / 2, y);
  232. tft.println(text);
  233. }
  234. void Display::initScrollValues(bool tte)
  235. {
  236. Serial.println("initScrollValues()");
  237. yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
  238. xPos = 0;
  239. if (!tte)
  240. {
  241. yStart = TOP_FIXED_AREA;
  242. yArea = YMAX - TOP_FIXED_AREA - BOT_FIXED_AREA;
  243. }
  244. else
  245. {
  246. yStart = TOP_FIXED_AREA_2;
  247. yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
  248. }
  249. for(int i = 0; i < 18; i++) blank[i] = 0;
  250. }
  251. // Function to execute hardware scroll for TFT screen
  252. int Display::scroll_line(uint32_t color) {
  253. //Serial.println("scroll_line()");
  254. int yTemp = yStart; // Store the old yStart, this is where we draw the next line
  255. // Use the record of line lengths to optimise the rectangle size we need to erase the top line
  256. // Check if we have the "touch to exit bar"
  257. if (!tteBar)
  258. {
  259. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  260. // Change the top of the scroll area
  261. yStart+=TEXT_HEIGHT;
  262. // The value must wrap around as the screen memory is a circular buffer
  263. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA);
  264. }
  265. else
  266. {
  267. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA_2)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  268. // Change the top of the scroll area
  269. yStart+=TEXT_HEIGHT;
  270. // The value must wrap around as the screen memory is a circular buffer
  271. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA_2 + (yStart - YMAX + BOT_FIXED_AREA);
  272. }
  273. // Now we can scroll the display
  274. scrollAddress(yStart);
  275. return yTemp;
  276. }
  277. // Function to setup hardware scroll for TFT screen
  278. void Display::setupScrollArea(uint16_t tfa, uint16_t bfa) {
  279. Serial.println("setupScrollAread()");
  280. tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
  281. tft.writedata(tfa >> 8); // Top Fixed Area line count
  282. tft.writedata(tfa);
  283. tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count
  284. tft.writedata(YMAX-tfa-bfa);
  285. tft.writedata(bfa >> 8); // Bottom Fixed Area line count
  286. tft.writedata(bfa);
  287. }
  288. void Display::scrollAddress(uint16_t vsp) {
  289. tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
  290. tft.writedata(vsp>>8);
  291. tft.writedata(vsp);
  292. }
  293. // JPEG_functions
  294. void Display::drawJpeg(const char *filename, int xpos, int ypos) {
  295. // Open the named file (the Jpeg decoder library will close it after rendering image)
  296. fs::File jpegFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  297. //ESP32 always seems to return 1 for jpegFile so this null trap does not work
  298. if ( !jpegFile ) {
  299. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  300. return;
  301. }
  302. // Use one of the three following methods to initialise the decoder,
  303. // the filename can be a String or character array type:
  304. boolean decoded = JpegDec.decodeFsFile(filename); // or pass the filename (leading / distinguishes SPIFFS files)
  305. if (decoded) {
  306. // print information about the image to the serial port
  307. jpegInfo();
  308. // render the image onto the screen at given coordinates
  309. jpegRender(xpos, ypos);
  310. }
  311. else {
  312. Serial.println("Jpeg file format not supported!");
  313. }
  314. }
  315. void Display::drawStylus()
  316. {
  317. uint16_t x = 0, y = 0; // To store the touch coordinates
  318. // Pressed will be set true is there is a valid touch on the screen
  319. boolean pressed = tft.getTouch(&x, &y);
  320. // Draw a white spot at the detected coordinates
  321. if (pressed) {
  322. tft.fillCircle(x, y, 2, TFT_WHITE);
  323. //Serial.print("x,y = ");
  324. //Serial.print(x);
  325. //Serial.print(",");
  326. //Serial.println(y);
  327. }
  328. }
  329. //====================================================================================
  330. // Decode and render the Jpeg image onto the TFT screen
  331. //====================================================================================
  332. void Display::jpegRender(int xpos, int ypos) {
  333. // retrieve infomration about the image
  334. uint16_t *pImg;
  335. int16_t mcu_w = JpegDec.MCUWidth;
  336. int16_t mcu_h = JpegDec.MCUHeight;
  337. int32_t max_x = JpegDec.width;
  338. int32_t max_y = JpegDec.height;
  339. // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
  340. // Typically these MCUs are 16x16 pixel blocks
  341. // Determine the width and height of the right and bottom edge image blocks
  342. int32_t min_w = minimum(mcu_w, max_x % mcu_w);
  343. int32_t min_h = minimum(mcu_h, max_y % mcu_h);
  344. // save the current image block size
  345. int32_t win_w = mcu_w;
  346. int32_t win_h = mcu_h;
  347. // record the current time so we can measure how long it takes to draw an image
  348. uint32_t drawTime = millis();
  349. // save the coordinate of the right and bottom edges to assist image cropping
  350. // to the screen size
  351. max_x += xpos;
  352. max_y += ypos;
  353. // read each MCU block until there are no more
  354. while ( JpegDec.readSwappedBytes()) { // Swapped byte order read
  355. // save a pointer to the image block
  356. pImg = JpegDec.pImage;
  357. // calculate where the image block should be drawn on the screen
  358. int mcu_x = JpegDec.MCUx * mcu_w + xpos; // Calculate coordinates of top left corner of current MCU
  359. int mcu_y = JpegDec.MCUy * mcu_h + ypos;
  360. // check if the image block size needs to be changed for the right edge
  361. if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
  362. else win_w = min_w;
  363. // check if the image block size needs to be changed for the bottom edge
  364. if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
  365. else win_h = min_h;
  366. // copy pixels into a contiguous block
  367. if (win_w != mcu_w)
  368. {
  369. for (int h = 1; h < win_h-1; h++)
  370. {
  371. memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
  372. }
  373. }
  374. // draw image MCU block only if it will fit on the screen
  375. if ( mcu_x < tft.width() && mcu_y < tft.height())
  376. {
  377. // Now push the image block to the screen
  378. tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
  379. }
  380. else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();
  381. }
  382. // calculate how long it took to draw the image
  383. drawTime = millis() - drawTime; // Calculate the time it took
  384. }
  385. //====================================================================================
  386. // Print information decoded from the Jpeg image
  387. //====================================================================================
  388. void Display::jpegInfo() {
  389. /*
  390. Serial.println("===============");
  391. Serial.println("JPEG image info");
  392. Serial.println("===============");
  393. Serial.print ("Width :"); Serial.println(JpegDec.width);
  394. Serial.print ("Height :"); Serial.println(JpegDec.height);
  395. Serial.print ("Components :"); Serial.println(JpegDec.comps);
  396. Serial.print ("MCU / row :"); Serial.println(JpegDec.MCUSPerRow);
  397. Serial.print ("MCU / col :"); Serial.println(JpegDec.MCUSPerCol);
  398. Serial.print ("Scan type :"); Serial.println(JpegDec.scanType);
  399. Serial.print ("MCU width :"); Serial.println(JpegDec.MCUWidth);
  400. Serial.print ("MCU height :"); Serial.println(JpegDec.MCUHeight);
  401. Serial.println("===============");
  402. Serial.println("");
  403. */
  404. }
  405. //====================================================================================
  406. // Open a Jpeg file and send it to the Serial port in a C array compatible format
  407. //====================================================================================
  408. void createArray(const char *filename) {
  409. // Open the named file
  410. fs::File jpgFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  411. // File jpgFile = SD.open( filename, FILE_READ); // or, file handle reference for SD library
  412. if ( !jpgFile ) {
  413. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  414. return;
  415. }
  416. uint8_t data;
  417. byte line_len = 0;
  418. Serial.println("");
  419. Serial.println("// Generated by a JPEGDecoder library example sketch:");
  420. Serial.println("// https://github.com/Bodmer/JPEGDecoder");
  421. Serial.println("");
  422. Serial.println("#if defined(__AVR__)");
  423. Serial.println(" #include <avr/pgmspace.h>");
  424. Serial.println("#endif");
  425. Serial.println("");
  426. Serial.print ("const uint8_t ");
  427. while (*filename != '.') Serial.print(*filename++);
  428. Serial.println("[] PROGMEM = {"); // PROGMEM added for AVR processors, it is ignored by Due
  429. while ( jpgFile.available()) {
  430. data = jpgFile.read();
  431. Serial.print("0x"); if (abs(data) < 16) Serial.print("0");
  432. Serial.print(data, HEX); Serial.print(",");// Add value and comma
  433. line_len++;
  434. if ( line_len >= 32) {
  435. line_len = 0;
  436. Serial.println();
  437. }
  438. }
  439. Serial.println("};\r\n");
  440. jpgFile.close();
  441. }
  442. // End JPEG_functions
  443. // SPIFFS_functions
  444. #ifdef ESP8266
  445. void Display::listFiles(void) {
  446. Serial.println();
  447. Serial.println("SPIFFS files found:");
  448. fs::Dir dir = SPIFFS.openDir("/"); // Root directory
  449. String line = "=====================================";
  450. Serial.println(line);
  451. Serial.println(" File name Size");
  452. Serial.println(line);
  453. while (dir.next()) {
  454. String fileName = dir.fileName();
  455. Serial.print(fileName);
  456. int spaces = 21 - fileName.length(); // Tabulate nicely
  457. while (spaces--) Serial.print(" ");
  458. fs::File f = dir.openFile("r");
  459. String fileSize = (String) f.size();
  460. spaces = 10 - fileSize.length(); // Tabulate nicely
  461. while (spaces--) Serial.print(" ");
  462. Serial.println(fileSize + " bytes");
  463. }
  464. Serial.println(line);
  465. Serial.println();
  466. delay(1000);
  467. }
  468. #endif
  469. //====================================================================================
  470. #ifdef ESP32
  471. void Display::listFiles(void) {
  472. listDir(SPIFFS, "/", 0);
  473. }
  474. void Display::listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
  475. Serial.println();
  476. Serial.println("SPIFFS files found:");
  477. Serial.printf("Listing directory: %s\n", "/");
  478. String line = "=====================================";
  479. Serial.println(line);
  480. Serial.println(" File name Size");
  481. Serial.println(line);
  482. fs::File root = fs.open(dirname);
  483. if (!root) {
  484. Serial.println("Failed to open directory");
  485. return;
  486. }
  487. if (!root.isDirectory()) {
  488. Serial.println("Not a directory");
  489. return;
  490. }
  491. fs::File file = root.openNextFile();
  492. while (file) {
  493. if (file.isDirectory()) {
  494. Serial.print("DIR : ");
  495. String fileName = file.name();
  496. Serial.print(fileName);
  497. if (levels) {
  498. listDir(fs, file.name(), levels - 1);
  499. }
  500. } else {
  501. String fileName = file.name();
  502. Serial.print(" " + fileName);
  503. int spaces = 20 - fileName.length(); // Tabulate nicely
  504. while (spaces--) Serial.print(" ");
  505. String fileSize = (String) file.size();
  506. spaces = 10 - fileSize.length(); // Tabulate nicely
  507. while (spaces--) Serial.print(" ");
  508. Serial.println(fileSize + " bytes");
  509. }
  510. file = root.openNextFile();
  511. }
  512. Serial.println(line);
  513. Serial.println();
  514. delay(1000);
  515. }
  516. #endif
  517. void Display::updateBanner(String msg)
  518. {
  519. this->img.deleteSprite();
  520. this->img.setColorDepth(8);
  521. this->img.createSprite(SCREEN_WIDTH, TEXT_HEIGHT);
  522. this->buildBanner(msg, current_banner_pos);
  523. this->img.pushSprite(0, STATUS_BAR_WIDTH);
  524. current_banner_pos--;
  525. if (current_banner_pos <= 0)
  526. current_banner_pos = SCREEN_WIDTH + 2;
  527. }
  528. void Display::buildBanner(String msg, int xpos)
  529. {
  530. int h = TEXT_HEIGHT;
  531. // We could just use fillSprite(color) but lets be a bit more creative...
  532. // Fill with rainbow stripes
  533. //while (h--) img.drawFastHLine(0, h, SCREEN_WIDTH, 255);
  534. // Draw some graphics, the text will apear to scroll over these
  535. //img.fillRect (SCREEN_WIDTH / 2 - 20, TEXT_HEIGHT / 2 - 10, 40, 20, TFT_YELLOW);
  536. //img.fillCircle(SCREEN_WIDTH / 2, TEXT_HEIGHT / 2, 10, TFT_ORANGE);
  537. // Now print text on top of the graphics
  538. img.setTextSize(2); // Font size scaling is x1
  539. img.setTextFont(0); // Font 4 selected
  540. img.setTextColor(TFT_WHITE); // Black text, no background colour
  541. img.setTextWrap(false); // Turn of wrap so we can print past end of sprite
  542. // Need to print twice so text appears to wrap around at left and right edges
  543. img.setCursor(xpos, 2); // Print text at xpos
  544. img.print(msg);
  545. img.setCursor(xpos - SCREEN_WIDTH, 2); // Print text at xpos - sprite width
  546. img.print(msg);
  547. }
  548. void Display::main()
  549. {
  550. return;
  551. }
  552. // End SPIFFS_functions