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
|
11
|
18 #include <windows.h>>
|
7
|
19 #include <conio.h>
|
|
20 #endif
|
1
|
21
|
|
22 #define DEEPNESS 5
|
|
23 #define MAXPOINT 4096
|
13
|
24 #define UNITS "G20\n"
|
2
|
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;
|
11
|
36 unsigned int Y = 25;
|
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();
|
10
|
49 gotoxy(0,3);
|
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){
|
9
|
60 printf("X");
|
5
|
61 }
|
|
62 else{
|
9
|
63 printf("*");
|
5
|
64 }
|
1
|
65
|
7
|
66
|
1
|
67 }
|
|
68
|
5
|
69 //Render cursor
|
7
|
70
|
|
71 gotoxy(X,Y);
|
|
72
|
5
|
73 puts("&");
|
|
74
|
10
|
75 //Move cursor to top of document, so its not trailing the cadcursor
|
|
76 gotoxy(0,0);
|
|
77
|
5
|
78
|
1
|
79
|
|
80 }
|
|
81
|
|
82 /*********************************************
|
|
83 * Description - This function compiles instructions for CNC machines.
|
|
84 * Author - William King
|
|
85 * Date - Sep 08 2023
|
|
86 * *******************************************/
|
|
87 void Compile(){
|
12
|
88
|
13
|
89 char filename[64];
|
12
|
90 char file[8192];
|
13
|
91 char buffer[64];
|
12
|
92 unsigned int choice;
|
|
93
|
11
|
94 clrscr();
|
6
|
95 puts("Select your format\n1. RAW GCODE");
|
1
|
96 scanf("%d",&choice);
|
|
97
|
|
98
|
|
99 puts("Enter the filename");
|
|
100 scanf("%s",filename);
|
13
|
101 printf("Compiling %s...\n",filename);
|
1
|
102 if(choice == 1){
|
2
|
103 //Set the miller
|
|
104 strcat(file,UNITS);
|
13
|
105 strcat(file,"G0 X0 Y0 Z0\n");
|
2
|
106 //Meat of instructions
|
|
107 for(int i = 0;i != numpoints;i++){
|
4
|
108 //Compose
|
15
|
109 char instruction[64];
|
13
|
110 strcat(instruction,"G0 X ");
|
14
|
111 //Convert X to string
|
|
112 sprintf(buffer,"%d",points[i].X);
|
8
|
113 strcat(instruction,buffer);
|
13
|
114 strcat(instruction," Y ");
|
11
|
115 //Convert Y to string
|
14
|
116 sprintf(buffer,"%d",points[i].Y);
|
8
|
117 strcat(instruction,buffer);
|
12
|
118 if(points[i].down = 1){
|
13
|
119 strcat(instruction," Z 5\n");
|
12
|
120 }
|
|
121 else{
|
13
|
122 strcat(instruction," Z 0\n");
|
12
|
123 }
|
16
|
124 //strcat(instruction,buffer);
|
4
|
125 //Write to string
|
|
126 strcat(file,instruction);
|
2
|
127 }
|
16
|
128
|
2
|
129 //Finish
|
13
|
130 strcat(file,"G0 X0 Y0 Z0\n");
|
2
|
131 WriteFile(filename,file);
|
1
|
132 }
|
12
|
133 else{
|
|
134
|
16
|
135 puts("Invalid compiliation format");
|
|
136 scanf("");
|
12
|
137
|
|
138
|
|
139 }
|
1
|
140
|
11
|
141 puts("Finished Compiling GCODE");
|
16
|
142 scanf("");
|
12
|
143
|
1
|
144 }
|
|
145
|
|
146
|
|
147 /*********************************************
|
|
148 * Description - Main function
|
|
149 * Author - William King
|
|
150 * Date - Sep 08 2023
|
|
151 * *******************************************/
|
|
152 void main(int argc, char* argv[]){
|
9
|
153 clrscr();
|
5
|
154 while(1){
|
8
|
155 Render();
|
9
|
156 switch(getchar()){
|
12
|
157 case 'h':
|
|
158 X -= step;
|
|
159 break;
|
|
160 case 'j':
|
|
161 Y += step;
|
|
162 break;
|
|
163 case 'k':
|
|
164 Y -= step;
|
|
165 break;
|
|
166 case 'l':
|
|
167 X += step;
|
|
168 break;
|
2
|
169
|
12
|
170 case 's':
|
|
171 puts("New stepsize");
|
|
172 scanf("%d",&step);
|
9
|
173
|
12
|
174 break;
|
9
|
175
|
12
|
176 case 'a':
|
|
177 points[numpoints].X = X;
|
|
178 points[numpoints].Y = Y;
|
|
179 points[numpoints].down = down;
|
|
180 numpoints++;
|
|
181 break;
|
|
182 case 'd':
|
|
183 if(down == 1){
|
|
184 down = 0;
|
|
185 }
|
|
186 else{
|
|
187 down = 1;
|
|
188 }
|
|
189 break;
|
9
|
190
|
12
|
191 case 'c':
|
|
192 Compile();
|
|
193 break;
|
14
|
194 case 'q':
|
|
195 clrscr();
|
|
196 exit(0);
|
|
197 break;
|
12
|
198 default:
|
|
199 putchar('\a');
|
|
200 break;
|
8
|
201 }
|
5
|
202 }
|
|
203
|
1
|
204 exit(0);
|
|
205 }
|