|
@@ -23,7 +23,7 @@
|
23
|
23
|
/**
|
24
|
24
|
* configuration_store.cpp
|
25
|
25
|
*
|
26
|
|
- * Configuration and EEPROM storage
|
|
26
|
+ * Settings and EEPROM storage
|
27
|
27
|
*
|
28
|
28
|
* IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
|
29
|
29
|
* in the functions below, also increment the version number. This makes sure that
|
|
@@ -152,13 +152,16 @@
|
152
|
152
|
* 580 Minimum end-point
|
153
|
153
|
* 1901 (580 + 36 + 9 + 288 + 988) Maximum end-point
|
154
|
154
|
*/
|
|
155
|
+#include "configuration_store.h"
|
|
156
|
+
|
|
157
|
+MarlinSettings settings;
|
|
158
|
+
|
155
|
159
|
#include "Marlin.h"
|
156
|
160
|
#include "language.h"
|
157
|
161
|
#include "endstops.h"
|
158
|
162
|
#include "planner.h"
|
159
|
163
|
#include "temperature.h"
|
160
|
164
|
#include "ultralcd.h"
|
161
|
|
-#include "configuration_store.h"
|
162
|
165
|
|
163
|
166
|
#if ENABLED(MESH_BED_LEVELING)
|
164
|
167
|
#include "mesh_bed_leveling.h"
|
|
@@ -179,7 +182,7 @@
|
179
|
182
|
/**
|
180
|
183
|
* Post-process after Retrieve or Reset
|
181
|
184
|
*/
|
182
|
|
-void Config_Postprocess() {
|
|
185
|
+void MarlinSettings::postprocess() {
|
183
|
186
|
// steps per s2 needs to be updated to agree with units per s2
|
184
|
187
|
planner.reset_acceleration_rates();
|
185
|
188
|
|
|
@@ -217,12 +220,14 @@ void Config_Postprocess() {
|
217
|
220
|
|
218
|
221
|
#if ENABLED(EEPROM_SETTINGS)
|
219
|
222
|
|
220
|
|
- uint16_t eeprom_checksum;
|
221
|
223
|
const char version[4] = EEPROM_VERSION;
|
222
|
224
|
|
223
|
|
- bool eeprom_write_error;
|
|
225
|
+ uint16_t MarlinSettings::eeprom_checksum;
|
|
226
|
+
|
|
227
|
+ bool MarlinSettings::eeprom_write_error,
|
|
228
|
+ MarlinSettings::eeprom_read_error;
|
224
|
229
|
|
225
|
|
- void _EEPROM_writeData(int &pos, const uint8_t* value, uint16_t size) {
|
|
230
|
+ void MarlinSettings::write_data(int &pos, const uint8_t* value, uint16_t size) {
|
226
|
231
|
if (eeprom_write_error) return;
|
227
|
232
|
while (size--) {
|
228
|
233
|
uint8_t * const p = (uint8_t * const)pos;
|
|
@@ -243,8 +248,7 @@ void Config_Postprocess() {
|
243
|
248
|
value++;
|
244
|
249
|
};
|
245
|
250
|
}
|
246
|
|
- bool eeprom_read_error;
|
247
|
|
- void _EEPROM_readData(int &pos, uint8_t* value, uint16_t size) {
|
|
251
|
+ void MarlinSettings::read_data(int &pos, uint8_t* value, uint16_t size) {
|
248
|
252
|
do {
|
249
|
253
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
250
|
254
|
if (!eeprom_read_error) *value = c;
|
|
@@ -257,14 +261,14 @@ void Config_Postprocess() {
|
257
|
261
|
#define DUMMY_PID_VALUE 3000.0f
|
258
|
262
|
#define EEPROM_START() int eeprom_index = EEPROM_OFFSET
|
259
|
263
|
#define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
|
260
|
|
- #define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
|
261
|
|
- #define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
|
262
|
|
- #define EEPROM_ASSERT(TST,ERR) if () do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error |= true; }while(0)
|
|
264
|
+ #define EEPROM_WRITE(VAR) write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
|
|
265
|
+ #define EEPROM_READ(VAR) read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
|
|
266
|
+ #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
|
263
|
267
|
|
264
|
268
|
/**
|
265
|
269
|
* M500 - Store Configuration
|
266
|
270
|
*/
|
267
|
|
- bool Config_StoreSettings() {
|
|
271
|
+ bool MarlinSettings::save() {
|
268
|
272
|
float dummy = 0.0f;
|
269
|
273
|
char ver[4] = "000";
|
270
|
274
|
|
|
@@ -576,7 +580,7 @@ void Config_Postprocess() {
|
576
|
580
|
/**
|
577
|
581
|
* M501 - Retrieve Configuration
|
578
|
582
|
*/
|
579
|
|
- bool Config_RetrieveSettings() {
|
|
583
|
+ bool MarlinSettings::load() {
|
580
|
584
|
|
581
|
585
|
EEPROM_START();
|
582
|
586
|
eeprom_read_error = false; // If set EEPROM_READ won't write into RAM
|
|
@@ -597,7 +601,7 @@ void Config_Postprocess() {
|
597
|
601
|
SERIAL_ECHOPGM("EEPROM version mismatch ");
|
598
|
602
|
SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
|
599
|
603
|
SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
|
600
|
|
- Config_ResetDefault();
|
|
604
|
+ reset();
|
601
|
605
|
}
|
602
|
606
|
else {
|
603
|
607
|
float dummy = 0;
|
|
@@ -747,6 +751,11 @@ void Config_Postprocess() {
|
747
|
751
|
EEPROM_READ(lcd_preheat_bed_temp);
|
748
|
752
|
EEPROM_READ(lcd_preheat_fan_speed);
|
749
|
753
|
|
|
754
|
+ //EEPROM_ASSERT(
|
|
755
|
+ // WITHIN(lcd_preheat_fan_speed, 0, 255),
|
|
756
|
+ // "lcd_preheat_fan_speed out of range"
|
|
757
|
+ //);
|
|
758
|
+
|
750
|
759
|
#if ENABLED(PIDTEMP)
|
751
|
760
|
for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
|
752
|
761
|
EEPROM_READ(dummy); // Kp
|
|
@@ -869,9 +878,9 @@ void Config_Postprocess() {
|
869
|
878
|
|
870
|
879
|
if (eeprom_checksum == stored_checksum) {
|
871
|
880
|
if (eeprom_read_error)
|
872
|
|
- Config_ResetDefault();
|
|
881
|
+ reset();
|
873
|
882
|
else {
|
874
|
|
- Config_Postprocess();
|
|
883
|
+ postprocess();
|
875
|
884
|
SERIAL_ECHO_START;
|
876
|
885
|
SERIAL_ECHO(version);
|
877
|
886
|
SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
|
|
@@ -881,7 +890,7 @@ void Config_Postprocess() {
|
881
|
890
|
else {
|
882
|
891
|
SERIAL_ERROR_START;
|
883
|
892
|
SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
|
884
|
|
- Config_ResetDefault();
|
|
893
|
+ reset();
|
885
|
894
|
}
|
886
|
895
|
|
887
|
896
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
@@ -923,7 +932,7 @@ void Config_Postprocess() {
|
923
|
932
|
#endif
|
924
|
933
|
}
|
925
|
934
|
#if ENABLED(EEPROM_CHITCHAT)
|
926
|
|
- Config_PrintSettings();
|
|
935
|
+ report();
|
927
|
936
|
#endif
|
928
|
937
|
|
929
|
938
|
return !eeprom_read_error;
|
|
@@ -931,7 +940,7 @@ void Config_Postprocess() {
|
931
|
940
|
|
932
|
941
|
#else // !EEPROM_SETTINGS
|
933
|
942
|
|
934
|
|
- bool Config_StoreSettings() {
|
|
943
|
+ bool MarlinSettings::save() {
|
935
|
944
|
SERIAL_ERROR_START;
|
936
|
945
|
SERIAL_ERRORLNPGM("EEPROM disabled");
|
937
|
946
|
return false;
|
|
@@ -942,7 +951,7 @@ void Config_Postprocess() {
|
942
|
951
|
/**
|
943
|
952
|
* M502 - Reset Configuration
|
944
|
953
|
*/
|
945
|
|
-void Config_ResetDefault() {
|
|
954
|
+void MarlinSettings::reset() {
|
946
|
955
|
const float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] = DEFAULT_MAX_FEEDRATE;
|
947
|
956
|
const uint32_t tmp3[] = DEFAULT_MAX_ACCELERATION;
|
948
|
957
|
LOOP_XYZE_N(i) {
|
|
@@ -1118,7 +1127,7 @@ void Config_ResetDefault() {
|
1118
|
1127
|
#endif
|
1119
|
1128
|
#endif
|
1120
|
1129
|
|
1121
|
|
- Config_Postprocess();
|
|
1130
|
+ postprocess();
|
1122
|
1131
|
|
1123
|
1132
|
SERIAL_ECHO_START;
|
1124
|
1133
|
SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
|
|
@@ -1129,10 +1138,11 @@ void Config_ResetDefault() {
|
1129
|
1138
|
#define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START; }while(0)
|
1130
|
1139
|
|
1131
|
1140
|
/**
|
1132
|
|
- * M503 - Print Configuration
|
|
1141
|
+ * M503 - Report current settings in RAM
|
|
1142
|
+ *
|
|
1143
|
+ * Unless specifically disabled, M503 is available even without EEPROM
|
1133
|
1144
|
*/
|
1134
|
|
- void Config_PrintSettings(bool forReplay) {
|
1135
|
|
- // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
|
|
1145
|
+ void MarlinSettings::report(bool forReplay) {
|
1136
|
1146
|
|
1137
|
1147
|
CONFIG_ECHO_START;
|
1138
|
1148
|
|