main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "u8g2.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "mui.h"
  6. #include "mui_u8g2.h"
  7. /*=================================================*/
  8. /* global variables */
  9. u8g2_t u8g2;
  10. mui_t ui;
  11. uint8_t var1;
  12. uint8_t var2;
  13. uint8_t var3;
  14. uint8_t var4;
  15. muif_t muif_list[] MUI_PROGMEM = {
  16. MUIF_U8G2_LABEL(),
  17. MUIF_U8G2_FONT_STYLE(0, u8g2_font_5x8_tr),
  18. // MUIF_U8G2_U8_MIN_MAX_STEP("B1", /*valptr=*/ &var1, /*min=*/ 10 , /*max=*/ 20, /*step=*/ 2, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_bar_wm_mse_pi),
  19. // MUIF_U8G2_U8_MIN_MAX_STEP("B2", /*valptr=*/ &var2, /*min=*/ 10 , /*max=*/ 20, /*step=*/ 2, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_bar_wm_mud_pi),
  20. // MUIF_U8G2_U8_MIN_MAX_STEP("B3", /*valptr=*/ &var3, /*min=*/ 10 , /*max=*/ 20, /*step=*/ 2, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_bar_wm_mse_pf),
  21. // MUIF_U8G2_U8_MIN_MAX_STEP("B4", /*valptr=*/ &var4, /*min=*/ 10 , /*max=*/ 20, /*step=*/ 2, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_bar_wm_mud_pf)
  22. MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH("B1", /*valptr=*/ &var1, /*min=*/ 10 , /*max=*/ 200, /*step=*/ 1, /*width=*/ 40, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_fixed_width_bar_wm_mse_pi),
  23. MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH("B2", /*valptr=*/ &var2, /*min=*/ 10 , /*max=*/ 200, /*step=*/ 1, /*width=*/ 40, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_fixed_width_bar_wm_mud_pi),
  24. MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH("B3", /*valptr=*/ &var3, /*min=*/ 10 , /*max=*/ 200, /*step=*/ 1, /*width=*/ 40, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_fixed_width_bar_wm_mse_pf),
  25. MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH("B4", /*valptr=*/ &var4, /*min=*/ 10 , /*max=*/ 200, /*step=*/ 1, /*width=*/ 40, MUI_MMS_2X_BAR|MUI_MMS_SHOW_VALUE, mui_u8g2_u8_fixed_width_bar_wm_mud_pf)
  26. };
  27. fds_t fds[] MUI_PROGMEM =
  28. MUI_FORM(1)
  29. MUI_STYLE(0)
  30. MUI_LABEL(5,10, "5x8")
  31. MUI_XY("B1", 5, 20)
  32. MUI_XY("B2", 5, 30)
  33. MUI_XY("B3", 5, 40)
  34. MUI_XY("B4", 5, 50)
  35. ;
  36. int screenshot_n = 0;
  37. void do_screenshot(void)
  38. {
  39. char s[4096];
  40. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  41. sprintf( s,
  42. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  43. " -fill 'rgb(255,170,0)' -opaque white"
  44. " -filter point -resize 200%%"
  45. " screenshot.tga pic%04d.png", screenshot_n);
  46. system(s);
  47. screenshot_n++;
  48. /*
  49. gif animation:
  50. convert -delay 40 -loop 0 pic*.png animation.gif
  51. */
  52. }
  53. int main(void)
  54. {
  55. int x, y;
  56. int k;
  57. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  58. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  59. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  60. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  61. u8g2_SetFont(&u8g2, u8g2_font_6x10_tr);
  62. u8g2_SetFontMode(&u8g2, 1);
  63. mui_Init(&ui, &u8g2, fds, muif_list, sizeof(muif_list)/sizeof(muif_t));
  64. mui_GotoForm(&ui, 1, 0);
  65. x = 4; // use as height for the box
  66. y = 0;
  67. for(;;)
  68. {
  69. u8g2_SetFontRefHeightExtendedText(&u8g2);
  70. u8g2_FirstPage(&u8g2);
  71. do
  72. {
  73. mui_Draw(&ui);
  74. } while( u8g2_NextPage(&u8g2) );
  75. do_screenshot();
  76. // printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui));
  77. do
  78. {
  79. k = u8g_sdl_get_key();
  80. } while( k < 0 );
  81. if ( k == 273 ) y -= 1;
  82. if ( k == 274 ) y += 1;
  83. if ( k == 276 ) x -= 1;
  84. if ( k == 275 ) x += 1;
  85. /*
  86. if ( k == 'e' ) y -= 1;
  87. if ( k == 'x' ) y += 1;
  88. if ( k == 's' ) x -= 1;
  89. if ( k == 'd' ) x += 1;
  90. */
  91. if ( k == 'q' ) break;
  92. if ( k == 'n' )
  93. {
  94. mui_NextField(&ui);
  95. }
  96. if ( k == 'p' )
  97. {
  98. mui_PrevField(&ui);
  99. }
  100. if ( k == 's' )
  101. {
  102. mui_SendSelect(&ui);
  103. }
  104. if ( k == 't' )
  105. {
  106. puts("screenshot");
  107. do_screenshot();
  108. }
  109. if ( x < 0 )
  110. x = 0;
  111. }
  112. return 0;
  113. }