Mercurial Hosting > harelet
view harelet.c @ 17:e13e2d661cc8
Make it pretty
author | VilyaemKenyaz |
---|---|
date | Wed, 13 Sep 2023 04:38:20 -0400 |
parents | 43dcb67b173d |
children | 7bf25e90a1de |
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\n" #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 = 25; 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,3); 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){ printf("X"); } else{ printf("*"); } } //Render cursor gotoxy(X,Y); puts("&"); //Move cursor to top of document, so its not trailing the cadcursor gotoxy(0,0); } /********************************************* * Description - This function compiles instructions for CNC machines. * Author - William King * Date - Sep 08 2023 * *******************************************/ void Compile(){ char filename[64]; char file[8192]; char buffer[64]; unsigned int choice; clrscr(); puts("Select your format\n1. RAW GCODE"); scanf("%d",&choice); puts("Enter the filename"); scanf("%s",filename); printf("Compiling %s...\n",filename); if(choice == 1){ //Set the miller strcat(file,UNITS); strcat(file,"G0 X0 Y0 Z0\n"); //Meat of instructions for(int i = 0;i != numpoints;i++){ //Compose char instruction[64]; strcat(instruction,"G0 X "); //Convert X to string sprintf(buffer,"%d",points[i].X); strcat(instruction,buffer); strcat(instruction," Y "); //Convert Y to string sprintf(buffer,"%d",points[i].Y); strcat(instruction,buffer); if(points[i].down = 1){ strcat(instruction," Z 5\n"); } else{ strcat(instruction," Z 0\n"); } //strcat(instruction,buffer); //Write to string strcat(file,instruction); } //Finish strcat(file,"G0 X0 Y0 Z0\n"); WriteFile(filename,file); } else{ puts("Invalid compiliation format"); scanf(""); } puts("Finished Compiling GCODE"); scanf(""); } /********************************************* * Description - Main function * Author - William King * Date - Sep 08 2023 * *******************************************/ void main(int argc, char* argv[]){ clrscr(); while(1){ Render(); switch(getchar()){ case 'h': X -= step; break; case 'j': Y += step; break; case 'k': Y -= step; break; case 'l': X += step; break; case 's': puts("New stepsize"); scanf("%d",&step); break; case 'a': points[numpoints].X = X; points[numpoints].Y = Y; points[numpoints].down = down; numpoints++; break; case 'd': if(down == 1){ down = 0; } else{ down = 1; } break; case 'c': Compile(); break; case 'q': clrscr(); exit(0); break; default: putchar('\a'); break; } } exit(0); }