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