Browse Source

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

daid303 12 years ago
parent
commit
97fa2a9c30
6 changed files with 36 additions and 25 deletions
  1. 1
    0
      Marlin/Marlin.h
  2. 23
    13
      Marlin/Marlin_main.cpp
  3. 2
    2
      Marlin/SdBaseFile.cpp
  4. 8
    8
      Marlin/cardreader.cpp
  5. 1
    1
      Marlin/stepper.cpp
  6. 1
    1
      Marlin/stepper.h

+ 1
- 0
Marlin/Marlin.h View File

164
 bool IsStopped();
164
 bool IsStopped();
165
 
165
 
166
 void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
166
 void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
167
+void enquecommand_P(const char *cmd); //put an ascii command at the end of the current buffer, read from flash
167
 void prepare_arc_move(char isclockwise);
168
 void prepare_arc_move(char isclockwise);
168
 void clamp_to_software_endstops(float target[3]);
169
 void clamp_to_software_endstops(float target[3]);
169
 
170
 

+ 23
- 13
Marlin/Marlin_main.cpp View File

254
   }
254
   }
255
 }
255
 }
256
 
256
 
257
+void enquecommand_P(const char *cmd)
258
+{
259
+  if(buflen < BUFSIZE)
260
+  {
261
+    //this is dangerous if a mixing of serial and this happsens
262
+    strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
263
+    SERIAL_ECHO_START;
264
+    SERIAL_ECHOPGM("enqueing \"");
265
+    SERIAL_ECHO(cmdbuffer[bufindw]);
266
+    SERIAL_ECHOLNPGM("\"");
267
+    bufindw= (bufindw + 1)%BUFSIZE;
268
+    buflen += 1;
269
+  }
270
+}
271
+
257
 void setup_killpin()
272
 void setup_killpin()
258
 {
273
 {
259
   #if( KILL_PIN>-1 )
274
   #if( KILL_PIN>-1 )
362
     #ifdef SDSUPPORT
377
     #ifdef SDSUPPORT
363
       if(card.saving)
378
       if(card.saving)
364
       {
379
       {
365
-	if(strstr(cmdbuffer[bufindr],"M29") == NULL)
380
+	if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL)
366
 	{
381
 	{
367
 	  card.write_command(cmdbuffer[bufindr]);
382
 	  card.write_command(cmdbuffer[bufindr]);
368
 	  SERIAL_PROTOCOLLNPGM(MSG_OK);
383
 	  SERIAL_PROTOCOLLNPGM(MSG_OK);
407
       if(!comment_mode){
422
       if(!comment_mode){
408
         comment_mode = false; //for new command
423
         comment_mode = false; //for new command
409
         fromsd[bufindw] = false;
424
         fromsd[bufindw] = false;
410
-        if(strstr(cmdbuffer[bufindw], "N") != NULL)
425
+        if(strchr(cmdbuffer[bufindw], 'N') != NULL)
411
         {
426
         {
412
           strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
427
           strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
413
           gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
428
           gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
414
-          if(gcode_N != gcode_LastN+1 && (strstr(cmdbuffer[bufindw], "M110") == NULL) ) {
429
+          if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
415
             SERIAL_ERROR_START;
430
             SERIAL_ERROR_START;
416
             SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
431
             SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
417
             SERIAL_ERRORLN(gcode_LastN);
432
             SERIAL_ERRORLN(gcode_LastN);
421
             return;
436
             return;
422
           }
437
           }
423
 
438
 
424
-          if(strstr(cmdbuffer[bufindw], "*") != NULL)
439
+          if(strchr(cmdbuffer[bufindw], '*') != NULL)
425
           {
440
           {
426
             byte checksum = 0;
441
             byte checksum = 0;
427
             byte count = 0;
442
             byte count = 0;
453
         }
468
         }
454
         else  // if we don't receive 'N' but still see '*'
469
         else  // if we don't receive 'N' but still see '*'
455
         {
470
         {
456
-          if((strstr(cmdbuffer[bufindw], "*") != NULL))
471
+          if((strchr(cmdbuffer[bufindw], '*') != NULL))
457
           {
472
           {
458
             SERIAL_ERROR_START;
473
             SERIAL_ERROR_START;
459
             SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
474
             SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
462
             return;
477
             return;
463
           }
478
           }
464
         }
479
         }
465
-        if((strstr(cmdbuffer[bufindw], "G") != NULL)){
480
+        if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
466
           strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
481
           strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
467
           switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
482
           switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){
468
           case 0:
483
           case 0:
517
         int sec,min;
532
         int sec,min;
518
         min=t/60;
533
         min=t/60;
519
         sec=t%60;
534
         sec=t%60;
520
-        sprintf(time,"%i min, %i sec",min,sec);
535
+        sprintf_P(time, PSTR("%i min, %i sec"),min,sec);
521
         SERIAL_ECHO_START;
536
         SERIAL_ECHO_START;
522
         SERIAL_ECHOLN(time);
537
         SERIAL_ECHOLN(time);
523
         LCD_MESSAGE(time);
538
         LCD_MESSAGE(time);
561
   return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); 
576
   return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); 
562
 }
577
 }
563
 
578
 
564
-bool code_seen(char code_string[]) //Return True if the string was found
565
-{ 
566
-  return (strstr(cmdbuffer[bufindr], code_string) != NULL); 
567
-}  
568
-
569
 bool code_seen(char code)
579
 bool code_seen(char code)
570
 {
580
 {
571
   strchr_pointer = strchr(cmdbuffer[bufindr], code);
581
   strchr_pointer = strchr(cmdbuffer[bufindr], code);
935
       int sec,min;
945
       int sec,min;
936
       min=t/60;
946
       min=t/60;
937
       sec=t%60;
947
       sec=t%60;
938
-      sprintf(time,"%i min, %i sec",min,sec);
948
+      sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
939
       SERIAL_ECHO_START;
949
       SERIAL_ECHO_START;
940
       SERIAL_ECHOLN(time);
950
       SERIAL_ECHOLN(time);
941
       LCD_MESSAGE(time);
951
       LCD_MESSAGE(time);

+ 2
- 2
Marlin/SdBaseFile.cpp View File

400
       // check size and only allow ASCII printable characters
400
       // check size and only allow ASCII printable characters
401
       if (i > n || c < 0X21 || c > 0X7E)goto fail;
401
       if (i > n || c < 0X21 || c > 0X7E)goto fail;
402
       // only upper case allowed in 8.3 names - convert lower to upper
402
       // only upper case allowed in 8.3 names - convert lower to upper
403
-      name[i++] = c < 'a' || c > 'z' ?  c : c + ('A' - 'a');
403
+      name[i++] = (c < 'a' || c > 'z') ?  (c) : (c + ('A' - 'a'));
404
     }
404
     }
405
   }
405
   }
406
   *ptr = str;
406
   *ptr = str;
1822
 #endif  // ALLOW_DEPRECATED_FUNCTIONS
1822
 #endif  // ALLOW_DEPRECATED_FUNCTIONS
1823
 
1823
 
1824
 
1824
 
1825
-#endif
1825
+#endif

+ 8
- 8
Marlin/cardreader.cpp View File

245
           SERIAL_PROTOCOLLNPGM(".");
245
           SERIAL_PROTOCOLLNPGM(".");
246
           return;
246
           return;
247
         }
247
         }
248
-        else
248
+        else
249
         {
249
         {
250
-          //SERIAL_ECHOLN("dive ok");
250
+          //SERIAL_ECHOLN("dive ok");
251
         }
251
         }
252
           
252
           
253
         curDir=&myDir; 
253
         curDir=&myDir; 
341
           SERIAL_PROTOCOLLNPGM(".");
341
           SERIAL_PROTOCOLLNPGM(".");
342
           return;
342
           return;
343
         }
