guimenu.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /*
  2. guimenu.c
  3. */
  4. #include "gui.h"
  5. #include <string.h>
  6. /*============================================*/
  7. /* global variable for the gui menues */
  8. uint8_t gui_alarm_index = 0;
  9. gui_alarm_t gui_alarm_current;
  10. const char weekdaystr[7][4] = {
  11. "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"
  12. };
  13. /*============================================*/
  14. const static uint8_t ok_xbm[] = { /* 16x16 */
  15. 0xfe, 0x7f, 0x03, 0xc0, 0x01, 0x80, 0x01, 0xb8, 0x01, 0x9c, 0x01, 0x8e,
  16. 0x01, 0x87, 0x01, 0x87, 0x9d, 0x83, 0xb9, 0x83, 0xf1, 0x81, 0xe1, 0x81,
  17. 0xc1, 0x80, 0x01, 0x80, 0x03, 0xc0, 0xfe, 0x7f };
  18. const static uint8_t alarm_xbm[] = { /* 12x12 */
  19. 0x00, 0x00, 0x0c, 0x06, 0xf6, 0x0d, 0x1a, 0x0b, 0x4c, 0x06, 0x44, 0x04,
  20. 0xc4, 0x05, 0x04, 0x04, 0x0c, 0x06, 0x18, 0x03, 0xf0, 0x01, 0x00, 0x00 };
  21. int me_action_to_top_menu(menu_t *menu, const me_t *me, uint8_t msg)
  22. {
  23. if ( msg == ME_MSG_SELECT )
  24. {
  25. menu_SetMEList(menu, melist_top_menu, 0);
  26. return 1;
  27. }
  28. return 0;
  29. }
  30. int me_action_to_setup_menu(menu_t *menu, const me_t *me, uint8_t msg)
  31. {
  32. if ( msg == ME_MSG_SELECT )
  33. {
  34. menu_SetMEList(menu, melist_setup_menu, 0);
  35. return 1;
  36. }
  37. return 0;
  38. }
  39. int me_action_save_time(menu_t *menu, const me_t *me, uint8_t msg)
  40. {
  41. if ( msg == ME_MSG_SELECT )
  42. {
  43. set_time(gui_data.h / 10, gui_data.h % 10, gui_data.mt, gui_data.mo, gui_data.st, gui_data.so);
  44. //menu_SetMEList(menu, melist_top_menu, 0); /* first set the normal menu */
  45. menu_SetMEList(menu, melist_setup_menu, 0);
  46. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  47. return 1;
  48. }
  49. return 0;
  50. }
  51. #ifdef D12832
  52. #define ME_TIME_Y 19
  53. #endif
  54. #ifdef D12864
  55. #define ME_TIME_Y 26
  56. #endif
  57. #ifdef D12832
  58. #define ME_TIME_XO 11
  59. const me_t melist_setup_time[] =
  60. {
  61. { me_cb_0_23, &gui_data.h, NULL, ME_TIME_XO+2,ME_TIME_Y },
  62. { me_cb_num_label, NULL, ":", ME_TIME_XO+30,ME_TIME_Y-3 },
  63. { me_cb_0_5, &gui_data.mt, NULL, ME_TIME_XO+39,ME_TIME_Y },
  64. { me_cb_0_9, &gui_data.mo, NULL, ME_TIME_XO+52,ME_TIME_Y },
  65. { me_cb_num_label, NULL, ":", ME_TIME_XO+67,ME_TIME_Y-3 },
  66. { me_cb_0_5, &gui_data.st, NULL, ME_TIME_XO+67+9,ME_TIME_Y },
  67. { me_cb_0_9, &gui_data.so, NULL, ME_TIME_XO+80+9,ME_TIME_Y },
  68. { me_cb_button_half_line, (void *)me_action_to_setup_menu, "Abbrechen", 0,30 },
  69. { me_cb_button_half_line, (void *)me_action_save_time, "Speichern", 64,30 },
  70. //{ me_cb_button_full_line, (void *)me_action_save_time, "Speichern", 40,30 },
  71. { me_cb_null, NULL, NULL, 0, 0 },
  72. };
  73. #endif
  74. #ifdef D12864
  75. #define ME_TIME_XO 11
  76. const me_t melist_setup_time[] =
  77. {
  78. { me_cb_0_23, &gui_data.h, NULL, 1,ME_TIME_Y },
  79. { me_cb_num_label, NULL, ":", 37,ME_TIME_Y-3 },
  80. { me_cb_0_5, &gui_data.mt, NULL, 45,ME_TIME_Y },
  81. { me_cb_0_9, &gui_data.mo, NULL, 63,ME_TIME_Y },
  82. { me_cb_num_label, NULL, ":", 81,ME_TIME_Y-3 },
  83. { me_cb_0_5, &gui_data.st, NULL, 89,ME_TIME_Y },
  84. { me_cb_0_9, &gui_data.so, NULL, 107,ME_TIME_Y },
  85. { me_cb_button_half_line, (void *)me_action_to_setup_menu, "Abbrechen", 0,42 },
  86. { me_cb_button_half_line, (void *)me_action_save_time, "Speichern", 64,42 },
  87. //{ me_cb_button_full_line, (void *)me_action_save_time, "Speichern", 40,42 },
  88. { me_cb_null, NULL, NULL, 0, 0 },
  89. };
  90. #endif
  91. /*============================================*/
  92. /* Display Time */
  93. void gui_alarm_to_str(uint8_t idx)
  94. {
  95. strcpy(gui_data.s, weekdaystr[gui_alarm_list[gui_data.next_alarm_index].na_wd]);
  96. gui_data.s[2] = ',';
  97. gui_data.s[3] = ' ';
  98. strcpy(gui_data.s+4, u8x8_u8toa(gui_alarm_list[gui_data.next_alarm_index].na_h, 2));
  99. gui_data.s[6] = ':';
  100. strcpy(gui_data.s+7, u8x8_u8toa(gui_alarm_list[gui_data.next_alarm_index].na_m, 2));
  101. if ( gui_alarm_list[gui_data.next_alarm_index].snooze_count != 0 )
  102. {
  103. gui_data.s[9] = '+';
  104. gui_data.s[10] = '\0';
  105. }
  106. else
  107. {
  108. gui_data.s[9] = '\0';
  109. }
  110. }
  111. int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
  112. {
  113. if ( msg == ME_MSG_DRAW )
  114. {
  115. char s[14];
  116. u8g2_uint_t w;
  117. #ifdef D12832
  118. u8g2_uint_t x = 4;
  119. u8g2_uint_t y = 30;
  120. u8g2_SetFont(menu->u8g2, MENU_LARGE_FONT);
  121. if ( gui_data.next_alarm_index < GUI_ALARM_CNT )
  122. {
  123. u8g2_DrawXBM(menu->u8g2, 67, y-11, 12, 12, (const uint8_t *)(alarm_xbm));
  124. gui_alarm_to_str(gui_data.next_alarm_index);
  125. u8g2_DrawUTF8(menu->u8g2, 81, y, gui_data.s);
  126. }
  127. else
  128. {
  129. x= 34;
  130. }
  131. strcpy(s, weekdaystr[gui_data.weekday]);
  132. s[2] = ',';
  133. s[3] = ' ';
  134. strcpy(s+4, u8x8_u8toa(gui_data.day, 2));
  135. s[6] = '.';
  136. strcpy(s+7, u8x8_u8toa(gui_data.month, 2));
  137. s[9] = '.';
  138. s[10] = gui_data.year_t+'0';
  139. s[11] = gui_data.year_o+'0';
  140. s[12] = '\0';
  141. u8g2_DrawUTF8(menu->u8g2, x, y, s);
  142. #endif
  143. #ifdef D12864
  144. u8g2_uint_t x = 27;
  145. u8g2_uint_t y = 61;
  146. u8g2_SetFont(menu->u8g2, MENU_LARGE_FONT);
  147. if ( gui_data.next_alarm_index < GUI_ALARM_CNT )
  148. {
  149. gui_alarm_to_str(gui_data.next_alarm_index);
  150. w = u8g2_GetUTF8Width(menu->u8g2, gui_data.s)+14;
  151. //u8g2_DrawUTF8(menu->u8g2, x+14, y, gui_data.s);
  152. u8g2_DrawXBM(menu->u8g2, (128-w)/2, y-11, 12, 12, (const uint8_t *)(alarm_xbm));
  153. u8g2_DrawUTF8(menu->u8g2, (128-w)/2+14, y, gui_data.s);
  154. }
  155. y -= 17;
  156. x -= 3;
  157. strcpy(s, weekdaystr[gui_data.weekday]);
  158. s[2] = ',';
  159. s[3] = ' ';
  160. strcpy(s+4, u8x8_u8toa(gui_data.day, 2));
  161. s[6] = '.';
  162. strcpy(s+7, u8x8_u8toa(gui_data.month, 2));
  163. s[9] = '.';
  164. s[10] = gui_data.year_t+'0';
  165. s[11] = gui_data.year_o+'0';
  166. s[12] = '\0';
  167. w = u8g2_GetUTF8Width(menu->u8g2, s);
  168. u8g2_DrawUTF8(menu->u8g2, (128-w)/2, y, s);
  169. #endif
  170. return 1;
  171. }
  172. else if ( msg == ME_MSG_SELECT )
  173. {
  174. menu_SetMEList(menu, melist_top_menu, 0);
  175. return 1;
  176. }
  177. return 0;
  178. }
  179. #ifdef D12832
  180. #define ME_TIME_DXO 30
  181. const me_t melist_display_time[] =
  182. {
  183. { me_cb_0_23_ro, &gui_data.h, NULL, ME_TIME_DXO+2,ME_TIME_Y },
  184. { me_cb_num_label, NULL, ":", ME_TIME_DXO+30,ME_TIME_Y-3 },
  185. { me_cb_0_9_ro, &gui_data.mt, NULL, ME_TIME_DXO+39,ME_TIME_Y },
  186. { me_cb_0_9_ro, &gui_data.mo, NULL, ME_TIME_DXO+52,ME_TIME_Y },
  187. { me_cb_0_9_small_ro, &gui_data.st, NULL, 118,ME_TIME_Y },
  188. { me_cb_0_9_small_ro, &gui_data.so, NULL, 123,ME_TIME_Y },
  189. { me_cb_button_empty, (void *)me_action_handle_display_time, NULL, 0, 0 },
  190. { me_cb_null, NULL, NULL, 0, 0 },
  191. };
  192. #endif
  193. #ifdef D12864
  194. #define ME_TIME_DXO 29
  195. const me_t melist_display_time[] =
  196. {
  197. { me_cb_0_23_ro, &gui_data.h, NULL, ME_TIME_DXO-7,ME_TIME_Y },
  198. { me_cb_num_label, NULL, ":", ME_TIME_DXO+30,ME_TIME_Y-3 },
  199. { me_cb_0_9_ro, &gui_data.mt, NULL, ME_TIME_DXO+39,ME_TIME_Y },
  200. { me_cb_0_9_ro, &gui_data.mo, NULL, ME_TIME_DXO+57,ME_TIME_Y },
  201. { me_cb_0_9_small_ro, &gui_data.st, NULL, 118,ME_TIME_Y },
  202. { me_cb_0_9_small_ro, &gui_data.so, NULL, 123,ME_TIME_Y },
  203. { me_cb_button_empty, (void *)me_action_handle_display_time, NULL, 0, 0 },
  204. { me_cb_null, NULL, NULL, 0, 0 },
  205. };
  206. #endif
  207. /*============================================*/
  208. /* Date Edit Dialog */
  209. int me_action_save_date(menu_t *menu, const me_t *me, uint8_t msg)
  210. {
  211. if ( msg == ME_MSG_SELECT )
  212. {
  213. gui_date_adjust(); /* calculate the weekday */
  214. set_date(gui_data.year_t, gui_data.year_o, gui_data.month / 10, gui_data.month % 10, gui_data.day / 10 , gui_data.day % 10, gui_data.weekday);
  215. menu_SetMEList(menu, melist_setup_menu, 0); /* first set the normal menu */
  216. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  217. return 1;
  218. }
  219. return 0;
  220. }
  221. #ifdef D12832
  222. const me_t melist_setup_date[] =
  223. {
  224. { me_cb_1_31, &gui_data.day, NULL, ME_TIME_XO+2,ME_TIME_Y },
  225. { me_cb_num_label, NULL, ".", ME_TIME_XO+30,ME_TIME_Y },
  226. { me_cb_1_12, &gui_data.month, NULL, ME_TIME_XO+39,ME_TIME_Y },
  227. { me_cb_num_label, NULL, ".", ME_TIME_XO+67,ME_TIME_Y },
  228. { me_cb_0_9, &gui_data.year_t, NULL, ME_TIME_XO+67+9,ME_TIME_Y },
  229. { me_cb_0_9, &gui_data.year_o, NULL, ME_TIME_XO+80+9,ME_TIME_Y },
  230. { me_cb_button_full_line, (void *)me_action_save_date, "Speichern", 40,30 },
  231. { me_cb_null, NULL, NULL, 0, 0 },
  232. };
  233. #endif
  234. #ifdef D12864
  235. const me_t melist_setup_date[] =
  236. {
  237. { me_cb_1_31, &gui_data.day, NULL, 1,ME_TIME_Y },
  238. { me_cb_num_label, NULL, ".", 37,ME_TIME_Y },
  239. { me_cb_1_12, &gui_data.month, NULL, 45,ME_TIME_Y },
  240. { me_cb_num_label, NULL, ".", 81,ME_TIME_Y },
  241. { me_cb_0_9, &gui_data.year_t, NULL, 89,ME_TIME_Y },
  242. { me_cb_0_9, &gui_data.year_o, NULL, 107,ME_TIME_Y },
  243. //{ me_cb_button_full_line, (void *)me_action_save_date, "Speichern", 40,42 },
  244. { me_cb_button_half_line, (void *)me_action_to_setup_menu, "Abbrechen", 0,42 },
  245. { me_cb_button_half_line, (void *)me_action_save_date, "Speichern", 64,42 },
  246. { me_cb_null, NULL, NULL, 0, 0 },
  247. };
  248. #endif
  249. /*============================================*/
  250. /* Alarm Edit Dialog */
  251. int me_action_alarm_done(menu_t *menu, const me_t *me, uint8_t msg)
  252. {
  253. if ( msg == ME_MSG_SELECT )
  254. {
  255. gui_alarm_list[gui_alarm_index] = gui_alarm_current;
  256. gui_alarm_list[gui_alarm_index].skip_wd = 0; /* clear the skip alarm (if any) */
  257. gui_alarm_list[gui_alarm_index].snooze_count = 0; /* clear snooze (if any) */
  258. //gui_alarm_calc_str_time(gui_alarm_index);
  259. menu_SetMEList(menu, melist_alarm_menu, gui_alarm_index); /* first set the normal menu */
  260. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  261. return 1;
  262. }
  263. return 0;
  264. }
  265. #ifdef D12832
  266. #define ME_ALARM_TIME_XO 28
  267. #define ME_ALARM_TIME_Y 20
  268. #define ME_ALARM_WD_Y 29
  269. #define ME_ALARM_WD_XO 8
  270. const me_t melist_setup_alarm[] =
  271. {
  272. { me_cb_big_toggle, &(gui_alarm_current.enable), NULL, 4 , 6},
  273. { me_cb_0_23, &(gui_alarm_current.h), NULL, ME_ALARM_TIME_XO+2,ME_ALARM_TIME_Y },
  274. { me_cb_num_label, NULL, ":", ME_ALARM_TIME_XO+30,ME_ALARM_TIME_Y-3 },
  275. { me_cb_0_55, &(gui_alarm_current.m), NULL, ME_ALARM_TIME_XO+39,ME_ALARM_TIME_Y },
  276. { me_cb_wd_toggle, &(gui_alarm_current.wd[0]), (void *)weekdaystr[0], ME_ALARM_WD_XO+17*0, ME_ALARM_WD_Y},
  277. { me_cb_wd_toggle, &(gui_alarm_current.wd[1]), (void *)weekdaystr[1], ME_ALARM_WD_XO+17*1, ME_ALARM_WD_Y},
  278. { me_cb_wd_toggle, &(gui_alarm_current.wd[2]), (void *)weekdaystr[2], ME_ALARM_WD_XO+17*2, ME_ALARM_WD_Y},
  279. { me_cb_wd_toggle, &(gui_alarm_current.wd[3]), (void *)weekdaystr[3], ME_ALARM_WD_XO+17*3, ME_ALARM_WD_Y},
  280. { me_cb_wd_toggle, &(gui_alarm_current.wd[4]), (void *)weekdaystr[4], ME_ALARM_WD_XO+17*4, ME_ALARM_WD_Y},
  281. { me_cb_wd_toggle, &(gui_alarm_current.wd[5]), (void *)weekdaystr[5], ME_ALARM_WD_XO+17*5, ME_ALARM_WD_Y},
  282. { me_cb_wd_toggle, &(gui_alarm_current.wd[6]), (void *)weekdaystr[6], ME_ALARM_WD_XO+17*6, ME_ALARM_WD_Y},
  283. { me_cb_16x16_bitmap_button, (void *)me_action_alarm_done, (void *)ok_xbm, ME_ALARM_TIME_XO+80,ME_ALARM_TIME_Y-17 },
  284. { me_cb_null, NULL, NULL, 0, 0 },
  285. };
  286. #endif
  287. #ifdef D12864
  288. #define ME_ALARM_TIME_XO 28
  289. #define ME_ALARM_TIME_Y 26
  290. #define ME_ALARM_WD_Y 36
  291. #define ME_ALARM_WD_XO 8
  292. const me_t melist_setup_alarm[] =
  293. {
  294. { me_cb_0_23, &(gui_alarm_current.h), NULL, ME_ALARM_TIME_XO-7,ME_ALARM_TIME_Y },
  295. { me_cb_num_label, NULL, ":", ME_ALARM_TIME_XO+30,ME_ALARM_TIME_Y-3 },
  296. { me_cb_0_55, &(gui_alarm_current.m), NULL, ME_ALARM_TIME_XO+39,ME_ALARM_TIME_Y },
  297. { me_cb_wd_toggle, &(gui_alarm_current.wd[0]), (void *)weekdaystr[0], ME_ALARM_WD_XO+17*0, ME_ALARM_WD_Y},
  298. { me_cb_wd_toggle, &(gui_alarm_current.wd[1]), (void *)weekdaystr[1], ME_ALARM_WD_XO+17*1, ME_ALARM_WD_Y},
  299. { me_cb_wd_toggle, &(gui_alarm_current.wd[2]), (void *)weekdaystr[2], ME_ALARM_WD_XO+17*2, ME_ALARM_WD_Y},
  300. { me_cb_wd_toggle, &(gui_alarm_current.wd[3]), (void *)weekdaystr[3], ME_ALARM_WD_XO+17*3, ME_ALARM_WD_Y},
  301. { me_cb_wd_toggle, &(gui_alarm_current.wd[4]), (void *)weekdaystr[4], ME_ALARM_WD_XO+17*4, ME_ALARM_WD_Y},
  302. { me_cb_wd_toggle, &(gui_alarm_current.wd[5]), (void *)weekdaystr[5], ME_ALARM_WD_XO+17*5, ME_ALARM_WD_Y},
  303. { me_cb_wd_toggle, &(gui_alarm_current.wd[6]), (void *)weekdaystr[6], ME_ALARM_WD_XO+17*6, ME_ALARM_WD_Y},
  304. { me_cb_big_toggle, (void *)&(gui_alarm_current.enable), NULL, 28, 47},
  305. { me_cb_16x16_bitmap_button, (void *)me_action_alarm_done, (void *)ok_xbm, 80, 44 },
  306. { me_cb_null, NULL, NULL, 0, 0 },
  307. };
  308. #endif
  309. /*============================================*/
  310. /* Alarm Setup Menu */
  311. static int me_action_alarm_common(menu_t *menu, const me_t *me, uint8_t msg) U8G2_NOINLINE;
  312. static int me_action_alarm_common(menu_t *menu, const me_t *me, uint8_t msg)
  313. {
  314. if ( msg == ME_MSG_SELECT )
  315. {
  316. gui_alarm_current = gui_alarm_list[gui_alarm_index];
  317. menu_SetMEList(menu, melist_setup_alarm, 0);
  318. return 1;
  319. }
  320. return 0;
  321. }
  322. int me_action_alarm1(menu_t *menu, const me_t *me, uint8_t msg)
  323. {
  324. gui_alarm_index = 0;
  325. return me_action_alarm_common(menu, me, msg);
  326. }
  327. int me_action_alarm2(menu_t *menu, const me_t *me, uint8_t msg)
  328. {
  329. gui_alarm_index = 1;
  330. return me_action_alarm_common(menu, me, msg);
  331. }
  332. int me_action_alarm3(menu_t *menu, const me_t *me, uint8_t msg)
  333. {
  334. gui_alarm_index = 2;
  335. return me_action_alarm_common(menu, me, msg);
  336. }
  337. int me_action_alarm4(menu_t *menu, const me_t *me, uint8_t msg)
  338. {
  339. gui_alarm_index = 3;
  340. return me_action_alarm_common(menu, me, msg);
  341. }
  342. int me_action_handle_alarm_list(menu_t *menu, const me_t *me, uint8_t msg)
  343. {
  344. if ( msg == ME_MSG_DRAW )
  345. {
  346. uint8_t y, x;
  347. uint8_t ym;
  348. u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT);
  349. for( y = 0; y < 4; y++ )
  350. {
  351. ym = y*8+7;
  352. for( x = 0; x < 7; x++ )
  353. {
  354. u8g2_DrawGlyph(menu->u8g2, 0, ym, y+'1');
  355. u8g2_DrawGlyph(menu->u8g2, 5, ym, ':');
  356. u8g2_DrawStr(menu->u8g2, 9, ym, gui_alarm_str[y]);
  357. if ( gui_alarm_list[y].wd[x] )
  358. {
  359. u8g2_DrawStr(menu->u8g2, 40+x*12, ym, weekdaystr[x]);
  360. }
  361. }
  362. }
  363. }
  364. else if ( msg == ME_MSG_SELECT )
  365. {
  366. menu_SetMEList(menu, melist_alarm_menu, 4);
  367. return 1;
  368. }
  369. return 0;
  370. }
  371. const me_t melist_alarm_list_menu[] =
  372. {
  373. { me_cb_button_empty, (void *)me_action_handle_alarm_list, NULL, 0, 0 },
  374. { me_cb_null, NULL, NULL, 0, 0 },
  375. };
  376. int me_action_goto_alarm_list(menu_t *menu, const me_t *me, uint8_t msg)
  377. {
  378. if ( msg == ME_MSG_SELECT )
  379. {
  380. menu_SetMEList(menu, melist_alarm_list_menu, 0);
  381. return 1;
  382. }
  383. return 0;
  384. }
  385. #ifdef D12832
  386. const me_t melist_alarm_menu[] =
  387. {
  388. { me_cb_button_half_line, (void *)me_action_alarm1, gui_alarm_str[0], 0,10 },
  389. { me_cb_button_half_line, (void *)me_action_alarm2, gui_alarm_str[1], 64,10 },
  390. { me_cb_button_half_line, (void *)me_action_alarm3, gui_alarm_str[2], 0,20 },
  391. { me_cb_button_half_line, (void *)me_action_alarm4, gui_alarm_str[3], 64,20 },
  392. { me_cb_button_half_line, (void *)me_action_goto_alarm_list, "Liste", 0,30 },
  393. { me_cb_button_half_line, (void *)me_action_to_top_menu, "Zurück", 64,30 },
  394. { me_cb_null, NULL, NULL, 0, 0 },
  395. };
  396. #endif
  397. #ifdef D12864
  398. const me_t melist_alarm_menu[] =
  399. {
  400. { me_cb_button_half_line, (void *)me_action_alarm1, gui_alarm_str[0], 0,12 },
  401. { me_cb_button_half_line, (void *)me_action_alarm2, gui_alarm_str[1], 64,12 },
  402. { me_cb_button_half_line, (void *)me_action_alarm3, gui_alarm_str[2], 0,24 },
  403. { me_cb_button_half_line, (void *)me_action_alarm4, gui_alarm_str[3], 64,24 },
  404. { me_cb_button_half_line, (void *)me_action_goto_alarm_list, "Liste", 0,36 },
  405. { me_cb_button_half_line, (void *)me_action_to_top_menu, "Zurück", 64,36 },
  406. { me_cb_null, NULL, NULL, 0, 0 },
  407. };
  408. #endif
  409. /*============================================*/
  410. /* Reset Menu */
  411. int me_action_reset_no(menu_t *menu, const me_t *me, uint8_t msg)
  412. {
  413. if ( msg == ME_MSG_SELECT )
  414. {
  415. menu_SetMEList(menu, melist_setup_menu, 0);
  416. return 1;
  417. }
  418. return 0;
  419. }
  420. int me_action_reset_yes(menu_t *menu, const me_t *me, uint8_t msg)
  421. {
  422. if ( msg == ME_MSG_SELECT )
  423. {
  424. do_reset();
  425. return 1;
  426. }
  427. return 0;
  428. }
  429. const me_t melist_reset_menu[] =
  430. {
  431. { me_cb_label, NULL, "Reset?", 44, 13},
  432. { me_cb_button_half_line, (void *)me_action_reset_no, "Nein", 0,30 },
  433. { me_cb_button_half_line, (void *)me_action_reset_yes, "Ja", 64,30 },
  434. { me_cb_null, NULL, NULL, 0, 0 },
  435. };
  436. /*============================================*/
  437. /* Boot Info */
  438. const char *bitstr(uint32_t v, int bitcnt)
  439. {
  440. static char s[34];
  441. char *t = s;
  442. uint32_t mask;
  443. mask = 1<<(bitcnt-1);
  444. while( mask > 0 )
  445. {
  446. *t = ((v & mask) == 0 ? '0' : '1');
  447. t++;
  448. mask >>= 1;
  449. }
  450. *t = '\0';
  451. return s;
  452. }
  453. static const char *reset_reason_str[] = { "POR", "NVIC", "T2", "T3", "WUF" };
  454. int me_action_handle_boot_info(menu_t *menu, const me_t *me, uint8_t msg)
  455. {
  456. if ( msg == ME_MSG_DRAW )
  457. {
  458. u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT);
  459. u8g2_DrawStr(menu->u8g2, 0, 8-1, "RCC_CSR 31..24");
  460. u8g2_DrawStr(menu->u8g2, 64, 8-1, bitstr(get_boot_status_register(), 8));
  461. u8g2_DrawStr(menu->u8g2, 0, 16-1, "PWR_CSR 7..0");
  462. u8g2_DrawStr(menu->u8g2, 64, 16-1, bitstr(get_pwr_status_register(), 8));
  463. u8g2_DrawStr(menu->u8g2, 0, 24-1, "ResetReason");
  464. u8g2_DrawStr(menu->u8g2, 64, 24-1, reset_reason_str[get_reset_reason()]);
  465. u8g2_DrawStr(menu->u8g2, 0, 32-1, "Uptime");
  466. u8g2_DrawStr(menu->u8g2, 64, 32-1, u8x8_u16toa(gui_data.uptime, 3));
  467. u8g2_DrawStr(menu->u8g2, 0, 40-1, "Wakeups");
  468. u8g2_DrawStr(menu->u8g2, 64, 40-1, u8x8_u16toa(get_wakeup_count(), 5));
  469. u8g2_DrawStr(menu->u8g2, 0, 48-1, "DST by Date:");
  470. u8g2_DrawStr(menu->u8g2, 50, 48-1, u8x8_u16toa(get_dst_by_date(), 2));
  471. u8g2_DrawStr(menu->u8g2, 64, 48-1, "by RTC:");
  472. u8g2_DrawStr(menu->u8g2, 95, 48-1, u8x8_u16toa(get_dst_by_RTC(), 1));
  473. }
  474. else if ( msg == ME_MSG_SELECT )
  475. {
  476. menu_SetMEList(menu, melist_display_time, 4);
  477. return 1;
  478. }
  479. return 0;
  480. }
  481. const me_t melist_boot_info_menu[] =
  482. {
  483. { me_cb_button_empty, (void *)me_action_handle_boot_info, NULL, 0, 0 },
  484. { me_cb_null, NULL, NULL, 0, 0 },
  485. };
  486. /*============================================*/
  487. /* System Menu */
  488. const me_t melist_system_menu[] =
  489. {
  490. { me_cb_label, NULL, "Helligkeit:", 0, 10},
  491. { me_cb_scale_1_7, &(gui_data.contrast), NULL, 103-10, 8},
  492. { me_cb_label, NULL, "Batteriespannung:", 0, 10+12},
  493. { me_cb_big_toggle, &(gui_data.display_voltage), NULL, 100-7, 10+12-8},
  494. { me_cb_button_full_line, (void *)me_action_to_setup_menu, "Speichern", 40,10+2*12 },
  495. { me_cb_null, NULL, NULL, 0, 0 },
  496. };
  497. /*============================================*/
  498. /* System 2 Menu */
  499. int me_action_goto_boot_info(menu_t *menu, const me_t *me, uint8_t msg)
  500. {
  501. if ( msg == ME_MSG_SELECT )
  502. {
  503. menu_SetMEList(menu, melist_boot_info_menu, 0);
  504. return 1;
  505. }
  506. return 0;
  507. }
  508. int me_action_goto_reset(menu_t *menu, const me_t *me, uint8_t msg)
  509. {
  510. if ( msg == ME_MSG_SELECT )
  511. {
  512. menu_SetMEList(menu, melist_reset_menu, 0);
  513. return 1;
  514. }
  515. return 0;
  516. }
  517. const me_t melist_system_2_menu[] =
  518. {
  519. //{ me_cb_button_half_line, (void *)me_action_setup_time, "Uhrzeit", 0,10 },
  520. //{ me_cb_button_half_line, (void *)me_action_setup_date, "Datum", 64,10 },
  521. { me_cb_button_half_line, (void *)me_action_goto_boot_info, "Info", 0,20 },
  522. { me_cb_button_half_line, (void *)me_action_goto_reset, "Reset", 64,20 },
  523. { me_cb_button_full_line, (void *)me_action_to_setup_menu, "Zurück", 40,30 },
  524. { me_cb_null, NULL, NULL, 0, 0 },
  525. };
  526. /*============================================*/
  527. /* Setup Menu */
  528. int me_action_setup_time(menu_t *menu, const me_t *me, uint8_t msg)
  529. {
  530. if ( msg == ME_MSG_SELECT )
  531. {
  532. menu_SetMEList(menu, melist_setup_time, 0);
  533. return 1;
  534. }
  535. return 0;
  536. }
  537. int me_action_setup_date(menu_t *menu, const me_t *me, uint8_t msg)
  538. {
  539. if ( msg == ME_MSG_SELECT )
  540. {
  541. menu_SetMEList(menu, melist_setup_date, 0);
  542. return 1;
  543. }
  544. return 0;
  545. }
  546. int me_action_goto_system(menu_t *menu, const me_t *me, uint8_t msg)
  547. {
  548. if ( msg == ME_MSG_SELECT )
  549. {
  550. menu_SetMEList(menu, melist_system_menu, 0);
  551. return 1;
  552. }
  553. return 0;
  554. }
  555. int me_action_goto_system_2(menu_t *menu, const me_t *me, uint8_t msg)
  556. {
  557. if ( msg == ME_MSG_SELECT )
  558. {
  559. //menu_SetMEList(menu, melist_reset_menu, 0);
  560. menu_SetMEList(menu, melist_system_2_menu, 0);
  561. return 1;
  562. }
  563. return 0;
  564. }
  565. const me_t melist_setup_menu[] =
  566. {
  567. { me_cb_button_half_line, (void *)me_action_setup_time, "Uhrzeit", 0,10 },
  568. { me_cb_button_half_line, (void *)me_action_setup_date, "Datum", 64,10 },
  569. { me_cb_button_half_line, (void *)me_action_goto_system, "Anzeige", 0,20 },
  570. { me_cb_button_half_line, (void *)me_action_goto_system_2, "System", 64,20 },
  571. { me_cb_button_full_line, (void *)me_action_to_top_menu, "Zurück", 40,31 },
  572. { me_cb_null, NULL, NULL, 0, 0 },
  573. };
  574. /*============================================*/
  575. /* Alarm Menu */
  576. int me_action_deactivate_alarm(menu_t *menu, const me_t *me, uint8_t msg)
  577. {
  578. if ( msg == ME_MSG_SELECT )
  579. {
  580. menu_SetMEList(menu, melist_display_time, 0);
  581. return 1;
  582. }
  583. return 0;
  584. }
  585. int me_action_do_snooze(menu_t *menu, const me_t *me, uint8_t msg)
  586. {
  587. if ( msg == ME_MSG_SELECT )
  588. {
  589. menu_SetMEList(menu, melist_display_time, 0);
  590. return 1;
  591. }
  592. return 0;
  593. }
  594. int me_cb_cond_inv_label(menu_t *menu, const me_t *me, uint8_t msg)
  595. {
  596. if ( gui_data.is_alarm == 0 )
  597. return me_cb_inv_label(menu, me, msg);
  598. if ( gui_alarm_list[gui_data.active_alarm_idx].snooze_count == 0 )
  599. return me_cb_inv_label(menu, me, msg);
  600. return 0;
  601. }
  602. #ifdef D12832
  603. const me_t melist_active_alarm_menu[] =
  604. {
  605. { me_cb_label, NULL, "Alarm", 2, 13},
  606. { me_cb_0_23_ro, &gui_data.h, NULL, ME_TIME_DXO+2+20,ME_TIME_Y },
  607. { me_cb_num_label, NULL, ":", ME_TIME_DXO+30+20,ME_TIME_Y-3 },
  608. { me_cb_0_9_ro, &gui_data.mt, NULL, ME_TIME_DXO+39+20,ME_TIME_Y },
  609. { me_cb_0_9_ro, &gui_data.mo, NULL, ME_TIME_DXO+52+20,ME_TIME_Y },
  610. { me_cb_button_empty, (void *)me_action_deactivate_alarm, NULL, 0,0 },
  611. //{ me_cb_button_half_line, (void *)me_action_deactivate_alarm, "Alarm aus", 0,30 },
  612. //{ me_cb_button_half_line, (void *)me_action_do_snooze, "+5 Min ", 64,30 },
  613. { me_cb_inv_label, NULL, "Alarm aus", 4,30 },
  614. { me_cb_cond_inv_label, NULL, "+5 Min", 76,30 },
  615. { me_cb_null, NULL, NULL, 0, 0 },
  616. };
  617. #endif
  618. #ifdef D12864
  619. const me_t melist_active_alarm_menu[] =
  620. {
  621. { me_cb_label, NULL, "Alarm", 2, 13},
  622. { me_cb_0_23_ro, &gui_data.h, NULL, ME_TIME_DXO+2+12,ME_TIME_Y },
  623. { me_cb_num_label, NULL, ":", ME_TIME_DXO+30+20,ME_TIME_Y-3 },
  624. { me_cb_0_9_ro, &gui_data.mt, NULL, ME_TIME_DXO+39+19,ME_TIME_Y },
  625. { me_cb_0_9_ro, &gui_data.mo, NULL, ME_TIME_DXO+52+24,ME_TIME_Y },
  626. { me_cb_button_empty, (void *)me_action_deactivate_alarm, NULL, 0,0 },
  627. //{ me_cb_button_half_line, (void *)me_action_deactivate_alarm, "Alarm aus", 0,30 },
  628. //{ me_cb_button_half_line, (void *)me_action_do_snooze, "+5 Min ", 64,30 },
  629. { me_cb_inv_label, NULL, "Alarm aus", 4,40 },
  630. { me_cb_cond_inv_label, NULL, "+5 Min", 76,40 },
  631. { me_cb_null, NULL, NULL, 0, 0 },
  632. };
  633. #endif
  634. /*============================================*/
  635. /* toplevel menu */
  636. int me_action_to_display_time(menu_t *menu, const me_t *me, uint8_t msg)
  637. {
  638. if ( msg == ME_MSG_SELECT )
  639. {
  640. menu_SetMEList(menu, melist_display_time, 0);
  641. return 1;
  642. }
  643. return 0;
  644. }
  645. int me_action_to_alarm_menu(menu_t *menu, const me_t *me, uint8_t msg)
  646. {
  647. if ( msg == ME_MSG_SELECT )
  648. {
  649. menu_SetMEList(menu, melist_alarm_menu, 0);
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int me_cb_button_skip_alarm(menu_t *menu, const me_t *me, uint8_t msg)
  655. {
  656. int r = 0;
  657. u8g2_uint_t x;
  658. switch(msg)
  659. {
  660. case ME_MSG_IS_FOCUS:
  661. return gui_data.is_skip_possible;
  662. case ME_MSG_DRAW_FOCUS:
  663. u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT);
  664. menu_DrawBoxFocus(menu,
  665. 0,
  666. me->y - u8g2_GetAscent(menu->u8g2)-1,
  667. u8g2_GetDisplayWidth(menu->u8g2) ,
  668. u8g2_GetAscent(menu->u8g2) - u8g2_GetDescent(menu->u8g2) +1);
  669. r = 1;
  670. break;
  671. case ME_MSG_DRAW:
  672. if ( gui_data.is_skip_possible )
  673. {
  674. u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT);
  675. gui_alarm_to_str(gui_data.next_alarm_index);
  676. x = u8g2_DrawUTF8(menu->u8g2, me->x, me->y, gui_data.s );
  677. u8g2_DrawUTF8(menu->u8g2, me->x+x, me->y, " deaktvieren" );
  678. }
  679. r = 1;
  680. break;
  681. case ME_MSG_SELECT:
  682. //printf("me_cb_button_skip_alarm ME_MSG_SELECT\n");
  683. gui_alarm_list[gui_data.next_alarm_index].skip_wd =
  684. gui_alarm_list[gui_data.next_alarm_index].na_wd + 1;
  685. gui_alarm_list[gui_data.next_alarm_index].snooze_count = 0; /* clear snooze (if any) */
  686. menu_SetMEList(menu, melist_display_time, 0); /* first set the normal menu */
  687. gui_Recalculate(); /* it might be changed here to the alarm menu */
  688. r = 1;
  689. break;
  690. }
  691. return r;
  692. }
  693. #ifdef D12832
  694. const me_t melist_top_menu[] =
  695. {
  696. { me_cb_button_half_line, (void *)me_action_to_display_time, "Zurück", 0,10 },
  697. { me_cb_button_half_line, (void *)me_action_to_alarm_menu, "Alarm", 64,10 },
  698. { me_cb_button_skip_alarm, NULL, NULL, 3,20 },
  699. { me_cb_button_full_line, (void *)me_action_to_setup_menu, "Weitere Funktionen", 3,30 },
  700. { me_cb_null, NULL, NULL, 0, 0 },
  701. };
  702. #endif
  703. #ifdef D12864
  704. const me_t melist_top_menu[] =
  705. {
  706. { me_cb_button_full_line, (void *)me_action_to_display_time, "Zurück", 3,12 },
  707. { me_cb_button_full_line, (void *)me_action_to_alarm_menu, "Alarm", 3,24 },
  708. { me_cb_button_skip_alarm, NULL, NULL, 3,36 },
  709. { me_cb_button_full_line, (void *)me_action_to_setup_menu, "Weitere Funktionen", 3,48 },
  710. { me_cb_null, NULL, NULL, 0, 0 },
  711. };
  712. #endif