1
|
1 /*********************************************
|
|
2 * Description - Harelet is a CAD and compiler program for CNC milling machines
|
|
3 * Author - William King
|
|
4 * Date - Sep 08 2023
|
|
5 * *******************************************/
|
|
6
|
|
7 #include <stdio.h>
|
|
8 #include <stdlib.h>
|
4
|
9 #include <string.h>
|
8
|
10
|
1
|
11 #include "basedfilelib.h"
|
7
|
12
|
|
13 #ifdef __linux__
|
|
14 #include "linuxconio.h"
|
|
15 #endif
|
|
16
|
|
17 #ifdef _WIN32
|
|
18 #include <Windows.h>>
|
|
19 #include <conio.h>
|
|
20 #endif
|
1
|
21
|
|
22 #define DEEPNESS 5
|
|
23 #define MAXPOINT 4096
|
2
|
24 #define UNITS "G20"
|
|
25 #define SPEED 20
|
1
|
26
|
|
27 typedef struct{
|
6
|
28 unsigned int X;
|
|
29 unsigned int Y;
|
|
30 unsigned int down;
|
1
|
31 }point;
|
|
32
|
4
|
33 point points[MAXPOINT];
|
1
|
34
|
8
|
35 unsigned int X = 100;
|
|
36 unsigned int Y = 100;
|
6
|
37 unsigned int step = 5;
|
5
|
38 unsigned int down = 0;
|
|
39 unsigned int numpoints = 0;
|
1
|
40 char action;
|
|
41
|
|
42 /*********************************************
|
|
43 * Description - Renders the screen
|
|
44 * Author - William King
|
|
45 * Date - Sep 08 2023
|
|
46 * *******************************************/
|
8
|
47 void Render(){
|
7
|
48 clrscr();
|
8
|
49 gotoxy(0,30);
|
6
|
50 puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023");
|
|
51 printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down);
|
|
52
|
5
|
53 //Render points
|
1
|
54 for(int i = 0;i != MAXPOINT;i++){
|
8
|
55 gotoxy(0,50);
|
7
|
56
|
|
57 gotoxy(points[i].X,points[i].Y);
|
|
58
|
5
|
59 if(points[i].down == 0){
|
|
60 puts("X");
|
|
61 }
|
|
62 else{
|
|
63 puts("*");
|
|
64 }
|
1
|
65
|
7
|
66
|
1
|
67 }
|
|
68
|
5
|
69 //Render cursor
|
7
|
70
|
|
71 gotoxy(X,Y);
|
|
72
|
5
|
73 puts("&");
|
|
74
|
|
75
|
1
|
76
|
|
77 }
|
|
78
|
|
79 /*********************************************
|
|
80 * Description - This function compiles instructions for CNC machines.
|
|
81 * Author - William King
|
|
82 * Date - Sep 08 2023
|
|
83 * *******************************************/
|
|
84 void Compile(){
|
|
85 char * filename;
|
2
|
86 char * file;
|
8
|
87 char buffer[sizeof(int)*8+1];
|
1
|
88 int choice;
|
|
89
|
6
|
90 puts("Select your format\n1. RAW GCODE");
|
1
|
91 scanf("%d",&choice);
|
|
92
|
|
93
|
|
94 puts("Enter the filename");
|
|
95 scanf("%s",filename);
|
|
96
|
|
97 if(choice == 1){
|
2
|
98 //Set the miller
|
|
99 strcat(file,UNITS);
|
6
|
100 strcat(file,"G0 X0 Y0 Z0");
|
2
|
101 //Meat of instructions
|
|
102 for(int i = 0;i != numpoints;i++){
|
4
|
103 //Compose
|
|
104 char * instruction;
|
|
105 strcat(instruction,"G0 X");
|
8
|
106 itoa(points[i].X,buffer);
|
|
107 strcat(instruction,buffer);
|
4
|
108 strcat(instruction," Y");
|
8
|
109 itoa(points[i].Y,buffer);
|
|
110 strcat(instruction,buffer);
|
4
|
111 strcat(instruction," Z");
|
8
|
112 itoa(DEEPNESS,buffer);
|
|
113 strcat(instruction,buffer);
|
4
|
114 //Write to string
|
|
115 strcat(file,instruction);
|
2
|
116 }
|
|
117 //Finish
|
|
118 strcat(file,"G0, X0, Y0, Z0");
|
|
119 WriteFile(filename,file);
|
1
|
120 }
|
|
121
|
|
122 puts("Finished Compiling");
|
|
123
|
|
124 }
|
|
125
|
|
126
|
|
127 /*********************************************
|
|
128 * Description - Main function
|
|
129 * Author - William King
|
|
130 * Date - Sep 08 2023
|
|
131 * *******************************************/
|
|
132 void main(int argc, char* argv[]){
|
5
|
133 while(1){
|
8
|
134 Render();
|
|
135 scanf("%c",&action);
|
|
136 switch(action){
|
|
137 case 'a': points[numpoints].X = X;
|
|
138 points[numpoints].Y = Y;
|
|
139 points[numpoints].down = down;
|
|
140 numpoints++;
|
|
141 break;
|
|
142 case 'h':
|
6
|
143
|
8
|
144 X += step;
|
|
145 break;
|
|
146 case 'j':
|
|
147 Y += step;
|
|
148 break;
|
|
149 case 'k':
|
|
150 Y -= step;
|
|
151 break;
|
|
152 case 'l':
|
|
153 X -= step;
|
|
154 break;
|
|
155 case 's':
|
|
156 puts("Enter new step:");
|
|
157 scanf("%d",&step);
|
|
158 break;
|
2
|
159
|
8
|
160 case 'c': Compile();
|
|
161 break;
|
|
162 default:
|
|
163 break;
|
|
164 }
|
5
|
165 }
|
|
166
|
1
|
167 exit(0);
|
|
168 }
|