343
         }
344
-        else
344
+        else
345
         {
345
         {
346
-          //SERIAL_ECHOLN("dive ok");
346
+          //SERIAL_ECHOLN("dive ok");
347
         }
347
         }
348
           
348
           
349
         curDir=&myDir; 
349
         curDir=&myDir; 
432
   }
432
   }
433
   
433
   
434
   char autoname[30];
434
   char autoname[30];
435
-  sprintf(autoname,"auto%i.g",lastnr);
435
+  sprintf_P(autoname, PSTR("auto%i.g"), lastnr);
436
   for(int8_t i=0;i<(int8_t)strlen(autoname);i++)
436
   for(int8_t i=0;i<(int8_t)strlen(autoname);i++)
437
     autoname[i]=tolower(autoname[i]);
437
     autoname[i]=tolower(autoname[i]);
438
   dir_t p;
438
   dir_t p;
452
     {
452
     {
453
       char cmd[30];
453
       char cmd[30];
454
 
454
 
455
-      sprintf(cmd,"M23 %s",autoname);
455
+      sprintf_P(cmd, PSTR("M23 %s"), autoname);
456
       enquecommand(cmd);
456
       enquecommand(cmd);
457
-      enquecommand("M24");
457
+      enquecommand_P(PSTR("M24"));
458
       found=true;
458
       found=true;
459
     }
459
     }
460
   }
460
   }
533
  if(SD_FINISHED_STEPPERRELEASE)
533
  if(SD_FINISHED_STEPPERRELEASE)
534
  {
534
  {
535
    //finishAndDisableSteppers();
535
    //finishAndDisableSteppers();
536
-   enquecommand(SD_FINISHED_RELEASECOMMAND);
536
+   enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
537
  }
537
  }
538
  autotempShutdown();
538
  autotempShutdown();
539
 }
539
 }

+ 1
- 1
Marlin/stepper.cpp View File

956
   ENABLE_STEPPER_DRIVER_INTERRUPT();
956
   ENABLE_STEPPER_DRIVER_INTERRUPT();
957
 }
957
 }
958
 
958
 
959
-int digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
959
+void digitalPotWrite(int address, int value) // From Arduino DigitalPotControl example
960
 {
960
 {
961
   #if DIGIPOTSS_PIN > -1
961
   #if DIGIPOTSS_PIN > -1
962
     digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip
962
     digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip

+ 1
- 1
Marlin/stepper.h View File

69
 
69
 
70
 void quickStop();
70
 void quickStop();
71
 
71
 
72
-int digitalPotWrite(int address, int value);
72
+void digitalPotWrite(int address, int value);
73
 void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
73
 void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2);
74
 void microstep_mode(uint8_t driver, uint8_t stepping);
74
 void microstep_mode(uint8_t driver, uint8_t stepping);
75
 void digipot_init();
75
 void digipot_init();

Loading…
Cancel
Save