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