Welcome! Log In Create A New Profile

Advanced

Marlin parse SD file update LCD

Posted by DaveOB 
Marlin parse SD file update LCD
July 14, 2015 12:51PM
Help please

I just can not find a way to get the graphical LCD to update or refresh after it detects an M23 command from the LCD menu, before I start parsing the SD file for a custom mod to count the layers and print lines in the gcode file.

After I press the encoder button to select the SD card file, the top half of the graphical LCD goes blank, and remains like that until the parsing of the sd file has completed.

in the file : Marlin_main.cpp
in the function : void process_commands

I have changed the code to :
case 23: //M23 - Select file
		starpos = (strchr(strchr_pointer + 4,'*'));
		if(starpos!=NULL)
			*(starpos)='\0';

		// my note : add code to count the Z axis commands ( layers ) in the file and the G1 print lines in the file
		#ifdef SDSUPPORT
		#ifdef ShowLayerCountAndEstTime
			CountLinesAndLayers = true;
		#endif //layer counter
		#endif //SDSUPPORT
    break;

so that the boolean ( CountLinesAndLayers ) can is used to tell the code to parse the SD file and count the print lines and layers.

At the end of void process_commands, I have added, just before the
ClearToSend();

this code :

	if(CountLinesAndLayers == true){ // read the SD file and count the lines and layers
		CountLinesAndLayers = false;

		// update the LCD here and display a message to say "Reading SD file .."


		PrintLinesTotal = 0;
		LayerCountTotal = 0;
		card.openFile(strchr_pointer + 4,true);
		chPos = 0;  // pointer for position of next char in buffer array
		while(!card.eof()){
			int16_t n=card.get();
			serial_char = (char)n;
			if(chPos < 59) SDbuffer[chPos] = serial_char;
			if(chPos >= 1 && chPos < 99){ // chPos = 99 is set when X or Z is found, so used to skip the check until the next end of line char
				// reset the counters if custom gcode comment ';SLC' that was added in Slic3r at the start of the print job, after the nozzle was positioned
				if(chPos == 3){
					if(SDbuffer[0] == ';' && SDbuffer[1] == 'S' && SDbuffer[2] == 'L' && SDbuffer[3] == 'C'){  // check if the buffer line starts with ';SLC' ( SLC = Start Layer Count )
						LayersToIgnore = LayerCountTotal;
						MYSERIAL.print("Set LayersToIgnore = ");
						MYSERIAL.println(LayersToIgnore);
						PrintLinesTotal=0;
						LayerCountTotal=0;
					}
				}
				if(SDbuffer[0] == 'G' && SDbuffer[1] == '1'){  // check if the buffer line starts with 'G1'
					if(serial_char == 'X'){
						PrintLinesTotal++;
						chPos = 99;
					}
					if(serial_char == 'Z'){
						LayerCountTotal++;
						MYSERIAL.print("LayerCountTotal = ");
						MYSERIAL.println(LayerCountTotal);
						chPos = 99;
					}
				}
			}
			chPos++;
			if(serial_char == '\n'){ // if the character read from the SD card is a line ending
				chPos = 0; // reset the position for the next character in the buffer. Set to 0 = empty the buffer.
			}
		}
		card.closefile();
		delay(200);
		card.openFile(strchr_pointer + 4,true);  //this is in M23 - Select file
	}  // end of : if(CountLinesAndLayers = true)

The above code is definitely executing, because I am getting the serial echo back to my PC as expected.
Re: Marlin parse SD file update LCD
July 15, 2015 03:33PM
This requirement no longer exists.

I have had a re-look at the problem, and decided to attack this problem from a different angle.

I have a complete working solution and am busy with the last final test. Once that is done, I will create a new post with a step by step of what I did, and how it works.

If you want to get the Layer number and the estimated time remaining to display on your graphical LCD screen, then it may be worth a read.

New post to follow soon.
Sorry, only registered users may post in this forum.

Click here to login