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