-
Notifications
You must be signed in to change notification settings - Fork 1
/
memory.c
117 lines (89 loc) · 1.73 KB
/
memory.c
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
116
117
#include "memory.h"
struct _USER_CONFIG uconf;
void memory_init(){
NutNvMemLoad(1024, &uconf, sizeof(uconf));
if (uconf.len != sizeof(uconf)) {
puts("Size mismatch: There is no valid configuration present. A new configuration will be created.");
reset();
} else {
printf("According to the user configuration this board was already rebooted %d times.\n", uconf.count);
}
uconf.len = sizeof(uconf);
uconf.count++;
save();
}
void set_first_volume(void){
uconf.volume = 7;
}
void reset(){
uconf.count = 0;
uconf.timezone= 0;
uconf.timezone_set = 0;
uconf.volume = 7;
uconf.alarm1_stream_id = 0;
uconf.alarm2_stream_id = 0;
}
void save(){
NutNvMemSave(1024, &uconf, sizeof(uconf));
}
void factory_reset() {
reset();
save();
}
int get_bootcount() {
return uconf.count;
}
int get_timezone() {
return uconf.timezone;
}
int get_volume(void)
{
return uconf.volume;
}
int get_bass()
{
return uconf.bass;
}
int get_treble()
{
return uconf.treble;
}
int get_timezone_set() {
return uconf.timezone_set;
}
void set_timezone(int timezone){
uconf.timezone = timezone;
uconf.timezone_set = 1;
save();
}
int get_alarm1_stream_id(){
return uconf.alarm1_stream_id;
}
int get_alarm2_stream_id(){
return uconf.alarm2_stream_id;
}
void set_alarm1_stream_id(int id){
uconf.alarm1_stream_id = id;
}
void set_alarm2_stream_id(int id){
uconf.alarm2_stream_id = id;
}
void save_volume(int volume)
{
uconf.volume = volume;
save();
}
void save_bass(int basst)
{
uconf.bass = basst;
save();
}
void save_treble(int treblet)
{
uconf.treble = treblet;
save();
}
void set_timezone_set(int val) {
uconf.timezone_set = val;
save();
}