main.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. #include <time.h>
  4. u8g2_t u8g2;
  5. u8log_t u8log;
  6. #define U8LOG_WIDTH 10
  7. #define U8LOG_HEIGHT 4
  8. uint8_t u8log_buf[U8LOG_WIDTH*U8LOG_HEIGHT];
  9. int main(void)
  10. {
  11. int k;
  12. clock_t t;
  13. uint8_t c;
  14. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  15. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  16. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  17. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  18. u8g2_SetFont(&u8g2, u8g2_font_helvB12_tr);
  19. u8log_Init(&u8log, U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buf);
  20. u8log_SetCallback(&u8log, u8log_u8g2_cb, &u8g2);
  21. u8log_SetRedrawMode(&u8log, /* is_redraw_line_for_each_char = */ 1);
  22. //u8log_SetRedrawMode(&u8log, /* is_redraw_line_for_each_char = */ 0);
  23. u8log_SetLineHeightOffset(&u8log, -3); /* decrese line spacing, u8g2 only */
  24. u8g2_SetFontRefHeightExtendedText(&u8g2); /* increase distance from top and line height */
  25. u8g2_SetFontRefHeightAll(&u8g2); /* increase distance from top and line height */
  26. t = clock()+CLOCKS_PER_SEC/10;
  27. for(;;)
  28. {
  29. if ( t < clock() )
  30. {
  31. c = (t % 10) + '0';
  32. if ( c == '0' )
  33. c = '\n';
  34. u8log_WriteChar(&u8log, c);
  35. t = clock()+CLOCKS_PER_SEC/10;
  36. }
  37. k = u8g_sdl_get_key();
  38. if ( k == 'q' ) break;
  39. if ( k == 't' )
  40. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  41. }
  42. return 0;
  43. }