view harelet.c @ 4:0ed615367b10

Automated Vimcurial commmit
author VilyaemKenyaz
date Fri, 08 Sep 2023 08:16:07 -0400
parents eb7a7364994c
children 3879c1178448
line wrap: on
line source

/*********************************************
 * Description - Harelet is a CAD and compiler program for CNC milling machines
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/

#include <stdio.h> 
#include <stdlib.h>
#include <string.h>
#include "basedfilelib.h"
#include "minibasediolib.h"

#define DEEPNESS 5
#define MAXPOINT 4096
#define UNITS	"G20"
#define SPEED	20

typedef struct{
	unsigned int X,Y,down;
}point;

point points[MAXPOINT];

unsigned int X,Y,step,down,numpoints;
char action;

/*********************************************
 * Description - Renders the screen
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/
void Render(){

	for(int i = 0;i != MAXPOINT;i++){
		DocTop();
		//Move X
		for(int j = 0;j != points[i].X;j++){

			printf("");

		}

		//Move Y
		for(int k = 0;k != points[i].Y;k++){

			puts("");


		}

		puts("X");


	}


}

/*********************************************
 * Description - This function compiles instructions for CNC machines.
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/
void Compile(){
	char * filename;
	char * file;
	int choice;

	puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
	scanf("%d",&choice);


	puts("Enter the filename");
	scanf("%s",filename);

	if(choice == 1){
		//Set the miller
		strcat(file,UNITS);

		//Meat of instructions
		for(int i = 0;i != numpoints;i++){
			//Compose
			char * instruction;
			strcat(instruction,"G0 X");
			strcat(instruction,sprintf("%d",points[i].X));
			strcat(instruction," Y");
			strcat(instruction,sprintf("%d",points[i].Y));
			strcat(instruction," Z");
			strcat(instruction,sprintf("%d",DEEPNESS));
			//Write to string
			strcat(file,instruction);
		}
		//Finish
		strcat(file,"G0, X0, Y0, Z0");
		WriteFile(filename,file);
	}
	else{
		puts("Superhare implementation not done");
		exit(1);
		//Set the miller


		//Meat of instructions


		//Finish

	}

	puts("Finished Compiling");

}


/*********************************************
 * Description - Main function
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/
void main(int argc, char* argv[]){
	scanf("%c",&action);
	switch(action){
		case 'a':		points[numpoints].X = X;
					points[numpoints].Y = Y;
					points[numpoints].down = down;
					numpoints++;
					break;
		case 'h': 
					X+=step;
					break;
		case 'j': 
					Y+=step;
					break;
		case 'k': 
					Y-=step;
					break;
		case 'l': 
					X-=step;
					break;

		case 's':		
					puts("Enter new step:");
					scanf("%d",&step);
					break;

		case 'c':		Compile();
					break;
		default:
					break;
	}
	exit(0);
}