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/Marlin.h
Marlin/Marlin.pde

index c8115af4114f39850be31991dab2e23c2abde063..a78d2ee847494a13de129f8519c1f9e9ec1eeb3a 100644 (file)
@@ -84,7 +84,11 @@ const char echomagic[] PROGMEM ="echo:";
 #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
 #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
 
-#define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);}
+#define SERIAL_ECHOPAIR(name,value) (serial_echopair(PSTR(name),(value)))
+
+void serial_echopair(const PROGMEM char *s, float v);
+void serial_echopair(const PROGMEM char *s, double v);
+void serial_echopair(const PROGMEM char *s, unsigned long v);
 
 
 //things to write to serial from Programmemory. saves 400 to 2k of RAM.
index 9f8e98c249422caa2d2f618b8cb4ae7cc10a45f1..d0c8d795da30c3402ae994a87538c6319afcbaab 100644 (file)
@@ -200,6 +200,13 @@ bool Stopped=false;
 
 void get_arc_coordinates();
 
+void serial_echopair(const PROGMEM char *s, float v)
+    { serialprintPGM(s); SERIAL_ECHO(v); }
+void serial_echopair(const PROGMEM char *s, double v)
+    { serialprintPGM(s); SERIAL_ECHO(v); }
+void serial_echopair(const PROGMEM char *s, unsigned long v)
+    { serialprintPGM(s); SERIAL_ECHO(v); }
+
 extern "C"{
   extern unsigned int __bss_end;
   extern unsigned int __heap_start;