ssd1306_tests.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #include "../ssd1306/ssd1306_tests.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include "../ssd1306/ssd1306.h"
  5. void ssd1306_TestBorder() {
  6. ssd1306_Fill(Black);
  7. uint32_t start = HAL_GetTick();
  8. uint32_t end = start;
  9. uint8_t x = 0;
  10. uint8_t y = 0;
  11. do {
  12. ssd1306_DrawPixel(x, y, Black);
  13. if((y == 0) && (x < 127))
  14. x++;
  15. else if((x == 127) && (y < (SSD1306_HEIGHT-1)))
  16. y++;
  17. else if((y == (SSD1306_HEIGHT-1)) && (x > 0))
  18. x--;
  19. else
  20. y--;
  21. ssd1306_DrawPixel(x, y, White);
  22. ssd1306_UpdateScreen();
  23. HAL_Delay(5);
  24. end = HAL_GetTick();
  25. } while((end - start) < 8000);
  26. HAL_Delay(1000);
  27. }
  28. void ssd1306_TestFonts() {
  29. uint8_t y = 0;
  30. ssd1306_Fill(Black);
  31. #ifdef SSD1306_INCLUDE_FONT_16x26
  32. ssd1306_SetCursor(2, y);
  33. ssd1306_WriteString("Font 16x26", Font_16x26, White);
  34. y += 26;
  35. #endif
  36. #ifdef SSD1306_INCLUDE_FONT_11x18
  37. ssd1306_SetCursor(2, y);
  38. ssd1306_WriteString("Font 11x18", Font_11x18, White);
  39. y += 18;
  40. #endif
  41. #ifdef SSD1306_INCLUDE_FONT_7x10
  42. ssd1306_SetCursor(2, y);
  43. ssd1306_WriteString("Font 7x10", Font_7x10, White);
  44. y += 10;
  45. #endif
  46. #ifdef SSD1306_INCLUDE_FONT_6x8
  47. ssd1306_SetCursor(2, y);
  48. ssd1306_WriteString("Font 6x8", Font_6x8, White);
  49. #endif
  50. ssd1306_UpdateScreen();
  51. }
  52. void ssd1306_TestFPS() {
  53. ssd1306_Fill(White);
  54. uint32_t start = HAL_GetTick();
  55. uint32_t end = start;
  56. int fps = 0;
  57. char message[] = "ABCDEFGHIJK";
  58. ssd1306_SetCursor(2,0);
  59. ssd1306_WriteString("Testing...", Font_11x18, Black);
  60. do {
  61. ssd1306_SetCursor(2, 18);
  62. ssd1306_WriteString(message, Font_11x18, Black);
  63. ssd1306_UpdateScreen();
  64. char ch = message[0];
  65. memmove(message, message+1, sizeof(message)-2);
  66. message[sizeof(message)-2] = ch;
  67. fps++;
  68. end = HAL_GetTick();
  69. } while((end - start) < 5000);
  70. HAL_Delay(1000);
  71. char buff[64];
  72. fps = (float)fps / ((end - start) / 1000.0);
  73. snprintf(buff, sizeof(buff), "~%d FPS", fps);
  74. ssd1306_Fill(White);
  75. ssd1306_SetCursor(2, 2);
  76. ssd1306_WriteString(buff, Font_11x18, Black);
  77. ssd1306_UpdateScreen();
  78. }
  79. void ssd1306_TestLine() {
  80. ssd1306_Line(1,1,SSD1306_WIDTH - 1,SSD1306_HEIGHT - 1,White);
  81. ssd1306_Line(SSD1306_WIDTH - 1,1,1,SSD1306_HEIGHT - 1,White);
  82. ssd1306_UpdateScreen();
  83. return;
  84. }
  85. void ssd1306_TestRectangle() {
  86. uint32_t delta;
  87. for(delta = 0; delta < 5; delta ++) {
  88. ssd1306_DrawRectangle(1 + (5*delta),1 + (5*delta) ,SSD1306_WIDTH-1 - (5*delta),SSD1306_HEIGHT-1 - (5*delta),White);
  89. }
  90. ssd1306_UpdateScreen();
  91. return;
  92. }
  93. void ssd1306_TestCircle() {
  94. uint32_t delta;
  95. for(delta = 0; delta < 5; delta ++) {
  96. ssd1306_DrawCircle(20* delta+30, 15, 10, White);
  97. }
  98. ssd1306_UpdateScreen();
  99. return;
  100. }
  101. void ssd1306_TestArc() {
  102. ssd1306_DrawArc(30, 30, 30, 20, 270, White);
  103. ssd1306_UpdateScreen();
  104. return;
  105. }
  106. void ssd1306_TestPolyline() {
  107. SSD1306_VERTEX loc_vertex[] =
  108. {
  109. {35,40},
  110. {40,20},
  111. {45,28},
  112. {50,10},
  113. {45,16},
  114. {50,10},
  115. {53,16}
  116. };
  117. ssd1306_Polyline(loc_vertex,sizeof(loc_vertex)/sizeof(loc_vertex[0]),White);
  118. ssd1306_UpdateScreen();
  119. return;
  120. }
  121. void ssd1306_TestAll() {
  122. ssd1306_Init();
  123. ssd1306_TestFPS();
  124. HAL_Delay(3000);
  125. ssd1306_TestBorder();
  126. ssd1306_TestFonts();
  127. HAL_Delay(3000);
  128. ssd1306_Fill(Black);
  129. ssd1306_TestRectangle();
  130. ssd1306_TestLine();
  131. HAL_Delay(3000);
  132. ssd1306_Fill(Black);
  133. ssd1306_TestPolyline();
  134. HAL_Delay(3000);
  135. ssd1306_Fill(Black);
  136. ssd1306_TestArc();
  137. HAL_Delay(3000);
  138. ssd1306_Fill(Black);
  139. ssd1306_TestCircle();
  140. HAL_Delay(3000);
  141. }