annotate harelet.c @ 4:0ed615367b10

Automated Vimcurial commmit
author VilyaemKenyaz
date Fri, 08 Sep 2023 08:16:07 -0400
parents eb7a7364994c
children 3879c1178448
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{
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
19 unsigned int X,Y,down;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
20 }point;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
21
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
22 point points[MAXPOINT];
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
23
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
24 unsigned int X,Y,step,down,numpoints;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
25 char action;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
26
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
27 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
28 * Description - Renders the screen
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
29 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
30 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
31 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
32 void Render(){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
33
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
34 for(int i = 0;i != MAXPOINT;i++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
35 DocTop();
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
36 //Move X
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
37 for(int j = 0;j != points[i].X;j++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
38
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
39 printf("");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
40
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
41 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
42
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
43 //Move Y
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
44 for(int k = 0;k != points[i].Y;k++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
45
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
46 puts("");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
47
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 puts("X");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
52
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
53
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
54 }
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 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
58
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
59 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
60 * Description - This function compiles instructions for CNC machines.
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
61 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
62 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
63 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
64 void Compile(){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
65 char * filename;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
66 char * file;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
67 int choice;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
68
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
69 puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
70 scanf("%d",&choice);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
71
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
72
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
73 puts("Enter the filename");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
74 scanf("%s",filename);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
75
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
76 if(choice == 1){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
77 //Set the miller
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
78 strcat(file,UNITS);
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
79
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
80 //Meat of instructions
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
81 for(int i = 0;i != numpoints;i++){
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
82 //Compose
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
83 char * instruction;
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
84 strcat(instruction,"G0 X");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
85 strcat(instruction,sprintf("%d",points[i].X));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
86 strcat(instruction," Y");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
87 strcat(instruction,sprintf("%d",points[i].Y));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
88 strcat(instruction," Z");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
89 strcat(instruction,sprintf("%d",DEEPNESS));
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
90 //Write to string
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
91 strcat(file,instruction);
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
92 }
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
93 //Finish
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
94 strcat(file,"G0, X0, Y0, Z0");
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
95 WriteFile(filename,file);
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
96 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
97 else{
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
98 puts("Superhare implementation not done");
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
99 exit(1);
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
100 //Set the miller
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
101
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
102
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
103 //Meat of instructions
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
104
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
105
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
106 //Finish
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
107
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
108 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
109
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
110 puts("Finished Compiling");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
111
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
112 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
113
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
114
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
115 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
116 * Description - Main function
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
117 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
118 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
119 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
120 void main(int argc, char* argv[]){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
121 scanf("%c",&action);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
122 switch(action){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
123 case 'a': points[numpoints].X = X;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
124 points[numpoints].Y = Y;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
125 points[numpoints].down = down;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
126 numpoints++;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
127 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
128 case 'h':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
129 X+=step;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
130 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
131 case 'j':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
132 Y+=step;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
133 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
134 case 'k':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
135 Y-=step;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
136 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
137 case 'l':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
138 X-=step;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
139 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
140
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
141 case 's':
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
142 puts("Enter new step:");
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
143 scanf("%d",&step);
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
144 break;
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
145
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
146 case 'c': Compile();
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
147 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
148 default:
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
149 break;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
150 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
151 exit(0);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
152 }