OLED_1in5_test.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*****************************************************************************
  2. * | File : OLED_1in5_test.c
  3. * | Author : Waveshare team
  4. * | Function : 1.5inch OLED Module test demo
  5. * | Info :
  6. *----------------
  7. * | This version: V2.0
  8. * | Date : 2020-08-15
  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_1in5.h"
  33. int OLED_1in5_test(void)
  34. {
  35. printf("1.5inch OLED test demo\n");
  36. if(DEV_ModuleInit() != 0) {
  37. return -1;
  38. }
  39. printf("OLED Init...\r\n");
  40. OLED_1in5_Init();
  41. DEV_Delay_ms(500);
  42. // 0.Create a new image cache
  43. UBYTE *BlackImage;
  44. UWORD Imagesize = ((OLED_1in5_WIDTH%2==0)? (OLED_1in5_WIDTH/2): (OLED_1in5_WIDTH/2+1)) * OLED_1in5_HEIGHT;
  45. if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
  46. printf("Failed to apply for black memory...\r\n");
  47. return -1;
  48. }
  49. printf("Paint_NewImage\r\n");
  50. Paint_NewImage(BlackImage, OLED_1in5_WIDTH, OLED_1in5_HEIGHT, 0, BLACK);
  51. Paint_SetScale(16);
  52. printf("Drawing\r\n");
  53. //1.Select Image
  54. Paint_SelectImage(BlackImage);
  55. DEV_Delay_ms(500);
  56. Paint_Clear(BLACK);
  57. // 2.Drawing on the image
  58. printf("Drawing:page 1\r\n");
  59. Paint_DrawPoint(20, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
  60. Paint_DrawPoint(30, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
  61. Paint_DrawPoint(40, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
  62. Paint_DrawLine(10, 10, 10, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  63. Paint_DrawLine(20, 20, 20, 30, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  64. Paint_DrawLine(30, 30, 30, 40, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  65. Paint_DrawLine(40, 40, 40, 50, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
  66. Paint_DrawCircle(60, 30, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  67. Paint_DrawCircle(100, 40, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  68. Paint_DrawRectangle(50, 30, 60, 40, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
  69. Paint_DrawRectangle(90, 30, 110, 50, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  70. // 3.Show image on page1
  71. OLED_1in5_Display(BlackImage);
  72. DEV_Delay_ms(2000);
  73. Paint_Clear(BLACK);
  74. // Drawing on the image
  75. printf("Drawing:page 2\r\n");
  76. for(UBYTE i=0; i<16; i++){
  77. Paint_DrawRectangle(0, 8*i, 127, 8*(i+1), i, DOT_PIXEL_1X1, DRAW_FILL_FULL);
  78. }
  79. // Show image on page2
  80. OLED_1in5_Display(BlackImage);
  81. DEV_Delay_ms(2000);
  82. Paint_Clear(BLACK);
  83. // Drawing on the image
  84. printf("Drawing:page 3\r\n");
  85. Paint_DrawString_EN(10, 0, "waveshare", &Font16, 0x1, 0xb);
  86. Paint_DrawString_EN(10, 17, "hello world", &Font8, 0x2, 0xc);
  87. Paint_DrawNum(10, 30, 123.456789, &Font8, 4, 0x3, 0xd);
  88. Paint_DrawNum(10, 43, 987654, &Font12, 5, 0x4, 0xe);
  89. // Show image on page2
  90. OLED_1in5_Display(BlackImage);
  91. DEV_Delay_ms(2000);
  92. Paint_Clear(BLACK);
  93. // Drawing on the image
  94. printf("Drawing:page 4\r\n");
  95. Paint_DrawString_CN(10, 0,"ÄãºÃAbc", &Font12CN, WHITE, WHITE);
  96. Paint_DrawString_CN(0, 20, "΢ѩµç×Ó", &Font24CN, WHITE, WHITE);
  97. // Show image on page3
  98. OLED_1in5_Display(BlackImage);
  99. DEV_Delay_ms(2000);
  100. Paint_Clear(BLACK);
  101. // Drawing on the image
  102. printf("Drawing:page 5\r\n");
  103. GUI_ReadBmp_16Gray("./pic/1in5.bmp", 0, 0);
  104. // Show image on page4
  105. OLED_1in5_Display(BlackImage);
  106. DEV_Delay_ms(2000);
  107. Paint_Clear(BLACK);
  108. OLED_1in5_Clear();
  109. return 0;
  110. }