myTest.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * myTest.c
  3. *
  4. * Created on: Jul 1, 2021
  5. * Author: David
  6. */
  7. #include "myTest.h"
  8. #include "main.h"
  9. #include "board.h"
  10. #include "iron.h"
  11. #include "ssd1306.h"
  12. #include "gui.h"
  13. struct{
  14. uint32_t tim_fps, tim_move;
  15. uint16_t fps,last_fps, rate, seconds;
  16. int8_t rad,x,y,xdir,ydir,run;
  17. }test;
  18. void myTest(void){
  19. test.tim_fps = test.tim_move = HAL_GetTick();
  20. test.rad=12;
  21. test.x=63+32;
  22. test.y=test.rad+1;
  23. test.xdir=1;
  24. test.ydir=1;
  25. test.rate=20;
  26. #ifndef DEBUG
  27. test.run=1;
  28. #endif
  29. char str[16];
  30. setContrast(255);
  31. FillBuffer(BLACK, fill_dma);
  32. u8g2_SetFont(&u8g2,default_font );
  33. u8g2_SetDrawColor(&u8g2, WHITE);
  34. if(oled.use_sw){
  35. u8g2_DrawStr(&u8g2,0,0,"SW Mode");
  36. }
  37. else{
  38. u8g2_DrawStr(&u8g2,0,0,"HW Mode");
  39. }
  40. u8g2_DrawStr(&u8g2,0,16,"FPS:");
  41. u8g2_DrawStr(&u8g2,0,32,"TIM:");
  42. while(1){
  43. SetFailState(setError);
  44. if(oled.status==oled_idle){
  45. if((HAL_GetTick()-test.tim_fps)>999){
  46. test.seconds++;
  47. test.tim_fps=HAL_GetTick();
  48. u8g2_SetDrawColor(&u8g2, BLACK);
  49. u8g2_DrawBox(&u8g2, 30, 16, 34, 32);
  50. u8g2_SetDrawColor(&u8g2, WHITE);
  51. sprintf(str,"%u", test.fps);
  52. u8g2_DrawStr(&u8g2,30,16,str);
  53. sprintf(str,"%u", test.seconds);
  54. u8g2_DrawStr(&u8g2,30,32,str);
  55. test.last_fps = test.fps;
  56. test.fps=0;
  57. }
  58. if((HAL_GetTick()-test.tim_move)>=test.rate){
  59. test.tim_move=HAL_GetTick();
  60. u8g2_SetDrawColor(&u8g2, BLACK);
  61. u8g2_DrawBox(&u8g2, test.x-test.rad, test.y-test.rad, (test.rad*2)+1, (test.rad*2)+1);
  62. u8g2_SetDrawColor(&u8g2, WHITE);
  63. if(test.run){
  64. test.x += test.xdir;
  65. test.y += test.ydir;
  66. if(test.x>=(127-(test.rad+1)) || test.x<=(64+test.rad+1)){
  67. test.xdir = -test.xdir;
  68. }
  69. if(test.y>=(63-(test.rad+1))|| test.y<=(test.rad+1)){
  70. test.ydir = -test.ydir;
  71. }
  72. }
  73. u8g2_DrawDisc(&u8g2, test.x, test.y, test.rad, U8G2_DRAW_ALL);
  74. u8g2_DrawFrame(&u8g2, 64, 0, 64, 64);
  75. }
  76. test.fps++;
  77. update_display();
  78. }
  79. }
  80. }