summaryrefslogtreecommitdiffstats
path: root/firmware/presets.c
blob: f5d788097dd512a246b8eabc517672fa6fccc0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Xytronic LF-1600
 * Temperature presets
 *
 * Copyright (c) 2016 Michael Buesch <m@bues.ch>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "presets.h"
#include "settings.h"
#include "controller_temp.h"
#include "ring.h"

#include <string.h>


#if CONF_PRESETS
struct presets_context {
	uint8_t active;
};

static struct presets_context presets;
#endif


#if CONF_PRESETS
void presets_update_index(uint8_t active)
{
	struct settings *settings;

	presets.active = active;
	settings = get_settings();
	settings->temp_setpoint_active = active;
	store_settings();
	contrtemp_update_setpoint();
}
#endif

void presets_next(void)
{
#if CONF_PRESETS
	uint8_t active;

	active = ring_next(presets.active, NR_PRESETS - 1u);
	presets_update_index(active);
#endif
}

void presets_prev(void)
{
#if CONF_PRESETS
	uint8_t active;

	active = ring_prev(presets.active, NR_PRESETS - 1u);
	presets_update_index(active);
#endif
}

uint8_t presets_get_active_index(void)
{
#if CONF_PRESETS
	return presets.active;
#else
	return 0u;
#endif
}

fixpt_t presets_get_active_value(void)
{
	struct settings *settings;
	uint8_t active_index;
	fixpt_t value;

	settings = get_settings();
	active_index = presets_get_active_index();
	value = settings->temp_setpoint[active_index];

	return value;
}

void presets_set_active_value(fixpt_t value)
{
	struct settings *settings;
	uint8_t active_index;

	settings = get_settings();
	active_index = presets_get_active_index();
	settings->temp_setpoint[active_index] = value;
	store_settings();
	contrtemp_update_setpoint();
}

void presets_init(void)
{
#if CONF_PRESETS
	struct settings *settings;

	settings = get_settings();
	presets.active = min(settings->temp_setpoint_active,
			     NR_PRESETS - 1u);
#endif
}
bues.ch cgit interface