-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaverecall.ino
122 lines (105 loc) · 2.3 KB
/
saverecall.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
#include "ursabb.h"
void recallSettings() {
byte counter = 0;
kP_angle = EEPROMreadFloat(counter);
kI_angle = EEPROMreadFloat(counter);
kD_angle = EEPROMreadFloat(counter);
kP_speed = EEPROMreadFloat(counter);
kI_speed = EEPROMreadFloat(counter);
kD_speed = EEPROMreadFloat(counter);
pitchOffset = EEPROMreadFloat(counter);
if (pitchOffset != pitchOffset) {//NaN check
pitchOffset = 0;
}
if (kP_angle != kP_angle) {//NaN check
kP_angle = 0;
}
if (kI_angle != kI_angle) {//NaN check
kI_angle = 0;
}
if (kD_angle != kD_angle) {//NaN check
kD_angle = 0;
}
if (kP_speed != kP_speed) {//NaN check
kP_speed = 0;
}
if (kI_speed != kI_speed) {//NaN check
kI_speed = 0;
}
if (kD_speed != kD_speed) {//NaN check
kD_speed = 0;
}
}
void saveSettings() {
byte counter = 0;
EEPROMwriteFloat(kP_angle, counter);
EEPROMwriteFloat(kI_angle, counter);
EEPROMwriteFloat(kD_angle, counter);
EEPROMwriteFloat(kP_speed, counter);
EEPROMwriteFloat(kI_speed, counter);
EEPROMwriteFloat(kD_speed, counter);
EEPROMwriteFloat(pitchOffset, counter);
EEPROM.commit();
}
boolean EEPROMreadBoolean(byte &pos) {
byte msg = byte(EEPROM.read(pos));
pos++;
return (msg == 1);
}
byte EEPROMreadByte(byte &pos) {
byte msg = byte(EEPROM.read(pos));
pos++;
return msg;
}
int EEPROMreadInt(byte &pos) {
union {
byte b[4];
int v;
} d;
for (int i = 0; i < 4; i++) {
d.b[i] = byte(EEPROM.read(pos));
pos++;
}
return d.v;
}
float EEPROMreadFloat(byte &pos) {
union {
byte b[4];
float v;
} d;
for (int i = 0; i < 4; i++) {
d.b[i] = byte(EEPROM.read(pos));
pos++;
}
return d.v;
}
void EEPROMwriteBool(boolean msg, byte &pos) {
EEPROM.write(pos, msg);
pos++;
}
void EEPROMwriteByte(byte msg, byte &pos) {
EEPROM.write(pos, msg);
pos++;
}
void EEPROMwriteInt(int msg, byte &pos) {
union {
byte b[4];
int v;
} d;
d.v = msg;
for (int i = 0; i < 4; i++) {
EEPROM.write(pos, d.b[i]);
pos++;
}
}
void EEPROMwriteFloat(float msg, byte &pos) {
union {
byte b[4];
float v;
} d;
d.v = msg;
for (int i = 0; i < 4; i++) {
EEPROM.write(pos, d.b[i]);
pos++;
}
}