-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.ino
112 lines (96 loc) · 2.37 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
//=====================================================================
// eeprom.ino
//
// Created on: 6th January 2012
// Author: Mike McPherson
//=====================================================================
#include <EEPROM.h>
// offsets into EEPROM
//====================
#define eeSERVER 0
#define eeUSERNAME 32
#define eePASSWORD 64
#define eeFTPPATH 96
#define eeWXID 128
//==============================================================
// "globals"
//==============================================================
extern uint8_t gServer[33];
extern uint8_t gUserName[33];
extern uint8_t gPassword[33];
extern uint8_t gFTPpath[33];
extern uint8_t gWxId[33];
// module to save and restore settings
// settings are stored in EEPROM
//====================================
void eepromDump(void)
{
int row;
int col;
byte oneByte;
// read entire eeprom
//===================
for (row=0; row<16; row++)
{
Serial.print("0");
Serial.print(row, HEX);
Serial.print(":");
for (col=0; col<16; col++)
{
oneByte = EEPROM.read(row*16+col);
Serial.print(" ");
if (oneByte < 16)
Serial.print("0");
Serial.print(oneByte, HEX);
}
Serial.println();
}
Serial.println();
}
void eepromRead(uint8_t *target, int offset, int size)
{
int i;
// read value from address
//========================
for (i=0; i<size; i++)
{
target[i] = EEPROM.read(offset + i);
}
target[size] = '/0';
}
void eepromReadAll(void)
{
// read saved settings from EEPROM
//================================
eepromRead(&gServer[0], eeSERVER, 32);
eepromRead(&gUserName[0], eeUSERNAME, 32);
eepromRead(&gPassword[0], eePASSWORD, 32);
eepromRead(&gFTPpath[0], eeFTPPATH, 32);
eepromRead(&gWxId[0], eeWXID, 32);
}
void eepromSaveAll(void)
{
// save all settings
//==================
eepromWrite(gServer, eeSERVER, 32);
eepromWrite(gUserName, eeUSERNAME, 32);
eepromWrite(gPassword, eePASSWORD, 32);
eepromWrite(gFTPpath, eeFTPPATH, 32);
eepromWrite(gWxId, eeWXID, 32);
}
void eepromWrite(uint8_t *target, int offset, int size)
{
int i;
// write value to next location
//=============================
for (i=0; i<size; i++)
{
// write one byte
//===============
EEPROM.write(offset + i, target[i]);
}
}
void eepromWriteByte(int address, uint8_t data)
{
EEPROM.write(address, data);
}