EPD_2in13b_V4_test.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*****************************************************************************
  2. * | File : EPD_2in13b_V4_test.c
  3. * | Author : Waveshare team
  4. * | Function : 2.13inch B V4 e-paper test demo
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2022-04-21
  9. * | Info :
  10. * -----------------------------------------------------------------------------
  11. #
  12. # Permission is hereby granted, free of charge, to any person obtaining a copy
  13. # of this software and associated documnetation files (the "Software"), to deal
  14. # in the Software without restriction, including without limitation the rights
  15. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. # copies of the Software, and to permit persons to whom the Software is
  17. # furished to do so, subject to the following conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be included in
  20. # all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. # THE SOFTWARE.
  29. #
  30. ******************************************************************************/
  31. #include "EPD_Test.h"
  32. #include "EPD_2in13b_V4.h"
  33. #include "time.h"
  34. int EPD_2in13b_V4_test(void)
  35. {
  36. printf("EPD_2IN13B_V4_test Demo\r\n");
  37. if(DEV_Module_Init()!=0){
  38. return -1;
  39. }
  40. printf("e-Paper Init and Clear...\r\n");
  41. EPD_2IN13B_V4_Init();
  42. struct timespec start={0,0}, finish={0,0};
  43. clock_gettime(CLOCK_REALTIME,&start);
  44. EPD_2IN13B_V4_Clear();
  45. clock_gettime(CLOCK_REALTIME,&finish);
  46. Debug("%ld S\r\n",finish.tv_sec-start.tv_sec);
  47. DEV_Delay_ms(500);
  48. //Create a new image cache named IMAGE_BW and fill it with white
  49. UBYTE *BlackImage, *RYImage; // Red or Yellow
  50. UWORD Imagesize = ((EPD_2IN13B_V4_WIDTH % 8 == 0)? (EPD_2IN13B_V4_WIDTH / 8 ): (EPD_2IN13B_V4_WIDTH / 8 + 1)) * EPD_2IN13B_V4_HEIGHT;
  51. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  52. printf("Failed to apply for black memory...\r\n");
  53. return -1;
  54. }
  55. if((RYImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  56. printf("Failed to apply for red memory...\r\n");
  57. return -1;
  58. }
  59. printf("NewImage:BlackImage and RYImage\r\n");
  60. Paint_NewImage(BlackImage, EPD_2IN13B_V4_WIDTH, EPD_2IN13B_V4_HEIGHT, 90, WHITE);
  61. Paint_NewImage(RYImage, EPD_2IN13B_V4_WIDTH, EPD_2IN13B_V4_HEIGHT, 90, WHITE);
  62. //Select Image
  63. Paint_SelectImage(BlackImage);
  64. Paint_Clear(WHITE);
  65. Paint_SelectImage(RYImage);
  66. Paint_Clear(WHITE);
  67. #if 1 // show bmp
  68. printf("show window BMP-----------------\r\n");
  69. Paint_SelectImage(BlackImage);
  70. GUI_ReadBmp("./pic/100x100.bmp", 10, 0);
  71. Paint_SelectImage(RYImage);
  72. Paint_Clear(WHITE);
  73. EPD_2IN13B_V4_Display(BlackImage, RYImage);
  74. DEV_Delay_ms(2000);
  75. printf("show red bmp------------------------\r\n");
  76. Paint_SelectImage(BlackImage);
  77. GUI_ReadBmp("./pic/2in13b_V4b.bmp", 0, 0);
  78. Paint_SelectImage(RYImage);
  79. GUI_ReadBmp("./pic/2in13b_V4r.bmp", 0, 0);
  80. EPD_2IN13B_V4_Display(BlackImage, RYImage);
  81. DEV_Delay_ms(2000);
  82. #endif
  83. #if 1 // show image for array
  84. printf("show image for array\r\n");
  85. EPD_2IN13B_V4_Display(gImage_2in13b_V4b, gImage_2in13b_V4r);
  86. DEV_Delay_ms(2000);
  87. #endif
  88. #if 1 // Drawing on the image
  89. /*Horizontal screen*/
  90. //1.Draw black image
  91. printf("Draw black image\r\n");
  92. Paint_SelectImage(BlackImage);
  93. Paint_Clear(WHITE);
  94. Paint_DrawPoint(5, 70, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  95. Paint_DrawPoint(5, 80, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  96. Paint_DrawLine(20, 70, 50, 100, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  97. Paint_DrawLine(50, 70, 20, 100, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  98. Paint_DrawRectangle(60, 70, 90, 100, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  99. Paint_DrawCircle(125, 85, 15, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  100. Paint_DrawString_CN(5, 15, "ÄãºÃabc", &Font12CN, WHITE, BLACK);
  101. //2.Draw red image
  102. printf("Draw red image\r\n");
  103. Paint_SelectImage(RYImage);
  104. Paint_Clear(WHITE);
  105. Paint_DrawPoint(5, 90, RED, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  106. Paint_DrawPoint(5, 100, RED, DOT_PIXEL_4X4, DOT_STYLE_DFT);
  107. Paint_DrawLine(125, 70, 125, 100, RED, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  108. Paint_DrawLine(110, 85, 140, 85, RED, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  109. Paint_DrawRectangle(20, 70, 50, 100, RED, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  110. Paint_DrawCircle(165, 85, 15, RED, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  111. Paint_DrawString_EN(5, 0, "waveshare Electronics", &Font12, BLACK, WHITE);
  112. Paint_DrawNum(5, 50, 987654321, &Font16, WHITE, RED);
  113. printf("EPD_Display\r\n");
  114. EPD_2IN13B_V4_Display(BlackImage, RYImage);
  115. DEV_Delay_ms(5000);
  116. #endif
  117. printf("Clear...\r\n");
  118. EPD_2IN13B_V4_Clear();
  119. printf("Goto Sleep...\r\n");
  120. EPD_2IN13B_V4_Sleep();
  121. free(BlackImage);
  122. free(RYImage);
  123. BlackImage = NULL;
  124. RYImage = NULL;
  125. DEV_Delay_ms(2000);//important, at least 2s
  126. // close 5V
  127. printf("close 5V, Module enters 0 power consumption ...\r\n");
  128. DEV_Module_Exit();
  129. return 0;
  130. }