chiark / gitweb /
eeprom: provide smaller code for SERIAL_ECHOPAIR_DOUBLE
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Aug 2012 15:13:25 +0000 (16:13 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Aug 2012 18:27:47 +0000 (19:27 +0100)
SERIAL_ECHOPAIR implies, eventually, two calls to MYSERIAL.print.  One
of these has FORCE_INLINE for a per-character loop, and both involve
constructing a method call rather than a simple function call.

Produce better and smaller code by providing SERIAL_ECHOPAIR_DOUBLE
which is a typechecking syntactic wrapper around a new function
serial_echopair_double.  This saves XXXX bytes of program memory.

It would arguably be nice to do this in general for each of the calls
to SERIAL_ECHOPAIR in EEPROM_printSettings.  But actually I think a
better approach would be a table-driving settings printer, so we'll
have this incremental improvement for now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Marlin/EEPROMwrite.h

index 96e2ec9856e5b63421ab0be59f052a3a2723d045..96791c7148ebb8ce2adca13769b548e1c348cbf1 100644 (file)
@@ -75,25 +75,34 @@ inline void EEPROM_StoreSettings()
 }
 
 
+static void serial_echopair_double(const PROGMEM char *s, double v) {
+      serialprintPGM(s);
+      SERIAL_ECHO(v);
+}
+
+#define SERIAL_ECHOPAIR_DOUBLE(s,v) \
+  ((void)(&(v) == &acceleration), /* type check */ \
+   serial_echopair_double(PSTR(s),(v)))
+
 inline void EEPROM_printSettings()
 {  // if def=true, the default values will be used
   #ifdef EEPROM_SETTINGS  
       SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("Steps per unit:");
       SERIAL_ECHO_START;
-      SERIAL_ECHOPAIR("  M92 X",axis_steps_per_unit[0]);
-      SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]);
-      SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]);
-      SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]);
+      SERIAL_ECHOPAIR_DOUBLE("  M92 X",axis_steps_per_unit[0]);
+      SERIAL_ECHOPAIR_DOUBLE(" Y",axis_steps_per_unit[1]);
+      SERIAL_ECHOPAIR_DOUBLE(" Z",axis_steps_per_unit[2]);
+      SERIAL_ECHOPAIR_DOUBLE(" E",axis_steps_per_unit[3]);
       SERIAL_ECHOLN("");
       
     SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
       SERIAL_ECHO_START;
-      SERIAL_ECHOPAIR("  M203 X",max_feedrate[0]);
-      SERIAL_ECHOPAIR(" Y",max_feedrate[1] ); 
-      SERIAL_ECHOPAIR(" Z", max_feedrate[2] ); 
-      SERIAL_ECHOPAIR(" E", max_feedrate[3]);
+      SERIAL_ECHOPAIR_DOUBLE("  M203 X",max_feedrate[0]);
+      SERIAL_ECHOPAIR_DOUBLE(" Y",max_feedrate[1] ); 
+      SERIAL_ECHOPAIR_DOUBLE(" Z", max_feedrate[2] ); 
+      SERIAL_ECHOPAIR_DOUBLE(" E", max_feedrate[3]);
       SERIAL_ECHOLN("");
     SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
@@ -106,24 +115,24 @@ inline void EEPROM_printSettings()
     SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
       SERIAL_ECHO_START;
-      SERIAL_ECHOPAIR("  M204 S",acceleration ); 
-      SERIAL_ECHOPAIR(" T" ,retract_acceleration);
+      SERIAL_ECHOPAIR_DOUBLE("  M204 S",acceleration ); 
+      SERIAL_ECHOPAIR_DOUBLE(" T" ,retract_acceleration);
       SERIAL_ECHOLN("");
     SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s),  Z=maximum Z jerk (mm/s)");
       SERIAL_ECHO_START;
-      SERIAL_ECHOPAIR("  M205 S",minimumfeedrate ); 
-      SERIAL_ECHOPAIR(" T" ,mintravelfeedrate ); 
+      SERIAL_ECHOPAIR_DOUBLE("  M205 S",minimumfeedrate ); 
+      SERIAL_ECHOPAIR_DOUBLE(" T" ,mintravelfeedrate ); 
       SERIAL_ECHOPAIR(" B" ,minsegmenttime ); 
-      SERIAL_ECHOPAIR(" X" ,max_xy_jerk ); 
-      SERIAL_ECHOPAIR(" Z" ,max_z_jerk);
-      SERIAL_ECHOPAIR(" E" ,max_e_jerk);
+      SERIAL_ECHOPAIR_DOUBLE(" X" ,max_xy_jerk ); 
+      SERIAL_ECHOPAIR_DOUBLE(" Z" ,max_z_jerk);
+      SERIAL_ECHOPAIR_DOUBLE(" E" ,max_e_jerk);
       SERIAL_ECHOLN(""); 
     #ifdef PIDTEMP
       SERIAL_ECHO_START;
       SERIAL_ECHOLNPGM("PID settings:");
       SERIAL_ECHO_START;
-      SERIAL_ECHOPAIR("   M301 P",Kp); 
+      SERIAL_ECHOPAIR_DOUBLE("   M301 P",Kp); 
       SERIAL_ECHOPAIR(" I" ,Ki/PID_dT); 
       SERIAL_ECHOPAIR(" D" ,Kd*PID_dT);
       SERIAL_ECHOLN("");