main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include <signal.h> //signal()
  2. #include <stdlib.h> //exit()
  3. #include "ImageData.h"
  4. #include "GUI_Paint.h"
  5. #include "GUI_BMPfile.h"
  6. #include "EPD_1in54b.h"
  7. void Handler(int signo)
  8. {
  9. //System Exit
  10. printf("\r\nHandler:exit...\r\n");
  11. // EPD_Sleep();
  12. DEV_ModuleExit();
  13. exit(0);
  14. }
  15. int main(void)
  16. {
  17. printf("1.54inch e-Paper B demo\r\n");
  18. DEV_ModuleInit();
  19. // Exception handling:ctrl + c
  20. signal(SIGINT, Handler);
  21. printf("epd init and clear------------------------\r\n");
  22. if(EPD_Init()) {
  23. printf("e-Paper init failed\r\n");
  24. }
  25. EPD_Clear();
  26. DEV_Delay_ms(200);
  27. //Create a new image cache named IMAGE_BW and fill it with white
  28. UBYTE *BlackImage, *RedImage;
  29. UWORD Imagesize = ((EPD_WIDTH % 8 == 0)? (EPD_WIDTH / 8 ): (EPD_WIDTH / 8 + 1)) * EPD_HEIGHT;
  30. if((BlackImage = (UBYTE *)malloc(EPD_WIDTH / 8 * EPD_HEIGHT)) == NULL) {
  31. printf("Failed to apply for black memory...\r\n");
  32. exit(0);
  33. }
  34. if((RedImage = (UBYTE *)malloc(EPD_WIDTH / 8 * EPD_HEIGHT)) == NULL) {
  35. printf("Failed to apply for red memory...\r\n");
  36. exit(0);
  37. }
  38. printf("NewImage:BlackImage and RedImage\r\n");
  39. Paint_NewImage(BlackImage, EPD_WIDTH, EPD_HEIGHT, 270, WHITE);
  40. Paint_NewImage(RedImage, EPD_WIDTH, EPD_HEIGHT, 270, WHITE);
  41. //Select Image
  42. Paint_SelectImage(BlackImage);
  43. Paint_Clear(WHITE);
  44. Paint_SelectImage(RedImage);
  45. Paint_Clear(WHITE);
  46. #if 1 // show bmp
  47. printf("show windows------------------------\r\n");
  48. printf("read black bmp\r\n");
  49. Paint_SelectImage(BlackImage);
  50. Paint_Clear(WHITE);
  51. GUI_ReadBmp("./pic/100x100.bmp", 50, 50);
  52. printf("read red bmp\r\n");
  53. Paint_SelectImage(RedImage);
  54. Paint_Clear(WHITE);
  55. EPD_Display(BlackImage, RedImage);
  56. DEV_Delay_ms(2000);
  57. printf("show bmp------------------------\r\n");
  58. printf("read black bmp\r\n");
  59. Paint_SelectImage(BlackImage);
  60. GUI_ReadBmp("./pic/1in54b-b.bmp", 0, 0);
  61. printf("read red bmp\r\n");
  62. Paint_SelectImage(RedImage);
  63. GUI_ReadBmp("./pic/1in54b-r.bmp", 0, 0);
  64. EPD_Display(BlackImage, RedImage);
  65. DEV_Delay_ms(2000);
  66. #endif
  67. #if 1 //show image for array
  68. printf("show image for array------------------------\r\n");
  69. Paint_SelectImage(BlackImage);
  70. Paint_DrawBitMap(IMAGE_BLACK);
  71. Paint_SelectImage(RedImage);
  72. Paint_DrawBitMap(IMAGE_RED);
  73. EPD_Display(BlackImage, RedImage);
  74. DEV_Delay_ms(2000);
  75. #endif
  76. #if 1 //Drawing
  77. printf("Drawing------------------------\r\n");
  78. Paint_SelectImage(BlackImage);
  79. Paint_Clear(WHITE);
  80. Paint_DrawPoint(5, 10, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  81. Paint_DrawPoint(5, 25, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  82. Paint_DrawLine(20, 10, 70, 60, BLACK, LINE_STYLE_SOLID, DOT_PIXEL_1X1);
  83. Paint_DrawLine(70, 10, 20, 60, BLACK, LINE_STYLE_SOLID, DOT_PIXEL_1X1);
  84. Paint_DrawRectangle(20, 10, 70, 60, BLACK, DRAW_FILL_EMPTY, DOT_PIXEL_1X1);
  85. Paint_DrawCircle(170, 85, 20, BLACK, DRAW_FILL_FULL, DOT_PIXEL_1X1);
  86. Paint_DrawString_EN(5, 70, "hello world", &Font16, WHITE, BLACK);
  87. Paint_DrawString_CN(5, 160,"΢ѩµç×Ó", &Font24CN, WHITE, BLACK);
  88. Paint_SelectImage(RedImage);
  89. Paint_Clear(WHITE);
  90. Paint_DrawPoint(5, 40, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  91. Paint_DrawPoint(5, 55, BLACK, DOT_PIXEL_4X4, DOT_STYLE_DFT);
  92. Paint_DrawLine(170, 15, 170, 55, BLACK, LINE_STYLE_DOTTED, DOT_PIXEL_1X1);
  93. Paint_DrawLine(150, 35, 190, 35, BLACK, LINE_STYLE_DOTTED, DOT_PIXEL_1X1);
  94. Paint_DrawRectangle(85, 10, 130, 60, BLACK, DRAW_FILL_FULL, DOT_PIXEL_1X1);
  95. Paint_DrawCircle(170, 35, 20, BLACK, DRAW_FILL_EMPTY, DOT_PIXEL_1X1);
  96. Paint_DrawString_EN(5, 90, "waveshare", &Font20, BLACK, WHITE);
  97. Paint_DrawNum(5, 120, 123456789, &Font20, BLACK, WHITE);
  98. Paint_DrawString_CN(5, 135,"ÄãºÃabcÊ÷Ý®ÅÉ", &Font12CN, BLACK, WHITE);
  99. EPD_Display(BlackImage, RedImage);
  100. DEV_Delay_ms(2000);
  101. #endif
  102. printf("Goto Sleep mode...\r\n");
  103. EPD_Sleep();
  104. free(BlackImage);
  105. free(RedImage);
  106. BlackImage = NULL;
  107. RedImage = NULL;
  108. return 0;
  109. }