diff harelet.c @ 18:7bf25e90a1de

Finished writing OpenSBP Shopbot compiler
author VilyaemKenyaz
date Tue, 26 Sep 2023 23:19:42 -0400
parents 43dcb67b173d
children 8fe0b5711413
line wrap: on
line diff
--- a/harelet.c	Wed Sep 13 04:38:20 2023 -0400
+++ b/harelet.c	Tue Sep 26 23:19:42 2023 -0400
@@ -24,6 +24,10 @@
 #define UNITS	"G20\n"
 #define SPEED	20
 
+#define SBPUP "JZ &ZUP\n"
+#define SBPDWN 0.0625
+
+
 typedef struct{
 	unsigned int X;
 	unsigned int Y;
@@ -39,6 +43,19 @@
 unsigned int numpoints = 0;
 char action;
 
+
+/*********************************************
+* Description - Convert integers to strings, makes
+* source code more pretty.
+* Author - William King
+* Date - Sep 26 2023
+* *******************************************/
+char * IntToString(int num){
+	char * s;
+	sprintf(s,"%d",num);
+	return s;
+}
+
 /*********************************************
  * Description - Renders the screen
  * Author - William King
@@ -92,7 +109,7 @@
 	unsigned int choice;
 
 	clrscr();
-	puts("Select your format\n1. RAW GCODE");
+	puts("Select your format\n1. RAW GCODE\n2. OPENSBP");
 	scanf("%d",&choice);
 
 
@@ -121,7 +138,6 @@
 			else{
 				strcat(instruction," Z 0\n");
 			}
-			//strcat(instruction,buffer);
 			//Write to string
 			strcat(file,instruction);
 		}
@@ -130,6 +146,37 @@
 		strcat(file,"G0 X0 Y0 Z0\n");
 		WriteFile(filename,file);
 	}
+	else if(choice == 2){
+	// Setup the miller
+	strcat(file,"'OpenSBP file written by Harelet\n'Harelet, written by William King\n'No responsibilty is taken for any damages to any equipment\n\n'Starting\nSO, 1,1\nPause 2\nSA,\n&ZUP = 0.25\nMH\n\n'Bulk of instructions\n");
+
+	for(int i = 0;i != numpoints;i++){
+	
+			char instruction[64];
+
+			strcat(instruction,"J2 ");
+			strcat(instruction,IntToString(points[i].X));
+			strcat(instruction," ");
+			strcat(instruction,IntToString(points[i].Y));
+			strcat(instruction,"\n");
+
+			if(points[i].down == 0){
+				strcat(instruction,"MZ -0,0625\n");
+			}
+			else{
+				strcat(instruction,"JZ,&ZUP\n");
+			}
+				
+
+			strcat(file,instruction);
+	}
+
+	//Finished, add instructions to wait for the user
+	strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE");
+
+	WriteFile(filename,file);
+
+	}
 	else{
 
 		puts("Invalid compiliation format");
@@ -138,7 +185,7 @@
 
 	}
 
-	puts("Finished Compiling GCODE");
+	puts("Finished compiling instructions");
 	scanf("");
 
 }