gui.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. gui.c
  3. */
  4. #include "gui.h"
  5. #include "datecalc.h"
  6. #include <string.h>
  7. /*============================================*/
  8. extern const me_t melist_display_time[];
  9. extern const me_t melist_top_menu[];
  10. extern const me_t melist_active_alarm_menu[];
  11. extern const me_t melist_setup_menu[];
  12. extern const me_t melist_alarm_menu[];
  13. /*============================================*/
  14. uint8_t gui_alarm_index = 0;
  15. gui_alarm_t gui_alarm_current;
  16. gui_alarm_t gui_alarm_list[GUI_ALARM_CNT];
  17. char gui_alarm_str[GUI_ALARM_CNT][8];
  18. const char weekdaystr[7][4] = {
  19. "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"
  20. };
  21. gui_data_t gui_data;
  22. menu_t gui_menu;
  23. /*============================================*/
  24. void gui_alarm_calc_next_wd_alarm(uint8_t idx, uint16_t current_week_time_in_minutes)
  25. {
  26. uint8_t i;
  27. uint16_t week_time_abs;
  28. uint16_t week_time_diff; /* difference to current_week_time_in_minutes */
  29. uint16_t best_diff = 0x0ffff;
  30. gui_alarm_list[idx].na_week_time_in_minutes = 0x0ffff; /* not found */
  31. gui_alarm_list[idx].na_minutes_diff = 0x0ffff; /* not found */
  32. gui_alarm_list[idx].na_wd = 7; /* not found */
  33. //printf("gui_alarm_calc_next_wd_alarm: %d\n", idx);
  34. if ( gui_alarm_list[idx].enable != 0 )
  35. {
  36. //printf("gui_alarm_calc_next_wd_alarm: %d enabled\n", idx);
  37. for( i = 0; i < 7; i++ )
  38. {
  39. if ( gui_alarm_list[idx].wd[i] != 0 )
  40. {
  41. //printf("gui_alarm_calc_next_wd_alarm: %d i=%d gui_alarm_list[idx].skip_wd=%d \n", idx, i, gui_alarm_list[idx].skip_wd);
  42. if ( gui_alarm_list[idx].skip_wd != i+1 )
  43. {
  44. week_time_abs = i;
  45. week_time_abs *= 24;
  46. week_time_abs += gui_alarm_list[idx].h;
  47. week_time_abs *= 60;
  48. week_time_abs += gui_alarm_list[idx].m;
  49. week_time_abs += gui_alarm_list[idx].snooze_count*(uint16_t)SNOOZE_MINUTES;
  50. if ( current_week_time_in_minutes <= week_time_abs )
  51. week_time_diff = week_time_abs - current_week_time_in_minutes;
  52. else
  53. week_time_diff = week_time_abs + 7*24*60 - current_week_time_in_minutes;
  54. //printf("gui_alarm_calc_next_wd_alarm: %d week_time_abs=%d current_week_time_in_minutes=%d week_time_diff=%d\n", idx, week_time_abs, current_week_time_in_minutes,week_time_diff);
  55. if ( best_diff > week_time_diff )
  56. {
  57. best_diff = week_time_diff;
  58. /* found for this alarm */
  59. gui_alarm_list[idx].na_minutes_diff = week_time_diff;
  60. gui_alarm_list[idx].na_week_time_in_minutes = week_time_abs;
  61. gui_alarm_list[idx].na_h = gui_alarm_list[idx].h;
  62. gui_alarm_list[idx].na_m = gui_alarm_list[idx].m;
  63. gui_alarm_list[idx].na_wd = i;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. //printf("gui_alarm_calc_next_wd_alarm: %d na_minutes_diff=%d\n", idx, gui_alarm_list[idx].na_minutes_diff);
  70. //printf("gui_alarm_calc_next_wd_alarm: %d na_wd=%d\n", idx, gui_alarm_list[idx].na_wd);
  71. }
  72. void gui_alarm_calc_str_time(uint8_t idx) U8G2_NOINLINE;
  73. void gui_alarm_calc_str_time(uint8_t idx)
  74. {
  75. gui_alarm_str[idx][0] = ' ';
  76. strcpy(gui_alarm_str[idx]+1, u8x8_u8toa(gui_alarm_list[idx].h, 2));
  77. strcpy(gui_alarm_str[idx]+4, u8x8_u8toa(gui_alarm_list[idx].m, 2));
  78. gui_alarm_str[idx][3] = ':';
  79. if ( gui_alarm_list[idx].enable == 0 )
  80. {
  81. gui_alarm_str[idx][0] = '(';
  82. gui_alarm_str[idx][6] = ')';
  83. gui_alarm_str[idx][7] = '\0';
  84. }
  85. }
  86. /* adjust day/month and calculates the weekday */
  87. void gui_date_adjust(void) U8G2_NOINLINE;
  88. void gui_date_adjust(void)
  89. {
  90. uint16_t ydn;
  91. //uint16_t cdn;
  92. uint16_t year;
  93. if ( gui_data.month == 0 )
  94. gui_data.month++;
  95. if ( gui_data.day == 0 )
  96. gui_data.day++;
  97. year = 2000+gui_data.year_t*10 + gui_data.year_o;
  98. ydn = get_year_day_number(year, gui_data.month, gui_data.day);
  99. gui_data.month = get_month_by_year_day_number(year, ydn);
  100. gui_data.day = get_day_by_year_day_number(year, ydn);
  101. gui_data.weekday = get_weekday_by_year_day_number(year, ydn); /* 0 = Sunday */
  102. /* adjust the weekday so that 0 will be Monday */
  103. gui_data.weekday += 6;
  104. if ( gui_data.weekday >= 7 )
  105. gui_data.weekday -= 7;
  106. //cdn = to_century_day_number(y, ydn);
  107. //to_minutes(cdn, h, m);
  108. }
  109. /*
  110. calculate the minute within the week.
  111. this must be called after gui_date_adjust(), because the weekday is used here
  112. */
  113. void gui_calc_week_time(void)
  114. {
  115. gui_data.week_time = gui_data.weekday;
  116. gui_data.week_time *= 24;
  117. gui_data.week_time += gui_data.h;
  118. gui_data.week_time *= 60;
  119. gui_data.week_time += gui_data.mt * 10 + gui_data.mo;
  120. }
  121. /*
  122. calculate the next alarm.
  123. this must be called after gui_calc_week_time() because, we need week_time
  124. */
  125. void gui_calc_next_alarm(void)
  126. {
  127. uint8_t i;
  128. uint8_t lowest_i;
  129. uint16_t lowest_diff;
  130. /* step 1: Calculate the difference to current weektime for each alarm */
  131. /* result is stored in gui_alarm_list[i].na_minutes_diff */
  132. for( i = 0; i < GUI_ALARM_CNT; i++ )
  133. gui_alarm_calc_next_wd_alarm(i, gui_data.week_time);
  134. /* step 2: find the index with the lowest difference */
  135. lowest_diff = 0x0ffff;
  136. lowest_i = GUI_ALARM_CNT;
  137. for( i = 0; i < GUI_ALARM_CNT; i++ )
  138. {
  139. if ( lowest_diff > gui_alarm_list[i].na_minutes_diff )
  140. {
  141. lowest_diff = gui_alarm_list[i].na_minutes_diff;
  142. lowest_i = i;
  143. }
  144. }
  145. /* step 3: store the result */
  146. gui_data.next_alarm_index = lowest_i; /* this can be GUI_ALARM_CNT */
  147. //printf("gui_calc_next_alarm gui_data.next_alarm_index=%d\n", gui_data.next_alarm_index);
  148. /* calculate the is_skip_possible and the is_alarm flag */
  149. gui_data.is_skip_possible = 0;
  150. if ( lowest_i < GUI_ALARM_CNT )
  151. {
  152. if ( gui_alarm_list[lowest_i].na_minutes_diff <= 1 )
  153. {
  154. if ( gui_data.is_alarm == 0 )
  155. {
  156. gui_data.is_alarm = 1;
  157. gui_data.active_alarm_idx = lowest_i;
  158. menu_SetMEList(&gui_menu, melist_active_alarm_menu, 0);
  159. }
  160. }
  161. else
  162. {
  163. /* valid next alarm time */
  164. if ( gui_alarm_list[lowest_i].skip_wd == 0 )
  165. {
  166. /* skip flag not yet set */
  167. if ( gui_alarm_list[lowest_i].na_minutes_diff <= (uint16_t)60*(uint16_t)ALLOW_SKIP_HOURS )
  168. {
  169. /* within the limit before alarm */
  170. gui_data.is_skip_possible = 1;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. /* recalculate all internal data */
  177. /* additionally the active alarm menu might be set by this function */
  178. void gui_Recalculate(void)
  179. {
  180. int i;
  181. gui_date_adjust();
  182. gui_calc_week_time();
  183. gui_calc_next_alarm();
  184. for ( i = 0; i < GUI_ALARM_CNT; i++ )
  185. {
  186. gui_alarm_calc_str_time(i);
  187. }
  188. }
  189. void gui_Init(u8g2_t *u8g2)
  190. {
  191. menu_Init(&gui_menu, u8g2);
  192. menu_SetMEList(&gui_menu, melist_display_time, 0);
  193. gui_Recalculate();
  194. }
  195. void gui_Draw(void)
  196. {
  197. menu_Draw(&gui_menu);
  198. }
  199. void gui_Next(void)
  200. {
  201. menu_NextFocus(&gui_menu);
  202. }
  203. void gui_Select(void)
  204. {
  205. menu_Select(&gui_menu);
  206. }
  207. /*============================================*/
  208. const static uint8_t ok_xbm[] = { /* 16x16 */
  209. 0xfe, 0x7f, 0x03, 0xc0, 0x01, 0x80, 0x01, 0xb8, 0x01, 0x9c, 0x01, 0x8e,
  210. 0x01, 0x87, 0x01, 0x87, 0x9d, 0x83, 0xb9, 0x83, 0xf1, 0x81, 0xe1, 0x81,
  211. 0xc1, 0x80, 0x01, 0x80, 0x03, 0xc0, 0xfe, 0x7f };
  212. const static uint8_t alarm_xbm[] = { /* 12x12 */
  213. 0x00, 0x00, 0x0c, 0x06, 0xf6, 0x0d, 0x1a, 0x0b, 0x4c, 0x06, 0x44, 0x04,
  214. 0xc4, 0x05, 0x04, 0x04, 0x0c, 0x06, 0x18, 0x03, 0xf0, 0x01, 0x00, 0x00 };
  215. int me_action_to_top_menu(menu_t *menu, const me_t *me, uint8_t msg)
  216. {
  217. if ( msg == ME_MSG_SELECT )
  218. {
  219. menu_SetMEList(menu, melist_top_menu, 0);
  220. return 1;
  221. }
  222. return 0;
  223. }
  224. int me_action_save_time(menu_t *menu, const me_t *me, uint8_t msg)
  225. {
  226. if ( msg == ME_MSG_SELECT )
  227. {
  228. menu_SetMEList(menu, melist_top_menu, 0); /* first set the normal menu */
  229. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  230. return 1;
  231. }
  232. return 0;
  233. }
  234. #define ME_TIME_Y 19
  235. #define ME_TIME_XO 11
  236. const me_t melist_setup_time[] =
  237. {
  238. { me_cb_0_23, &gui_data.h, NULL, ME_TIME_XO+2,ME_TIME_Y },
  239. { me_cb_num_label, NULL, ":", ME_TIME_XO+30,ME_TIME_Y-3 },
  240. { me_cb_0_5, &gui_data.mt, NULL, ME_TIME_XO+39,ME_TIME_Y },
  241. { me_cb_0_9, &gui_data.mo, NULL, ME_TIME_XO+52,ME_TIME_Y },
  242. { me_cb_num_label, NULL, ":", ME_TIME_XO+67,ME_TIME_Y-3 },
  243. { me_cb_0_5, &gui_data.st, NULL, ME_TIME_XO+67+9,ME_TIME_Y },
  244. { me_cb_0_9, &gui_data.so, NULL, ME_TIME_XO+80+9,ME_TIME_Y },
  245. { me_cb_button_full_line, (void *)me_action_save_time, "Speichern", 40,30 },
  246. { me_cb_null, NULL, NULL, 0, 0 },
  247. };
  248. /*============================================*/
  249. /* Display Time */
  250. void gui_alarm_to_str(uint8_t idx)
  251. {
  252. strcpy(gui_data.s, weekdaystr[gui_alarm_list[gui_data.next_alarm_index].na_wd]);
  253. gui_data.s[2] = ',';
  254. gui_data.s[3] = ' ';
  255. strcpy(gui_data.s+4, u8x8_u8toa(gui_alarm_list[gui_data.next_alarm_index].na_h, 2));
  256. gui_data.s[6] = ':';
  257. strcpy(gui_data.s+7, u8x8_u8toa(gui_alarm_list[gui_data.next_alarm_index].na_m, 2));
  258. gui_data.s[9] = '\0';
  259. }
  260. int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
  261. {
  262. if ( msg == ME_MSG_DRAW )
  263. {
  264. char s[14];
  265. u8g2_uint_t x = 4;
  266. u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT);
  267. if ( gui_data.next_alarm_index < GUI_ALARM_CNT )
  268. {
  269. u8g2_DrawXBM(menu->u8g2, 67, 20, 12, 12, (const uint8_t *)(alarm_xbm));
  270. gui_alarm_to_str(gui_data.next_alarm_index);
  271. u8g2_DrawUTF8(menu->u8g2, 81, 30, gui_data.s);
  272. }
  273. else
  274. {
  275. x= 34;
  276. }
  277. strcpy(s, weekdaystr[gui_data.weekday]);
  278. s[2] = ',';
  279. s[3] = ' ';
  280. strcpy(s+4, u8x8_u8toa(gui_data.day, 2));
  281. s[6] = '.';
  282. strcpy(s+7, u8x8_u8toa(gui_data.month, 2));
  283. s[9] = '.';
  284. s[10] = gui_data.year_t+'0';
  285. s[11] = gui_data.year_o+'0';
  286. s[12] = '\0';
  287. u8g2_DrawUTF8(menu->u8g2, x, 30, s);
  288. return 1;
  289. }
  290. else if ( msg == ME_MSG_SELECT )
  291. {
  292. menu_SetMEList(menu, melist_top_menu, 0);
  293. return 1;
  294. }
  295. return 0;
  296. }
  297. #define ME_TIME_DXO 30
  298. const me_t melist_display_time[] =
  299. {
  300. { me_cb_0_23_ro, &gui_data.h, NULL, ME_TIME_DXO+2,ME_TIME_Y },
  301. { me_cb_num_label, NULL, ":", ME_TIME_DXO+30,ME_TIME_Y-3 },
  302. { me_cb_0_9_ro, &gui_data.mt, NULL, ME_TIME_DXO+39,ME_TIME_Y },
  303. { me_cb_0_9_ro, &gui_data.mo, NULL, ME_TIME_DXO+52,ME_TIME_Y },
  304. { me_cb_button_empty, (void *)me_action_handle_display_time, NULL, 0, 0 },
  305. { me_cb_null, NULL, NULL, 0, 0 },
  306. };
  307. /*============================================*/
  308. /* Date Edit Dialog */
  309. int me_action_save_date(menu_t *menu, const me_t *me, uint8_t msg)
  310. {
  311. if ( msg == ME_MSG_SELECT )
  312. {
  313. menu_SetMEList(menu, melist_top_menu, 0); /* first set the normal menu */
  314. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  315. return 1;
  316. }
  317. return 0;
  318. }
  319. const me_t melist_setup_date[] =
  320. {
  321. { me_cb_1_31, &gui_data.day, NULL, ME_TIME_XO+2,ME_TIME_Y },
  322. { me_cb_num_label, NULL, ".", ME_TIME_XO+30,ME_TIME_Y },
  323. { me_cb_1_12, &gui_data.month, NULL, ME_TIME_XO+39,ME_TIME_Y },
  324. { me_cb_num_label, NULL, ".", ME_TIME_XO+67,ME_TIME_Y },
  325. { me_cb_0_9, &gui_data.year_t, NULL, ME_TIME_XO+67+9,ME_TIME_Y },
  326. { me_cb_0_9, &gui_data.year_o, NULL, ME_TIME_XO+80+9,ME_TIME_Y },
  327. { me_cb_button_full_line, (void *)me_action_save_date, "Speichern", 40,30 },
  328. { me_cb_null, NULL, NULL, 0, 0 },
  329. };
  330. /*============================================*/
  331. /* Alarm Edit Dialog */
  332. #define ME_ALARM_TIME_XO 28
  333. #define ME_ALARM_TIME_Y 20
  334. #define ME_ALARM_WD_Y 29
  335. #define ME_ALARM_WD_XO 8
  336. int me_action_alarm_done(menu_t *menu, const me_t *me, uint8_t msg)
  337. {
  338. if ( msg == ME_MSG_SELECT )
  339. {
  340. gui_alarm_list[gui_alarm_index] = gui_alarm_current;
  341. gui_alarm_list[gui_alarm_index].skip_wd = 0; /* clear the skip alarm (if any) */
  342. gui_alarm_list[gui_alarm_index].snooze_count = 0; /* clear snooze (if any) */
  343. //gui_alarm_calc_str_time(gui_alarm_index);
  344. menu_SetMEList(menu, melist_alarm_menu, gui_alarm_index); /* first set the normal menu */
  345. gui_Recalculate(); /* because it might be overwritten with the alarm menu */
  346. return 1;
  347. }
  348. return 0;
  349. }
  350. const me_t melist_setup_alarm[] =
  351. {
  352. { me_cb_big_toggle, &(gui_alarm_current.enable), NULL, 4 , 6},
  353. { me_cb_0_23, &(gui_alarm_current.h), NULL, ME_ALARM_TIME_XO+2,ME_ALARM_TIME_Y },
  354. { me_cb_num_label, NULL, ":", ME_ALARM_TIME_XO+30,ME_ALARM_TIME_Y-3 },
  355. { me_cb_0_55, &(gui_alarm_current.m), NULL, ME_ALARM_TIME_XO+39,ME_ALARM_TIME_Y },
  356. { me_cb_wd_toggle, &(gui_alarm_current.wd[0]), (void *)weekdaystr[0], ME_ALARM_WD_XO+17*0, ME_ALARM_WD_Y},
  357. { me_cb_wd_toggle, &(gui_alarm_current.wd[1]), (void *)weekdaystr[1], ME_ALARM_WD_XO+17*1, ME_ALARM_WD_Y},
  358. { me_cb_wd_toggle, &(gui_alarm_current.wd[2]), (void *)weekdaystr[2], ME_ALARM_WD_XO+17*2, ME_ALARM_WD_Y},
  359. { me_cb_wd_toggle, &(gui_alarm_current.wd[3]), (void *)weekdaystr[3], ME_ALARM_WD_XO+17*3, ME_ALARM_WD_Y},
  360. { me_cb_wd_toggle, &(gui_alarm_current.wd[4]), (void *)weekdaystr[4], ME_ALARM_WD_XO+17*4, ME_ALARM_WD_Y},
  361. { me_cb_wd_toggle, &(gui_alarm_current.wd[5]), (void *)weekdaystr[5], ME_ALARM_WD_XO+17*5, ME_ALARM_WD_Y},
  362. { me_cb_wd_toggle, &(gui_alarm_current.wd[6]), (void *)weekdaystr[6], ME_ALARM_WD_XO+17*6, ME_ALARM_WD_Y},
  363. { me_cb_16x16_bitmap_button, (void *)me_action_alarm_done, (void *)ok_xbm, ME_ALARM_TIME_XO+80,ME_ALARM_TIME_Y-17 },
  364. { me_cb_null, NULL, NULL, 0, 0 },
  365. };
  366. /*============================================*/
  367. /* Alarm Setup Menu */
  368. static int me_action_alarm_common(menu_t *menu, const me_t *me, uint8_t msg) U8G2_NOINLINE;
  369. static int me_action_alarm_common(menu_t *menu, const me_t *me, uint8_t msg)
  370. {
  371. if ( msg == ME_MSG_SELECT )
  372. {
  373. gui_alarm_current = gui_alarm_list[gui_alarm_index];
  374. menu_SetMEList(menu, melist_setup_alarm, 0);
  375. return 1;
  376. }
  377. return 0;
  378. }
  379. int me_action_alarm1(menu_t *menu, const me_t *me, uint8_t msg)
  380. {
  381. gui_alarm_index = 0;
  382. return me_action_alarm_common(menu, me, msg);
  383. }
  384. int me_action_alarm2(menu_t *menu, const me_t *me, uint8_t msg)
  385. {
  386. gui_alarm_index = 1;
  387. return me_action_alarm_common(menu, me, msg);
  388. }
  389. int me_action_alarm3(menu_t *menu, const me_t *me, uint8_t msg)
  390. {
  391. gui_alarm_index = 2;
  392. return me_action_alarm_common(menu, me, msg);
  393. }
  394. int me_action_alarm4(menu_t *menu, const me_t *me, uint8_t msg)
  395. {
  396. gui_alarm_index = 3;
  397. return me_action_alarm_common(menu, me, msg);
  398. }
  399. int me_action_handle_alarm_list(menu_t *menu, const me_t *me, uint8_t msg)
  400. {
  401. if ( msg == ME_MSG_DRAW )
  402. {
  403. uint8_t y, x;
  404. uint8_t ym;
  405. u8g2_SetFont(menu->u8g2, MENU_SMALL_FONT);
  406. for( y = 0; y < 4; y++ )
  407. {
  408. ym = y*8+7;
  409. for( x = 0; x < 7; x++ )
  410. {
  411. u8g2_DrawGlyph(menu->u8g2, 0, ym, y+'1');
  412. u8g2_DrawGlyph(menu->u8g2, 5, ym, ':');
  413. u8g2_DrawStr(menu->u8g2, 9, ym, gui_alarm_str[y]);
  414. if ( gui_alarm_list[y].wd[x] )
  415. {
  416. u8g2_DrawStr(menu->u8g2, 40+x*12, ym, weekdaystr[x]);
  417. }
  418. }
  419. }
  420. }
  421. else if ( msg == ME_MSG_SELECT )
  422. {
  423. menu_SetMEList(menu, melist_alarm_menu, 4);
  424. return 1;
  425. }
  426. return 0;
  427. }
  428. const me_t melist_alarm_list_menu[] =
  429. {
  430. { me_cb_button_empty, (void *)me_action_handle_alarm_list, NULL, 0, 0 },
  431. { me_cb_null, NULL, NULL, 0, 0 },
  432. };
  433. int me_action_goto_alarm_list(menu_t *menu, const me_t *me, uint8_t msg)
  434. {
  435. if ( msg == ME_MSG_SELECT )
  436. {
  437. menu_SetMEList(menu, melist_alarm_list_menu, 0);
  438. return 1;
  439. }
  440. return 0;
  441. }
  442. const me_t melist_alarm_menu[] =
  443. {
  444. { me_cb_button_half_line, (void *)me_action_alarm1, gui_alarm_str[0], 0,10 },
  445. { me_cb_button_half_line, (void *)me_action_alarm2, gui_alarm_str[1], 64,10 },
  446. { me_cb_button_half_line, (void *)me_action_alarm3, gui_alarm_str[2], 0,20 },
  447. { me_cb_button_half_line, (void *)me_action_alarm4, gui_alarm_str[3], 64,20 },
  448. { me_cb_button_half_line, (void *)me_action_goto_alarm_list, "Liste", 0,30 },
  449. { me_cb_button_half_line, (void *)me_action_to_top_menu, "Zurück", 64,30 },
  450. { me_cb_null, NULL, NULL, 0, 0 },
  451. };
  452. /*============================================*/
  453. /* Setup Menu */
  454. int me_action_setup_time(menu_t *menu, const me_t *me, uint8_t msg)
  455. {
  456. if ( msg == ME_MSG_SELECT )
  457. {
  458. menu_SetMEList(menu, melist_setup_time, 0);
  459. return 1;
  460. }
  461. return 0;
  462. }
  463. int me_action_setup_date(menu_t *menu, const me_t *me, uint8_t msg)
  464. {
  465. if ( msg == ME_MSG_SELECT )
  466. {
  467. menu_SetMEList(menu, melist_setup_date, 0);
  468. return 1;
  469. }
  470. return 0;
  471. }
  472. const me_t melist_setup_menu[] =
  473. {
  474. { me_cb_button_half_line, (void *)me_action_setup_time, "Uhrzeit", 0,10 },
  475. { me_cb_button_half_line, (void *)me_action_setup_date, "Datum", 64,10 },
  476. { me_cb_button_half_line, (void *)NULL, "Power", 0,20 },
  477. { me_cb_button_half_line, (void *)me_action_goto_alarm_list, "Alarme", 64,20 },
  478. { me_cb_button_full_line, (void *)me_action_to_top_menu, "Zurück", 40,30 },
  479. { me_cb_null, NULL, NULL, 0, 0 },
  480. };
  481. /*============================================*/
  482. /* Alarm Menu */
  483. int me_action_deactivate_alarm(menu_t *menu, const me_t *me, uint8_t msg)
  484. {
  485. if ( msg == ME_MSG_SELECT )
  486. {
  487. menu_SetMEList(menu, melist_display_time, 0);
  488. return 1;
  489. }
  490. return 0;
  491. }
  492. int me_action_do_snooze(menu_t *menu, const me_t *me, uint8_t msg)
  493. {
  494. if ( msg == ME_MSG_SELECT )
  495. {
  496. menu_SetMEList(menu, melist_display_time, 0);
  497. return 1;
  498. }
  499. return 0;
  500. }
  501. const me_t melist_active_alarm_menu[] =
  502. {
  503. { me_cb_button_full_line, (void *)0, "", 3,10 },
  504. { me_cb_button_full_line, (void *)me_action_deactivate_alarm, "Alarm abschalten", 3,20 },
  505. { me_cb_button_full_line, (void *)me_action_do_snooze, "5 Min schlummern", 3,30 },
  506. { me_cb_null, NULL, NULL, 0, 0 },
  507. };
  508. /*============================================*/
  509. /* toplevel menu */
  510. int me_action_to_display_time(menu_t *menu, const me_t *me, uint8_t msg)
  511. {
  512. if ( msg == ME_MSG_SELECT )
  513. {
  514. menu_SetMEList(menu, melist_display_time, 0);
  515. return 1;
  516. }
  517. return 0;
  518. }
  519. int me_action_to_alarm_menu(menu_t *menu, const me_t *me, uint8_t msg)
  520. {
  521. if ( msg == ME_MSG_SELECT )
  522. {
  523. menu_SetMEList(menu, melist_alarm_menu, 0);
  524. return 1;
  525. }
  526. return 0;
  527. }
  528. int me_action_to_setup_menu(menu_t *menu, const me_t *me, uint8_t msg)
  529. {
  530. if ( msg == ME_MSG_SELECT )
  531. {
  532. menu_SetMEList(menu, melist_setup_menu, 0);
  533. return 1;
  534. }
  535. return 0;
  536. }
  537. int me_cb_button_skip_alarm(menu_t *menu, const me_t *me, uint8_t msg)
  538. {
  539. int r = 0;
  540. u8g2_uint_t x;
  541. switch(msg)
  542. {
  543. case ME_MSG_IS_FOCUS:
  544. return gui_data.is_skip_possible;
  545. case ME_MSG_DRAW_FOCUS:
  546. menu_DrawBoxFocus(menu,
  547. 0,
  548. me->y - u8g2_GetAscent(menu->u8g2)-1,
  549. u8g2_GetDisplayWidth(menu->u8g2) ,
  550. u8g2_GetAscent(menu->u8g2) - u8g2_GetDescent(menu->u8g2) +1);
  551. r = 1;
  552. break;
  553. case ME_MSG_DRAW:
  554. if ( gui_data.is_skip_possible )
  555. {
  556. u8g2_SetFont(menu->u8g2, MENU_NORMAL_FONT);
  557. gui_alarm_to_str(gui_data.next_alarm_index);
  558. x = u8g2_DrawUTF8(menu->u8g2, me->x, me->y, gui_data.s );
  559. u8g2_DrawUTF8(menu->u8g2, me->x+x, me->y, " deaktvieren" );
  560. }
  561. r = 1;
  562. break;
  563. case ME_MSG_SELECT:
  564. //printf("me_cb_button_skip_alarm ME_MSG_SELECT\n");
  565. gui_alarm_list[gui_data.next_alarm_index].skip_wd =
  566. gui_alarm_list[gui_data.next_alarm_index].na_wd + 1;
  567. gui_alarm_list[gui_data.next_alarm_index].snooze_count = 0; /* clear snooze (if any) */
  568. menu_SetMEList(menu, melist_display_time, 0); /* first set the normal menu */
  569. gui_Recalculate(); /* it might be changed here to the alarm menu */
  570. r = 1;
  571. break;
  572. }
  573. return r;
  574. }
  575. const me_t melist_top_menu[] =
  576. {
  577. { me_cb_button_half_line, (void *)me_action_to_display_time, "Zurück", 0,10 },
  578. { me_cb_button_half_line, (void *)me_action_to_alarm_menu, "Alarm", 64,10 },
  579. { me_cb_button_skip_alarm, NULL, NULL, 3,20 },
  580. { me_cb_button_full_line, (void *)me_action_to_setup_menu, "Weitere Funktionen", 3,30 },
  581. { me_cb_null, NULL, NULL, 0, 0 },
  582. };