main.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. u8g2_t u8g2;
  6. int screenshot_n = 0;
  7. void do_screenshot(void)
  8. {
  9. char s[4096];
  10. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  11. sprintf( s,
  12. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  13. " -fill 'rgb(255,170,0)' -opaque white"
  14. " -filter point -resize 200%%"
  15. " screenshot.tga pic%04d.png", screenshot_n);
  16. system(s);
  17. screenshot_n++;
  18. /*
  19. gif animation:
  20. convert -delay 40 -loop 0 pic*.png animation.gif
  21. */
  22. }
  23. int main(void)
  24. {
  25. int x, y;
  26. int k;
  27. int offset = 100;
  28. int tw;
  29. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  30. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  31. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  32. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  33. x = 4; // use as height for the box
  34. y = 0;
  35. for(;;)
  36. {
  37. u8g2_FirstPage(&u8g2);
  38. do
  39. {
  40. #define Row1Y 50
  41. #define MinXT 80
  42. #define MinXO 110
  43. #define HourXT 13
  44. #define HourXO 45
  45. #define clockMinT "0"
  46. #define clockMinO "0"
  47. #define clockHourT "0"
  48. #define clockHourO "0"
  49. u8g2_SetFont(&u8g2, u8g2_font_fur42_tr);
  50. u8g2_SetFontDirection(&u8g2, 0);
  51. u8g2_DrawPixel(&u8g2, 0, 0);
  52. u8g2_DrawStr(&u8g2, -4, 45, "00");
  53. u8g2_DrawLine(&u8g2, 0,22,127,22);
  54. /*
  55. tw = (int)u8g2_GetUTF8Width(&u8g2, clockMinT);
  56. u8g2_DrawStr(&u8g2, MinXT-tw/2, Row1Y, clockMinT);
  57. tw = (int)u8g2_GetUTF8Width(&u8g2, clockMinO);
  58. u8g2_DrawStr(&u8g2, MinXO-tw/2, Row1Y, clockMinO);
  59. //hours
  60. tw = (int)u8g2_GetUTF8Width(&u8g2, clockHourT);
  61. u8g2_DrawStr(&u8g2, HourXT-tw/2, Row1Y, clockHourT);
  62. tw = (int)u8g2_GetUTF8Width(&u8g2, clockHourO);
  63. u8g2_DrawStr(&u8g2, HourXO-tw/2, Row1Y, clockHourO);
  64. */
  65. //u8g2_SetDrawColor(&u8g2, 1);
  66. //u8g2_SetFont(&u8g2, u8g2_font_helvB08_tf);
  67. //u8g2_SetDrawColor(&u8g2, 2);
  68. //u8g2_DrawVLine(&u8g2, x, 0, 64);
  69. //u8g2_DrawLine(&u8g2, 30, 10, 30, 100);
  70. } while( u8g2_NextPage(&u8g2) );
  71. do
  72. {
  73. k = u8g_sdl_get_key();
  74. } while( k < 0 );
  75. if ( k == 273 ) y -= 1;
  76. if ( k == 274 ) y += 1;
  77. if ( k == 276 ) x -= 1;
  78. if ( k == 275 ) x += 1;
  79. if ( k == 'e' ) y -= 1;
  80. if ( k == 'x' ) y += 1;
  81. if ( k == 's' ) x -= 1;
  82. if ( k == 'd' ) x += 1;
  83. if ( k == 'q' ) break;
  84. if ( k == 32 )
  85. offset -= 1;
  86. if ( k == 't' )
  87. {
  88. puts("screenshot");
  89. do_screenshot();
  90. }
  91. if ( x < 0 )
  92. x = 0;
  93. }
  94. return 0;
  95. }