forked from akafugu/VFDDeluxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
121 lines (112 loc) · 3.48 KB
/
settings.cpp
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
118
119
120
121
/*
* Settings for VFD Modular Clock
* (C) 2011-2013 Akafugu Corporation
* (C) 2011-2013 William B Phelps
*
* 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.
*
*/
//#define FEATURE_AUTO_DIM // moved to Makefile
#include "global.h"
//#include <util/delay.h>
#include <avr/eeprom.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "settings.h"
#include "display.h"
#define EE_CHECK 43 // change this value if you change EE addresses
#define EE_settings 0 // eeprom address
__settings settings = {
EE_CHECK,
true, // clock_24h
false, // show temp
false, // show humid
false, // show press
true, // show dots
8, // brightness
0, // volume
13, 1, 1, // year, month, day
ALARM_NORMAL, // alarm type
false, // snooze enabled
#ifdef HAVE_FLW
false, // flw enabled
#endif
#ifdef HAVE_GPS
false, // gps enabled
0, 0, // TZ hour, minute
#endif
#if defined HAVE_GPS || defined HAVE_AUTO_DST
0, 0, // DST mode, offset
#endif
#ifdef HAVE_AUTO_DST // DST rules
#ifdef DST_NSW
10,1,1,2, 4,1,1,3, 1,
#else
3,1,2,2, 11,1,1,2, 1,
#endif
#endif
#ifdef HAVE_AUTO_DATE
FORMAT_YMD, // date format
false, // auto date
#endif
#ifdef HAVE_AUTO_DIM
false, // auto dim
7, 8, // auto dim1 hour, level
19, 5, // auto dim2 hour, level
22, 2, // auto dim3 hour, level
#endif
//#ifdef HAVE_RTC_SQW
// true, // sqw enabled
//#endif
EE_CHECK,
};
//uint8_t alarm_hour, alarm_min, alarm_sec;
//uint8_t hour, min, sec;
uint8_t g_gps_updating = false; // for signalling GPS update on some displays
uint8_t g_gps_nosignal = false; // no data received from GPS
uint8_t g_DST_updated = false; // DST update flag = allow update only once per day
uint8_t g_has_dots = false; // can current shield show dot (decimal points)
#ifdef HAVE_GPS
uint8_t g_gps_cks_errors = 0; // gps checksum error counter
uint8_t g_gps_parse_errors = 0; // gps parse error counter
uint8_t g_gps_time_errors = 0; // gps time error counter
#endif
void save_settings(uint8_t quiet)
{
uint8_t c1 = 0; // # of bytes written
// tone(PinMap::piezo, 3000, 20); // tick
for (unsigned int p=0; p<sizeof(settings); p++) {
uint8_t b1 = eeprom_read_byte((uint8_t *)EE_settings + p);
uint8_t b2 = *((uint8_t *) &settings + p);
if (b1 != b2) {
eeprom_write_byte((uint8_t *)EE_settings + p, *((uint8_t*)&settings + p));
c1++;
}
}
if (c1) {
if (quiet==0)
tone(PinMap::piezo, 1760, 25); // short beep (almost a tick)
}
}
void init_settings(void)
{
uint8_t ee_check1 = eeprom_read_byte((uint8_t *)EE_settings + (&settings.EEcheck1-&settings.EEcheck1));
uint8_t ee_check2 = eeprom_read_byte((uint8_t *)EE_settings + (&settings.EEcheck2-&settings.EEcheck1));
if ((ee_check1!=EE_CHECK) || (ee_check2!=EE_CHECK)) { // has EE been initialized?
for (unsigned int p=0; p<sizeof(settings); p++) { // copy settings structure to EE memory
eeprom_write_byte((uint8_t *)EE_settings + p, *((uint8_t*)&settings + p));
}
}
else { // read settings from EE
for (unsigned int p=0; p<sizeof(settings); p++) // read gloabls from EE
*((uint8_t*)&settings + p) = eeprom_read_byte((uint8_t *)EE_settings + p);
}
}