Few simple fixes that save RAM, as static strings are stored in RAM by default.

This commit is contained in:
daid303 2012-11-28 10:30:34 +01:00
parent c94ca24adc
commit 97fa2a9c30
6 changed files with 36 additions and 25 deletions

View File

@ -164,6 +164,7 @@ void Stop();
bool IsStopped();
void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
void enquecommand_P(const char *cmd); //put an ascii command at the end of the current buffer, read from flash
void prepare_arc_move(char isclockwise);
void clamp_to_software_endstops(float target[3]);

View File

@ -254,6 +254,21 @@ void enquecommand(const char *cmd)
}
}
void enquecommand_P(const char *cmd)
{
if(buflen < BUFSIZE)
{
//this is dangerous if a mixing of serial and this happsens
strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
SERIAL_ECHO_START;
SERIAL_ECHOPGM("enqueing \"");
SERIAL_ECHO(cmdbuffer[bufindw]);
SERIAL_ECHOLNPGM("\"");
bufindw= (bufindw + 1)%BUFSIZE;
buflen += 1;
}
}
void setup_killpin()
{
#if( KILL_PIN>-1 )
@ -362,7 +377,7 @@ void loop()
#ifdef SDSUPPORT
if(card.saving)
{
if(strstr(cmdbuffer[bufindr],"M29") == NULL)
if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL)
{
card.write_command(cmdbuffer[bufindr]);
SERIAL_PROTOCOLLNPGM(MSG_OK);
@ -407,11 +422,11 @@ void get_command()
if(!comment_mode){
comment_mode = false; //for new command
fromsd[bufindw] = false;
if(strstr(cmdbuffer[bufindw], "N") != NULL)
if(strchr(cmdbuffer[bufindw], 'N') != NULL)
{
strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) {
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
SERIAL_ERRORLN(gcode_LastN);
@ -421,7 +436,7 @@ void get_command()
return;
}
if(strstr(cmdbuffer[bufindw], "*") != NULL)
if(strchr(cmdbuffer[bufindw], '*') != NULL)
{
byte checksum = 0;
byte count = 0;
@ -453,7 +468,7 @@ void get_command()
}
else // if we don't receive 'N' but still see '*'
{
if((strstr(cmdbuffer[bufindw], "*") != NULL))
if((strchr(cmdbuffer[bufindw], '*') != NULL))
{
SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
@ -462,7 +477,7 @@ void get_command()
return;
}
}
if((strstr(cmdbuffer[bufindw], "G") != NULL)){
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
case 0:
@ -517,7 +532,7 @@ void get_command()
int sec,min;
min=t/60;
sec=t%60;
sprintf(time,"%i min, %i sec",min,sec);
sprintf_P(time, PSTR("%i min, %i sec"),min,sec);
SERIAL_ECHO_START;
SERIAL_ECHOLN(time);
LCD_MESSAGE(time);
@ -561,11 +576,6 @@ long code_value_long()
return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
}
bool code_seen(char code_string[]) //Return True if the string was found
{
return (strstr(cmdbuffer[bufindr], code_string) != NULL);
}
bool code_seen(char code)
{
strchr_pointer = strchr(cmdbuffer[bufindr], code);
@ -935,7 +945,7 @@ void process_commands()
int sec,min;
min=t/60;
sec=t%60;
sprintf(time,"%i min, %i sec",min,sec);
sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
SERIAL_ECHO_START;
SERIAL_ECHOLN(time);
LCD_MESSAGE(time);

View File

@ -400,7 +400,7 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
// check size and only allow ASCII printable characters
if (i > n || c < 0X21 || c > 0X7E)goto fail;
// only upper case allowed in 8.3 names - convert lower to upper
name[i++] = c < 'a' || c > 'z' ? c : c + ('A' - 'a');
name[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a'));
}
}
*ptr = str;
@ -1822,4 +1822,4 @@ void (*SdBaseFile::oldDateTime_)(uint16_t& date, uint16_t& time) = 0; // NOLINT
#endif // ALLOW_DEPRECATED_FUNCTIONS
#endif
#endif

View File

@ -245,9 +245,9 @@ void CardReader::openFile(char* name,bool read)
SERIAL_PROTOCOLLNPGM(".");
return;
}
else
else
{
//SERIAL_ECHOLN("dive ok");
//SERIAL_ECHOLN("dive ok");
}
curDir=&myDir;
@ -341,9 +341,9 @@ void CardReader::removeFile(char* name)
SERIAL_PROTOCOLLNPGM(".");
return;
}
else
else
{
//SERIAL_ECHOLN("dive ok");
//SERIAL_ECHOLN("dive ok");
}
curDir=&myDir;
@ -432,7 +432,7 @@ void CardReader::checkautostart(bool force)
}
char autoname[30];
sprintf(autoname,"auto%i.g",lastnr);
sprintf_P(autoname, PSTR("auto%i.g"), lastnr);
for(int8_t i=0;i<(int8_t)strlen(autoname);i++)
autoname[i]=tolower(autoname[i]);
dir_t p;
@ -452,9 +452,9 @@ void CardReader::checkautostart(bool force)
{
char cmd[30];
sprintf(cmd,"M23 %s",autoname);
sprintf_P(cmd, PSTR("M23 %s"), autoname);
enquecommand(cmd);
enquecommand("M24");
enquecommand_P(PSTR("M24"));
found=true;
}
}
@ -533,7 +533,7 @@ void CardReader::printingHasFinished()
if(SD_FINISHED_STEPPERRELEASE)
{
//finishAndDisableSteppers();
enquecommand(SD_FINISHED_RELEASECOMMAND);
enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
}
autotempShutdown();
}

View File

@ -956,7 +956,7 @@ void quickStop()
ENABLE_STEPPER_DRIVER_INTERRUPT();
}
int digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
void digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
{
#if DIGIPOTSS_PIN > -1
digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip

View File

@ -69,7 +69,7 @@ extern block_t *current_block; // A pointer to the block currently being traced
void quickStop();
int digitalPotWrite(int address, int value);
void digitalPotWrite(int address, int value);
void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
void microstep_mode(uint8_t driver, uint8_t stepping);
void digipot_init();