forked from mtongnz/ESP8266_ArtNetNode_DMX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.ino
186 lines (146 loc) · 4.34 KB
/
eeprom.ino
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
ESP8266_ArtNetNode_DMX - eeprom.ino
Copyright (c) 2015, Matthew Tong
https://github.com/mtongnz/ESP8266_ArtNetNode_DMX
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 3 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, see http://www.gnu.org/licenses/
*/
/* saveSettings()
* Save our variables into EEPROM
* Writes OK to 500 & 501 - use this to verify a write
*/
bool saveSettings() {
#ifdef VERBOSE
Serial.print("Saving Settings... ");
#endif
// Wipe our OK and check
EEPROM.write(500, '\0');
EEPROM.write(501, '\0');
EEPROM.commit();
if(EEPROM.read(500) != '\0'|| EEPROM.read(501) != '\0') {
#ifdef VERBOSE
Serial.println("fail!");
#endif
return false;
}
int x;
delay(100);
for(x = 0; x < 30 && nodeName[x] != '\0'; x++)
EEPROM.write(x, nodeName[x]);
EEPROM.write(x, '\0');
EEPROM.write(30, artNetUniA);
EEPROM.write(130, artNetUniB);
EEPROM.write(31, artNetSub);
for(x = 0; x < 30 && wifiSSID[x] != '\0'; x++)
EEPROM.write(32 + x, wifiSSID[x]);
EEPROM.write(32 + x, '\0');
for(x = 0; x < 30 && wifiPass[x] != '\0'; x++)
EEPROM.write(62 + x, wifiPass[x]);
EEPROM.write(62 + x, '\0');
delay(100);
EEPROM.write(92, dhcp);
EEPROM.write(93, ip[0]);
EEPROM.write(94, ip[1]);
EEPROM.write(95, ip[2]);
EEPROM.write(96, ip[3]);
EEPROM.write(97, broadcast_ip[0]);
EEPROM.write(98, broadcast_ip[1]);
EEPROM.write(99, broadcast_ip[2]);
EEPROM.write(100, broadcast_ip[3]);
EEPROM.write(101, subnet[0]);
EEPROM.write(102, subnet[1]);
EEPROM.write(103, subnet[2]);
EEPROM.write(104, subnet[3]);
EEPROM.write(106, hotSpotDelay & 0xFF);
EEPROM.write(107, (hotSpotDelay >> 8) & 0xFF);
EEPROM.write(108, standAlone);
EEPROM.write(500, 'O');
EEPROM.write(501, 'K');
delay(100);
EEPROM.commit();
delay (100);
// Verify our OK was written & return false if not
if(EEPROM.read(500) != 'O' || EEPROM.read(501) != 'K') {
#ifdef VERBOSE
Serial.println("fail!");
#endif
return false;
}
#ifdef VERBOSE
Serial.println("success!");
#endif
// Return true if all went well
return true;
}
/* loadSettings()
* Load our settings from EEPROM to our variables.
*/
bool loadSettings() {
#ifdef VERBOSE
Serial.print("Loading Settings... ");
#endif
int x;
// If no previous settings, start hotspot
if(EEPROM.read(502) != 'R') {
EEPROM.write(502, 'R');
return false;
}
hotSpotDelay = (EEPROM.read(106) & 0xFF) + ((EEPROM.read(107) << 8) & 0xFF00);
standAlone = EEPROM.read(108);
// Check if we have previous saves. If not, return false
if(EEPROM.read(500) != 'O' || EEPROM.read(501) != 'K') {
#ifdef VERBOSE
Serial.println("No previous saves.");
#endif
return false;
}
for(x = 0; x < 30; x++) {
nodeName[x] = EEPROM.read(x);
if (nodeName[x] == '\0')
break;
}
nodeName[x] = '\0';
artNetUniA = EEPROM.read(30);
artNetUniB = EEPROM.read(130);
artNetSub = EEPROM.read(31);
for(x = 0; x < 30; x++) {
wifiSSID[x] = EEPROM.read(32 + x);
if (wifiSSID[x] == '\0')
break;
}
wifiSSID[x] = '\0';
for(x = 0; x < 30; x++) {
wifiPass[x] = EEPROM.read(62 + x);
if (wifiPass[x] == '\0')
break;
}
wifiPass[x] = '\0';
dhcp = EEPROM.read(92);
// Only store IP if we're not using DHCP
if (dhcp != 1) {
ip[0] = EEPROM.read(93);
ip[1] = EEPROM.read(94);
ip[2] = EEPROM.read(95);
ip[3] = EEPROM.read(96);
broadcast_ip[0] = EEPROM.read(97);
broadcast_ip[1] = EEPROM.read(98);
broadcast_ip[2] = EEPROM.read(99);
broadcast_ip[3] = EEPROM.read(100);
subnet[0] = EEPROM.read(101);
subnet[1] = EEPROM.read(102);
subnet[2] = EEPROM.read(103);
subnet[3] = EEPROM.read(104);
}
#ifdef VERBOSE
Serial.println("success!");
#endif
artNetUniA = artNetUniA;
artNetUniB = artNetUniB;
// Return
return true;
}