forked from mriscoc/Ender3V2S1
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsettings.cpp
More file actions
4379 lines (3812 loc) · 125 KB
/
settings.cpp
File metadata and controls
4379 lines (3812 loc) · 125 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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
* (at your option) 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 <https://www.gnu.org/licenses/>.
*
*/
/**
* settings.cpp
*
* Settings and EEPROM storage
*
* IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
* in the functions below, also increment the version number. This makes sure that
* the default values are used whenever there is a change to the data, to prevent
* wrong data being written to the variables.
*
* ALSO: Variables in the Store and Retrieve sections must be in the same order.
* If a feature is disabled, some data must still be written that, when read,
* either sets a Sane Default, or results in No Change to the existing value.
*/
// Change EEPROM version if the structure changes
#define EEPROM_VERSION "V90"
#define EEPROM_OFFSET 100
// Check the integrity of data offsets.
// Can be disabled for production build.
//#define DEBUG_EEPROM_READWRITE
//#define DEBUG_EEPROM_OBSERVE
#include "settings.h"
#include "endstops.h"
#include "planner.h"
#include "stepper.h"
#include "temperature.h"
#include "../lcd/marlinui.h"
#include "../libs/vector_3.h" // for matrix_3x3
#include "../gcode/gcode.h"
#include "../MarlinCore.h"
#if ANY(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
#include "../HAL/shared/eeprom_api.h"
#endif
#if HAS_SPINDLE_ACCELERATION
#include "../feature/spindle_laser.h"
#endif
#if HAS_BED_PROBE
#include "probe.h"
#endif
#if HAS_LEVELING
#include "../feature/bedlevel/bedlevel.h"
#if ENABLED(X_AXIS_TWIST_COMPENSATION)
#include "../feature/x_twist.h"
#endif
#endif
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
#include "../feature/z_stepper_align.h"
#endif
#if ENABLED(DWIN_LCD_PROUI)
#include "../lcd/e3v2/proui/dwin.h"
#include "../lcd/e3v2/proui/bedlevel_tools.h"
#endif
#if ENABLED(EXTENSIBLE_UI)
#include "../lcd/extui/ui_api.h"
#endif
#if ENABLED(HOST_PROMPT_SUPPORT)
#include "../feature/host_actions.h"
#endif
#if HAS_SERVOS
#include "servo.h"
#endif
#include "../feature/fwretract.h"
#if ENABLED(POWER_LOSS_RECOVERY)
#include "../feature/powerloss.h"
#endif
#if HAS_POWER_MONITOR
#include "../feature/power_monitor.h"
#endif
#include "../feature/pause.h"
#if ENABLED(BACKLASH_COMPENSATION)
#include "../feature/backlash.h"
#endif
#if ENABLED(FT_MOTION)
#include "../module/ft_motion.h"
#endif
#if HAS_FILAMENT_SENSOR
#include "../feature/runout.h"
#ifndef FIL_RUNOUT_ENABLED_DEFAULT
#define FIL_RUNOUT_ENABLED_DEFAULT true
#endif
#endif
#if ENABLED(ADVANCE_K_EXTRA)
extern float other_extruder_advance_K[EXTRUDERS];
#endif
#if HAS_MULTI_EXTRUDER
#include "tool_change.h"
void M217_report(const bool eeprom);
#endif
#if ENABLED(BLTOUCH)
#include "../feature/bltouch.h"
#endif
#if HAS_TRINAMIC_CONFIG
#include "stepper/indirection.h"
#include "../feature/tmc_util.h"
#endif
#if HAS_PTC
#include "../feature/probe_temp_comp.h"
#endif
#include "../feature/controllerfan.h"
#if ENABLED(CASE_LIGHT_ENABLE)
#include "../feature/caselight.h"
#endif
#if ENABLED(PASSWORD_FEATURE)
#include "../feature/password/password.h"
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../lcd/tft_io/touch_calibration.h"
#endif
#if HAS_ETHERNET
#include "../feature/ethernet.h"
#endif
#if ENABLED(SOUND_MENU_ITEM)
#include "../libs/buzzer.h"
#endif
#if HAS_FANCHECK
#include "../feature/fancheck.h"
#endif
#if DGUS_LCD_UI_MKS
#include "../lcd/extui/dgus/DGUSScreenHandler.h"
#include "../lcd/extui/dgus/DGUSDisplayDef.h"
#endif
#if ENABLED(HOTEND_IDLE_TIMEOUT)
#include "../feature/hotend_idle.h"
#endif
#if HAS_PRUSA_MMU3
#include "../feature/mmu3/mmu3.h"
#include "../feature/mmu3/SpoolJoin.h"
#include "../feature/mmu3/mmu3_reporting.h"
#endif
#pragma pack(push, 1) // No padding between variables
#define _EN_ITEM(N) , E##N
#define _EN1_ITEM(N) , E##N:1
typedef struct { uint16_t MAIN_AXIS_NAMES_ X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint16_t;
typedef struct { uint32_t MAIN_AXIS_NAMES_ X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint32_t;
typedef struct { int16_t MAIN_AXIS_NAMES_ X2, Y2, Z2, Z3, Z4; } mot_stepper_int16_t;
typedef struct { bool NUM_AXIS_LIST_(X:1, Y:1, Z:1, I:1, J:1, K:1, U:1, V:1, W:1) X2:1, Y2:1, Z2:1, Z3:1, Z4:1 REPEAT(E_STEPPERS, _EN1_ITEM); } per_stepper_bool_t;
#undef _EN_ITEM
// Defaults for reset / fill in on load
static const uint32_t _DMA[] PROGMEM = DEFAULT_MAX_ACCELERATION;
static const feedRate_t _DMF[] PROGMEM = DEFAULT_MAX_FEEDRATE;
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
static const float _DASU[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT;
#endif
/**
* Current EEPROM Layout
*
* Keep this data structure up to date so
* EEPROM size is known at compile time!
*/
typedef struct SettingsDataStruct {
char version[4]; // Vnn\0
#if ENABLED(EEPROM_INIT_NOW)
uint32_t build_hash; // Unique build hash
#endif
uint16_t crc; // Data Checksum for validation
uint16_t data_size; // Data Size for validation
//
// DISTINCT_E_FACTORS
//
uint8_t e_factors; // DISTINCT_AXES - NUM_AXES
//
// Planner settings
//
planner_settings_t planner_settings;
xyze_float_t planner_max_jerk; // M205 XYZE planner.max_jerk
float planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
//
// Home Offset
//
#if NUM_AXES //&& DISABLED(NO_HOME_OFFSETS)
xyz_pos_t home_offset; // M206 XYZ / M665 PTZ
#endif
//
// Hotend Offset
//
#if HAS_HOTEND_OFFSET
xyz_pos_t hotend_offset[HOTENDS - 1]; // M218 XYZ
#endif
//
// Spindle Acceleration
//
#if HAS_SPINDLE_ACCELERATION
uint32_t acceleration_spindle; // cutter.acceleration_spindle_deg_per_s2
#endif
//
// FILAMENT_RUNOUT_SENSOR
//
bool runout_sensor_enabled; // M412 S
float runout_distance_mm; // M412 D
//
// ENABLE_LEVELING_FADE_HEIGHT
//
float planner_z_fade_height; // M420 Zn planner.z_fade_height
//
// AUTOTEMP
//
#if ENABLED(AUTOTEMP)
celsius_t planner_autotemp_max, planner_autotemp_min;
float planner_autotemp_factor;
#endif
//
// MESH_BED_LEVELING
//
float mbl_z_offset; // bedlevel.z_offset
uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
uint16_t mesh_check; // Hash to check against X/Y
#if ANY(PROUI_EX, PROUI_GRID_PNTS)
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_LIMIT, 3)] // bedlevel.z_values
[TERN(MESH_BED_LEVELING, GRID_LIMIT, 3)];
#else
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // bedlevel.z_values
[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
#endif
//
// Probe XYZ Offsets
//
#if NUM_AXES
xyz_pos_t probe_offset; // M851 X Y Z
#endif
//
// Planar Bed Leveling matrix
//
matrix_3x3 planner_bed_level_matrix; // planner.bed_level_matrix
//
// AUTO_BED_LEVELING_BILINEAR
//
uint8_t grid_max_x, grid_max_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
uint16_t grid_check; // Hash to check against X/Y
xy_pos_t bilinear_grid_spacing, bilinear_start; // G29 L F
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bed_mesh_t z_values; // G29
#else
float z_values[3][3];
#endif
//
// X Axis Twist Compensation
//
#if ENABLED(X_AXIS_TWIST_COMPENSATION)
float xatc_spacing; // M423 X Z
float xatc_start;
xatc_array_t xatc_z_offset;
#endif
//
// AUTO_BED_LEVELING_UBL
//
bool planner_leveling_active; // M420 S planner.leveling_active
int8_t ubl_storage_slot; // bedlevel.storage_slot
//
// Servo Angles
//
#if HAS_SERVO_ANGLES
uint16_t servo_angles[NUM_SERVOS][2]; // M281 P L U
#endif
//
// Probe Temperature Compensation
//
#if HAS_PTC
#if ENABLED(PTC_PROBE)
int16_t z_offsets_probe[COUNT(ptc.z_offsets_probe)]; // M871 P I V
#endif
#if ENABLED(PTC_BED)
int16_t z_offsets_bed[COUNT(ptc.z_offsets_bed)]; // M871 B I V
#endif
#if ENABLED(PTC_HOTEND)
int16_t z_offsets_hotend[COUNT(ptc.z_offsets_hotend)]; // M871 E I V
#endif
#endif
//
// BLTOUCH
//
#if ENABLED(BLTOUCH)
bool bltouch_od_5v_mode;
#if HAS_BLTOUCH_HS_MODE
bool bltouch_high_speed_mode; // M401 S
#endif
#endif
//
// Kinematic Settings (Delta, SCARA, TPARA, Polargraph...)
//
#if IS_KINEMATIC
float segments_per_second; // M665 S
#if ENABLED(DELTA)
float delta_height; // M666 H
abc_float_t delta_endstop_adj; // M666 X Y Z
float delta_radius, // M665 R
delta_diagonal_rod; // M665 L
abc_float_t delta_tower_angle_trim, // M665 X Y Z
delta_diagonal_rod_trim; // M665 A B C
#elif ENABLED(POLARGRAPH)
xy_pos_t draw_area_min, draw_area_max; // M665 L R T B
float polargraph_max_belt_len; // M665 H
#endif
#endif
//
// Extra Endstop adjustment
//
#if HAS_EXTRA_ENDSTOPS
float x2_endstop_adj, // M666 X
y2_endstop_adj, // M666 Y
z2_endstop_adj, // M666 (S2) Z
z3_endstop_adj, // M666 (S3) Z
z4_endstop_adj; // M666 (S4) Z
#endif
//
// Z Auto-Align
//
#if ENABLED(Z_STEPPER_AUTO_ALIGN)
xy_pos_t z_stepper_align_xy[NUM_Z_STEPPERS]; // M422 S X Y
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
xy_pos_t z_stepper_align_stepper_xy[NUM_Z_STEPPERS]; // M422 W X Y
#endif
#endif
//
// Material heatup parameters
//
#if HAS_PREHEAT
preheat_t ui_material_preset[PREHEAT_COUNT]; // M145 S0 H B F
#endif
//
// PIDTEMP
//
raw_pidcf_t hotendPID[HOTENDS]; // M301 En PIDCF / M303 En U
int16_t lpq_len; // M301 L
//
// PIDTEMPBED
//
raw_pid_t bedPID; // M304 PID / M303 E-1 U
//
// PIDTEMPCHAMBER
//
raw_pid_t chamberPID; // M309 PID / M303 E-2 U
//
// User-defined Thermistors
//
#if HAS_USER_THERMISTORS
user_thermistor_t user_thermistor[USER_THERMISTORS]; // M305 P0 R4700 T100000 B3950
#endif
//
// Power Monitor
//
#if HAS_POWER_MONITOR
uint8_t power_monitor_flags; // M430 I V W
#endif
//
// LCD Contrast
//
#if HAS_LCD_CONTRAST
uint8_t lcd_contrast; // M250 C
#endif
//
// LCD_BRIGHTNESS
//
uint8_t lcd_brightness; // M256 B
//
// Display Sleep
//
#if ENABLED(EDITABLE_DISPLAY_TIMEOUT)
#if HAS_BACKLIGHT_TIMEOUT
uint8_t backlight_timeout_minutes; // M255 S
#elif HAS_DISPLAY_SLEEP
uint8_t sleep_timeout_minutes; // M255 S
#endif
#endif
//
// Controller fan
//
controllerFan_settings_t controllerFan_settings; // M710
//
// Power-Loss Recovery
//
#if ENABLED(POWER_LOSS_RECOVERY)
bool recovery_enabled; // M413 S
celsius_t bed_temp_threshold; // M413 B
#endif
//
// Firmware Retraction
//
fwretract_settings_t fwretract_settings; // M207 S F Z W, M208 S F W R
bool autoretract_enabled; // M209 S
//
// EDITABLE_HOMING_FEEDRATE
//
#if ENABLED(EDITABLE_HOMING_FEEDRATE)
xyz_feedrate_t homing_feedrate_mm_m; // M210 X Y Z I J K U V W
#endif
//
// TMC Homing Current
//
#if ENABLED(EDITABLE_HOMING_CURRENT)
homing_current_t homing_current_mA; // M920 X Y Z...
#endif
//
// Volumetric Extrusion & Filament Diameter
//
bool parser_volumetric_enabled; // M200 S parser.volumetric_enabled
float planner_filament_size[EXTRUDERS]; // M200 T D planner.filament_size[]
float planner_volumetric_extruder_limit[EXTRUDERS]; // M200 T L planner.volumetric_extruder_limit[]
//
// TMC Stepper Current
//
#if HAS_TRINAMIC_CONFIG
per_stepper_uint16_t tmc_stepper_current; // M906 X Y Z...
per_stepper_uint32_t tmc_hybrid_threshold; // M913 X Y Z...
mot_stepper_int16_t tmc_sgt; // M914 X Y Z...
per_stepper_bool_t tmc_stealth_enabled; // M569 X Y Z...
#endif
//
// Linear Advance
//
#if ENABLED(LIN_ADVANCE)
float planner_extruder_advance_K[DISTINCT_E]; // M900 K planner.extruder_advance_K
#if ENABLED(SMOOTH_LIN_ADVANCE)
float stepper_extruder_advance_tau[DISTINCT_E]; // M900 U stepper.extruder_advance_tau
#endif
#endif
//
// Stepper Motors Current
//
#ifndef MOTOR_CURRENT_COUNT
#if HAS_MOTOR_CURRENT_PWM
#define MOTOR_CURRENT_COUNT 3
#elif HAS_MOTOR_CURRENT_DAC
#define MOTOR_CURRENT_COUNT LOGICAL_AXES
#elif HAS_MOTOR_CURRENT_I2C
#define MOTOR_CURRENT_COUNT DIGIPOT_I2C_NUM_CHANNELS
#else // HAS_MOTOR_CURRENT_SPI
#define MOTOR_CURRENT_COUNT DISTINCT_AXES
#endif
#endif
uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E ...
//
// Adaptive Step Smoothing state
//
#if ENABLED(ADAPTIVE_STEP_SMOOTHING_TOGGLE)
bool adaptive_step_smoothing_enabled; // G-code pending
#endif
//
// CNC Coordinate Systems
//
#if NUM_AXES
xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS]; // G54-G59.3
#endif
//
// Skew Factor
//
#if ENABLED(SKEW_CORRECTION)
skew_factor_t planner_skew_factor; // M852 I J K
#endif
//
// Filament load/unload
//
#if ENABLED(CONFIGURE_FILAMENT_CHANGE)
fil_change_settings_t fc_settings[EXTRUDERS]; // M603 T U L
#endif
//
// Tool-changing
//
#if HAS_MULTI_EXTRUDER
toolchange_settings_t toolchange_settings; // M217 S P R
#endif
//
// Backlash Compensation
//
#if NUM_AXES //&& ENABLED(BACKLASH_GCODE)
xyz_float_t backlash_distance_mm; // M425 X Y Z
uint8_t backlash_correction; // M425 F
float backlash_smoothing_mm; // M425 S
#endif
//
// EXTENSIBLE_UI
//
#if ENABLED(EXTENSIBLE_UI)
uint8_t extui_data[ExtUI::eeprom_data_size];
#endif
//
// DWIN ProUI User Data
//
#if ENABLED(DWIN_LCD_PROUI)
#if ENABLED(PROUI_MESH_EDIT)
MeshSet_t meshSet;
#endif
uint8_t dwin_data[eeprom_data_size];
#endif
//
// Case Light Brightness
//
#if CASELIGHT_USES_BRIGHTNESS
uint8_t caselight_brightness; // M355 P
#endif
//
// CONFIGURABLE_MACHINE_NAME
//
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
TString machine_name; // M550 P
#endif
//
// Password feature
//
#if ENABLED(PASSWORD_FEATURE)
bool password_is_set;
uint32_t password_value;
#endif
//
// Touch Screen Calibration
//
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
touch_calibration_t touch_calibration_data;
#endif
//
// Ethernet settings
//
#if HAS_ETHERNET
bool ethernet_hardware_enabled; // M552 S
uint32_t ethernet_ip, // M552 P
ethernet_dns,
ethernet_gateway, // M553 P
ethernet_subnet; // M554 P
#endif
//
// Buzzer enable/disable
//
#if ENABLED(SOUND_MENU_ITEM)
bool sound_on;
bool tick_on; //encoder beep
#endif
//
// Bed corner screw position
//
#ifdef BED_SCREW_INSET
float ui_screw_pos;
#endif
//
// Encoder Rate
//
#if ALL(ENCODER_RATE_MULTIPLIER, ENC_MENU_ITEM)
uint16_t enc_rateA;
uint16_t enc_rateB;
#endif
#if ENABLED(PROUI_ITEM_ENC)
bool rev_rate;
#endif
//
// Toggle the meshviwer
//
#if ALL(DWIN_LCD_PROUI, HAS_MESH, USE_GRID_MESHVIEWER)
bool view_mesh;
#endif
//
// Fan tachometer check
//
#if HAS_FANCHECK
bool fan_check_enabled;
#endif
//
// MKS UI controller
//
#if DGUS_LCD_UI_MKS
MKS_Language mks_language_index; // Display Language
xy_int_t mks_corner_offsets[5]; // Bed Tramming
xyz_int_t mks_park_pos; // Custom Parking (without NOZZLE_PARK)
celsius_t mks_min_extrusion_temp; // Min E Temp (shadow M302 value)
#endif
//
// UI Language
//
#if HAS_MULTI_LANGUAGE
uint8_t ui_language; // M414 S
#endif
//
// Model Predictive Control
//
#if ENABLED(MPCTEMP)
MPC_t mpc_constants[HOTENDS]; // M306
#endif
//
// Fixed-Time Motion
//
#if ENABLED(FT_MOTION)
ft_config_t ftMotion_cfg; // M493
#endif
//
// Input Shaping
//
#if ENABLED(INPUT_SHAPING_X)
float shaping_x_frequency, // M593 X F
shaping_x_zeta; // M593 X D
#endif
#if ENABLED(INPUT_SHAPING_Y)
float shaping_y_frequency, // M593 Y F
shaping_y_zeta; // M593 Y D
#endif
#if ENABLED(INPUT_SHAPING_Z)
float shaping_z_frequency, // M593 Z F
shaping_z_zeta; // M593 Z D
#endif
//
// Hotend Idle Timeout
//
#if ENABLED(HOTEND_IDLE_TIMEOUT)
hotend_idle_settings_t hotend_idle_config; // M86 S T E B
#endif
//
// Nonlinear Extrusion
//
#if ENABLED(NONLINEAR_EXTRUSION)
nonlinear_settings_t stepper_ne_settings; // M592 S A B C
#endif
//
// MMU3
//
#if HAS_PRUSA_MMU3
bool spool_join_enabled; // EEPROM_SPOOL_JOIN
uint16_t fail_total_num; // EEPROM_MMU_FAIL_TOT
uint8_t fail_num; // EEPROM_MMU_FAIL
uint16_t load_fail_total_num; // EEPROM_MMU_LOAD_FAIL_TOT
uint8_t load_fail_num; // EEPROM_MMU_LOAD_FAIL
uint16_t tool_change_counter;
uint32_t tool_change_total_counter; // EEPROM_MMU_MATERIAL_CHANGES
uint8_t cutter_mode; // EEPROM_MMU_CUTTER_ENABLED
uint8_t stealth_mode; // EEPROM_MMU_STEALTH
bool mmu_hw_enabled; // EEPROM_MMU_ENABLED
// uint32_t material_changes
#endif
} SettingsData;
//static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!");
MarlinSettings settings;
uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
/**
* Post-process after Retrieve or Reset
*/
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float new_z_fade_height;
#endif
void MarlinSettings::postprocess() {
xyze_pos_t oldpos = current_position;
// steps per s2 needs to be updated to agree with units per s2
planner.refresh_acceleration_rates();
// Make sure delta kinematics are updated before refreshing the
// planner position so the stepper counts will be set correctly.
TERN_(DELTA, recalc_delta_settings());
TERN_(PIDTEMP, thermalManager.updatePID());
#if DISABLED(NO_VOLUMETRICS)
planner.calculate_volumetric_multipliers();
#elif EXTRUDERS
for (uint8_t i = COUNT(planner.e_factor); i--;)
planner.refresh_e_factor(i);
#endif
// Software endstops depend on home_offset
LOOP_NUM_AXES(i) update_software_endstops((AxisEnum)i);
TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
TERN_(FWRETRACT, fwretract.refresh_autoretract());
TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.update_brightness());
TERN_(EXTENSIBLE_UI, ExtUI::onPostprocessSettings());
// Refresh mm_per_step with the reciprocal of axis_steps_per_mm
// and init stepper.count[], planner.position[] with current_position
planner.refresh_positioning();
// Various factors can change the current position
if (oldpos != current_position)
report_current_position();
// Moved as last update due to interference with NeoPixel init
TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast());
TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness());
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
TERN_(HAS_DISPLAY_SLEEP, ui.refresh_screen_timeout());
}
#if ALL(PRINTCOUNTER, EEPROM_SETTINGS)
#include "printcounter.h"
static_assert(
!WITHIN(STATS_EEPROM_ADDRESS, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)) &&
!WITHIN(STATS_EEPROM_ADDRESS + sizeof(printStatistics), EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
"STATS_EEPROM_ADDRESS collides with EEPROM settings storage."
);
#endif
#if ENABLED(SD_FIRMWARE_UPDATE)
#if ENABLED(EEPROM_SETTINGS)
static_assert(
!WITHIN(SD_FIRMWARE_UPDATE_EEPROM_ADDR, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
"SD_FIRMWARE_UPDATE_EEPROM_ADDR collides with EEPROM settings storage."
);
#endif
bool MarlinSettings::sd_update_status() {
uint8_t val;
int pos = SD_FIRMWARE_UPDATE_EEPROM_ADDR;
persistentStore.read_data(pos, &val);
return (val == SD_FIRMWARE_UPDATE_ACTIVE_VALUE);
}
bool MarlinSettings::set_sd_update_status(const bool enable) {
if (enable != sd_update_status())
persistentStore.write_data(
SD_FIRMWARE_UPDATE_EEPROM_ADDR,
enable ? SD_FIRMWARE_UPDATE_ACTIVE_VALUE : SD_FIRMWARE_UPDATE_INACTIVE_VALUE
);
return true;
}
#endif // SD_FIRMWARE_UPDATE
#ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
static_assert(EEPROM_OFFSET + sizeof(SettingsData) < ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE,
"ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE is insufficient to capture all EEPROM data.");
#endif
//
// This file simply uses the DEBUG_ECHO macros to implement EEPROM_CHITCHAT.
// For deeper debugging of EEPROM issues enable DEBUG_EEPROM_READWRITE.
//
#define DEBUG_OUT ANY(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
#include "../core/debug_out.h"
#if ALL(EEPROM_CHITCHAT, HOST_PROMPT_SUPPORT)
#define HOST_EEPROM_CHITCHAT 1
#endif
#if ENABLED(EEPROM_SETTINGS)
#define EEPROM_ASSERT(TST,ERR) do { if (!(TST)) { SERIAL_WARN_MSG(ERR); eeprom_error = ERR_EEPROM_SIZE; } } while (0)
#define TWO_BYTE_HASH(A,B) uint16_t((uint16_t(A ^ 0xC3) << 4) ^ (uint16_t(B ^ 0xC3) << 12))
#define EEPROM_OFFSETOF(FIELD) (EEPROM_OFFSET + offsetof(SettingsData, FIELD))
#if ENABLED(DEBUG_EEPROM_READWRITE)
#define _FIELD_TEST(FIELD) \
SERIAL_ECHOLNPGM("Field: " STRINGIFY(FIELD)); \
EEPROM_ASSERT( \
eeprom_error || eeprom_index == EEPROM_OFFSETOF(FIELD), \
"Field " STRINGIFY(FIELD) " mismatch." \
)
#else
#define _FIELD_TEST(FIELD) NOOP
#endif
#if ENABLED(DEBUG_EEPROM_OBSERVE)
#define EEPROM_READ(V...) do { SERIAL_ECHOLNPGM("READ: ", F(STRINGIFY(FIRST(V)))); EEPROM_READ_(V); } while (0)
#define EEPROM_READ_ALWAYS(V...) do { SERIAL_ECHOLNPGM("READ: ", F(STRINGIFY(FIRST(V)))); EEPROM_READ_ALWAYS_(V); } while (0)
#else
#define EEPROM_READ(V...) EEPROM_READ_(V)
#define EEPROM_READ_ALWAYS(V...) EEPROM_READ_ALWAYS_(V)
#endif
constexpr char version_str[4] = EEPROM_VERSION;
#if ENABLED(EEPROM_INIT_NOW)
constexpr uint32_t strhash32(const char *s, const uint32_t h=0) {
return *s ? strhash32(s + 1, ((h + *s) << (*s & 3)) ^ *s) : h;
}
constexpr uint32_t build_hash = strhash32(__DATE__ __TIME__);
#endif
bool MarlinSettings::validating;
int MarlinSettings::eeprom_index;
uint16_t MarlinSettings::working_crc;
EEPROM_Error MarlinSettings::size_error(const uint16_t size) {
if (size != datasize()) {
DEBUG_WARN_MSG("EEPROM datasize error."
#if ENABLED(MARLIN_DEV_MODE)
" (Actual:", size, " Expected:", datasize(), ")"
#endif
);
return ERR_EEPROM_SIZE;
}
return ERR_EEPROM_NOERR;
}
/**
* M500 - Store Configuration
*/
bool MarlinSettings::save() {
float dummyf = 0;
if (!EEPROM_START(EEPROM_OFFSET)) return false;
EEPROM_Error eeprom_error = ERR_EEPROM_NOERR;
// Write or Skip version. (Flash doesn't allow rewrite without erase.)
constexpr char dummy_version[] = "ERR";
TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(dummy_version);
#if ENABLED(EEPROM_INIT_NOW)
EEPROM_SKIP(build_hash); // Skip the hash slot which will be written later
#endif
EEPROM_SKIP(working_crc); // Skip the checksum slot
//
// Clear after skipping CRC and before writing the CRC'ed data
//
working_crc = 0;
//
// Write the size of the data structure for use in validation
//
const uint16_t data_size = datasize();
EEPROM_WRITE(data_size);
//
// DISTINCT_E_FACTORS
//
const uint8_t e_factors = DISTINCT_AXES - (NUM_AXES);
_FIELD_TEST(e_factors);
EEPROM_WRITE(e_factors);
//
// Planner Motion
//
{
EEPROM_WRITE(planner.settings);
#if ENABLED(CLASSIC_JERK)
EEPROM_WRITE(planner.max_jerk);
#else
const xyze_pos_t planner_max_jerk = LOGICAL_AXIS_ARRAY(10, 10, 10, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4);
EEPROM_WRITE(planner_max_jerk);
#endif
TERN_(CLASSIC_JERK, dummyf = 0.02f);
EEPROM_WRITE(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm));
}
//
// Home Offset
//
#if NUM_AXES// && DISABLED(NO_HOME_OFFSETS)
{
_FIELD_TEST(home_offset);
#if HAS_SCARA_OFFSET
EEPROM_WRITE(scara_home_offset);
#else
#if !HAS_HOME_OFFSET
const xyz_pos_t home_offset{0};
#endif
EEPROM_WRITE(home_offset);
#endif
}
#endif // NUM_AXES
//
// Hotend Offsets