OLED_0in91_test.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*****************************************************************************
  2. * | File : OLED_0in91_test.c
  3. * | Author : Waveshare team
  4. * | Function : 0.91inch 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_0in91.h"
  33. int OLED_0in91_test(void)
  34. {
  35. printf("0.91inch 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_0in91_Init();
  45. DEV_Delay_ms(500);
  46. OLED_0in91_Clear();
  47. // 0.Create a new image cache
  48. UBYTE *BlackImage;
  49. UWORD Imagesize = ((OLED_0in91_WIDTH%8==0)? (OLED_0in91_WIDTH/8): (OLED_0in91_WIDTH/8+1)) * OLED_0in91_HEIGHT;
  50. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  51. printf("Failed to apply for black memory...\r\n");
  52. return -1;
  53. }
  54. printf("Paint_NewImage\r\n");
  55. Paint_NewImage(BlackImage, OLED_0in91_HEIGHT, OLED_0in91_WIDTH, 90, BLACK);
  56. printf("Drawing\r\n");
  57. //1.Select Image
  58. Paint_SelectImage(BlackImage);
  59. DEV_Delay_ms(500);
  60. Paint_Clear(BLACK);
  61. // 2.Drawing on the image
  62. printf("Drawing:page 1\r\n");
  63. Paint_DrawPoint(15, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  64. Paint_DrawPoint(25, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  65. Paint_DrawPoint(35, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  66. Paint_DrawLine(10, 10, 10, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  67. Paint_DrawLine(20, 10, 20, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  68. Paint_DrawLine(30, 10, 30, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  69. Paint_DrawLine(40, 10, 40, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  70. Paint_DrawCircle(70, 16, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  71. Paint_DrawCircle(110, 16, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  72. Paint_DrawRectangle(60, 6, 80, 26, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  73. Paint_DrawRectangle(100, 6, 120, 26, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  74. // 3.Show image on page1
  75. OLED_0in91_Display(BlackImage);
  76. DEV_Delay_ms(2000);
  77. Paint_Clear(BLACK);
  78. // Drawing on the image
  79. printf("Drawing:page 2\r\n");
  80. Paint_DrawString_EN(10, 0, "waveshare", &Font16, WHITE, WHITE);
  81. Paint_DrawNum(10, 18, 123.456789, &Font12, 4, WHITE, WHITE);
  82. // Show image on page2
  83. OLED_0in91_Display(BlackImage);
  84. DEV_Delay_ms(2000);
  85. Paint_Clear(BLACK);
  86. // Drawing on the image
  87. printf("Drawing:page 3\r\n");
  88. Paint_DrawString_CN(20, 5,"ÄãºÃAbc", &Font12CN, WHITE, WHITE);
  89. // Show image on page3
  90. OLED_0in91_Display(BlackImage);
  91. DEV_Delay_ms(2000);
  92. Paint_Clear(BLACK);
  93. // Drawing on the image
  94. printf("Drawing:page 4\r\n");
  95. GUI_ReadBmp("./pic/0in91.bmp", 0, 0);
  96. // Show image on page4
  97. OLED_0in91_Display(BlackImage);
  98. DEV_Delay_ms(2000);
  99. Paint_Clear(BLACK);
  100. return 0;
  101. }