annotate harelet.c @ 5:3879c1178448

Automated Vimcurial commmit
author VilyaemKenyaz
date Fri, 08 Sep 2023 08:40:34 -0400
parents 0ed615367b10
children ec82c868b8b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
1 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
2 * Description - Harelet is a CAD and compiler program for CNC milling machines
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
3 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
4 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
5 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
6
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
7 #include <stdio.h>
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
8 #include <stdlib.h>
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
9 #include <string.h>
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
10 #include "basedfilelib.h"
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
11 #include "minibasediolib.h"
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
12
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
13 #define DEEPNESS 5
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
14 #define MAXPOINT 4096
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
15 #define UNITS "G20"
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
16 #define SPEED 20
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
17
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
18 typedef struct{
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
19 unsigned int X = 0;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
20 unsigned int Y = 0;;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
21 unsigned int down = 0;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
22 }point;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
23
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
24 point points[MAXPOINT];
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
25
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
26 unsigned int X = 0;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
27 unsigned int Y = 0;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
28 unsigned int step = 0;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
29 unsigned int down = 0;
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
30 unsigned int numpoints = 0;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
31 char action;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
32
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
33 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
34 * Description - Renders the screen
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
35 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
36 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
37 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
38 void Render(){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
39
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
40 //Render points
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
41 for(int i = 0;i != MAXPOINT;i++){
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
42 puts("\x1b[0;0f]");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
43
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
44 //Move X
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
45 for(int j = 0;j != points[i].X;j++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
46
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
47 printf("");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
48
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
49 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
50
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
51 //Move Y
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
52 for(int k = 0;k != points[i].Y;k++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
53
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
54 puts("");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
55
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
56
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
57 }
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
58 if(points[i].down == 0){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
59 puts("X");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
60 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
61 else{
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
62 puts("*");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
63 }
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
64
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
65 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
66
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
67 //Render cursor
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
68 DocTop();
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
69 for(int i = 0;i != X;i++){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
70 printf("");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
71
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
72 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
73 for(int i = 0;i != Y;i++){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
74 puts("");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
75 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
76 puts("&");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
77
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
78
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
79
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
80 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
81
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
82 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
83 * Description - This function compiles instructions for CNC machines.
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
84 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
85 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
86 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
87 void Compile(){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
88 char * filename;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
89 char * file;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
90 int choice;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
91
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
92 puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
93 scanf("%d",&choice);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
94
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
95
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
96 puts("Enter the filename");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
97 scanf("%s",filename);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
98
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
99 if(choice == 1){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
100 //Set the miller
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
101 strcat(file,UNITS);
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
102
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
103 //Meat of instructions
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
104 for(int i = 0;i != numpoints;i++){
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
105 //Compose
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
106 char * instruction;
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
107 strcat(instruction,"G0 X");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
108 strcat(instruction,sprintf("%d",points[i].X));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
109 strcat(instruction," Y");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
110 strcat(instruction,sprintf("%d",points[i].Y));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
111 strcat(instruction," Z");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
112 strcat(instruction,sprintf("%d",DEEPNESS));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
113 //Write to string
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
114 strcat(file,instruction);
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
115 }
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
116 //Finish
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
117 strcat(file,"G0, X0, Y0, Z0");
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
118 WriteFile(filename,file);
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
119 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
120 else{
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
121 puts("Superhare implementation not done");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
122 exit(1);
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
123 //Set the miller
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
124
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
125
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
126 //Meat of instructions
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
127
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
128
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
129 //Finish
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
130
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
131 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
132
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
133 puts("Finished Compiling");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
134
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
135 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
136
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
137
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
138 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
139 * Description - Main function
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
140 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
141 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
142 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
143 void main(int argc, char* argv[]){
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
144 while(1){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
145 Render();
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
146 scanf("%c",&action);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
147 switch(action){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
148 case 'a': points[numpoints].X = X;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
149 points[numpoints].Y = Y;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
150 points[numpoints].down = down;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
151 numpoints++;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
152 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
153 case 'h':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
154 X+=step;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
155 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
156 case 'j':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
157 Y+=step;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
158 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
159 case 'k':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
160 Y-=step;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
161 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
162 case 'l':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
163 X-=step;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
164 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
165
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
166 case 's':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
167 puts("Enter new step:");
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
168 scanf("%d",&step);
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
169 break;
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
170
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
171 case 'c': Compile();
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
172 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
173 default:
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
174 break;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
175 }
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
176 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
177
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
178 exit(0);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
179 }