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