Display.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. #include "Display.h"
  2. /*
  3. Big thanks to bodmer for having great TFT and JPEG libraries
  4. https://github.com/bodmer
  5. */
  6. //PROGMEM lv_obj_t * slider_label;
  7. //PROGMEM lv_obj_t * ta1;
  8. //PROGMEM lv_obj_t * ta2;
  9. Display::Display()
  10. {
  11. }
  12. // Function to prepare the display and the menus
  13. void Display::RunSetup()
  14. {
  15. run_setup = false;
  16. // Need to declare new
  17. display_buffer = new LinkedList<String>();
  18. tft.init();
  19. tft.setRotation(0); // Portrait
  20. tft.setCursor(0, 0);
  21. //tft.setFreeFont(&FreeMonoBold9pt7b);
  22. // Calibration data
  23. //uint16_t calData[5] = { 390, 3516, 253, 3520, 7 }; tft.setRotation(1); // Portrait
  24. #ifdef TFT_SHIELD
  25. uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
  26. Serial.println("Using TFT Shield");
  27. #else if defined(TFT_DIY)
  28. uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
  29. Serial.println("Using TFT DIY");
  30. #endif
  31. tft.setTouch(calData);
  32. //tft.fillScreen(TFT_BLACK);
  33. clearScreen();
  34. Serial.println("SPI_FREQUENCY: " + (String)SPI_FREQUENCY);
  35. Serial.println("SPI_READ_FREQUENCY: " + (String)SPI_READ_FREQUENCY);
  36. Serial.println("SPI_TOUCH_FREQUENCY: " + (String)SPI_TOUCH_FREQUENCY);
  37. // Initialize file system
  38. // This should probably have its own class
  39. if (!SPIFFS.begin()) {
  40. Serial.println("SPIFFS initialisation failed!");
  41. while (1) yield(); // Stay here twiddling thumbs waiting
  42. }
  43. // Draw the title screen
  44. drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image
  45. //showCenterText(version_number, 250);
  46. tft.drawCentreString(version_number, 120, 250, 2);
  47. digitalWrite(TFT_BL, HIGH);
  48. delay(5000);
  49. }
  50. /* Interrupt driven periodic handler */
  51. /*
  52. void Display::lv_tick_handler()
  53. {
  54. lv_tick_inc(LVGL_TICK_PERIOD);
  55. }*/
  56. /* Display flushing */
  57. /*void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  58. {
  59. extern Display display_obj;
  60. uint16_t c;
  61. display_obj.tft.startWrite();
  62. display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
  63. for (int y = area->y1; y <= area->y2; y++) {
  64. for (int x = area->x1; x <= area->x2; x++) {
  65. c = color_p->full;
  66. display_obj.tft.writeColor(c, 1);
  67. color_p++;
  68. }
  69. }
  70. display_obj.tft.endWrite();
  71. lv_disp_flush_ready(disp);
  72. }*/
  73. /*
  74. bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
  75. {
  76. extern Display display_obj;
  77. uint16_t touchX, touchY;
  78. bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
  79. if(!touched)
  80. {
  81. return false;
  82. }
  83. if(touchX>WIDTH_1 || touchY > HEIGHT_1)
  84. {
  85. Serial.println("Y or y outside of expected parameters..");
  86. Serial.print("y:");
  87. Serial.print(touchX);
  88. Serial.print(" x:");
  89. Serial.print(touchY);
  90. }
  91. else
  92. {
  93. data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  94. //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
  95. data->point.x = touchX;
  96. data->point.y = touchY;
  97. Serial.print("Data x");
  98. Serial.println(touchX);
  99. Serial.print("Data y");
  100. Serial.println(touchY);
  101. }
  102. return false;
  103. }*/
  104. void Display::tftDrawGraphObjects(byte x_scale)
  105. {
  106. //draw the graph objects
  107. tft.fillRect(11, 5, x_scale+1, 120, TFT_BLACK); // positive start point
  108. tft.fillRect(11, 121, x_scale+1, 119, TFT_BLACK); // negative start point
  109. tft.drawFastVLine(10, 5, 230, TFT_WHITE); // y axis
  110. tft.drawFastHLine(10, HEIGHT_1 - 1, 310, TFT_WHITE); // x axis
  111. tft.setTextColor(TFT_YELLOW); tft.setTextSize(1); // set parameters for y axis labels
  112. //tft.setCursor(3, 116); tft.print(midway); // "0" at center of ya axis
  113. tft.setCursor(3, 6); tft.print("+"); // "+' at top of y axis
  114. tft.setCursor(3, 228); tft.print("0"); // "-" at bottom of y axis
  115. }
  116. void Display::tftDrawEapolColorKey()
  117. {
  118. //Display color key
  119. tft.setTextSize(1); tft.setTextColor(TFT_WHITE);
  120. tft.fillRect(14, 0, 15, 8, TFT_CYAN); tft.setCursor(30, 0); tft.print(" - EAPOL");
  121. }
  122. void Display::tftDrawColorKey()
  123. {
  124. //Display color key
  125. tft.setTextSize(1); tft.setTextColor(TFT_WHITE);
  126. tft.fillRect(14, 0, 15, 8, TFT_GREEN); tft.setCursor(30, 0); tft.print(" - Beacons");
  127. tft.fillRect(14, 8, 15, 8, TFT_RED); tft.setCursor(30, 8); tft.print(" - Deauths");
  128. tft.fillRect(14, 16, 15, 8, TFT_BLUE); tft.setCursor(30, 16); tft.print(" - Probes");
  129. }
  130. void Display::tftDrawXScaleButtons(byte x_scale)
  131. {
  132. tft.drawFastVLine(234, 0, 20, TFT_WHITE);
  133. tft.setCursor(208, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("X Scale:"); tft.print(x_scale);
  134. key[0].initButton(&tft, // x - box
  135. 220,
  136. 10, // x, y, w, h, outline, fill, text
  137. 20,
  138. 20,
  139. TFT_BLACK, // Outline
  140. TFT_CYAN, // Fill
  141. TFT_BLACK, // Text
  142. "-",
  143. 2);
  144. key[1].initButton(&tft, // x + box
  145. 249,
  146. 10, // x, y, w, h, outline, fill, text
  147. 20,
  148. 20,
  149. TFT_BLACK, // Outline
  150. TFT_CYAN, // Fill
  151. TFT_BLACK, // Text
  152. "+",
  153. 2);
  154. key[0].setLabelDatum(1, 5, MC_DATUM);
  155. key[1].setLabelDatum(1, 5, MC_DATUM);
  156. key[0].drawButton();
  157. key[1].drawButton();
  158. }
  159. void Display::tftDrawYScaleButtons(byte y_scale)
  160. {
  161. tft.drawFastVLine(290, 0, 20, TFT_WHITE);
  162. tft.setCursor(265, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Y Scale:"); tft.print(y_scale);
  163. key[2].initButton(&tft, // y - box
  164. 276,
  165. 10, // x, y, w, h, outline, fill, text
  166. 20,
  167. 20,
  168. TFT_BLACK, // Outline
  169. TFT_MAGENTA, // Fill
  170. TFT_BLACK, // Text
  171. "-",
  172. 2);
  173. key[3].initButton(&tft, // y + box
  174. 305,
  175. 10, // x, y, w, h, outline, fill, text
  176. 20,
  177. 20,
  178. TFT_BLACK, // Outline
  179. TFT_MAGENTA, // Fill
  180. TFT_BLACK, // Text
  181. "+",
  182. 2);
  183. key[2].setLabelDatum(1, 5, MC_DATUM);
  184. key[3].setLabelDatum(1, 5, MC_DATUM);
  185. key[2].drawButton();
  186. key[3].drawButton();
  187. }
  188. void Display::tftDrawChannelScaleButtons(int set_channel)
  189. {
  190. tft.drawFastVLine(178, 0, 20, TFT_WHITE);
  191. tft.setCursor(145, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Channel:"); tft.print(set_channel);
  192. key[4].initButton(&tft, // channel - box
  193. 164,
  194. 10, // x, y, w, h, outline, fill, text
  195. 20,
  196. 20,
  197. TFT_BLACK, // Outline
  198. TFT_BLUE, // Fill
  199. TFT_BLACK, // Text
  200. "-",
  201. 2);
  202. key[5].initButton(&tft, // channel + box
  203. 193,
  204. 10, // x, y, w, h, outline, fill, text
  205. 20,
  206. 20,
  207. TFT_BLACK, // Outline
  208. TFT_BLUE, // Fill
  209. TFT_BLACK, // Text
  210. "+",
  211. 2);
  212. key[4].setLabelDatum(1, 5, MC_DATUM);
  213. key[5].setLabelDatum(1, 5, MC_DATUM);
  214. key[4].drawButton();
  215. key[5].drawButton();
  216. }
  217. void Display::tftDrawExitScaleButtons()
  218. {
  219. //tft.drawFastVLine(178, 0, 20, TFT_WHITE);
  220. //tft.setCursor(145, 21); tft.setTextColor(TFT_WHITE); tft.setTextSize(1); tft.print("Channel:"); tft.print(set_channel);
  221. key[6].initButton(&tft, // Exit box
  222. 137,
  223. 10, // x, y, w, h, outline, fill, text
  224. 20,
  225. 20,
  226. TFT_ORANGE, // Outline
  227. TFT_RED, // Fill
  228. TFT_BLACK, // Text
  229. "X",
  230. 2);
  231. key[6].setLabelDatum(1, 5, MC_DATUM);
  232. key[6].drawButton();
  233. }
  234. void Display::twoPartDisplay(String center_text)
  235. {
  236. tft.setTextColor(TFT_BLACK, TFT_YELLOW);
  237. tft.fillRect(0,16,HEIGHT_1,144, TFT_YELLOW);
  238. //tft.drawCentreString(center_text,120,82,1);
  239. tft.setTextWrap(true);
  240. tft.setFreeFont(NULL);
  241. //showCenterText(center_text, 82);
  242. //tft.drawCentreString(center_text,120,82,1);
  243. tft.setCursor(0, 82);
  244. tft.println(center_text);
  245. tft.setFreeFont(MENU_FONT);
  246. tft.setTextWrap(false);
  247. }
  248. void Display::touchToExit()
  249. {
  250. tft.setTextColor(TFT_BLACK, TFT_LIGHTGREY);
  251. tft.fillRect(0,32,HEIGHT_1,16, TFT_LIGHTGREY);
  252. tft.drawCentreString("Touch screen to exit",120,32,2);
  253. }
  254. // Function to just draw the screen black
  255. void Display::clearScreen()
  256. {
  257. Serial.println("clearScreen()");
  258. tft.fillScreen(TFT_BLACK);
  259. tft.setCursor(0, 0);
  260. }
  261. void Display::displayBuffer(bool do_clear)
  262. {
  263. if (this->display_buffer->size() > 0)
  264. {
  265. delay(1);
  266. while (display_buffer->size() > 0)
  267. {
  268. xPos = 0;
  269. if ((display_buffer->size() > 0) && (!loading))
  270. {
  271. printing = true;
  272. delay(print_delay_1);
  273. yDraw = scroll_line(TFT_RED);
  274. tft.setCursor(xPos, yDraw);
  275. tft.setTextColor(TFT_GREEN, TFT_BLACK);
  276. tft.print(display_buffer->shift());
  277. printing = false;
  278. delay(print_delay_2);
  279. }
  280. if (!tteBar)
  281. blank[(18+(yStart - TOP_FIXED_AREA) / TEXT_HEIGHT)%19] = xPos;
  282. else
  283. blank[(18+(yStart - TOP_FIXED_AREA_2) / TEXT_HEIGHT)%19] = xPos;
  284. }
  285. }
  286. }
  287. void Display::showCenterText(String text, int y)
  288. {
  289. tft.setCursor((SCREEN_WIDTH - (text.length() * 6)) / 2, y);
  290. tft.println(text);
  291. }
  292. void Display::initScrollValues(bool tte)
  293. {
  294. Serial.println("initScrollValues()");
  295. yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
  296. xPos = 0;
  297. if (!tte)
  298. {
  299. yStart = TOP_FIXED_AREA;
  300. yArea = YMAX - TOP_FIXED_AREA - BOT_FIXED_AREA;
  301. }
  302. else
  303. {
  304. yStart = TOP_FIXED_AREA_2;
  305. yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
  306. }
  307. for(int i = 0; i < 18; i++) blank[i] = 0;
  308. }
  309. // Function to execute hardware scroll for TFT screen
  310. int Display::scroll_line(uint32_t color) {
  311. //Serial.println("scroll_line()");
  312. int yTemp = yStart; // Store the old yStart, this is where we draw the next line
  313. // Use the record of line lengths to optimise the rectangle size we need to erase the top line
  314. // Check if we have the "touch to exit bar"
  315. if (!tteBar)
  316. {
  317. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  318. // Change the top of the scroll area
  319. yStart+=TEXT_HEIGHT;
  320. // The value must wrap around as the screen memory is a circular buffer
  321. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA);
  322. }
  323. else
  324. {
  325. tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA_2)/TEXT_HEIGHT],TEXT_HEIGHT, color);
  326. // Change the top of the scroll area
  327. yStart+=TEXT_HEIGHT;
  328. // The value must wrap around as the screen memory is a circular buffer
  329. if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA_2 + (yStart - YMAX + BOT_FIXED_AREA);
  330. }
  331. // Now we can scroll the display
  332. scrollAddress(yStart);
  333. return yTemp;
  334. }
  335. // Function to setup hardware scroll for TFT screen
  336. void Display::setupScrollArea(uint16_t tfa, uint16_t bfa) {
  337. Serial.println("setupScrollArea()");
  338. Serial.println(" tfa: " + (String)tfa);
  339. Serial.println(" bfa: " + (String)bfa);
  340. Serial.println("yStart: " + (String)this->yStart);
  341. tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
  342. tft.writedata(tfa >> 8); // Top Fixed Area line count
  343. tft.writedata(tfa);
  344. tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count
  345. tft.writedata(YMAX-tfa-bfa);
  346. tft.writedata(bfa >> 8); // Bottom Fixed Area line count
  347. tft.writedata(bfa);
  348. }
  349. void Display::scrollAddress(uint16_t vsp) {
  350. tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
  351. tft.writedata(vsp>>8);
  352. tft.writedata(vsp);
  353. }
  354. // JPEG_functions
  355. void Display::drawJpeg(const char *filename, int xpos, int ypos) {
  356. // Open the named file (the Jpeg decoder library will close it after rendering image)
  357. fs::File jpegFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  358. //ESP32 always seems to return 1 for jpegFile so this null trap does not work
  359. if ( !jpegFile ) {
  360. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  361. return;
  362. }
  363. // Use one of the three following methods to initialise the decoder,
  364. // the filename can be a String or character array type:
  365. boolean decoded = JpegDec.decodeFsFile(filename); // or pass the filename (leading / distinguishes SPIFFS files)
  366. if (decoded) {
  367. // print information about the image to the serial port
  368. jpegInfo();
  369. // render the image onto the screen at given coordinates
  370. jpegRender(xpos, ypos);
  371. }
  372. else {
  373. Serial.println("Jpeg file format not supported!");
  374. }
  375. }
  376. uint16_t xlast;
  377. uint16_t ylast;
  378. uint32_t AH;
  379. void Display::drawStylus()
  380. {
  381. uint16_t x = 0, y = 0; // To store the touch coordinates
  382. // Pressed will be set true is there is a valid touch on the screen
  383. boolean pressed = tft.getTouch(&x, &y);
  384. // Draw a white spot at the detected coordinates
  385. if (pressed) {
  386. // tft.fillCircle(x, y, 2, TFT_WHITE);
  387. if ( xlast > 0 && ylast > 0 ) {
  388. uint16_t the_color = TFT_WHITE;
  389. uint16_t wd = 1;
  390. int xlast2;
  391. int ylast2;
  392. int x2;
  393. int y2;
  394. int n;
  395. int n2 = -wd;
  396. xlast2 = xlast - wd;
  397. x2 = x - wd;
  398. for (n = -wd; n <= wd; n++) {
  399. ylast2 = ylast + n;
  400. y2 = y + n;
  401. tft.drawLine(xlast2, ylast2, x2, y2, the_color);
  402. }
  403. for (n2 = -wd; n2 <= wd; n2++) {
  404. xlast2 = xlast + n2;
  405. x2 = x + n2;
  406. tft.drawLine(xlast2, ylast2, x2, y2, the_color);
  407. }
  408. for (n = wd; n >= -wd; n--) {
  409. ylast2 = ylast + n;
  410. y2 = y + n;
  411. tft.drawLine(xlast2, ylast2, x2, y2, the_color);
  412. }
  413. for (n2 = wd; n2 >= -wd; n2--) {
  414. xlast2 = xlast + n2;
  415. x2 = x + n2;
  416. tft.drawLine(xlast2, ylast2, x2, y2, the_color);
  417. }
  418. // tft.drawLine(xlast, ylast, x, y, TFT_WHITE);
  419. }
  420. xlast = x;
  421. ylast = y;
  422. AH = 0;
  423. //Serial.print("x,y = ");
  424. //Serial.print(x);
  425. //Serial.print(",");
  426. //Serial.println(y);
  427. } else if ( AH < 5 ) {
  428. AH++;
  429. } else if ( AH == 5 ) {
  430. xlast = 0;
  431. ylast = 0;
  432. }
  433. }
  434. //====================================================================================
  435. // Decode and render the Jpeg image onto the TFT screen
  436. //====================================================================================
  437. void Display::jpegRender(int xpos, int ypos) {
  438. // retrieve infomration about the image
  439. uint16_t *pImg;
  440. int16_t mcu_w = JpegDec.MCUWidth;
  441. int16_t mcu_h = JpegDec.MCUHeight;
  442. int32_t max_x = JpegDec.width;
  443. int32_t max_y = JpegDec.height;
  444. // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
  445. // Typically these MCUs are 16x16 pixel blocks
  446. // Determine the width and height of the right and bottom edge image blocks
  447. int32_t min_w = minimum(mcu_w, max_x % mcu_w);
  448. int32_t min_h = minimum(mcu_h, max_y % mcu_h);
  449. // save the current image block size
  450. int32_t win_w = mcu_w;
  451. int32_t win_h = mcu_h;
  452. // record the current time so we can measure how long it takes to draw an image
  453. uint32_t drawTime = millis();
  454. // save the coordinate of the right and bottom edges to assist image cropping
  455. // to the screen size
  456. max_x += xpos;
  457. max_y += ypos;
  458. // read each MCU block until there are no more
  459. while ( JpegDec.readSwappedBytes()) { // Swapped byte order read
  460. // save a pointer to the image block
  461. pImg = JpegDec.pImage;
  462. // calculate where the image block should be drawn on the screen
  463. int mcu_x = JpegDec.MCUx * mcu_w + xpos; // Calculate coordinates of top left corner of current MCU
  464. int mcu_y = JpegDec.MCUy * mcu_h + ypos;
  465. // check if the image block size needs to be changed for the right edge
  466. if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
  467. else win_w = min_w;
  468. // check if the image block size needs to be changed for the bottom edge
  469. if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
  470. else win_h = min_h;
  471. // copy pixels into a contiguous block
  472. if (win_w != mcu_w)
  473. {
  474. for (int h = 1; h < win_h-1; h++)
  475. {
  476. memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
  477. }
  478. }
  479. // draw image MCU block only if it will fit on the screen
  480. if ( mcu_x < tft.width() && mcu_y < tft.height())
  481. {
  482. // Now push the image block to the screen
  483. tft.pushImage(mcu_x, mcu_y, win_w, win_h, pImg);
  484. }
  485. else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();
  486. }
  487. // calculate how long it took to draw the image
  488. drawTime = millis() - drawTime; // Calculate the time it took
  489. }
  490. //====================================================================================
  491. // Print information decoded from the Jpeg image
  492. //====================================================================================
  493. void Display::jpegInfo() {
  494. /*
  495. Serial.println("===============");
  496. Serial.println("JPEG image info");
  497. Serial.println("===============");
  498. Serial.print ("Width :"); Serial.println(JpegDec.width);
  499. Serial.print ("Height :"); Serial.println(JpegDec.height);
  500. Serial.print ("Components :"); Serial.println(JpegDec.comps);
  501. Serial.print ("MCU / row :"); Serial.println(JpegDec.MCUSPerRow);
  502. Serial.print ("MCU / col :"); Serial.println(JpegDec.MCUSPerCol);
  503. Serial.print ("Scan type :"); Serial.println(JpegDec.scanType);
  504. Serial.print ("MCU width :"); Serial.println(JpegDec.MCUWidth);
  505. Serial.print ("MCU height :"); Serial.println(JpegDec.MCUHeight);
  506. Serial.println("===============");
  507. Serial.println("");
  508. */
  509. }
  510. //====================================================================================
  511. // Open a Jpeg file and send it to the Serial port in a C array compatible format
  512. //====================================================================================
  513. void createArray(const char *filename) {
  514. // Open the named file
  515. fs::File jpgFile = SPIFFS.open( filename, "r"); // File handle reference for SPIFFS
  516. // File jpgFile = SD.open( filename, FILE_READ); // or, file handle reference for SD library
  517. if ( !jpgFile ) {
  518. Serial.print("ERROR: File \""); Serial.print(filename); Serial.println ("\" not found!");
  519. return;
  520. }
  521. uint8_t data;
  522. byte line_len = 0;
  523. Serial.println("");
  524. Serial.println("// Generated by a JPEGDecoder library example sketch:");
  525. Serial.println("// https://github.com/Bodmer/JPEGDecoder");
  526. Serial.println("");
  527. Serial.println("#if defined(__AVR__)");
  528. Serial.println(" #include <avr/pgmspace.h>");
  529. Serial.println("#endif");
  530. Serial.println("");
  531. Serial.print ("const uint8_t ");
  532. while (*filename != '.') Serial.print(*filename++);
  533. Serial.println("[] PROGMEM = {"); // PROGMEM added for AVR processors, it is ignored by Due
  534. while ( jpgFile.available()) {
  535. data = jpgFile.read();
  536. Serial.print("0x"); if (abs(data) < 16) Serial.print("0");
  537. Serial.print(data, HEX); Serial.print(",");// Add value and comma
  538. line_len++;
  539. if ( line_len >= 32) {
  540. line_len = 0;
  541. Serial.println();
  542. }
  543. }
  544. Serial.println("};\r\n");
  545. jpgFile.close();
  546. }
  547. // End JPEG_functions
  548. // SPIFFS_functions
  549. #ifdef ESP8266
  550. void Display::listFiles(void) {
  551. Serial.println();
  552. Serial.println("SPIFFS files found:");
  553. fs::Dir dir = SPIFFS.openDir("/"); // Root directory
  554. String line = "=====================================";
  555. Serial.println(line);
  556. Serial.println(" File name Size");
  557. Serial.println(line);
  558. while (dir.next()) {
  559. String fileName = dir.fileName();
  560. Serial.print(fileName);
  561. int spaces = 21 - fileName.length(); // Tabulate nicely
  562. while (spaces--) Serial.print(" ");
  563. fs::File f = dir.openFile("r");
  564. String fileSize = (String) f.size();
  565. spaces = 10 - fileSize.length(); // Tabulate nicely
  566. while (spaces--) Serial.print(" ");
  567. Serial.println(fileSize + " bytes");
  568. }
  569. Serial.println(line);
  570. Serial.println();
  571. delay(1000);
  572. }
  573. #endif
  574. //====================================================================================
  575. #ifdef ESP32
  576. void Display::listFiles(void) {
  577. listDir(SPIFFS, "/", 0);
  578. }
  579. void Display::listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
  580. Serial.println();
  581. Serial.println("SPIFFS files found:");
  582. Serial.printf("Listing directory: %s\n", "/");
  583. String line = "=====================================";
  584. Serial.println(line);
  585. Serial.println(" File name Size");
  586. Serial.println(line);
  587. fs::File root = fs.open(dirname);
  588. if (!root) {
  589. Serial.println("Failed to open directory");
  590. return;
  591. }
  592. if (!root.isDirectory()) {
  593. Serial.println("Not a directory");
  594. return;
  595. }
  596. fs::File file = root.openNextFile();
  597. while (file) {
  598. if (file.isDirectory()) {
  599. Serial.print("DIR : ");
  600. String fileName = file.name();
  601. Serial.print(fileName);
  602. if (levels) {
  603. listDir(fs, file.name(), levels - 1);
  604. }
  605. } else {
  606. String fileName = file.name();
  607. Serial.print(" " + fileName);
  608. int spaces = 20 - fileName.length(); // Tabulate nicely
  609. while (spaces--) Serial.print(" ");
  610. String fileSize = (String) file.size();
  611. spaces = 10 - fileSize.length(); // Tabulate nicely
  612. while (spaces--) Serial.print(" ");
  613. Serial.println(fileSize + " bytes");
  614. }
  615. file = root.openNextFile();
  616. }
  617. Serial.println(line);
  618. Serial.println();
  619. delay(1000);
  620. }
  621. #endif
  622. void Display::updateBanner(String msg)
  623. {
  624. this->img.deleteSprite();
  625. this->img.setColorDepth(8);
  626. this->img.createSprite(SCREEN_WIDTH, TEXT_HEIGHT);
  627. this->buildBanner(msg, current_banner_pos);
  628. this->img.pushSprite(0, STATUS_BAR_WIDTH);
  629. current_banner_pos--;
  630. if (current_banner_pos <= 0)
  631. current_banner_pos = SCREEN_WIDTH + 2;
  632. }
  633. void Display::buildBanner(String msg, int xpos)
  634. {
  635. int h = TEXT_HEIGHT;
  636. // We could just use fillSprite(color) but lets be a bit more creative...
  637. // Fill with rainbow stripes
  638. //while (h--) img.drawFastHLine(0, h, SCREEN_WIDTH, 255);
  639. // Draw some graphics, the text will apear to scroll over these
  640. //img.fillRect (SCREEN_WIDTH / 2 - 20, TEXT_HEIGHT / 2 - 10, 40, 20, TFT_YELLOW);
  641. //img.fillCircle(SCREEN_WIDTH / 2, TEXT_HEIGHT / 2, 10, TFT_ORANGE);
  642. // Now print text on top of the graphics
  643. img.setTextSize(2); // Font size scaling is x1
  644. img.setTextFont(0); // Font 4 selected
  645. img.setTextColor(TFT_WHITE); // Black text, no background colour
  646. img.setTextWrap(false); // Turn of wrap so we can print past end of sprite
  647. // Need to print twice so text appears to wrap around at left and right edges
  648. img.setCursor(xpos, 2); // Print text at xpos
  649. img.print(msg);
  650. img.setCursor(xpos - SCREEN_WIDTH, 2); // Print text at xpos - sprite width
  651. img.print(msg);
  652. }
  653. /*
  654. void Display::initLVGL() {
  655. tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
  656. lv_init();
  657. lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  658. lv_disp_drv_t disp_drv;
  659. lv_disp_drv_init(&disp_drv);
  660. disp_drv.hor_res = WIDTH_1;
  661. disp_drv.ver_res = HEIGHT_1;
  662. disp_drv.flush_cb = my_disp_flush;
  663. disp_drv.buffer = &disp_buf;
  664. lv_disp_drv_register(&disp_drv);
  665. lv_indev_drv_t indev_drv;
  666. lv_indev_drv_init(&indev_drv);
  667. indev_drv.type = LV_INDEV_TYPE_POINTER;
  668. indev_drv.read_cb = my_touchpad_read;
  669. lv_indev_drv_register(&indev_drv);
  670. }*/
  671. /*
  672. void Display::deinitLVGL() {
  673. lv_deinit();
  674. }
  675. */
  676. /*
  677. void Display::joinWiFiGFX(){
  678. // Create one text area
  679. ta1 = lv_textarea_create(lv_scr_act(), NULL);
  680. lv_textarea_set_one_line(ta1, true);
  681. lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
  682. lv_obj_set_pos(ta1, 5, 20);
  683. //lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
  684. lv_textarea_set_text(ta1, "");
  685. lv_obj_set_event_cb(ta1, ta_event_cb);
  686. // Create first label
  687. lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL);
  688. lv_label_set_text(ssid_label, "SSID:");
  689. lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  690. // Create second text area
  691. ta2 = lv_textarea_create(lv_scr_act(), ta1);
  692. lv_textarea_set_pwd_mode(ta2, true);
  693. lv_textarea_set_pwd_show_time(ta2, 1000);
  694. lv_textarea_set_cursor_hidden(ta2, true);
  695. lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
  696. // Create second label
  697. lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL);
  698. lv_label_set_text(pw_label, "Password:");
  699. lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
  700. // Create a keyboard and apply the styles
  701. kb = lv_keyboard_create(lv_scr_act(), NULL);
  702. lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
  703. lv_obj_set_event_cb(kb, keyboard_event_cb);
  704. // Focus it on one of the text areas to start
  705. lv_keyboard_set_textarea(kb, ta1);
  706. lv_keyboard_set_cursor_manage(kb, true);
  707. }*/
  708. /*
  709. void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
  710. lv_keyboard_def_event_cb(kb, event);
  711. if(event == LV_EVENT_APPLY){
  712. printf("LV_EVENT_APPLY\n");
  713. //String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
  714. String ta1_text = lv_textarea_get_text(ta1);
  715. String ta2_text = lv_textarea_get_text(ta2);
  716. Serial.println(ta1_text);
  717. Serial.println(ta2_text);
  718. //joinWiFi(ta1_text, ta2_text);
  719. }else if(event == LV_EVENT_CANCEL){
  720. printf("LV_EVENT_CANCEL\n");
  721. lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
  722. }
  723. }*/
  724. /*
  725. void ta_event_cb(lv_obj_t * ta, lv_event_t event)
  726. {
  727. if(event == LV_EVENT_CLICKED) {
  728. if(kb != NULL)
  729. lv_keyboard_set_textarea(kb, ta);
  730. }
  731. //else if(event == LV_EVENT_INSERT) {
  732. // const char * str = lv_event_get_data();
  733. // if(str[0] == '\n') {
  734. // printf("Ready\n");
  735. // }
  736. //}
  737. }*/
  738. void Display::main()
  739. {
  740. //lv_task_handler();
  741. return;
  742. }
  743. // End SPIFFS_functions