menu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * Xytronic LF-1600
  3. * User menu
  4. *
  5. * Copyright (c) 2015-2017 Michael Buesch <m@bues.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "menu.h"
  22. #include "display.h"
  23. #include "buttons.h"
  24. #include "timer.h"
  25. #include "controller_temp.h"
  26. #include "controller_current.h"
  27. #include "measure_temp.h"
  28. #include "debug_uart.h"
  29. #include "settings.h"
  30. #include "presets.h"
  31. #include <string.h>
  32. #define MENU_SELPRESET_TIMEOUT 3000
  33. #define MENU_CHGPRESET_TIMEOUT 3000
  34. #define MENU_IDLETEMP_TIMEOUT 3000
  35. #define MENU_KCONF_PRE_TIMEOUT 1500
  36. #define MENU_ADJ_PRE_TIMEOUT 1500
  37. enum menu_state {
  38. MENU_CURTEMP, /* Show the current temperature. */
  39. MENU_SELPRESET, /* Select temperature preset. */
  40. MENU_CHGPRESET, /* Change temperature preset. */
  41. MENU_IDLETEMP, /* Idle temperature setpoint. */
  42. MENU_DEBUG, /* Debug enable. */
  43. MENU_ADJ_PRE, /* Temp adjust */
  44. MENU_ADJ, /* Temp adjust */
  45. MENU_KP_PRE, /* Temp KP config */
  46. MENU_KP, /* Temp KP config */
  47. MENU_KI_PRE, /* Temp KI config */
  48. MENU_KI, /* Temp KI config */
  49. MENU_KD_PRE, /* Temp KD config */
  50. MENU_KD, /* Temp KD config */
  51. };
  52. enum ramp_state {
  53. RAMP_NONE,
  54. RAMP_UP,
  55. RAMP_DOWN,
  56. RAMP_PRE_UP,
  57. RAMP_PRE_DOWN,
  58. };
  59. #define RAMP_PRE_TIMEOUT_MS 1000u
  60. #define RAMP_START_PERIOD_MS 400u
  61. #define RAMP_MIN_PERIOD_MS (RAMP_START_PERIOD_MS >> 4)
  62. typedef void (*ramp_handler_t)(bool up);
  63. struct menu_context {
  64. enum menu_state state;
  65. struct timer timeout;
  66. enum ramp_state ramp;
  67. struct timer ramp_timer;
  68. struct timer ramp_pre_timer;
  69. ramp_handler_t ramp_handler;
  70. uint16_t ramp_period;
  71. uint8_t displayed_error;
  72. bool displayed_heating;
  73. bool display_update_requested;
  74. };
  75. static struct menu_context menu;
  76. static void int_to_ascii_align_right(char *buf,
  77. uint8_t align_to_digit,
  78. int16_t val,
  79. int16_t min_val, int16_t max_val,
  80. char fill_char)
  81. {
  82. int8_t i, d;
  83. bool neg;
  84. val = clamp(val, min_val, max_val);
  85. neg = val < 0;
  86. if (neg)
  87. val = -val;
  88. i = (int8_t)align_to_digit;
  89. buf[i + 1] = '\0';
  90. do {
  91. d = (int8_t)(val % 10);
  92. val /= 10;
  93. buf[i--] = (char)('0' + d);
  94. if (i < 0)
  95. break;
  96. } while (val);
  97. if (neg && i >= 0)
  98. buf[i--] = '-';
  99. while (i >= 0)
  100. buf[i--] = fill_char;
  101. }
  102. #define menu_putstr(dest, str) strcpy((dest), (str))
  103. static void menu_put_temp(char *disp, fixpt_t temp, const char *symbol)
  104. {
  105. int16_t temp_int;
  106. temp_int = (int16_t)fixpt_to_int(temp);
  107. int_to_ascii_align_right(disp,
  108. 2,
  109. temp_int,
  110. -99,
  111. 999,
  112. ' ');
  113. menu_putstr(disp + 3, symbol);
  114. }
  115. static void menu_put_fixpt(char *disp, fixpt_t val, uint8_t fract_digits)
  116. {
  117. int16_t ipart, fpart;
  118. int16_t ipart_max, fpart_max;
  119. int16_t ipart_digits;
  120. uint8_t ipart_align, fpart_align;
  121. if (fract_digits == 2) {
  122. ipart_max = 99;
  123. ipart_align = 1;
  124. fpart_max = 99;
  125. fpart_align = 1;
  126. } else { /* fract_digits == 3 */
  127. ipart_max = 9;
  128. ipart_align = 0;
  129. fpart_max = 999;
  130. fpart_align = 2;
  131. }
  132. ipart_digits = 4 - fract_digits;
  133. ipart = (int16_t)clamp(fixpt_get_int_part(val), 0, ipart_max);
  134. fpart = (int16_t)fixpt_get_dec_fract(val, fract_digits);
  135. int_to_ascii_align_right(&disp[0], ipart_align, ipart,
  136. 0, ipart_max, ' ');
  137. disp[ipart_digits] = '.';
  138. int_to_ascii_align_right(&disp[ipart_digits + 1], fpart_align, fpart,
  139. 0, fpart_max, '0');
  140. }
  141. static void menu_update_display(void)
  142. {
  143. char disp[6];
  144. const char *symbol;
  145. char _symbol[3];
  146. uint8_t displayed_error;
  147. uint8_t active_index;
  148. bool show_heating;
  149. enum contrtemp_boostmode boost_mode;
  150. boost_mode = contrtemp_get_boost_mode();
  151. displayed_error = menu.displayed_error;
  152. show_heating = true;
  153. disp[0] = '\0';
  154. switch (menu.state) {
  155. case MENU_CURTEMP:
  156. if (displayed_error) {
  157. menu_putstr(disp, "Err ");
  158. disp[3] = (char)('0' + displayed_error);
  159. show_heating = false;
  160. } else {
  161. if (contrtemp_is_idle()) {
  162. symbol = "L.";
  163. } else {
  164. switch (boost_mode) {
  165. case NR_BOOST_MODES:
  166. default:
  167. case TEMPBOOST_NORMAL:
  168. symbol = "C.";
  169. break;
  170. #if CONF_BOOST
  171. case TEMPBOOST_BOOST1:
  172. symbol = "b.";
  173. break;
  174. case TEMPBOOST_BOOST2:
  175. symbol = "8.";
  176. break;
  177. #endif
  178. }
  179. }
  180. menu_put_temp(disp, contrtemp_get_feedback(), symbol);
  181. }
  182. break;
  183. case MENU_SELPRESET:
  184. case MENU_CHGPRESET:
  185. if (CONF_PRESETS) {
  186. active_index = presets_get_active_index();
  187. _symbol[0] = (char)('1' + active_index);
  188. _symbol[1] = '.';
  189. _symbol[2] = '\0';
  190. symbol = _symbol;
  191. } else
  192. symbol = " ";
  193. menu_put_temp(disp, presets_get_active_value(), symbol);
  194. break;
  195. case MENU_IDLETEMP:
  196. if (!CONF_IDLE)
  197. break;
  198. menu_put_temp(disp, get_settings()->temp_idle_setpoint, "L");
  199. break;
  200. case MENU_DEBUG:
  201. if (!CONF_DEBUG)
  202. break;
  203. menu_putstr(disp, "DBG");
  204. break;
  205. case MENU_ADJ_PRE:
  206. if (!CONF_ADJ)
  207. break;
  208. menu_putstr(disp, "ADJC.");
  209. show_heating = false;
  210. break;
  211. case MENU_ADJ:
  212. if (!CONF_ADJ)
  213. break;
  214. menu_put_temp(disp, meastemp_adjust_get(), "C.");
  215. show_heating = false;
  216. break;
  217. case MENU_KP_PRE:
  218. if (!CONF_KCONF)
  219. break;
  220. menu_putstr(disp, " P");
  221. show_heating = false;
  222. break;
  223. case MENU_KP:
  224. if (!CONF_KCONF)
  225. break;
  226. menu_put_fixpt(disp, get_settings()->temp_k[boost_mode].kp, 2);
  227. show_heating = false;
  228. break;
  229. case MENU_KI_PRE:
  230. if (!CONF_KCONF)
  231. break;
  232. menu_putstr(disp, " I");
  233. show_heating = false;
  234. break;
  235. case MENU_KI:
  236. if (!CONF_KCONF)
  237. break;
  238. menu_put_fixpt(disp, get_settings()->temp_k[boost_mode].ki, 3);
  239. show_heating = false;
  240. break;
  241. case MENU_KD_PRE:
  242. if (!CONF_KCONF)
  243. break;
  244. menu_putstr(disp, " D");
  245. show_heating = false;
  246. break;
  247. case MENU_KD:
  248. if (!CONF_KCONF)
  249. break;
  250. menu_put_fixpt(disp, get_settings()->temp_k[boost_mode].kd, 2);
  251. show_heating = false;
  252. break;
  253. }
  254. /* Show the 'is heating' dot. */
  255. display_force_dp(2, true, show_heating ? menu.displayed_heating : false);
  256. /* Update the display content. */
  257. display_show(disp);
  258. }
  259. void menu_request_display_update(void)
  260. {
  261. menu.display_update_requested = true;
  262. mb();
  263. }
  264. static enum menu_state next_menu_state(enum menu_state cur_state)
  265. {
  266. switch (cur_state) {
  267. case MENU_CURTEMP:
  268. if (CONF_IDLE)
  269. return MENU_IDLETEMP;
  270. if (CONF_DEBUG)
  271. return MENU_DEBUG;
  272. if (CONF_ADJ)
  273. return MENU_ADJ_PRE;
  274. if (CONF_KCONF)
  275. return MENU_KP_PRE;
  276. return MENU_CURTEMP;
  277. case MENU_SELPRESET:
  278. case MENU_CHGPRESET:
  279. return MENU_CURTEMP;
  280. case MENU_IDLETEMP:
  281. if (CONF_DEBUG)
  282. return MENU_DEBUG;
  283. if (CONF_ADJ)
  284. return MENU_ADJ_PRE;
  285. if (CONF_KCONF)
  286. return MENU_KP_PRE;
  287. return MENU_CURTEMP;
  288. case MENU_DEBUG:
  289. if (CONF_ADJ)
  290. return MENU_ADJ_PRE;
  291. if (CONF_KCONF)
  292. return MENU_KP_PRE;
  293. return MENU_CURTEMP;
  294. case MENU_ADJ_PRE:
  295. if (CONF_ADJ)
  296. return MENU_ADJ;
  297. if (CONF_KCONF)
  298. return MENU_KP_PRE;
  299. return MENU_CURTEMP;
  300. case MENU_ADJ:
  301. if (CONF_KCONF)
  302. return MENU_KP_PRE;
  303. return MENU_CURTEMP;
  304. case MENU_KP_PRE:
  305. if (CONF_KCONF)
  306. return MENU_KP;
  307. return MENU_CURTEMP;
  308. case MENU_KP:
  309. if (CONF_KCONF)
  310. return MENU_KI_PRE;
  311. return MENU_CURTEMP;
  312. case MENU_KI_PRE:
  313. if (CONF_KCONF)
  314. return MENU_KI;
  315. return MENU_CURTEMP;
  316. case MENU_KI:
  317. if (CONF_KCONF)
  318. return MENU_KD_PRE;
  319. return MENU_CURTEMP;
  320. case MENU_KD_PRE:
  321. if (CONF_KCONF)
  322. return MENU_KD;
  323. return MENU_CURTEMP;
  324. case MENU_KD:
  325. if (CONF_KCONF)
  326. return MENU_CURTEMP;
  327. return MENU_CURTEMP;
  328. }
  329. return MENU_CURTEMP;
  330. }
  331. static void menu_set_state(enum menu_state new_state)
  332. {
  333. if (menu.state == new_state)
  334. return;
  335. menu.state = new_state;
  336. switch (new_state) {
  337. case MENU_SELPRESET:
  338. timer_arm(&menu.timeout, MENU_SELPRESET_TIMEOUT);
  339. break;
  340. case MENU_CHGPRESET:
  341. timer_arm(&menu.timeout, MENU_CHGPRESET_TIMEOUT);
  342. break;
  343. case MENU_IDLETEMP:
  344. timer_arm(&menu.timeout, MENU_IDLETEMP_TIMEOUT);
  345. break;
  346. case MENU_ADJ_PRE:
  347. if (!CONF_ADJ)
  348. break;
  349. timer_arm(&menu.timeout, MENU_ADJ_PRE_TIMEOUT);
  350. /* fall through... */
  351. case MENU_ADJ:
  352. if (!CONF_ADJ)
  353. break;
  354. contrtemp_set_enabled(false);
  355. break;
  356. case MENU_KP_PRE:
  357. case MENU_KI_PRE:
  358. case MENU_KD_PRE:
  359. if (!CONF_KCONF)
  360. break;
  361. timer_arm(&menu.timeout, MENU_KCONF_PRE_TIMEOUT);
  362. /* fall through... */
  363. case MENU_KP:
  364. case MENU_KI:
  365. case MENU_KD:
  366. if (!CONF_KCONF)
  367. break;
  368. contrtemp_set_enabled(false);
  369. break;
  370. case MENU_CURTEMP:
  371. contrtemp_set_enabled(true);
  372. break;
  373. case MENU_DEBUG:
  374. break;
  375. }
  376. menu_request_display_update();
  377. }
  378. static void menu_set_next_state(void)
  379. {
  380. menu_set_state(next_menu_state(menu.state));
  381. }
  382. static fixpt_t do_ramp_temp(fixpt_t temp, bool up,
  383. fixpt_t min_val, fixpt_t max_val)
  384. {
  385. return fixpt_add_limited(temp,
  386. (up ? float_to_fixpt(CELSIUS(1.0)) :
  387. float_to_fixpt(CELSIUS(-1.0))),
  388. min_val, max_val);
  389. }
  390. static void settemp_ramp_handler(bool up)
  391. {
  392. fixpt_t setpoint;
  393. setpoint = presets_get_active_value();
  394. setpoint = do_ramp_temp(setpoint, up,
  395. float_to_fixpt(CONTRTEMP_NEGLIM),
  396. float_to_fixpt(CONTRTEMP_POSLIM));
  397. presets_set_active_value(setpoint);
  398. menu_set_state(MENU_CHGPRESET);
  399. }
  400. static void idletemp_ramp_handler(bool up)
  401. {
  402. fixpt_t setpoint;
  403. setpoint = get_settings()->temp_idle_setpoint;
  404. setpoint = do_ramp_temp(setpoint, up,
  405. float_to_fixpt(CONTRTEMP_NEGLIM),
  406. float_to_fixpt(CONTRTEMP_POSLIM));
  407. contrtemp_set_idle_setpoint(setpoint);
  408. }
  409. static void do_ramp_k(fixpt_t *k, fixpt_t inc, fixpt_t max_val, bool up)
  410. {
  411. *k = fixpt_add_limited(*k, (up ? inc : fixpt_neg(inc)),
  412. float_to_fixpt(0.0), max_val);
  413. store_settings();
  414. contrtemp_update_pid_config();
  415. }
  416. static void adj_ramp_handler(bool up)
  417. {
  418. fixpt_t temp_adj;
  419. temp_adj = meastemp_adjust_get();
  420. temp_adj = do_ramp_temp(temp_adj, up,
  421. float_to_fixpt(CELSIUS(-99)),
  422. float_to_fixpt(CELSIUS(99)));
  423. meastemp_adjust_set(temp_adj);
  424. }
  425. static void kconf_kp_ramp_handler(bool up)
  426. {
  427. do_ramp_k(&(get_settings()->temp_k[contrtemp_get_boost_mode()].kp),
  428. float_to_fixpt(0.03125),
  429. float_to_fixpt(99.0), up);
  430. }
  431. static void kconf_ki_ramp_handler(bool up)
  432. {
  433. do_ramp_k(&(get_settings()->temp_k[contrtemp_get_boost_mode()].ki),
  434. float_to_fixpt(0.015625),
  435. float_to_fixpt(9.0), up);
  436. }
  437. static void kconf_kd_ramp_handler(bool up)
  438. {
  439. do_ramp_k(&(get_settings()->temp_k[contrtemp_get_boost_mode()].kd),
  440. float_to_fixpt(0.03125),
  441. float_to_fixpt(99.0), up);
  442. }
  443. static void start_ramping(bool up, bool pre_ramp_wait, ramp_handler_t handler)
  444. {
  445. if (pre_ramp_wait) {
  446. menu.ramp = up ? RAMP_PRE_UP : RAMP_PRE_DOWN;
  447. timer_arm(&menu.ramp_pre_timer, RAMP_PRE_TIMEOUT_MS);
  448. } else {
  449. menu.ramp = up ? RAMP_UP : RAMP_DOWN;
  450. }
  451. menu.ramp_handler = handler;
  452. menu.ramp_period = RAMP_START_PERIOD_MS;
  453. timer_set_now(&menu.ramp_timer);
  454. }
  455. static void start_ramping_button(enum button_id button,
  456. enum button_state bstate,
  457. bool pre_ramp_wait,
  458. ramp_handler_t handler)
  459. {
  460. if (bstate == BSTATE_POSEDGE) {
  461. if (button == BUTTON_MINUS)
  462. start_ramping(false, pre_ramp_wait, handler);
  463. else if (button == BUTTON_PLUS)
  464. start_ramping(true, pre_ramp_wait, handler);
  465. }
  466. }
  467. static void stop_ramping(void)
  468. {
  469. menu.ramp = RAMP_NONE;
  470. }
  471. /* Handler for SET, MINUS and PLUS buttons */
  472. void menu_button_handler(enum button_id button,
  473. enum button_state bstate);
  474. void menu_button_handler(enum button_id button,
  475. enum button_state bstate)
  476. {
  477. if (button == BUTTON_IRON)
  478. return;
  479. switch (menu.state) {
  480. case MENU_CURTEMP:
  481. start_ramping_button(button, bstate, (CONF_PRESETS),
  482. settemp_ramp_handler);
  483. if (CONF_PRESETS) {
  484. if (bstate == BSTATE_NEGEDGE) {
  485. if (button != BUTTON_SET)
  486. menu_set_state(MENU_SELPRESET);
  487. }
  488. } else {
  489. if (bstate == BSTATE_POSEDGE) {
  490. if (button != BUTTON_SET)
  491. menu_set_state(MENU_CHGPRESET);
  492. }
  493. }
  494. break;
  495. case MENU_SELPRESET:
  496. if (!CONF_PRESETS)
  497. break;
  498. timer_arm(&menu.timeout, MENU_SELPRESET_TIMEOUT);
  499. if (bstate == BSTATE_NEGEDGE) {
  500. if (button == BUTTON_PLUS)
  501. presets_next();
  502. if (button == BUTTON_MINUS)
  503. presets_prev();
  504. }
  505. start_ramping_button(button, bstate, true,
  506. settemp_ramp_handler);
  507. break;
  508. case MENU_CHGPRESET:
  509. timer_arm(&menu.timeout, MENU_CHGPRESET_TIMEOUT);
  510. start_ramping_button(button, bstate, false,
  511. settemp_ramp_handler);
  512. break;
  513. case MENU_IDLETEMP:
  514. if (!CONF_IDLE)
  515. break;
  516. timer_arm(&menu.timeout, MENU_IDLETEMP_TIMEOUT);
  517. start_ramping_button(button, bstate, false,
  518. idletemp_ramp_handler);
  519. break;
  520. case MENU_DEBUG:
  521. if (!CONF_DEBUG)
  522. break;
  523. if (bstate == BSTATE_POSEDGE) {
  524. if (button == BUTTON_PLUS)
  525. debug_enable(true);
  526. if (button == BUTTON_MINUS) {
  527. debug_enable(false);
  528. menu_request_display_update();
  529. }
  530. }
  531. break;
  532. case MENU_ADJ_PRE:
  533. break;
  534. case MENU_ADJ:
  535. if (!CONF_ADJ)
  536. break;
  537. start_ramping_button(button, bstate, false,
  538. adj_ramp_handler);
  539. break;
  540. case MENU_KP_PRE:
  541. break;
  542. case MENU_KP:
  543. if (!CONF_KCONF)
  544. break;
  545. start_ramping_button(button, bstate, false,
  546. kconf_kp_ramp_handler);
  547. break;
  548. case MENU_KI_PRE:
  549. break;
  550. case MENU_KI:
  551. if (!CONF_KCONF)
  552. break;
  553. start_ramping_button(button, bstate, false,
  554. kconf_ki_ramp_handler);
  555. break;
  556. case MENU_KD_PRE:
  557. break;
  558. case MENU_KD:
  559. if (!CONF_KCONF)
  560. break;
  561. start_ramping_button(button, bstate, false,
  562. kconf_kd_ramp_handler);
  563. break;
  564. }
  565. if (bstate == BSTATE_NEGEDGE) {
  566. /* Stop ramping, if any button is released. */
  567. stop_ramping();
  568. /* Switch to the next menu via SET. */
  569. if (button == BUTTON_SET) {
  570. if (!debug_is_enabled())
  571. menu_set_next_state();
  572. }
  573. }
  574. }
  575. /* Periodic work. */
  576. void menu_work(void)
  577. {
  578. enum ramp_state ramp;
  579. uint8_t error;
  580. bool heating;
  581. /* Menu timeouts */
  582. switch (menu.state) {
  583. case MENU_CURTEMP:
  584. case MENU_DEBUG:
  585. case MENU_ADJ:
  586. case MENU_KP:
  587. case MENU_KI:
  588. case MENU_KD:
  589. break;
  590. case MENU_ADJ_PRE:
  591. case MENU_KP_PRE:
  592. case MENU_KI_PRE:
  593. case MENU_KD_PRE:
  594. case MENU_SELPRESET:
  595. case MENU_CHGPRESET:
  596. case MENU_IDLETEMP:
  597. if (timer_expired(&menu.timeout)) {
  598. if (menu.state == MENU_IDLETEMP)
  599. menu_set_state(MENU_CURTEMP);
  600. else
  601. menu_set_next_state();
  602. stop_ramping();
  603. break;
  604. }
  605. break;
  606. }
  607. /* Evaluate error conditions. */
  608. error = 0;
  609. if (contrcurr_get_emerg() & CONTRCURR_EMERG_UNPLAUS_FEEDBACK)
  610. error |= 1;
  611. if (contrtemp_in_emerg())
  612. error |= 2;
  613. if (error != menu.displayed_error) {
  614. menu.displayed_error = error;
  615. stop_ramping();
  616. menu.display_update_requested = true;
  617. }
  618. /* Update heating condition. */
  619. heating = contrtemp_is_heating_up();
  620. if (heating != menu.displayed_heating) {
  621. menu.displayed_heating = heating;
  622. menu.display_update_requested = true;
  623. }
  624. /* Generic ramping handler. */
  625. ramp = menu.ramp;
  626. if (ramp != RAMP_NONE) {
  627. if (ramp == RAMP_PRE_UP ||
  628. ramp == RAMP_PRE_DOWN) {
  629. if (timer_expired(&menu.ramp_pre_timer)) {
  630. start_ramping(ramp == RAMP_PRE_UP, false,
  631. menu.ramp_handler);
  632. }
  633. } else {
  634. if (timer_expired(&menu.ramp_timer)) {
  635. menu.ramp_handler(ramp == RAMP_UP);
  636. menu.display_update_requested = true;
  637. timer_add(&menu.ramp_timer, menu.ramp_period);
  638. if (menu.ramp_period > RAMP_MIN_PERIOD_MS)
  639. menu.ramp_period /= 2;
  640. }
  641. }
  642. }
  643. /* Update the display, if requested. */
  644. mb();
  645. if (menu.display_update_requested) {
  646. menu.display_update_requested = false;
  647. mb();
  648. menu_update_display();
  649. }
  650. }
  651. void menu_init(void)
  652. {
  653. if (CONF_DEBUG) {
  654. if (button_is_pressed(BUTTON_SET)) {
  655. debug_enable(true);
  656. menu_set_state(MENU_DEBUG);
  657. } else {
  658. menu_set_state(MENU_CURTEMP);
  659. }
  660. } else {
  661. menu_set_state(MENU_CURTEMP);
  662. }
  663. }