main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. u8g2_t u8g2;
  4. /*
  5. Limitations:
  6. - Tile positions and sizes (pixel position divided by 8)
  7. - Any display rotation/mirror is ignored
  8. - Only works with displays, which support U8x8 API
  9. - Only available in full buffer mode
  10. - Will not send the e-paper refresh message
  11. */
  12. u8g2_SendTileSubBuffer(u8g2_t *u8g2, uint8_t x, uint8_t y, uint8_t w, uint8_t h)
  13. {
  14. uint16_t page_size;
  15. uint8_t *ptr;
  16. page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
  17. ptr = u8g2_GetBufferPtr(u8g2);
  18. ptr += x*8;
  19. ptr += page_size*y;
  20. while( h > 0 )
  21. {
  22. u8x8_DrawTile( u8g2_GetU8x8(u8g2), x, y, w, ptr );
  23. ptr += page_size;
  24. y++;
  25. h--;
  26. }
  27. }
  28. /*
  29. sub buffer window in pixel coordinates
  30. lower left corner is NOT included, this means the transfer range is from
  31. x0..x1-1
  32. y0..y1-1
  33. */
  34. void u8g2_SendWindow(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
  35. {
  36. x0 /= 8;
  37. y0 /= 8;
  38. x1 += 7;
  39. x1 /= 8;
  40. y1 +=7;
  41. y1 /= 8;
  42. u8g2_SendTileSubBuffer(u8g2, x0, y0, x1-x0, y1-y0);
  43. }
  44. int main(void)
  45. {
  46. int x, y;
  47. int k;
  48. //u8g2_SetupBuffer_SDL_240x160(&u8g2, &u8g2_cb_r0);
  49. u8g2_SetupBuffer_SDL_128x64(&u8g2, &u8g2_cb_r0);
  50. //u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  51. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  52. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  53. u8g2_SetFont(&u8g2, u8g2_font_helvB18_tr);
  54. x = 30;
  55. y = 35;
  56. for(;;)
  57. {
  58. #ifdef U8G2_WITH_HVLINE_COUNT
  59. u8g2.hv_cnt = 0UL;
  60. #endif /* U8G2_WITH_HVLINE_COUNT */
  61. u8g2_ClearBuffer(&u8g2);
  62. u8g2_SetFontDirection(&u8g2, 0);
  63. u8g2_DrawStr(&u8g2, x, y, "A");
  64. u8g2_SetFontDirection(&u8g2, 1);
  65. u8g2_DrawStr(&u8g2, x, y, "a");
  66. u8g2_SetFontDirection(&u8g2, 2);
  67. u8g2_DrawStr(&u8g2, x, y, "a");
  68. u8g2_SetFontDirection(&u8g2, 3);
  69. u8g2_DrawStr(&u8g2, x, y, "a");
  70. u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y0, 1, 0);
  71. u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y1-1, 1, 0);
  72. u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0);
  73. u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0);
  74. //u8g2_SendBuffer(&u8g2);
  75. //u8g2_SendTileSubBuffer(&u8g2, 2, 2, 12, 3);
  76. u8g2_SendWindow(&u8g2, 9, 17, 120, 42);
  77. //u8g2_SendTileWindow(&u8g2, 0, 0, 16, 8);
  78. /*
  79. u8g2_FirstPage(&u8g2);
  80. i = 0;
  81. do
  82. {
  83. u8g2_SetFontDirection(&u8g2, 0);
  84. u8g2_DrawStr(&u8g2, x, y, "ABC");
  85. u8g2_SetFontDirection(&u8g2, 1);
  86. u8g2_DrawStr(&u8g2, x, y, "abc");
  87. u8g2_SetFontDirection(&u8g2, 2);
  88. u8g2_DrawStr(&u8g2, x, y, "abc");
  89. u8g2_SetFontDirection(&u8g2, 3);
  90. u8g2_DrawStr(&u8g2, x, y, "abc");
  91. if ( i == 1 )
  92. {
  93. u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y0, 1, 0);
  94. u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y1-1, 1, 0);
  95. u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0);
  96. u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0);
  97. }
  98. i++;
  99. } while( u8g2_NextPage(&u8g2) );
  100. */
  101. #ifdef U8G2_WITH_HVLINE_COUNT
  102. printf("hv cnt: %ld\n", u8g2.hv_cnt);
  103. #endif /* U8G2_WITH_HVLINE_COUNT */
  104. do
  105. {
  106. k = u8g_sdl_get_key();
  107. } while( k < 0 );
  108. if ( k == 273 ) y -= 7;
  109. if ( k == 274 ) y += 7;
  110. if ( k == 276 ) x -= 7;
  111. if ( k == 275 ) x += 7;
  112. if ( k == 'e' ) y -= 1;
  113. if ( k == 'x' ) y += 1;
  114. if ( k == 's' ) x -= 1;
  115. if ( k == 'd' ) x += 1;
  116. if ( k == 'q' ) break;
  117. //if ( k == 't' )
  118. // u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  119. }
  120. //u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font);
  121. //u8x8_Draw8x8String(u8g2_GetU8x8(&u8g2), 0, 0, "Hello World!");
  122. return 0;
  123. }