Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

690 linhas
19 KiB

  1. /* ePaper demo
  2. *
  3. * Author: LoBo (loboris@gmail.com, loboris.github)
  4. */
  5. #include <time.h>
  6. #include <errno.h>
  7. #include <sys/fcntl.h>
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "freertos/FreeRTOS.h"
  13. #include "freertos/task.h"
  14. #include "esp_system.h"
  15. #include "driver/gpio.h"
  16. #include "esp_system.h"
  17. #include "esp_heap_alloc_caps.h"
  18. #include "spiffs_vfs.h"
  19. #include "esp_log.h"
  20. #ifdef CONFIG_EXAMPLE_USE_WIFI
  21. #include "esp_wifi.h"
  22. #include "esp_system.h"
  23. #include "esp_event.h"
  24. #include "esp_event_loop.h"
  25. #include "freertos/event_groups.h"
  26. #include "esp_attr.h"
  27. #include <sys/time.h>
  28. #include <unistd.h>
  29. #include "lwip/err.h"
  30. #include "apps/sntp/sntp.h"
  31. #include "nvs_flash.h"
  32. #endif
  33. #include "spi_master_lobo.h"
  34. #include "img1.h"
  35. #include "img2.h"
  36. #include "img3.h"
  37. #include "img_hacking.c"
  38. #include "EPD.h"
  39. //#include "EPDspi.h"
  40. #define DELAYTIME 1500
  41. static struct tm* tm_info;
  42. static char tmp_buff[128];
  43. static time_t time_now, time_last = 0;
  44. static const char *file_fonts[3] = {"/spiffs/fonts/DotMatrix_M.fon", "/spiffs/fonts/Ubuntu.fon", "/spiffs/fonts/Grotesk24x48.fon"};
  45. static const char tag[] = "[Eink Demo]";
  46. //==================================================================================
  47. #ifdef CONFIG_EXAMPLE_USE_WIFI
  48. /* FreeRTOS event group to signal when we are connected & ready to make a request */
  49. static EventGroupHandle_t wifi_event_group;
  50. /* The event group allows multiple bits for each event,
  51. but we only care about one event - are we connected
  52. to the AP with an IP? */
  53. const int CONNECTED_BIT = 0x00000001;
  54. //------------------------------------------------------------
  55. static esp_err_t event_handler(void *ctx, system_event_t *event)
  56. {
  57. switch(event->event_id) {
  58. case SYSTEM_EVENT_STA_START:
  59. esp_wifi_connect();
  60. break;
  61. case SYSTEM_EVENT_STA_GOT_IP:
  62. xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
  63. break;
  64. case SYSTEM_EVENT_STA_DISCONNECTED:
  65. /* This is a workaround as ESP32 WiFi libs don't currently
  66. auto-reassociate. */
  67. esp_wifi_connect();
  68. xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  69. break;
  70. default:
  71. break;
  72. }
  73. return ESP_OK;
  74. }
  75. //-------------------------------
  76. static void initialise_wifi(void)
  77. {
  78. tcpip_adapter_init();
  79. wifi_event_group = xEventGroupCreate();
  80. ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
  81. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  82. ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
  83. ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
  84. wifi_config_t wifi_config = {
  85. .sta = {
  86. .ssid = CONFIG_WIFI_SSID,
  87. .password = CONFIG_WIFI_PASSWORD,
  88. },
  89. };
  90. ESP_LOGI(tag, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
  91. ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  92. ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
  93. ESP_ERROR_CHECK( esp_wifi_start() );
  94. }
  95. //-------------------------------
  96. static void initialize_sntp(void)
  97. {
  98. ESP_LOGI(tag, "Initializing SNTP");
  99. sntp_setoperatingmode(SNTP_OPMODE_POLL);
  100. sntp_setservername(0, "pool.ntp.org");
  101. sntp_init();
  102. }
  103. //--------------------------
  104. static int obtain_time(void)
  105. {
  106. int res = 1;
  107. initialise_wifi();
  108. xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, false, true, portMAX_DELAY);
  109. initialize_sntp();
  110. // wait for time to be set
  111. int retry = 0;
  112. const int retry_count = 20;
  113. time(&time_now);
  114. tm_info = localtime(&time_now);
  115. while(tm_info->tm_year < (2016 - 1900) && ++retry < retry_count) {
  116. //ESP_LOGI(tag, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
  117. vTaskDelay(500 / portTICK_RATE_MS);
  118. time(&time_now);
  119. tm_info = localtime(&time_now);
  120. }
  121. if (tm_info->tm_year < (2016 - 1900)) {
  122. ESP_LOGI(tag, "System time NOT set.");
  123. res = 0;
  124. }
  125. else {
  126. ESP_LOGI(tag, "System time is set.");
  127. }
  128. ESP_ERROR_CHECK( esp_wifi_stop() );
  129. return res;
  130. }
  131. #endif //CONFIG_EXAMPLE_USE_WIFI
  132. //==================================================================================
  133. //=============
  134. void app_main()
  135. {
  136. // ======== PREPARE DISPLAY INITIALIZATION =========
  137. esp_err_t ret;
  138. disp_buffer = pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
  139. assert(disp_buffer);
  140. drawBuff = disp_buffer;
  141. gs_disp_buffer = pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA);
  142. assert(gs_disp_buffer);
  143. gs_drawBuff = gs_disp_buffer;
  144. // ==== CONFIGURE SPI DEVICES(s) ====================================================================================
  145. gpio_set_direction(DC_Pin, GPIO_MODE_OUTPUT);
  146. gpio_set_level(DC_Pin, 1);
  147. gpio_set_direction(RST_Pin, GPIO_MODE_OUTPUT);
  148. gpio_set_level(RST_Pin, 0);
  149. gpio_set_direction(BUSY_Pin, GPIO_MODE_INPUT);
  150. gpio_set_pull_mode(BUSY_Pin, GPIO_PULLUP_ONLY);
  151. #if POWER_Pin
  152. gpio_set_direction(POWER_Pin, GPIO_MODE_OUTPUT);
  153. gpio_set_level(POWER_Pin, 1);
  154. #endif
  155. spi_lobo_bus_config_t buscfg={
  156. .miso_io_num = -1, // set SPI MISO pin
  157. .mosi_io_num = MOSI_Pin, // set SPI MOSI pin
  158. .sclk_io_num = SCK_Pin, // set SPI CLK pin
  159. .quadwp_io_num=-1,
  160. .quadhd_io_num=-1,
  161. .max_transfer_sz = 5*1024, // max transfer size is 4736 bytes
  162. };
  163. spi_lobo_device_interface_config_t devcfg={
  164. .clock_speed_hz=40000000, // SPI clock is 40 MHz
  165. .mode=0, // SPI mode 0
  166. .spics_io_num=-1, // we will use external CS pin
  167. .spics_ext_io_num = CS_Pin, // external CS pin
  168. .flags=SPI_DEVICE_HALFDUPLEX, // ALWAYS SET to HALF DUPLEX MODE for display spi !!
  169. };
  170. // ====================================================================================================================
  171. vTaskDelay(500 / portTICK_RATE_MS);
  172. printf("\r\n=================================\r\n");
  173. printf("ePaper display DEMO, LoBo 06/2017\r\n");
  174. printf("=================================\r\n\r\n");
  175. // ==================================================================
  176. // ==== Initialize the SPI bus and attach the EPD to the SPI bus ====
  177. ret=spi_lobo_bus_add_device(SPI_BUS, &buscfg, &devcfg, &disp_spi);
  178. assert(ret==ESP_OK);
  179. printf("SPI: display device added to spi bus\r\n");
  180. // ==== Test select/deselect ====
  181. ret = spi_lobo_device_select(disp_spi, 1);
  182. assert(ret==ESP_OK);
  183. ret = spi_lobo_device_deselect(disp_spi);
  184. assert(ret==ESP_OK);
  185. printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(disp_spi));
  186. printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(disp_spi) ? "true" : "false");
  187. printf("\r\n-------------------\r\n");
  188. printf("ePaper demo started\r\n");
  189. printf("-------------------\r\n");
  190. EPD_DisplayClearFull();
  191. #ifdef CONFIG_EXAMPLE_USE_WIFI
  192. ESP_ERROR_CHECK( nvs_flash_init() );
  193. EPD_DisplayClearPart();
  194. EPD_fillScreen(_bg);
  195. EPD_setFont(DEFAULT_FONT, NULL);
  196. sprintf(tmp_buff, "Waiting for NTP time...");
  197. EPD_print(tmp_buff, CENTER, CENTER);
  198. EPD_drawRect(10,10,274,108, EPD_BLACK);
  199. EPD_drawRect(12,12,270,104, EPD_BLACK);
  200. EPD_UpdateScreen();
  201. // ===== Set time zone ======
  202. setenv("TZ", "CET-1CEST", 0);
  203. tzset();
  204. // ==========================
  205. time(&time_now);
  206. tm_info = localtime(&time_now);
  207. // Is time set? If not, tm_year will be (1970 - 1900).
  208. if (tm_info->tm_year < (2016 - 1900)) {
  209. ESP_LOGI(tag, "Time is not set yet. Connecting to WiFi and getting time over NTP.");
  210. if (obtain_time()) {
  211. }
  212. else {
  213. }
  214. time(&time_now);
  215. }
  216. #endif
  217. // ==== Initialize the file system ====
  218. printf("\r\n\n");
  219. vfs_spiffs_register();
  220. if (spiffs_is_mounted) {
  221. ESP_LOGI(tag, "File system mounted.");
  222. }
  223. else {
  224. ESP_LOGE(tag, "Error mounting file system.");
  225. }
  226. //=========
  227. // Run demo
  228. //=========
  229. /*
  230. EPD_DisplayClearFull();
  231. EPD_DisplayClearPart();
  232. EPD_fillScreen(_bg);
  233. //EPD_DisplaySetPart(0x00);
  234. //EPD_DisplaySetPart(0xFF);
  235. uint8_t LUTTest1[31] = {0x32, 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  236. uint8_t LUTTest2[31] = {0x32, 0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  237. _gs = 0;
  238. _fg = 1;
  239. _bg = 0;
  240. int n = 0;
  241. while (1) {
  242. //EPD_DisplayClearFull();
  243. EPD_fillRect(14, 14, 100, 100, ((n&1) ? 0 : 1));
  244. EPD_fillRect(_width/2+14, 14, 100, 100, ((n&1) ? 1 : 0));
  245. //LUT_part = LUTTest1;
  246. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  247. //EPD_wait(2000);
  248. //LUT_part = LUTTest2;
  249. //EPD_DisplayFull(disp_buffer);
  250. printf("Updated\r\n");
  251. EPD_wait(4000);
  252. n++;
  253. n = 0;
  254. printf("\r\n==== FULL UPDATE TEST ====\r\n\n");
  255. EPD_DisplayClearFull();
  256. while (n < 2) {
  257. EPD_fillScreen(_bg);
  258. printf("Black\r\n");
  259. EPD_fillRect(0,0,_width/2,_height-1, EPD_BLACK);
  260. EPD_fillRect(20,20,_width/2-40,_height-1-40, EPD_WHITE);
  261. EPD_DisplayFull(disp_buffer);
  262. EPD_wait(4000);
  263. printf("White\r\n");
  264. EPD_fillRect(0,0,_width/2,_height-1, EPD_WHITE);
  265. EPD_DisplayFull(disp_buffer);
  266. EPD_wait(2000);
  267. n++;
  268. }
  269. printf("\r\n==== PARTIAL UPDATE TEST ====\r\n\n");
  270. EPD_DisplayClearFull();
  271. n = 0;
  272. while (n < 2) {
  273. EPD_fillScreen(_bg);
  274. printf("Black\r\n");
  275. EPD_fillRect(0,0,_width/2,_height-1, EPD_BLACK);
  276. EPD_fillRect(20,20,_width/2-40,_height-1-40, EPD_WHITE);
  277. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  278. EPD_wait(4000);
  279. printf("White\r\n");
  280. EPD_fillRect(0,0,_width/2,_height-1, EPD_WHITE);
  281. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  282. EPD_wait(2000);
  283. n++;
  284. }
  285. printf("\r\n==== PARTIAL UPDATE TEST - gray scale ====\r\n\n");
  286. EPD_DisplayClearFull();
  287. n = 0;
  288. while (n < 3) {
  289. EPD_fillScreen(_bg);
  290. LUT_part = LUT_gs;
  291. for (uint8_t sh=1; sh<16; sh++) {
  292. LUT_gs[21] = sh;
  293. printf("Black (%d)\r\n", LUT_gs[21]);
  294. EPD_fillRect((sh-1)*19,0,19,_height, EPD_BLACK);
  295. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  296. }
  297. EPD_wait(4000);
  298. //LUT_part = LUTDefault_part;
  299. printf("White\r\n");
  300. //EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  301. //EPD_DisplaySetPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, 0xFF);
  302. LUT_gs[21] = 15;
  303. LUT_gs[1] = 0x28;
  304. EPD_fillRect(190,0,76,_height, EPD_WHITE);
  305. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  306. EPD_wait(2000);
  307. EPD_fillRect(0,0,_width,_height, EPD_WHITE);
  308. EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  309. LUT_gs[1] = 0x18;
  310. EPD_wait(2000);
  311. n++;
  312. }
  313. LUT_part = LUTDefault_part;
  314. }
  315. */
  316. printf("==== START ====\r\n\n");
  317. _gs = 1;
  318. uint32_t tstart;
  319. int pass = 0, ftype = 9;
  320. while (1) {
  321. ftype++;
  322. if (ftype > 10) {
  323. ftype = 1;
  324. for (int t=40; t>0; t--) {
  325. printf("Wait %d seconds ... \r", t);
  326. fflush(stdout);
  327. EPD_wait(100);
  328. }
  329. printf(" \r");
  330. fflush(stdout);
  331. _gs ^= 1;
  332. }
  333. printf("\r\n-- Test %d\r\n", ftype);
  334. EPD_DisplayClearPart();
  335. //EPD_Cls(0);
  336. EPD_fillScreen(_bg);
  337. _fg = 15;
  338. _bg = 0;
  339. EPD_drawRect(1,1,294,126, EPD_BLACK);
  340. int y = 4;
  341. tstart = clock();
  342. if (ftype == 1) {
  343. for (int f=0; f<4; f++) {
  344. if (f == 0) _fg = 15;
  345. else if (f == 1) _fg = 9;
  346. else if (f == 2) _fg = 5;
  347. else if (f == 2) _fg = 3;
  348. EPD_setFont(f, NULL);
  349. if (f == 3) {
  350. EPD_print("Welcome to ", 4, y);
  351. font_rotate = 90;
  352. EPD_print("ESP32", EPD_getStringWidth("Welcome to ")+EPD_getfontheight()+4, y);
  353. font_rotate = 0;
  354. }
  355. else if (f == 1) {
  356. EPD_print("HR chars: \xA6\xA8\xB4\xB5\xB0", 4, y);
  357. }
  358. else {
  359. EPD_print("Welcome to ESP32", 4, y);
  360. }
  361. y += EPD_getfontheight() + 2;
  362. }
  363. font_rotate = 45;
  364. EPD_print("ESP32", LASTX+8, LASTY);
  365. font_rotate = 0;
  366. _fg = 15;
  367. EPD_setFont(DEFAULT_FONT, NULL);
  368. sprintf(tmp_buff, "Pass: %d", pass+1);
  369. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  370. EPD_UpdateScreen();
  371. }
  372. else if (ftype == 2) {
  373. orientation = LANDSCAPE_180;
  374. for (int f=4; f<FONT_7SEG; f++) {
  375. if (f == 4) _fg = 15;
  376. else if (f == 5) _fg = 9;
  377. else if (f == 6) _fg = 5;
  378. else if (f == 7) _fg = 3;
  379. EPD_setFont(f, NULL);
  380. EPD_print("Welcome to ESP32", 4, y);
  381. y += EPD_getfontheight() + 1;
  382. }
  383. _fg = 15;
  384. EPD_setFont(DEFAULT_FONT, NULL);
  385. sprintf(tmp_buff, "Pass: %d (rotated 180)", pass+1);
  386. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  387. orientation = LANDSCAPE_0;
  388. EPD_UpdateScreen();
  389. }
  390. else if (ftype == 3) {
  391. for (int f=0; f<3; f++) {
  392. if (f == 0) _fg = 15;
  393. else if (f == 1) _fg = 9;
  394. else if (f == 2) _fg = 5;
  395. EPD_setFont(USER_FONT, file_fonts[f]);
  396. if (f == 0) font_line_space = 4;
  397. EPD_print("Welcome to ESP32", 4, y);
  398. font_line_space = 0;
  399. y += EPD_getfontheight() + 2;
  400. }
  401. _fg = 15;
  402. EPD_setFont(DEFAULT_FONT, NULL);
  403. sprintf(tmp_buff, "Pass: %d (Fonts from file)", pass+1);
  404. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  405. EPD_UpdateScreen();
  406. }
  407. else if (ftype == 4) {
  408. y = 16;
  409. time(&time_now);
  410. tm_info = localtime(&time_now);
  411. int _sec = -1, y2, _day = -1;
  412. EPD_setFont(FONT_7SEG, NULL);
  413. set_7seg_font_atrib(10, 2, 0, 15);
  414. y2 = y + EPD_getfontheight() + 10;
  415. for (int t=0; t<100; t++) {
  416. time(&time_now);
  417. tm_info = localtime(&time_now);
  418. if (tm_info->tm_sec != _sec) {
  419. _sec = tm_info->tm_sec;
  420. sprintf(tmp_buff, "%02d:%02d:%02d", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec);
  421. _fg = 15; // fill = 15
  422. set_7seg_font_atrib(10, 2, 0, 15); // outline = 15
  423. EPD_print(tmp_buff, CENTER, y);
  424. _fg = 15;
  425. if (tm_info->tm_mday != _day) {
  426. sprintf(tmp_buff, "%02d.%02d.%04d", tm_info->tm_mday, tm_info->tm_mon + 1, tm_info->tm_year+1900);
  427. _fg = 7; // fill = 7
  428. set_7seg_font_atrib(8, 2, 1, 15); // outline = 15
  429. EPD_print(tmp_buff, CENTER, y2);
  430. _fg = 15;
  431. }
  432. EPD_UpdateScreen();
  433. }
  434. EPD_wait(100);
  435. }
  436. tstart = clock();
  437. _fg = 15;
  438. EPD_setFont(DEFAULT_FONT, NULL);
  439. font_rotate = 90;
  440. sprintf(tmp_buff, "%02d:%02d:%02d %02d/%02d", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec, tm_info->tm_mday, tm_info->tm_mon + 1);
  441. EPD_print(tmp_buff, 20, 4);
  442. font_rotate = 0;
  443. sprintf(tmp_buff, "Pass: %d", pass+1);
  444. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  445. EPD_UpdateScreen();
  446. }
  447. else if (ftype == 5) {
  448. uint8_t old_gs = _gs;
  449. _gs = 1;
  450. EPD_drawRect(4,4,20,20, 15);
  451. EPD_fillRect(27,5,18,18, 1);
  452. EPD_drawRect(26,4,20,20, 15);
  453. EPD_drawCircle(66,16,10, 15);
  454. EPD_fillCircle(92,16,10, 2);
  455. EPD_drawCircle(92,16,11, 15);
  456. EPD_fillRect(185,4,80,80, 3);
  457. EPD_drawRect(185,4,80,80, 15);
  458. EPD_fillCircle(225,44,35, 0);
  459. EPD_drawCircle(225,44,35, 15);
  460. EPD_fillCircle(225,44,35, 5);
  461. EPD_fillCircle(225,44,20, 0);
  462. EPD_drawCircle(225,44,20, 15);
  463. orientation = LANDSCAPE_180;
  464. EPD_drawRect(4,4,20,20, 15);
  465. EPD_fillRect(27,5,18,18, 1);
  466. EPD_drawRect(26,4,20,20, 15);
  467. EPD_drawCircle(66,16,10, 15);
  468. EPD_fillCircle(92,16,10, 2);
  469. EPD_drawCircle(92,16,11, 15);
  470. EPD_fillRect(185,4,80,80, 3);
  471. EPD_drawRect(185,4,80,80, 15);
  472. EPD_fillCircle(225,44,35, 0);
  473. EPD_drawCircle(225,44,35, 15);
  474. EPD_fillCircle(225,44,35, 5);
  475. EPD_fillCircle(225,44,20, 0);
  476. EPD_drawCircle(225,44,20, 15);
  477. orientation = LANDSCAPE_0;
  478. EPD_setFont(DEFAULT_FONT, NULL);
  479. font_rotate = 90;
  480. sprintf(tmp_buff, "Pass: %d", pass+1);
  481. EPD_print("Gray scale demo", _width/2+EPD_getfontheight()+2, 4);
  482. EPD_print(tmp_buff, _width/2, 4);
  483. font_rotate = 0;
  484. EPD_UpdateScreen();
  485. _gs = old_gs;
  486. }
  487. else if (ftype == 6) {
  488. uint8_t old_gs = _gs;
  489. _gs = 0;
  490. memcpy(disp_buffer, (unsigned char *)gImage_img1, sizeof(gImage_img1));
  491. EPD_setFont(DEFAULT_FONT, NULL);
  492. sprintf(tmp_buff, "Pass: %d", pass+1);
  493. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  494. EPD_UpdateScreen();
  495. _gs = old_gs;
  496. }
  497. else if (ftype == 7) {
  498. uint8_t old_gs = _gs;
  499. _gs = 0;
  500. memcpy(disp_buffer, (unsigned char *)gImage_img3, sizeof(gImage_img3));
  501. EPD_setFont(DEFAULT_FONT, NULL);
  502. _fg = 0;
  503. _bg = 1;
  504. sprintf(tmp_buff, "Pass: %d", pass+1);
  505. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  506. EPD_UpdateScreen();
  507. _fg = 15;
  508. _bg = 0;
  509. _gs = old_gs;
  510. }
  511. else if (ftype == 8) {
  512. uint8_t old_gs = _gs;
  513. _gs = 1;
  514. int i, x, y;
  515. uint8_t last_lvl = 0;
  516. for (i=0; i<16; i++) {
  517. for (x = 0; x < EPD_DISPLAY_WIDTH; x++) {
  518. for (y = 0; y < EPD_DISPLAY_HEIGHT; y++) {
  519. uint8_t pix = img_hacking[(x * EPD_DISPLAY_HEIGHT) + (EPD_DISPLAY_HEIGHT-y-1)];
  520. if ((pix > last_lvl) && (pix <= lvl_buf[i])) {
  521. gs_disp_buffer[(y * EPD_DISPLAY_WIDTH) + x] = i;
  522. gs_used_shades |= (1 << i);
  523. }
  524. }
  525. }
  526. last_lvl = lvl_buf[i];
  527. }
  528. EPD_setFont(DEFAULT_FONT, NULL);
  529. sprintf(tmp_buff, "Pass: %d (Gray scale image)", pass+1);
  530. EPD_print(tmp_buff, 4, 128-EPD_getfontheight()-2);
  531. EPD_UpdateScreen();
  532. _gs = old_gs;
  533. }
  534. else if (ftype == 9) {
  535. uint8_t old_gs = _gs;
  536. _gs = 0;
  537. memcpy(disp_buffer, gImage_img2, sizeof(gImage_img2));
  538. EPD_setFont(DEFAULT_FONT, NULL);
  539. sprintf(tmp_buff, "Pass: %d", pass+1);
  540. EPD_print(tmp_buff, 4, 4);
  541. EPD_UpdateScreen();
  542. _gs = old_gs;
  543. }
  544. else if (ftype == 10) {
  545. if (spiffs_is_mounted) {
  546. // ** Show scaled (1/8, 1/4, 1/2 size) JPG images
  547. uint8_t old_gs = _gs;
  548. _gs = 1;
  549. EPD_Cls();
  550. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/evolution-of-human.jpg", NULL, 0);
  551. EPD_UpdateScreen();
  552. EPD_wait(5000);
  553. EPD_Cls();
  554. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/people_silhouettes.jpg", NULL, 0);
  555. EPD_UpdateScreen();
  556. EPD_wait(5000);
  557. EPD_Cls();
  558. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/silhouettes-dancing.jpg", NULL, 0);
  559. EPD_UpdateScreen();
  560. EPD_wait(5000);
  561. EPD_Cls();
  562. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/girl_silhouettes.jpg", NULL, 0);
  563. EPD_UpdateScreen();
  564. EPD_wait(5000);
  565. EPD_Cls();
  566. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/animal-silhouettes.jpg", NULL, 0);
  567. EPD_UpdateScreen();
  568. EPD_wait(5000);
  569. EPD_Cls();
  570. EPD_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/Flintstones.jpg", NULL, 0);
  571. EPD_UpdateScreen();
  572. EPD_wait(5000);
  573. _gs = old_gs;
  574. }
  575. }
  576. //EPD_DisplayPart(0, EPD_DISPLAY_WIDTH-1, 0, EPD_DISPLAY_HEIGHT-1, disp_buffer);
  577. tstart = clock() - tstart;
  578. pass++;
  579. printf("-- Type: %d Pass: %d Time: %u ms\r\n", ftype, pass, tstart);
  580. EPD_PowerOff();
  581. EPD_wait(8000);
  582. }
  583. }