Переглянути джерело

Pretty up EEPROM port args

Scott Lahteine 7 роки тому
джерело
коміт
4aebe3d82e

+ 23
- 64
Marlin/src/module/configuration_store.cpp Переглянути файл

@@ -45,6 +45,17 @@
45 45
 //#define DEBUG_EEPROM_READWRITE
46 46
 
47 47
 #include "configuration_store.h"
48
+
49
+#if ADD_PORT_ARG
50
+  #define PORTARG_SOLO     const int8_t port
51
+  #define PORTARG_AFTER   ,const int8_t port
52
+  #define PORTVAR_SOLO     port
53
+#else
54
+  #define PORTARG_SOLO
55
+  #define PORTARG_AFTER
56
+  #define PORTVAR_SOLO
57
+#endif
58
+
48 59
 #include "endstops.h"
49 60
 #include "planner.h"
50 61
 #include "stepper.h"
@@ -345,11 +356,7 @@ void MarlinSettings::postprocess() {
345 356
 
346 357
   bool MarlinSettings::eeprom_error, MarlinSettings::validating;
347 358
 
348
-  bool MarlinSettings::size_error(const uint16_t size
349
-    #if ADD_PORT_ARG
350
-      , const int8_t port/*=-1*/
351
-    #endif
352
-  ) {
359
+  bool MarlinSettings::size_error(const uint16_t size PORTARG_AFTER) {
353 360
     if (size != datasize()) {
354 361
       #if ENABLED(EEPROM_CHITCHAT)
355 362
         SERIAL_ERROR_START_P(port);
@@ -363,11 +370,7 @@ void MarlinSettings::postprocess() {
363 370
   /**
364 371
    * M500 - Store Configuration
365 372
    */
366
-  bool MarlinSettings::save(
367
-    #if ADD_PORT_ARG
368
-      const int8_t port/*=-1*/
369
-    #endif
370
-  ) {
373
+  bool MarlinSettings::save(PORTARG_SOLO) {
371 374
     float dummy = 0.0f;
372 375
     char ver[4] = "ERR";
373 376
 
@@ -853,11 +856,7 @@ void MarlinSettings::postprocess() {
853 856
   /**
854 857
    * M501 - Retrieve Configuration
855 858
    */
856
-  bool MarlinSettings::_load(
857
-    #if ADD_PORT_ARG
858
-      const int8_t port/*=-1*/
859
-    #endif
860
-  ) {
859
+  bool MarlinSettings::_load(PORTARG_SOLO) {
861 860
     uint16_t working_crc = 0;
862 861
 
863 862
     EEPROM_START();
@@ -1431,46 +1430,22 @@ void MarlinSettings::postprocess() {
1431 1430
     }
1432 1431
 
1433 1432
     #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
1434
-      if (!validating) report(
1435
-        #if ADD_PORT_ARG
1436
-          port
1437
-        #endif
1438
-      );
1433
+      if (!validating) report(PORTVAR_SOLO);
1439 1434
     #endif
1440 1435
     EEPROM_FINISH();
1441 1436
 
1442 1437
     return !eeprom_error;
1443 1438
   }
1444 1439
 
1445
-  bool MarlinSettings::validate(
1446
-    #if ADD_PORT_ARG
1447
-      const int8_t port/*=-1*/
1448
-    #endif
1449
-  ) {
1440
+  bool MarlinSettings::validate(PORTARG_SOLO) {
1450 1441
     validating = true;
1451
-    const bool success = _load(
1452
-      #if ADD_PORT_ARG
1453
-        port
1454
-      #endif
1455
-    );
1442
+    const bool success = _load(PORTVAR_SOLO);
1456 1443
     validating = false;
1457 1444
     return success;
1458 1445
   }
1459 1446
 
1460
-  bool MarlinSettings::load(
1461
-    #if ADD_PORT_ARG
1462
-      const int8_t port/*=-1*/
1463
-    #endif
1464
-  ) {
1465
-    if (validate(
1466
-      #if ADD_PORT_ARG
1467
-        port
1468
-      #endif
1469
-    )) return _load(
1470
-      #if ADD_PORT_ARG
1471
-        port
1472
-      #endif
1473
-    );
1447
+  bool MarlinSettings::load(PORTARG_SOLO) {
1448
+    if (validate(PORTVAR_SOLO)) return _load(PORTVAR_SOLO);
1474 1449
     reset();
1475 1450
     return true;
1476 1451
   }
@@ -1581,11 +1556,7 @@ void MarlinSettings::postprocess() {
1581 1556
 
1582 1557
 #else // !EEPROM_SETTINGS
1583 1558
 
1584
-  bool MarlinSettings::save(
1585
-    #if ADD_PORT_ARG
1586
-      const int8_t port/*=-1*/
1587
-    #endif
1588
-  ) {
1559
+  bool MarlinSettings::save(PORTARG_SOLO) {
1589 1560
     #if ENABLED(EEPROM_CHITCHAT)
1590 1561
       SERIAL_ERROR_START_P(port);
1591 1562
       SERIAL_ERRORLNPGM_P(port, "EEPROM disabled");
@@ -1598,11 +1569,7 @@ void MarlinSettings::postprocess() {
1598 1569
 /**
1599 1570
  * M502 - Reset Configuration
1600 1571
  */
1601
-void MarlinSettings::reset(
1602
-  #if ADD_PORT_ARG
1603
-    const int8_t port/*=-1*/
1604
-  #endif
1605
-) {
1572
+void MarlinSettings::reset(PORTARG_SOLO) {
1606 1573
   static const float tmp1[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT, tmp2[] PROGMEM = DEFAULT_MAX_FEEDRATE;
1607 1574
   static const uint32_t tmp3[] PROGMEM = DEFAULT_MAX_ACCELERATION;
1608 1575
   LOOP_XYZE_N(i) {
@@ -1860,11 +1827,7 @@ void MarlinSettings::reset(
1860 1827
 
1861 1828
 #if DISABLED(DISABLE_M503)
1862 1829
 
1863
-  #if ADD_PORT_ARG
1864
-    #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(port); }while(0)
1865
-  #else
1866
-    #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
1867
-  #endif
1830
+  #define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START_P(PORTVAR_SOLO); }while(0)
1868 1831
 
1869 1832
   /**
1870 1833
    * M503 - Report current settings in RAM
@@ -2129,11 +2092,7 @@ void MarlinSettings::reset(
2129 2092
           SERIAL_ECHOLNPGM_P(port, " meshes.\n");
2130 2093
         }
2131 2094
 
2132
-        ubl.report_current_mesh(
2133
-          #if ADD_PORT_ARG
2134
-            port
2135
-          #endif
2136
-        );
2095
+        ubl.report_current_mesh(PORTVAR_SOLO);
2137 2096
 
2138 2097
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
2139 2098
 

+ 17
- 30
Marlin/src/module/configuration_store.h Переглянути файл

@@ -27,22 +27,22 @@
27 27
 
28 28
 #define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
29 29
 
30
+#if ADD_PORT_ARG
31
+  #define PORTINIT_SOLO    const int8_t port=-1
32
+  #define PORTINIT_AFTER  ,const int8_t port=-1
33
+#else
34
+  #define PORTINIT_SOLO
35
+  #define PORTINIT_AFTER
36
+#endif
37
+
30 38
 class MarlinSettings {
31 39
   public:
32 40
     MarlinSettings() { }
33 41
 
34 42
     static uint16_t datasize();
35 43
 
36
-    static void reset(
37
-      #if ADD_PORT_ARG
38
-        const int8_t port=-1
39
-      #endif
40
-    );
41
-    static bool save(
42
-      #if ADD_PORT_ARG
43
-        const int8_t port=-1
44
-      #endif
45
-    );   // Return 'true' if data was saved
44
+    static void reset(PORTINIT_SOLO);
45
+    static bool save(PORTINIT_SOLO);    // Return 'true' if data was saved
46 46
 
47 47
     FORCE_INLINE static bool init_eeprom() {
48 48
       bool success = true;
@@ -57,16 +57,8 @@ class MarlinSettings {
57 57
     }
58 58
 
59 59
     #if ENABLED(EEPROM_SETTINGS)
60
-      static bool load(
61
-        #if ADD_PORT_ARG
62
-          const int8_t port=-1
63
-        #endif
64
-      );     // Return 'true' if data was loaded ok
65
-      static bool validate(
66
-        #if ADD_PORT_ARG
67
-          const int8_t port=-1
68
-        #endif
69
-      ); // Return 'true' if EEPROM data is ok
60
+      static bool load(PORTINIT_SOLO);      // Return 'true' if data was loaded ok
61
+      static bool validate(PORTINIT_SOLO);  // Return 'true' if EEPROM data is ok
70 62
 
71 63
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
72 64
                                          // That can store is enabled
@@ -110,19 +102,14 @@ class MarlinSettings {
110 102
 
111 103
       #endif
112 104
 
113
-      static bool _load(
114
-        #if ADD_PORT_ARG
115
-          const int8_t port=-1
116
-        #endif
117
-      );
118
-      static bool size_error(const uint16_t size
119
-        #if ADD_PORT_ARG
120
-          , const int8_t port=-1
121
-        #endif
122
-      );
105
+      static bool _load(PORTINIT_SOLO);
106
+      static bool size_error(const uint16_t size PORTINIT_AFTER);
123 107
     #endif
124 108
 };
125 109
 
126 110
 extern MarlinSettings settings;
127 111
 
112
+#undef PORTINIT_SOLO
113
+#undef PORTINIT_AFTER
114
+
128 115
 #endif // CONFIGURATION_STORE_H

Завантаження…
Відмінити
Зберегти