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){
|
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
|
|
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(){
|
9
|
88 /*
|
1
|
89 char * filename;
|
2
|
90 char * file;
|
8
|
91 char buffer[sizeof(int)*8+1];
|
1
|
92 int choice;
|
|
93
|
6
|
94 puts("Select your format\n1. RAW GCODE");
|
1
|
95 scanf("%d",&choice);
|
|
96
|
|
97
|
|
98 puts("Enter the filename");
|
|
99 scanf("%s",filename);
|
|
100
|
|
101 if(choice == 1){
|
2
|
102 //Set the miller
|
|
103 strcat(file,UNITS);
|
6
|
104 strcat(file,"G0 X0 Y0 Z0");
|
2
|
105 //Meat of instructions
|
|
106 for(int i = 0;i != numpoints;i++){
|
4
|
107 //Compose
|
|
108 char * instruction;
|
|
109 strcat(instruction,"G0 X");
|
8
|
110 itoa(points[i].X,buffer);
|
|
111 strcat(instruction,buffer);
|
4
|
112 strcat(instruction," Y");
|
8
|
113 itoa(points[i].Y,buffer);
|
|
114 strcat(instruction,buffer);
|
4
|
115 strcat(instruction," Z");
|
8
|
116 itoa(DEEPNESS,buffer);
|
|
117 strcat(instruction,buffer);
|
4
|
118 //Write to string
|
|
119 strcat(file,instruction);
|
2
|
120 }
|
|
121 //Finish
|
|
122 strcat(file,"G0, X0, Y0, Z0");
|
|
123 WriteFile(filename,file);
|
1
|
124 }
|
|
125
|
|
126 puts("Finished Compiling");
|
|
127
|
9
|
128 */
|
1
|
129 }
|
|
130
|
|
131
|
|
132 /*********************************************
|
|
133 * Description - Main function
|
|
134 * Author - William King
|
|
135 * Date - Sep 08 2023
|
|
136 * *******************************************/
|
|
137 void main(int argc, char* argv[]){
|
9
|
138 clrscr();
|
5
|
139 while(1){
|
8
|
140 Render();
|
9
|
141 /*
|
|
142 scanf("%c",&action);
|
|
143 switch(action){
|
|
144 case 'a':
|
|
145 points[numpoints].X = X;
|
|
146 points[numpoints].Y = Y;
|
|
147 points[numpoints].down = down;
|
|
148 numpoints++;
|
|
149 break;
|
|
150 case 'h':
|
|
151
|
|
152 X += step;
|
|
153 break;
|
|
154 case 'j':
|
|
155 Y += step;
|
|
156 break;
|
|
157 case 'k':
|
|
158 Y -= step;
|
|
159 break;
|
|
160 case 'l':
|
|
161 X -= step;
|
|
162 break;
|
|
163 case 's':
|
|
164 puts("Enter new step:");
|
|
165 scanf("%d",&step);
|
|
166 break;
|
|
167
|
|
168 case 'c': Compile();
|
|
169 break;
|
|
170 default:
|
|
171 break;
|
|
172 }
|
|
173 */
|
6
|
174
|
9
|
175 //New CONIO controls
|
|
176 switch(getchar()){
|
|
177 case 'h':
|
|
178 X += step;
|
|
179 break;
|
|
180 case 'j':
|
|
181 Y += step;
|
|
182 break;
|
|
183 case 'k':
|
|
184 Y -= step;
|
|
185 break;
|
|
186 case 'l':
|
|
187 X -= step;
|
|
188 break;
|
2
|
189
|
9
|
190 case 's':
|
|
191 puts("New stepsize");
|
|
192 scanf("%d",&step);
|
|
193
|
|
194 break;
|
|
195
|
|
196 case 'a':
|
|
197 points[numpoints].X = X;
|
|
198 points[numpoints].Y = Y;
|
|
199 points[numpoints].down = down;
|
|
200 numpoints++;
|
|
201 break;
|
|
202
|
|
203 case 'c':
|
|
204 Compile();
|
|
205 break;
|
|
206
|
|
207 default:
|
|
208 putchar('\a');
|
|
209 break;
|
8
|
210 }
|
5
|
211 }
|
|
212
|
1
|
213 exit(0);
|
|
214 }
|