OLED_0in49_test.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*****************************************************************************
  2. * | File : OLED_0in49_test.c
  3. * | Author : Waveshare team
  4. * | Function : 0.49inch OLED Module test demo
  5. * | Info :
  6. *----------------
  7. * | This version: V2.0
  8. * | Date : 2020-08-17
  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 "test.h"
  32. #include "OLED_0in49.h"
  33. int OLED_0in49_test(void)
  34. {
  35. printf("0.49inch OLED test demo\n");
  36. if(DEV_ModuleInit() != 0) {
  37. return -1;
  38. }
  39. if(USE_SPI) {
  40. printf("Only USE_IIC, Please revise DEV_Config.h !!!\r\n");
  41. return -1;
  42. }
  43. printf("OLED Init...\r\n");
  44. OLED_0in49_Init();
  45. DEV_Delay_ms(500);
  46. OLED_0in49_Clear();
  47. // 0.Create a new image cache
  48. UBYTE *BlackImage;
  49. UWORD Imagesize = ((OLED_0in49_WIDTH == 0) ? (OLED_0in49_WIDTH) : (OLED_0in49_WIDTH + 1)) * OLED_0in49_HEIGHT;
  50. if ((BlackImage = (UBYTE *)malloc(Imagesize / 8)) == NULL)
  51. { // No enough memory
  52. printf("Failed to apply for black memory...\r\n");
  53. return -1;
  54. }
  55. printf("Paint_NewImage\r\n");
  56. Paint_NewImage(BlackImage, OLED_0in49_HEIGHT, OLED_0in49_WIDTH, 270, BLACK);
  57. printf("Drawing\r\n");
  58. //1.Select Image
  59. Paint_SelectImage(BlackImage);
  60. DEV_Delay_ms(500);
  61. Paint_Clear(BLACK);
  62. while(1) {
  63. // 2.Drawing on the image
  64. printf("Drawing:page 1\r\n");
  65. Paint_DrawPoint(10, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  66. Paint_DrawPoint(25, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  67. Paint_DrawPoint(40, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  68. OLED_0in49_Display(BlackImage);
  69. Paint_DrawLine(2, 10, 2, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  70. Paint_DrawLine(20, 10, 20, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  71. Paint_DrawLine(30, 10, 30, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  72. Paint_DrawLine(62, 10, 62, 25, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  73. // 3.Show image on page1
  74. OLED_0in49_Display(BlackImage);
  75. DEV_Delay_ms(2000);
  76. Paint_Clear(BLACK);
  77. // Drawing on the image
  78. printf("Drawing:page 2\r\n");
  79. Paint_DrawCircle(30, 16, 12, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  80. // Show image on page2
  81. OLED_0in49_Display(BlackImage);
  82. DEV_Delay_ms(2000);
  83. Paint_Clear(BLACK);
  84. // Drawing on the image
  85. printf("Drawing:page 3\r\n");
  86. Paint_DrawString_EN(0, 0, "waveshare", &Font12, WHITE, WHITE);
  87. // Show image on page3
  88. OLED_0in49_Display(BlackImage);
  89. DEV_Delay_ms(2000);
  90. Paint_Clear(BLACK);
  91. // Drawing on the image
  92. printf("Drawing:page 4\r\n");
  93. Paint_DrawNum(0, 10, 123.456, &Font12, 3, WHITE, WHITE);
  94. // Show image on page4
  95. OLED_0in49_Display(BlackImage);
  96. DEV_Delay_ms(2000);
  97. Paint_Clear(BLACK);
  98. // Drawing on the image
  99. printf("Drawing:page 5\r\n");
  100. Paint_DrawString_CN(0, 5, "ÄãºÃ", &Font12CN, WHITE, WHITE);
  101. Paint_DrawString_EN(35, 10, "RPi", &Font8, WHITE, WHITE);
  102. // Show image on page5
  103. OLED_0in49_Display(BlackImage);
  104. DEV_Delay_ms(2000);
  105. Paint_Clear(BLACK);
  106. //Drawing on the image
  107. printf("Drawing:page 6\r\n");
  108. GUI_ReadBmp("./pic/0in49.bmp", 0, 0);
  109. //Show image on page6
  110. OLED_0in49_Display(BlackImage);
  111. DEV_Delay_ms(2000);
  112. Paint_Clear(BLACK);
  113. }
  114. }