forked from euphy/polargraph_server_a1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eeprom.ino
162 lines (138 loc) · 3.83 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
/**
* Polargraph Server. - CORE
* Written by Sandy Noble
* Released under GNU License version 3.
* http://www.polargraph.co.uk
* https://github.com/euphy/polargraph_server_a1
EEPROM.
This is one of the core files for the polargraph server program.
Has a couple of little helper methods for reading and writing
ints and floats to EEPROM using the EEPROM library.
But mostly it contains the loadMachineSpecFromEeprom method, which is
used to retrieve the machines saved values when it restarts, or
whenever a value is written to the EEPROM.
*/
void eeprom_resetEeprom()
{
for (int i = 0; i <50; i++)
{
EEPROM.write(i, 0);
}
eeprom_loadMachineSpecFromEeprom();
}
void eeprom_dumpEeprom()
{
for (int i = 0; i <40; i++)
{
Serial.print(i);
Serial.print(". ");
Serial.println(EEPROM.read(i));
}
}
void eeprom_loadMachineSize()
{
EEPROM_readAnything(EEPROM_MACHINE_WIDTH, machineWidth);
if (machineWidth < 1)
{
machineWidth = defaultMachineWidth;
}
Serial.print(F("Loaded width:"));
Serial.println(machineWidth);
EEPROM_readAnything(EEPROM_MACHINE_HEIGHT, machineHeight);
if (machineHeight < 1)
{
machineHeight = defaultMachineHeight;
}
Serial.print(F("Loaded height:"));
Serial.println(machineHeight);
}
void eeprom_loadSpoolSpec()
{
EEPROM_readAnything(EEPROM_MACHINE_MM_PER_REV, mmPerRev);
if (mmPerRev < 1)
{
mmPerRev = defaultMmPerRev;
}
Serial.print(F("Loaded mmPerRev:"));
Serial.println(mmPerRev);
EEPROM_readAnything(EEPROM_MACHINE_STEPS_PER_REV, motorStepsPerRev);
if (motorStepsPerRev < 1)
{
motorStepsPerRev = defaultStepsPerRev;
}
Serial.print(F("Loaded steps per rev:"));
Serial.println(motorStepsPerRev);
}
void eeprom_loadPenLiftRange()
{
EEPROM_readAnything(EEPROM_PENLIFT_DOWN, downPosition);
if (downPosition < 0)
{
downPosition = DEFAULT_DOWN_POSITION;
}
Serial.print(F("Loaded down pos:"));
Serial.println(downPosition);
EEPROM_readAnything(EEPROM_PENLIFT_UP, upPosition);
if (upPosition < 0)
{
upPosition = DEFAULT_UP_POSITION;
}
Serial.print(F("Loaded up pos:"));
Serial.println(upPosition);
}
void eeprom_loadStepMultiplier()
{
EEPROM_readAnything(EEPROM_MACHINE_STEP_MULTIPLIER, stepMultiplier);
if (stepMultiplier < 1)
{
stepMultiplier = defaultStepMultiplier;
}
Serial.print(F("Loaded step multiplier:"));
Serial.println(stepMultiplier);
}
void eeprom_loadSpeed()
{
// load speed, acceleration
EEPROM_readAnything(EEPROM_MACHINE_MOTOR_SPEED, currentMaxSpeed);
// not sure why this requires a cast to int for the comparision, but a
// if (currentMaxSpeed < 1.0) wasn't catching cases where
// currentMaxSpeed == 0.00, ODD.
if (int(currentMaxSpeed) < 1) {
currentMaxSpeed = 800.0;
}
EEPROM_readAnything(EEPROM_MACHINE_MOTOR_ACCEL, currentAcceleration);
if (int(currentAcceleration) < 1) {
currentAcceleration = 800.0;
}
}
void eeprom_loadMachineSpecFromEeprom()
{
impl_loadMachineSpecFromEeprom();
eeprom_loadMachineSize();
eeprom_loadSpoolSpec();
eeprom_loadStepMultiplier();
eeprom_loadPenLiftRange();
eeprom_loadSpeed();
// load penwidth
EEPROM_readAnything(EEPROM_MACHINE_PEN_WIDTH, penWidth);
if (penWidth < 0.0001)
penWidth = 0.8;
mmPerStep = mmPerRev / multiplier(motorStepsPerRev);
stepsPerMM = multiplier(motorStepsPerRev) / mmPerRev;
Serial.print(F("Recalc mmPerStep ("));
Serial.print(mmPerStep);
Serial.print(F("), stepsPerMM ("));
Serial.print(stepsPerMM);
Serial.println(F(")"));
pageWidth = machineWidth * stepsPerMM;
Serial.print(F("Recalc pageWidth in steps ("));
Serial.print(pageWidth);
Serial.println(F(")"));
pageHeight = machineHeight * stepsPerMM;
Serial.print(F("Recalc "));
Serial.print(F("pageHeight in steps ("));
Serial.print(pageHeight);
Serial.print(F(")"));
Serial.println();
maxLength = 0;
}