Created
January 16, 2019 08:32
-
-
Save chuebsch/13e5661b56d6027f772f09b8095e0c23 to your computer and use it in GitHub Desktop.
This reads in GCODE file made by Cura (maybe other slicers work as well not tested) and prints usefull Information via M117 on the printer display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main(int argc,char **argv){ | |
if ((argc>1)&&(strstr(argv[1],".gcode"))){ | |
char inname[2048],outname[2048],line[250],type[24]="-",msg[41]; | |
strncpy(inname,argv[1],2046); | |
inname[strlen(inname)-6]='\0'; | |
sprintf(outname,"%s_verbose.gcode",inname); | |
FILE *g=fopen(argv[1],"rt"); | |
FILE *o=fopen(outname,"wt"); | |
fgets(line,248,g); | |
int layers=0,l=-666; | |
printf("reading %s ...\n",argv[1]); | |
printf("writing %s ...\n",outname); | |
while (!feof(g)) { | |
if(line[0]==';'){ | |
if (NULL!=strstr(line,";LAYER_COUNT:")) sscanf(line,";LAYER_COUNT:%d",&layers); | |
if (NULL!=strstr(line,";LAYER:")) sscanf(line,";LAYER:%d",&l); | |
if (NULL!=strstr(line,";TYPE:" )) { | |
sscanf(line,";TYPE:%s",type); | |
sprintf(msg,"L%d/%-3d %-9s",l,layers,type); | |
msg[19]='\0'; | |
msg[20]='\0'; | |
// printf("%s %d %d %s %d %d %d %s \n",msg,l,layers,type, (NULL!=strstr(line,";LAYER_COUNT:")), (NULL!=strstr(line,";LAYER:")), (NULL!=strstr(line,";TYPE:" )), line); | |
if ((l!=-666)&&(type[0]!='-')) fprintf(o,"M117 %-20s\r\n",msg); | |
} | |
} | |
fprintf(o,"%s",line); | |
fgets(line,248,g); | |
} | |
fclose(g); | |
fclose(o); | |
} | |
else fprintf(stderr,"USAGE: %s file.gcode\n",argv[0]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment