From e409f10047fb8e3d2265513abb2d8144b00d9b78 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Sun, 7 Mar 2010 23:10:41 +0100 Subject: [PATCH] moved all strings to pgm-memory --- config.c | 29 +++++++++++++++-------------- config.h | 3 ++- script/console | 3 ++- script/stream.rb | 2 +- serial_protocol.c | 12 ++++++------ stepper.c | 1 + wiring_serial.c | 10 ++++++++++ wiring_serial.h | 1 + 8 files changed, 38 insertions(+), 23 deletions(-) diff --git a/config.c b/config.c index e349005..1c9d7be 100644 --- a/config.c +++ b/config.c @@ -24,6 +24,7 @@ #include "config.h" #include "eeprom.h" #include "wiring_serial.h" +#include void reset_settings() { settings.steps_per_mm[0] = X_STEPS_PER_MM; @@ -37,16 +38,16 @@ void reset_settings() { } void dump_settings() { - printString("$0 = "); printFloat(settings.steps_per_mm[0]); - printString(" (steps/mm x)\r\n$1 = "); printFloat(settings.steps_per_mm[1]); - printString(" (steps/mm y)\r\n$2 = "); printFloat(settings.steps_per_mm[2]); - printString(" (steps/mm z)\r\n$3 = "); printInteger(settings.pulse_microseconds); - printString(" (microseconds step pulse)\r\n$4 = "); printFloat(settings.default_feed_rate); - printString(" (mm/sec default feed rate)\r\n$5 = "); printFloat(settings.default_seek_rate); - printString(" (mm/sec default seek rate)\r\n$6 = "); printFloat(settings.mm_per_arc_segment); - printString(" (mm/arc segment)\r\n$7 = "); printInteger(settings.invert_mask); - printString(" (step port invert mask. binary = "); printIntegerInBase(settings.invert_mask, 2); - printString(")\r\n\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"); + printPgmString(PSTR("$0 = ")); printFloat(settings.steps_per_mm[0]); + printPgmString(PSTR(" (steps/mm x)\r\n$1 = ")); printFloat(settings.steps_per_mm[1]); + printPgmString(PSTR(" (steps/mm y)\r\n$2 = ")); printFloat(settings.steps_per_mm[2]); + printPgmString(PSTR(" (steps/mm z)\r\n$3 = ")); printInteger(settings.pulse_microseconds); + printPgmString(PSTR(" (microseconds step pulse)\r\n$4 = ")); printFloat(settings.default_feed_rate); + printPgmString(PSTR(" (mm/sec default feed rate)\r\n$5 = ")); printFloat(settings.default_seek_rate); + printPgmString(PSTR(" (mm/sec default seek rate)\r\n$6 = ")); printFloat(settings.mm_per_arc_segment); + printPgmString(PSTR(" (mm/arc segment)\r\n$7 = ")); printInteger(settings.invert_mask); + printPgmString(PSTR(" (step port invert mask. binary = ")); printIntegerInBase(settings.invert_mask, 2); + printPgmString(PSTR(")\r\n\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n")); } int read_settings() { @@ -76,18 +77,18 @@ void store_setting(int parameter, double value) { case 6: settings.mm_per_arc_segment = value; break; case 7: settings.invert_mask = trunc(value); break; default: - printString("Unknown parameter\r\n"); + printPgmString(PSTR("Unknown parameter\r\n")); return; } write_settings(); - printString("Stored new setting\r\n"); + printPgmString(PSTR("Stored new setting\r\n")); } void config_init() { if(read_settings()) { - printString("'$' to dump current settings\r\n"); + printPgmString(PSTR("'$' to dump current settings\r\n")); } else { - printString("EEPROM blank. Rewrote default settings:\r\n"); + printPgmString(("EEPROM blank. Rewrote default settings:\r\n")); reset_settings(); write_settings(); dump_settings(); diff --git a/config.h b/config.h index 4d9ce08..0c5c64f 100644 --- a/config.h +++ b/config.h @@ -25,7 +25,8 @@ // Settings that can only be set at compile-time: -#define BAUD_RATE 9600 +// #define BAUD_RATE 9600 +#define BAUD_RATE 115200 #define STEPPERS_ENABLE_DDR DDRD #define STEPPERS_ENABLE_PORT PORTD diff --git a/script/console b/script/console index 5d72f72..c68c823 100755 --- a/script/console +++ b/script/console @@ -1,2 +1,3 @@ -socat -d -d READLINE /dev/tty.usbserial-A9007QcR,clocal=1,nonblock=1,cread=1,cs8,ixon=1,ixoff=1 +# socat -d -d READLINE /dev/tty.usbserial-A9007QcR,clocal=1,nonblock=1,cread=1,cs8,ixon=1,ixoff=1 +socat -d -d READLINE /dev/tty.FireFly-A964-SPP-1,clocal=1,nonblock=1,cread=1,cs8,ixon=1,ixoff=1 diff --git a/script/stream.rb b/script/stream.rb index 0698d67..65e3531 100644 --- a/script/stream.rb +++ b/script/stream.rb @@ -24,7 +24,7 @@ if ARGV.empty? exit end -SerialPort.open('/dev/tty.usbserial-A9007QcR', 9600) do |sp| +SerialPort.open('/dev/tty.FireFly-A964-SPP-1', 115200) do |sp| sp.write("\r\n\r\n"); sleep 5 ARGV.each do |file| diff --git a/serial_protocol.c b/serial_protocol.c index a4bbba5..a32813f 100644 --- a/serial_protocol.c +++ b/serial_protocol.c @@ -25,23 +25,23 @@ #include "config.h" #include #include "nuts_bolts.h" - -#define LINE_BUFFER_SIZE 60 +#include +#define LINE_BUFFER_SIZE 30 char line[LINE_BUFFER_SIZE]; uint8_t char_counter; void prompt() { - printString("ok\r\n"); + printPgmString(PSTR("ok\r\n")); } void sp_init() { beginSerial(BAUD_RATE); - printString("\r\nGrbl "); - printString(VERSION); - printString("\r\n"); + printPgmString(PSTR("\r\nGrbl ")); + printPgmString(PSTR(VERSION)); + printPgmString(PSTR("\r\n")); prompt(); } diff --git a/stepper.c b/stepper.c index 25e3be4..d84b92c 100644 --- a/stepper.c +++ b/stepper.c @@ -80,6 +80,7 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t line_buffer_head = next_buffer_head; // enable stepper interrupt TIMSK1 |= (1< +#include // Define constants and variables for buffering incoming serial data. We're // using a ring buffer (I think), in which rx_buffer_head is the index of the @@ -149,6 +151,14 @@ void printString(const char *s) printByte(*s++); } +// Print a string stored in PGM-memory +void printPgmString(const char *s) +{ + char c; + while ((c = pgm_read_byte_near(s++))) + printByte(c); +} + void printIntegerInBase(unsigned long n, unsigned long base) { unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. diff --git a/wiring_serial.h b/wiring_serial.h index ca09ab7..516a0ea 100644 --- a/wiring_serial.h +++ b/wiring_serial.h @@ -34,6 +34,7 @@ void printMode(int); void printByte(unsigned char c); void printNewline(void); void printString(const char *s); +void printPgmString(const char *s); void printInteger(long n); void printHex(unsigned long n); void printOctal(unsigned long n);