presets.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Xytronic LF-1600
  3. * Temperature presets
  4. *
  5. * Copyright (c) 2016-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 "presets.h"
  22. #include "settings.h"
  23. #include "controller_temp.h"
  24. #include "ring.h"
  25. #include "menu.h"
  26. #include <string.h>
  27. #if CONF_PRESETS
  28. static void presets_store(void)
  29. {
  30. store_settings();
  31. contrtemp_update_setpoint();
  32. menu_request_display_update();
  33. }
  34. #endif
  35. void presets_next(void)
  36. {
  37. #if CONF_PRESETS
  38. struct settings *settings;
  39. settings = get_settings();
  40. settings->temp_setpoint_active = ring_next(settings->temp_setpoint_active,
  41. NR_PRESETS - 1u);
  42. presets_store();
  43. #endif
  44. }
  45. void presets_prev(void)
  46. {
  47. #if CONF_PRESETS
  48. struct settings *settings;
  49. settings = get_settings();
  50. settings->temp_setpoint_active = ring_prev(settings->temp_setpoint_active,
  51. NR_PRESETS - 1u);
  52. presets_store();
  53. #endif
  54. }
  55. uint8_t presets_get_active_index(void)
  56. {
  57. #if CONF_PRESETS
  58. return get_settings()->temp_setpoint_active;
  59. #else
  60. return 0u;
  61. #endif
  62. }
  63. fixpt_t presets_get_active_value(void)
  64. {
  65. struct settings *settings;
  66. uint8_t active_index;
  67. fixpt_t value;
  68. settings = get_settings();
  69. active_index = settings->temp_setpoint_active;
  70. value = settings->temp_setpoint[active_index];
  71. return value;
  72. }
  73. void presets_set_active_value(fixpt_t value)
  74. {
  75. struct settings *settings;
  76. uint8_t active_index;
  77. settings = get_settings();
  78. active_index = settings->temp_setpoint_active;
  79. settings->temp_setpoint[active_index] = value;
  80. presets_store();
  81. }
  82. void presets_init(void)
  83. {
  84. }