main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 num_value = 0;
  12. uint8_t bar_value = 0;
  13. uint8_t TestModeRadioChoice = 0;
  14. long LastTime;
  15. uint16_t menu_get_cnt(void *data) {
  16. return 7; /* number of menu entries */
  17. }
  18. uint16_t menu_get_cnt2(void *data) {
  19. return 5; /* number of menu entries */
  20. }
  21. const char *menu_get_str(void *data, uint16_t index) {
  22. static const char *menu[] = {
  23. MUI_11 "Device 1",
  24. MUI_11 "Device 2",
  25. MUI_11 "Device 3",
  26. MUI_11 "Device 4",
  27. MUI_11 "Device 5",
  28. MUI_11 "Device 6"
  29. };
  30. return menu[index];
  31. }
  32. const char *menuAC_get_str(void *data, uint16_t index) {
  33. static const char *menu[] = {
  34. MUI_21 "Test",
  35. MUI_22 "Battery",
  36. MUI_23 "Timer",
  37. MUI_24 "Activation",
  38. MUI_1 "Back..",
  39. };
  40. return menu[index];
  41. }
  42. uint16_t selection = 0, selection2 = 0;
  43. uint8_t mui_hrule(mui_t *ui, uint8_t msg) {
  44. if (msg == MUIF_MSG_DRAW) {
  45. u8g2_DrawHLine(&u8g2, 0, mui_get_y(ui), 128);
  46. //Serial.println("drawHLine " + String(selection + 1));
  47. //Serial.println(String(selection2));
  48. selection2 = 0;
  49. }
  50. return 0;
  51. }
  52. uint8_t mui_draw_current_device(mui_t *ui, uint8_t msg) {
  53. if (msg == MUIF_MSG_DRAW) {
  54. //u8g2_SetCursor(mui_get_x(ui ), mui_get_y(ui));
  55. u8g2_DrawStr(&u8g2, mui_get_x(ui ), mui_get_y(ui ), "Device: ??");
  56. //u8g2.print("Device: " + String(selection + 1));
  57. }
  58. return 0;
  59. }
  60. //forced exit
  61. uint8_t mui_go_main_menu(mui_t *ui, uint8_t msg) {
  62. if (msg == MUIF_MSG_FORM_START) {
  63. mui_SendSelectWithExecuteOnSelectFieldSearch(ui);
  64. //Serial.println("mui_go_main_menu");
  65. }
  66. return 0;
  67. }
  68. muif_t muif_list[] = {
  69. MUIF_U8G2_FONT_STYLE(0, u8g2_font_6x12_t_cyrillic), /* regular font */
  70. MUIF_U8G2_FONT_STYLE(1, u8g2_font_6x12_t_cyrillic), /* bold font */
  71. MUIF_VARIABLE("TM",&TestModeRadioChoice,mui_u8g2_u8_chkbox_wm_pi),
  72. MUIF_RO("HR", mui_hrule),
  73. MUIF_U8G2_LABEL(),
  74. MUIF_RO("GP", mui_u8g2_goto_data),
  75. MUIF_BUTTON("GC", mui_u8g2_goto_form_w1_pi),
  76. MUIF_U8G2_U16_LIST("ID", &selection, NULL, menu_get_str, menu_get_cnt, mui_u8g2_u16_list_goto_w1_pi),
  77. MUIF_U8G2_U16_LIST("AC", &selection2, NULL, menuAC_get_str, menu_get_cnt2, mui_u8g2_u16_list_goto_w1_pi),
  78. MUIF_RO("DD", mui_draw_current_device),
  79. MUIF_RO("GG", mui_go_main_menu),
  80. /* a button for the menu... */
  81. MUIF_EXECUTE_ON_SELECT_BUTTON("ST", mui_u8g2_btn_exit_wm_fi)
  82. //MUIF_BUTTON("ST", mui_u8g2_btn_exit_wm_fi)
  83. };
  84. fds_t fds_data[] =
  85. MUI_FORM(1)
  86. MUI_STYLE(1)
  87. MUI_LABEL(5, 10, "Choose:")
  88. MUI_XY("HR", 0,11)
  89. MUI_XYA("ID", 5, 24, 0)
  90. MUI_XYA("ID", 5, 36, 1)
  91. MUI_XYA("ID", 5, 48, 2)
  92. MUI_XYA("ID", 5, 60, 3)
  93. MUI_FORM(11)
  94. MUI_STYLE(1)
  95. MUI_XY("HR", 0,11)
  96. MUI_XY("DD", 5, 10)
  97. MUI_XYA("AC", 5, 24, 0)
  98. MUI_XYA("AC", 5, 36, 1)
  99. MUI_XYA("AC", 5, 48, 2)
  100. MUI_XYA("AC", 5, 60, 3)
  101. MUI_FORM(25)
  102. MUI_STYLE(1)
  103. MUI_XYT("ST", 5, 24, "Exit")
  104. MUI_AUX("GG")
  105. ;
  106. int screenshot_n = 0;
  107. void do_screenshot(void)
  108. {
  109. char s[4096];
  110. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  111. sprintf( s,
  112. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  113. " -fill 'rgb(255,170,0)' -opaque white"
  114. " -filter point -resize 200%%"
  115. " screenshot.tga pic%04d.png", screenshot_n);
  116. system(s);
  117. screenshot_n++;
  118. /*
  119. gif animation:
  120. convert -delay 40 -loop 0 pic*.png animation.gif
  121. */
  122. }
  123. void clearFormPositionCache( mui_t *mui, uint8_t form_id )
  124. {
  125. uint8_t i;
  126. for( i = 0; i < MUI_MENU_CACHE_CNT; i++ )
  127. if ( mui->menu_form_id[i] == form_id )
  128. mui->menu_form_cursor_focus_position[i] = 0;
  129. }
  130. int main(void)
  131. {
  132. int x, y;
  133. int k;
  134. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  135. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  136. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  137. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  138. u8g2_SetFont(&u8g2, u8g2_font_6x10_tr);
  139. u8g2_SetFontMode(&u8g2, 1);
  140. mui_Init(&ui, &u8g2, fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
  141. mui_GotoForm(&ui, 1, 0);
  142. x = 4; // use as height for the box
  143. y = 0;
  144. for(;;)
  145. {
  146. u8g2_SetFontRefHeightExtendedText(&u8g2);
  147. u8g2_FirstPage(&u8g2);
  148. do
  149. {
  150. mui_Draw(&ui);
  151. } while( u8g2_NextPage(&u8g2) );
  152. do_screenshot();
  153. // printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui));
  154. do
  155. {
  156. k = u8g_sdl_get_key();
  157. } while( k < 0 );
  158. if ( k == 273 ) y -= 1;
  159. if ( k == 274 ) y += 1;
  160. if ( k == 276 ) x -= 1;
  161. if ( k == 275 ) x += 1;
  162. /*
  163. if ( k == 'e' ) y -= 1;
  164. if ( k == 'x' ) y += 1;
  165. if ( k == 's' ) x -= 1;
  166. if ( k == 'd' ) x += 1;
  167. */
  168. if ( k == 'q' ) break;
  169. if ( k == 'n' )
  170. {
  171. mui_NextField(&ui);
  172. }
  173. if ( k == 'p' )
  174. {
  175. mui_PrevField(&ui);
  176. }
  177. if ( k == 's' )
  178. {
  179. clearFormPositionCache( &ui, 11 );
  180. mui_SendSelect(&ui);
  181. }
  182. if ( k == 't' )
  183. {
  184. puts("screenshot");
  185. do_screenshot();
  186. }
  187. if ( x < 0 )
  188. x = 0;
  189. }
  190. return 0;
  191. }