main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. uint8_t mui_style_helv_r_08(mui_t *ui, uint8_t msg)
  8. {
  9. u8g2_t *u8g2 = mui_get_U8g2(ui);
  10. switch(msg)
  11. {
  12. case MUIF_MSG_DRAW:
  13. u8g2_SetFont(u8g2, u8g2_font_helvR08_tr);
  14. break;
  15. }
  16. return 0;
  17. }
  18. uint8_t mui_style_helv_b_08(mui_t *ui, uint8_t msg)
  19. {
  20. u8g2_t *u8g2 = mui_get_U8g2(ui);
  21. switch(msg)
  22. {
  23. case MUIF_MSG_DRAW:
  24. u8g2_SetFont(u8g2, u8g2_font_helvB08_tr);
  25. break;
  26. }
  27. return 0;
  28. }
  29. uint8_t mui_style_monospaced(mui_t *ui, uint8_t msg)
  30. {
  31. u8g2_t *u8g2 = mui_get_U8g2(ui);
  32. switch(msg)
  33. {
  34. case MUIF_MSG_DRAW:
  35. u8g2_SetFont(u8g2, u8g2_font_profont12_tr);
  36. //u8g2_SetFont(u8g2, u8g2_font_6x10_tr);
  37. break;
  38. }
  39. return 0;
  40. }
  41. uint8_t mui_style_streamline_food_drink(mui_t *ui, uint8_t msg)
  42. {
  43. u8g2_t *u8g2 = mui_get_U8g2(ui);
  44. switch(msg)
  45. {
  46. case MUIF_MSG_DRAW:
  47. u8g2_SetFont(u8g2, u8g2_font_streamline_food_drink_t);
  48. //u8g2_SetFont(u8g2, u8g2_font_6x10_tr);
  49. break;
  50. }
  51. return 0;
  52. }
  53. uint8_t mui_hrule(mui_t *ui, uint8_t msg)
  54. {
  55. u8g2_t *u8g2 = mui_get_U8g2(ui);
  56. switch(msg)
  57. {
  58. case MUIF_MSG_DRAW:
  59. u8g2_DrawHLine(u8g2, 0, mui_get_y(ui), u8g2_GetDisplayWidth(u8g2));
  60. break;
  61. }
  62. return 0;
  63. }
  64. u8g2_t u8g2;
  65. mui_t ui;
  66. /*
  67. global variables which form the communication gateway between the user interface and the rest of the code
  68. */
  69. uint8_t number_input = 2; // variable where the user can input a number between 0 and 9
  70. uint8_t number_input2 = 100; // variable where the user can input a number between 0 and 9
  71. uint8_t fruit_input = 2;
  72. uint8_t fruit_input2 = 2;
  73. uint8_t my_value3 = 0;
  74. uint8_t color_input = 0;
  75. uint8_t food_input = 0;
  76. uint8_t checkbox_input = 0;
  77. uint8_t direction_input = 0;
  78. uint8_t text_input[4] = { ' ',' ',' ',' '} ;
  79. uint8_t exit_code = 0;
  80. uint16_t list_selection = 0;
  81. uint16_t list_selection2 = 0;
  82. uint16_t list_selection3 = 0;
  83. uint16_t list_selection4 = 0;
  84. uint8_t array_pos = 0;
  85. uint8_t array_led_off_time[4] = { 10, 5, 3, 1};
  86. uint8_t led_off_time = 0;
  87. uint8_t array_led_on_time[4] = { 10, 5, 3, 1};
  88. uint8_t led_on_time = 0;
  89. uint8_t muif_array_pos_selection(mui_t *ui, uint8_t msg)
  90. {
  91. uint8_t return_value = 0;
  92. switch(msg)
  93. {
  94. case MUIF_MSG_FORM_START:
  95. led_off_time = array_led_off_time[array_pos];
  96. led_on_time = array_led_on_time[array_pos];
  97. return_value = mui_u8g2_u8_min_max_wm_mse_pi(ui, msg);
  98. break;
  99. case MUIF_MSG_FORM_END:
  100. return_value = mui_u8g2_u8_min_max_wm_mse_pi(ui, msg);
  101. break;
  102. case MUIF_MSG_CURSOR_SELECT:
  103. case MUIF_MSG_EVENT_NEXT:
  104. case MUIF_MSG_EVENT_PREV:
  105. array_led_off_time[array_pos] = led_off_time;
  106. array_led_on_time[array_pos] = led_on_time;
  107. return_value = mui_u8g2_u8_min_max_wm_mse_pi(ui, msg);
  108. led_off_time = array_led_off_time[array_pos];
  109. led_on_time = array_led_on_time[array_pos];
  110. break;
  111. default:
  112. return_value = mui_u8g2_u8_min_max_wm_mse_pi(ui, msg);
  113. }
  114. return return_value;
  115. }
  116. uint16_t list_get_cnt(void *data)
  117. {
  118. return 17; /* number of animals */
  119. }
  120. const char *list_get_str(void *data, uint16_t index)
  121. {
  122. static const char *animals[] = { "Bird", "Bison", "Cat", "Crow", "Dog", "Elephant", "Fish", "Gnu", "Horse", "Koala", "Lion", "Mouse", "Owl", "Rabbit", "Spider", "Turtle", "Zebra" };
  123. return animals[index];
  124. }
  125. uint16_t menu_get_cnt(void *data)
  126. {
  127. return 10; /* number of menu entries */
  128. }
  129. const char *menu_get_str(void *data, uint16_t index)
  130. {
  131. static const char *menu[] =
  132. {
  133. MUI_0 "Goto Main Menu",
  134. MUI_10 "Enter a number",
  135. MUI_11 "Parent/Child Selection",
  136. MUI_13 "Checkbox",
  137. MUI_14 "Radio Selection",
  138. MUI_15 "Text Input",
  139. MUI_16 "Single Line Selection",
  140. MUI_17 "List Line Selection",
  141. MUI_18 "Parent/Child List",
  142. MUI_20 "Array Edit",
  143. };
  144. return menu[index];
  145. }
  146. /*
  147. User interface fields list. Each entry is defined with the MUIF macro MUIF(id,cflags,data,cb)
  148. Arguments are:
  149. id:
  150. A string with exactly two characters. This is the unique "id" of the field, which is later used in the form definition string (fds)
  151. There are some special id's: ".L" for text labels and ".G" for a goto form command.
  152. cflags:
  153. Flags, which define static (constant) properties of the field. Currently this is either 0 or MUIF_CFLAG_IS_CURSOR_SELECTABLE which marks the field as editable.
  154. data:
  155. A pointer to a local variable, where the result of an editiable field is stored. Currently this is a pointer to uint8_t in most cases.
  156. It depends in the callback function (cb) whether this is used or what kind of data is stored
  157. cb:
  158. A callback function.
  159. The callback function will receive messages and have to react accordingly to the message. Some predefined callback functions are avilable in mui_u8g2.c
  160. */
  161. muif_t muif_list[] MUI_PROGMEM = {
  162. /* normal text style */
  163. MUIF_STYLE(0, mui_style_helv_r_08),
  164. /* bold text style */
  165. MUIF_STYLE(1, mui_style_helv_b_08),
  166. /* monospaced font */
  167. MUIF_STYLE(2, mui_style_monospaced),
  168. /* food and drink */
  169. MUIF_STYLE(3, mui_style_streamline_food_drink),
  170. /* horizontal line (hrule) */
  171. MUIF_RO("HR", mui_hrule),
  172. /* Goto Form Button where the width is equal to the size of the text, spaces can be used to extend the size */
  173. //MUIF("G1",MUIF_CFLAG_IS_CURSOR_SELECTABLE,0,mui_u8g2_btn_goto_wm_fi),
  174. MUIF_BUTTON("G1", mui_u8g2_btn_goto_wm_fi),
  175. /* input for a number between 0 to 9 */
  176. //MUIF("IN",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&number_input,mui_u8g2_u8_value_0_9_wm_mse_pi),
  177. //MUIF("IN",MUIF_CFLAG_IS_CURSOR_SELECTABLE, (void *)((mui_u8g2_u8_min_max_t [] ) {{ &number_input COMMA 1 COMMA 8 } } ) , mui_u8g2_u8_min_max_wm_mse_pi),
  178. MUIF_U8G2_U8_MIN_MAX("IN", &number_input, 0, 9, mui_u8g2_u8_min_max_wm_mse_pf),
  179. /* input for a number between 0 to 100 */
  180. //MUIF("IH",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&number_input2,mui_u8g2_u8_value_0_100_wm_mud_pi),
  181. MUIF_U8G2_U8_MIN_MAX("IH", &number_input2, 0, 100, mui_u8g2_u8_min_max_wm_mud_pf),
  182. /* input for text with four chars */
  183. /*
  184. MUIF("T0",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+0,mui_u8g2_u8_char_wm_mud_pi),
  185. MUIF("T1",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+1,mui_u8g2_u8_char_wm_mud_pi),
  186. MUIF("T2",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+2,mui_u8g2_u8_char_wm_mud_pi),
  187. MUIF("T3",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+3,mui_u8g2_u8_char_wm_mud_pi),
  188. */
  189. MUIF_VARIABLE("T0", text_input+0, mui_u8g2_u8_char_wm_mud_pi),
  190. MUIF_VARIABLE("T1", text_input+1, mui_u8g2_u8_char_wm_mud_pi),
  191. MUIF_VARIABLE("T2", text_input+2, mui_u8g2_u8_char_wm_mud_pi),
  192. MUIF_VARIABLE("T3", text_input+3, mui_u8g2_u8_char_wm_mud_pi),
  193. /* input for a fruit (0..3), implements a selection, where the user can cycle through the options */
  194. MUIF_VARIABLE("IF",&fruit_input,mui_u8g2_u8_opt_line_wa_mse_pi),
  195. MUIF_VARIABLE("IG",&fruit_input2,mui_u8g2_u8_opt_line_wa_mud_pi),
  196. /* checkbox */
  197. //MUIF("CB",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&checkbox_input,mui_u8g2_u8_chkbox_wm_pi),
  198. MUIF_VARIABLE("CB",&checkbox_input,mui_u8g2_u8_chkbox_wm_pi),
  199. /* the following two fields belong together and implement a single selection combo box to select a color */
  200. //MUIF("IC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_parent_wa_mse_pi),
  201. MUIF_VARIABLE("IC",&color_input,mui_u8g2_u8_opt_parent_wm_pi),
  202. //MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
  203. //MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
  204. //MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
  205. //MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
  206. MUIF_VARIABLE("OC",&color_input,mui_u8g2_u8_opt_radio_child_w1_pi),
  207. MUIF_VARIABLE("ID",&food_input,mui_u8g2_u8_opt_parent_wm_pi),
  208. MUIF_VARIABLE("OD",&food_input,mui_u8g2_u8_opt_child_wm_pi),
  209. /* radio button style */
  210. //MUIF("RS",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&direction_input,mui_u8g2_u8_radio_wm_pi),
  211. MUIF_VARIABLE("RS",&direction_input,mui_u8g2_u8_radio_wm_pi),
  212. MUIF_U8G2_U16_LIST("L1", &list_selection, NULL, list_get_str, list_get_cnt, mui_u8g2_u16_list_line_wa_mse_pi),
  213. MUIF_U8G2_U16_LIST("L2", &list_selection2, NULL, list_get_str, list_get_cnt, mui_u8g2_u16_list_line_wa_mud_pi),
  214. MUIF_U8G2_U16_LIST("LP", &list_selection3, NULL, list_get_str, list_get_cnt, mui_u8g2_u16_list_parent_wm_pi),
  215. MUIF_U8G2_U16_LIST("LC", &list_selection3, NULL, list_get_str, list_get_cnt, mui_u8g2_u16_list_child_w1_pi),
  216. MUIF_U8G2_U16_LIST("LG", &list_selection4, NULL, menu_get_str, menu_get_cnt, mui_u8g2_u16_list_goto_w1_pi),
  217. /* MUI_GOTO uses the fixed ".G" id and is intended for goto buttons. This is a full display width style button */
  218. MUIF_GOTO(mui_u8g2_btn_goto_w1_pi),
  219. /* MUI_LABEL uses the fixed ".L" id and is used to place read only text on a form */
  220. //MUIF(".L",0,0,mui_u8g2_draw_text),
  221. MUIF_LABEL(mui_u8g2_draw_text),
  222. /* array example */
  223. MUIF_U8G2_U8_MIN_MAX("AP", &array_pos, 0, 3, muif_array_pos_selection),
  224. MUIF_U8G2_U8_MIN_MAX("AF", &led_off_time, 0, 20, mui_u8g2_u8_min_max_wm_mse_pi),
  225. MUIF_U8G2_U8_MIN_MAX("AN", &led_on_time, 0, 20, mui_u8g2_u8_min_max_wm_mse_pi),
  226. /* button for the minimal example */
  227. MUIF("BN", MUIF_CFLAG_IS_CURSOR_SELECTABLE, 0, mui_u8g2_btn_exit_wm_fi),
  228. /* Leave the menu system */
  229. MUIF("LV",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&exit_code,mui_u8g2_btn_exit_wm_fi)
  230. };
  231. /*
  232. The form definition string (fds) defines all forms and the fields on those forms.
  233. A new form always starts with MUI_FORM(u). The form ends with the next MUI_FORM() or the end of the fds.
  234. Inside the form use fields or the style command (MUI_STYLE)
  235. The fields are define with
  236. MUI_XY(id, x, y) Field 'id' without extra argument or text placed at the specified xy position
  237. MUI_XYT(id, x, y, text) Field 'id' with the specified test at position xy
  238. MUI_XYA(id, x, y, a) Field 'id' with argument 'a' at position xy
  239. MUI_XYAT(id, x, y, a, text) Field 'id' with argument and text placed at position xy
  240. MUI_LABEL(x,y,text) Field '.L' (usually some readonly text) placed at position xy
  241. MUI_GOTO(x,y,n,text) Field '.G', usually a button placed at xy, which activates form n
  242. Note:
  243. MUI_LABEL(x,y,text) is the same as MUI_XYT(".L", x, y, text)
  244. MUI_GOTO(x,y,text) is the same as MUI_XYAT(".G", x, y, n, text)
  245. */
  246. fds_t fds[] =
  247. /* top level main menu */
  248. MUI_FORM(0)
  249. MUI_STYLE(1)
  250. MUI_LABEL(5,10, "Main Menu 1/3")
  251. MUI_XY("HR", 0,13)
  252. MUI_STYLE(0)
  253. MUI_GOTO(5,25,10, "Enter a number")
  254. MUI_GOTO(5,37,11, "Parent/Child Selection")
  255. MUI_GOTO(5,49,13, "Checkbox")
  256. MUI_GOTO(5,61,1, "More...")
  257. MUI_FORM(1)
  258. MUI_STYLE(1)
  259. MUI_LABEL(5,10, "Main Menu 2/3")
  260. MUI_XY("HR", 0,13)
  261. MUI_STYLE(0)
  262. MUI_GOTO(5,25,14, "Radio Selection")
  263. MUI_GOTO(5,37,15, "Text Input")
  264. MUI_GOTO(5,49,16, "Single Line Selection")
  265. MUI_GOTO(5,61,2, "More...")
  266. MUI_FORM(2)
  267. MUI_STYLE(1)
  268. MUI_LABEL(5,10, "Main Menu 3/3")
  269. MUI_XY("HR", 0,13)
  270. MUI_STYLE(0)
  271. MUI_GOTO(5,25,17, "List Line Selection")
  272. MUI_GOTO(5,37,18, "Parent/Child List")
  273. MUI_GOTO(5,49,20, "Array Edit")
  274. MUI_GOTO(5,61,3, "Alternative Menu")
  275. MUI_FORM(3)
  276. MUI_STYLE(1)
  277. MUI_LABEL(5,10, "Alternative Menu")
  278. MUI_XY("HR", 0,13)
  279. MUI_STYLE(0)
  280. MUI_XYA("LG", 5, 25, 0)
  281. MUI_XYA("LG", 5, 37, 1)
  282. MUI_XYA("LG", 5, 49, 2)
  283. MUI_XYA("LG", 5, 61, 3)
  284. /* number entry demo */
  285. MUI_FORM(10)
  286. MUI_STYLE(1)
  287. MUI_LABEL(5,10, "Number Menu")
  288. MUI_XY("HR", 0,13)
  289. MUI_STYLE(0)
  290. MUI_LABEL(5,27, "Number [mse]:")
  291. MUI_XY("IN",76, 27)
  292. MUI_LABEL(5,41, "Number [mud]:")
  293. MUI_XY("IH",76, 41)
  294. MUI_XYAT("G1",64, 59, 0, " OK ")
  295. /* parent / child selection */
  296. MUI_FORM(11)
  297. MUI_STYLE(1)
  298. MUI_LABEL(5,10, "Parent/Child Selection")
  299. MUI_XY("HR", 0,13)
  300. MUI_STYLE(0)
  301. MUI_LABEL(5,24, "Color:")
  302. MUI_XYAT("IC",80, 24, 12, "red|orange|yellow|green|cyan|azure|blue|violet|magenta|rose") /* jump to sub form 12 */
  303. MUI_LABEL(5,42, "We need:")
  304. MUI_STYLE(3)
  305. MUI_XYAT("ID",80, 49, 21, "\x30|\x31|\x32|\x33|\x34|\x35|\x36|\x37|\x38|\x39|\x40|\x41|\x42|\x43")
  306. MUI_STYLE(0)
  307. MUI_XYAT("G1",64, 60, 0, " OK ")
  308. /* combo box color selection */
  309. MUI_FORM(12)
  310. MUI_STYLE(1)
  311. MUI_LABEL(5,10, "Color Selection")
  312. MUI_XY("HR", 0,13)
  313. MUI_STYLE(0)
  314. MUI_XYA("OC", 5, 30, 0) /* takeover the selection text from calling field ("red") */
  315. MUI_XYA("OC", 5, 42, 1) /* takeover the selection text from calling field ("green") */
  316. MUI_XYA("OC", 5, 54, 2) /* */
  317. /* no ok required, clicking on the selection, will jump back */
  318. /* Checkbox demo */
  319. MUI_FORM(13)
  320. MUI_STYLE(1)
  321. MUI_LABEL(5,10, "Checkbox Menu")
  322. MUI_XY("HR", 0,13)
  323. MUI_STYLE(0)
  324. MUI_LABEL(5,30, "Checkbox:")
  325. MUI_XY("CB",60, 30)
  326. MUI_XYAT("G1",64, 59, 0, " OK ")
  327. /* Radio selection demo */
  328. MUI_FORM(14)
  329. MUI_STYLE(1)
  330. MUI_LABEL(5,10, "Radio Selection Menu")
  331. MUI_XY("HR", 0,13)
  332. MUI_STYLE(0)
  333. MUI_XYAT("RS",10, 28,0,"North")
  334. MUI_XYAT("RS",10, 40,1,"South")
  335. MUI_XYAT("RS",65, 28,2,"East")
  336. MUI_XYAT("RS",65, 40,3,"West")
  337. MUI_XYAT("G1",64, 59, 1, " OK ")
  338. /* text demo */
  339. MUI_FORM(15)
  340. MUI_STYLE(1)
  341. MUI_LABEL(5,10, "Enter Text Menu")
  342. MUI_XY("HR", 0,13)
  343. MUI_STYLE(0)
  344. MUI_LABEL(5,30, "Text:")
  345. MUI_STYLE(2)
  346. MUI_XY("T0",40, 30)
  347. MUI_XY("T1",48, 30)
  348. MUI_XY("T2",56, 30)
  349. MUI_XY("T3",64, 30)
  350. MUI_STYLE(0)
  351. MUI_XYAT("G1",64, 59, 1, " OK ")
  352. /* single line selection */
  353. MUI_FORM(16)
  354. MUI_STYLE(1)
  355. MUI_LABEL(5,10, "Single Line Selection")
  356. MUI_XY("HR", 0,13)
  357. MUI_STYLE(0)
  358. MUI_LABEL(5,29, "Fruit [mse]:")
  359. MUI_XYAT("IF",60, 29, 60, "Banana|Apple|Melon|Cranberry")
  360. MUI_LABEL(5,43, "Fruit [mud]:")
  361. MUI_XYAT("IG",60, 43, 60, "Banana|Apple|Melon|Cranberry")
  362. MUI_XYAT("G1",64, 59, 1, " OK ")
  363. /* long list example with list callback functions */
  364. MUI_FORM(17)
  365. MUI_STYLE(1)
  366. MUI_LABEL(5,10, "List Line Selection")
  367. MUI_XY("HR", 0,13)
  368. MUI_STYLE(0)
  369. MUI_LABEL(5,29, "List [mse]:")
  370. MUI_XYA("L1",60, 29, 60)
  371. MUI_LABEL(5,43, "List [mud]:")
  372. MUI_XYA("L2",60, 43, 60)
  373. MUI_XYAT("G1",64, 59, 2, " OK ")
  374. /* parent / child selection */
  375. MUI_FORM(18)
  376. MUI_STYLE(1)
  377. MUI_LABEL(5,10, "Parent/Child List")
  378. MUI_XY("HR", 0,13)
  379. MUI_STYLE(0)
  380. MUI_LABEL(5,29, "Animal:")
  381. MUI_XYA("LP",50, 29, 19) /* jump to sub form 19 */
  382. MUI_XYAT("G1",64, 59, 2, " OK ")
  383. /* combo box color selection */
  384. MUI_FORM(19)
  385. MUI_STYLE(1)
  386. MUI_LABEL(5,10, "Animal Selection")
  387. MUI_XY("HR", 0,13)
  388. MUI_STYLE(0)
  389. MUI_XYA("LC", 5, 30, 0) /* takeover the selection text from calling field ("red") */
  390. MUI_XYA("LC", 5, 42, 1) /* takeover the selection text from calling field ("green") */
  391. MUI_XYA("LC", 5, 54, 2) /* */
  392. /* no ok required, clicking on the selection, will jump back */
  393. MUI_FORM(20)
  394. MUI_STYLE(1)
  395. MUI_LABEL(5,10, "Array Edit")
  396. MUI_XY("HR", 0,13)
  397. MUI_STYLE(0)
  398. MUI_LABEL(5,24, "Position:")
  399. MUI_XY("AP",76, 24)
  400. MUI_LABEL(5,35, "LED off:")
  401. MUI_XY("AF",76, 35)
  402. MUI_LABEL(5,46, "LED on:")
  403. MUI_XY("AN",76, 46)
  404. MUI_XYAT("G1",64, 59, 2, " OK ")
  405. /* combo box Food & Drink Selection, called from form 11 */
  406. MUI_FORM(21)
  407. MUI_STYLE(1)
  408. MUI_LABEL(5,10, "Food & Drink Selection")
  409. MUI_XY("HR", 0,13)
  410. MUI_STYLE(3)
  411. MUI_XYA("OD", 3, 45, 0)
  412. MUI_XYA("OD", 28, 45, 1)
  413. MUI_XYA("OD", 53, 45, 2)
  414. MUI_XYA("OD", 78, 45, 3)
  415. MUI_XYA("OD", 103, 45, 4)
  416. /* minimal example */
  417. MUI_FORM(200)
  418. MUI_STYLE(0)
  419. MUI_XYT("BN",64, 30, " Select Me ")
  420. MUI_FORM(201)
  421. MUI_STYLE(0)
  422. MUI_LABEL(5,12, "Countdown Time")
  423. MUI_LABEL(5,30, "Seconds:")
  424. MUI_XY("IN",60, 30)
  425. MUI_XYT("LV",64, 59, " OK ")
  426. ;
  427. int screenshot_n = 0;
  428. void do_screenshot(void)
  429. {
  430. char s[4096];
  431. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  432. sprintf( s,
  433. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  434. " -fill 'rgb(255,170,0)' -opaque white"
  435. " -filter point -resize 200%%"
  436. " screenshot.tga pic%04d.png", screenshot_n);
  437. system(s);
  438. screenshot_n++;
  439. /*
  440. gif animation:
  441. convert -delay 40 -loop 0 pic*.png animation.gif
  442. */
  443. }
  444. int main(void)
  445. {
  446. int x, y;
  447. int k;
  448. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  449. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  450. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  451. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  452. u8g2_SetFontMode(&u8g2, 1);
  453. mui_Init(&ui, &u8g2, fds, muif_list, sizeof(muif_list)/sizeof(muif_t));
  454. //mui_GotoForm(&ui, 201, 0);
  455. mui_GotoForm(&ui, 0, 0);
  456. //puts(fds);
  457. x = 4; // use as height for the box
  458. y = 0;
  459. for(;;)
  460. {
  461. u8g2_SetFontRefHeightExtendedText(&u8g2);
  462. u8g2_FirstPage(&u8g2);
  463. do
  464. {
  465. mui_Draw(&ui);
  466. } while( u8g2_NextPage(&u8g2) );
  467. do_screenshot();
  468. // printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui));
  469. do
  470. {
  471. k = u8g_sdl_get_key();
  472. } while( k < 0 );
  473. if ( k == 273 ) y -= 1;
  474. if ( k == 274 ) y += 1;
  475. if ( k == 276 ) x -= 1;
  476. if ( k == 275 ) x += 1;
  477. /*
  478. if ( k == 'e' ) y -= 1;
  479. if ( k == 'x' ) y += 1;
  480. if ( k == 's' ) x -= 1;
  481. if ( k == 'd' ) x += 1;
  482. */
  483. if ( k == 'q' ) break;
  484. if ( k == 'n' )
  485. {
  486. mui_NextField(&ui);
  487. }
  488. if ( k == 'p' )
  489. {
  490. mui_PrevField(&ui);
  491. }
  492. if ( k == 's' )
  493. {
  494. mui_SendSelect(&ui);
  495. }
  496. if ( k == 't' )
  497. {
  498. puts("screenshot");
  499. do_screenshot();
  500. }
  501. if ( x < 0 )
  502. x = 0;
  503. }
  504. return 0;
  505. }