-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.cpp
49 lines (36 loc) · 1.6 KB
/
eeprom.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
/*
Copyright 2013 Brad Quick
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
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/>.
*/
#include <avr/eeprom.h>
#include "eeprom.h"
#include "multifly.h"
extern settingsstruct settings;
extern globalstruct global;
#define MAGICNUMBER 54321
void write_user_settings_to_eeprom() {
int magicnumber=MAGICNUMBER;
int size=sizeof(settingsstruct);
eeprom_write_block((const void*)&magicnumber, (void*)0, sizeof(magicnumber));
eeprom_write_block((const void*)&size, (void*)2, sizeof(size));
eeprom_write_block((const void*)&settings, (void*)4, size);
}
void read_user_settings_from_eeprom() {
int magicnumber=0;
unsigned int size=0;
eeprom_read_block((void*)&magicnumber, (void*)0, sizeof(magicnumber));
if (magicnumber!=MAGICNUMBER) return;
eeprom_read_block((void*)&size, (void*)2, sizeof(size));
if (size>sizeof(settingsstruct)) size=sizeof(settingsstruct);
eeprom_read_block((void*)&settings, (void*)4, size);
global.userSettingsFromEeprom=1; // set a flag so the rest of the program know it's working with calibtated settings
}