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{
|
5
|
19 unsigned int X = 0;
|
|
20 unsigned int Y = 0;;
|
|
21 unsigned int down = 0;
|
1
|
22 }point;
|
|
23
|
4
|
24 point points[MAXPOINT];
|
1
|
25
|
5
|
26 unsigned int X = 0;
|
|
27 unsigned int Y = 0;
|
|
28 unsigned int step = 0;
|
|
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
|
5
|
40 //Render points
|
1
|
41 for(int i = 0;i != MAXPOINT;i++){
|
5
|
42 puts("\x1b[0;0f]");
|
|
43
|
1
|
44 //Move X
|
|
45 for(int j = 0;j != points[i].X;j++){
|
|
46
|
|
47 printf("");
|
|
48
|
|
49 }
|
|
50
|
|
51 //Move Y
|
|
52 for(int k = 0;k != points[i].Y;k++){
|
|
53
|
|
54 puts("");
|
|
55
|
|
56
|
|
57 }
|
5
|
58 if(points[i].down == 0){
|
|
59 puts("X");
|
|
60 }
|
|
61 else{
|
|
62 puts("*");
|
|
63 }
|
1
|
64
|
|
65 }
|
|
66
|
5
|
67 //Render cursor
|
|
68 DocTop();
|
|
69 for(int i = 0;i != X;i++){
|
|
70 printf("");
|
|
71
|
|
72 }
|
|
73 for(int i = 0;i != Y;i++){
|
|
74 puts("");
|
|
75 }
|
|
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(){
|
|
88 char * filename;
|
2
|
89 char * file;
|
1
|
90 int choice;
|
|
91
|
|
92 puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
|
|
93 scanf("%d",&choice);
|
|
94
|
|
95
|
|
96 puts("Enter the filename");
|
|
97 scanf("%s",filename);
|
|
98
|
|
99 if(choice == 1){
|
2
|
100 //Set the miller
|
|
101 strcat(file,UNITS);
|
4
|
102
|
2
|
103 //Meat of instructions
|
|
104 for(int i = 0;i != numpoints;i++){
|
4
|
105 //Compose
|
|
106 char * instruction;
|
|
107 strcat(instruction,"G0 X");
|
|
108 strcat(instruction,sprintf("%d",points[i].X));
|
|
109 strcat(instruction," Y");
|
|
110 strcat(instruction,sprintf("%d",points[i].Y));
|
|
111 strcat(instruction," Z");
|
|
112 strcat(instruction,sprintf("%d",DEEPNESS));
|
|
113 //Write to string
|
|
114 strcat(file,instruction);
|
2
|
115 }
|
|
116 //Finish
|
|
117 strcat(file,"G0, X0, Y0, Z0");
|
|
118 WriteFile(filename,file);
|
1
|
119 }
|
|
120 else{
|
4
|
121 puts("Superhare implementation not done");
|
|
122 exit(1);
|
2
|
123 //Set the miller
|
4
|
124
|
1
|
125
|
2
|
126 //Meat of instructions
|
4
|
127
|
2
|
128
|
|
129 //Finish
|
1
|
130
|
|
131 }
|
|
132
|
|
133 puts("Finished Compiling");
|
|
134
|
|
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[]){
|
5
|
144 while(1){
|
|
145 Render();
|
1
|
146 scanf("%c",&action);
|
|
147 switch(action){
|
2
|
148 case 'a': points[numpoints].X = X;
|
|
149 points[numpoints].Y = Y;
|
|
150 points[numpoints].down = down;
|
|
151 numpoints++;
|
|
152 break;
|
|
153 case 'h':
|
|
154 X+=step;
|
|
155 break;
|
|
156 case 'j':
|
|
157 Y+=step;
|
1
|
158 break;
|
2
|
159 case 'k':
|
|
160 Y-=step;
|
|
161 break;
|
|
162 case 'l':
|
|
163 X-=step;
|
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 }
|