|
@ -219,7 +219,7 @@ void loop() |
|
|
if(buflen) |
|
|
if(buflen) |
|
|
{ |
|
|
{ |
|
|
#ifdef SDSUPPORT |
|
|
#ifdef SDSUPPORT |
|
|
if(card.savetosd) |
|
|
if(card.saving) |
|
|
{ |
|
|
{ |
|
|
if(strstr(cmdbuffer[bufindr],"M29") == NULL) |
|
|
if(strstr(cmdbuffer[bufindr],"M29") == NULL) |
|
|
{ |
|
|
{ |
|
@ -318,7 +318,7 @@ inline void get_command() |
|
|
case 2: |
|
|
case 2: |
|
|
case 3: |
|
|
case 3: |
|
|
#ifdef SDSUPPORT |
|
|
#ifdef SDSUPPORT |
|
|
if(card.savetosd) |
|
|
if(card.saving) |
|
|
break; |
|
|
break; |
|
|
#endif //SDSUPPORT |
|
|
#endif //SDSUPPORT |
|
|
Serial.println("ok"); |
|
|
Serial.println("ok"); |
|
@ -342,17 +342,17 @@ inline void get_command() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#ifdef SDSUPPORT |
|
|
#ifdef SDSUPPORT |
|
|
if(!card.sdmode || serial_count!=0){ |
|
|
if(!card.sdprinting || serial_count!=0){ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
while( card.filesize > card.sdpos && buflen < BUFSIZE) { |
|
|
while( !card.eof() && buflen < BUFSIZE) { |
|
|
short n = card.file.read(); |
|
|
|
|
|
serial_char = (char)n; |
|
|
serial_char = card.get(); |
|
|
if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) || n == -1) |
|
|
if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1)) |
|
|
{ |
|
|
{ |
|
|
card.sdpos = card.file.curPosition(); |
|
|
|
|
|
if(card.sdpos >= card.filesize){ |
|
|
if(card.eof()){ |
|
|
card.sdmode = false; |
|
|
card.sdprinting = false; |
|
|
Serial.println("echo: Done printing file"); |
|
|
Serial.println("echo: Done printing file"); |
|
|
stoptime=millis(); |
|
|
stoptime=millis(); |
|
|
char time[30]; |
|
|
char time[30]; |
|
@ -565,93 +565,52 @@ inline void process_commands() |
|
|
|
|
|
|
|
|
case 20: // M20 - list SD card |
|
|
case 20: // M20 - list SD card |
|
|
Serial.println("Begin file list"); |
|
|
Serial.println("Begin file list"); |
|
|
card.root.ls(); |
|
|
card.ls(); |
|
|
Serial.println("End file list"); |
|
|
Serial.println("End file list"); |
|
|
break; |
|
|
break; |
|
|
case 21: // M21 - init SD card |
|
|
case 21: // M21 - init SD card |
|
|
card.sdmode = false; |
|
|
|
|
|
card.initsd(); |
|
|
card.initsd(); |
|
|
break; |
|
|
break; |
|
|
case 22: //M22 - release SD card |
|
|
case 22: //M22 - release SD card |
|
|
card.sdmode = false; |
|
|
card.release(); |
|
|
card.sdactive = false; |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 23: //M23 - Select file |
|
|
case 23: //M23 - Select file |
|
|
if(card.sdactive){ |
|
|
|
|
|
card.sdmode = false; |
|
|
|
|
|
card.file.close(); |
|
|
|
|
|
starpos = (strchr(strchr_pointer + 4,'*')); |
|
|
starpos = (strchr(strchr_pointer + 4,'*')); |
|
|
if(starpos!=NULL) |
|
|
if(starpos!=NULL) |
|
|
*(starpos-1)='\0'; |
|
|
*(starpos-1)='\0'; |
|
|
if (card.file.open(&card.root, strchr_pointer + 4, O_READ)) { |
|
|
card.selectFile(strchr_pointer + 4); |
|
|
Serial.print("File opened:"); |
|
|
|
|
|
Serial.print(strchr_pointer + 4); |
|
|
|
|
|
Serial.print(" Size:"); |
|
|
|
|
|
Serial.println(card.file.fileSize()); |
|
|
|
|
|
card.sdpos = 0; |
|
|
|
|
|
card.filesize = card.file.fileSize(); |
|
|
|
|
|
Serial.println("File selected"); |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
Serial.println("file.open failed"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 24: //M24 - Start SD print |
|
|
case 24: //M24 - Start SD print |
|
|
if(card.sdactive){ |
|
|
card.startFileprint(); |
|
|
card.sdmode = true; |
|
|
|
|
|
starttime=millis(); |
|
|
starttime=millis(); |
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 25: //M25 - Pause SD print |
|
|
case 25: //M25 - Pause SD print |
|
|
if(card.sdmode){ |
|
|
card.pauseSDPrint(); |
|
|
card.sdmode = false; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 26: //M26 - Set SD index |
|
|
case 26: //M26 - Set SD index |
|
|
if(card.sdactive && code_seen('S')){ |
|
|
if(card.cardOK && code_seen('S')){ |
|
|
card.sdpos = code_value_long(); |
|
|
card.setIndex(code_value_long()); |
|
|
card.file.seekSet(card.sdpos); |
|
|
|
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 27: //M27 - Get SD status |
|
|
case 27: //M27 - Get SD status |
|
|
if(card.sdactive){ |
|
|
card.getStatus(); |
|
|
Serial.print("SD printing byte "); |
|
|
|
|
|
Serial.print(card.sdpos); |
|
|
|
|
|
Serial.print("/"); |
|
|
|
|
|
Serial.println(card.filesize); |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
Serial.println("Not SD printing"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 28: //M28 - Start SD write |
|
|
case 28: //M28 - Start SD write |
|
|
if(card.sdactive){ |
|
|
|
|
|
char* npos = 0; |
|
|
|
|
|
card.file.close(); |
|
|
|
|
|
card.sdmode = false; |
|
|
|
|
|
starpos = (strchr(strchr_pointer + 4,'*')); |
|
|
starpos = (strchr(strchr_pointer + 4,'*')); |
|
|
if(starpos != NULL){ |
|
|
if(starpos != NULL){ |
|
|
npos = strchr(cmdbuffer[bufindr], 'N'); |
|
|
char* npos = strchr(cmdbuffer[bufindr], 'N'); |
|
|
strchr_pointer = strchr(npos,' ') + 1; |
|
|
strchr_pointer = strchr(npos,' ') + 1; |
|
|
*(starpos-1) = '\0'; |
|
|
*(starpos-1) = '\0'; |
|
|
} |
|
|
} |
|
|
if (!card.file.open(&card.root, strchr_pointer+4, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) |
|
|
card.startFilewrite(strchr_pointer+4); |
|
|
{ |
|
|
|
|
|
Serial.print("open failed, File: "); |
|
|
|
|
|
Serial.print(strchr_pointer + 4); |
|
|
|
|
|
Serial.print("."); |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
card.savetosd = true; |
|
|
|
|
|
Serial.print("Writing to file: "); |
|
|
|
|
|
Serial.println(strchr_pointer + 4); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 29: //M29 - Stop SD write |
|
|
case 29: //M29 - Stop SD write |
|
|
//processed in write to file routine above |
|
|
//processed in write to file routine above |
|
|
//savetosd = false; |
|
|
//card,saving = false; |
|
|
break; |
|
|
break; |
|
|
#endif //SDSUPPORT |
|
|
#endif //SDSUPPORT |
|
|
|
|
|
|
|
|