view harelet.c @ 8:c60e4315cb7e

Automated Vimcurial commmit
author VilyaemKenyaz
date Tue, 12 Sep 2023 06:46:45 -0400
parents 1bb981516d87
children 4eb02dffc00f
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"

#ifdef __linux__
#include "linuxconio.h"
#endif

#ifdef _WIN32
#include <Windows.h>>
#include <conio.h>
#endif

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

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

point points[MAXPOINT];

unsigned int X = 100;
unsigned int Y = 100;
unsigned int step = 5;
unsigned int down = 0;
unsigned int numpoints = 0;
char action;

/*********************************************
 * Description - Renders the screen
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/
void Render(){	
	clrscr();
	gotoxy(0,30);
	puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023");
	printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down);

	//Render points
	for(int i = 0;i != MAXPOINT;i++){
		gotoxy(0,50);

		gotoxy(points[i].X,points[i].Y);

		if(points[i].down == 0){
			puts("X");
		}
		else{
			puts("*");
		}


	}

	//Render cursor

	gotoxy(X,Y);

	puts("&");



}

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

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


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

	if(choice == 1){
		//Set the miller
		strcat(file,UNITS);
		strcat(file,"G0 X0 Y0 Z0");
		//Meat of instructions
		for(int i = 0;i != numpoints;i++){
			//Compose
			char * instruction;
			strcat(instruction,"G0 X");
			itoa(points[i].X,buffer);
			strcat(instruction,buffer);
			strcat(instruction," Y");
			itoa(points[i].Y,buffer);
			strcat(instruction,buffer);
			strcat(instruction," Z");
			itoa(DEEPNESS,buffer);
			strcat(instruction,buffer);
			//Write to string
			strcat(file,instruction);
		}
		//Finish
		strcat(file,"G0, X0, Y0, Z0");
		WriteFile(filename,file);
	}

	puts("Finished Compiling");

}


/*********************************************
 * Description - Main function
 * Author - William King
 * Date - Sep 08 2023
 * *******************************************/
void main(int argc, char* argv[]){
	while(1){
		Render();
		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);
}