Display.cpp 23 KB

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