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