annotate harelet.c @ 6:ec82c868b8b0

Automated Vimcurial commmit
author VilyaemKenyaz
date Sat, 09 Sep 2023 16:44:53 -0400
parents 3879c1178448
children 1bb981516d87
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{
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
19 unsigned int X;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
20 unsigned int Y;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
21 unsigned int down;
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;
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
27 unsigned int Y = 0;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
28 unsigned int step = 5;
5
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
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
40 printf("\x1b[0;0f]");
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
41 puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023");
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
42 printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down);
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
43
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
44 //Render points
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
45 for(int i = 0;i != MAXPOINT;i++){
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
46 printf("\x1b[0;0f]");
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
47 //Move X
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
48 for(int j = 0;j != points[i].X;j++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
49
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
50 printf("");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
51
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 //Move Y
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
55 for(int k = 0;k != points[i].Y;k++){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
56
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
57 puts("");
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 }
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
61 if(points[i].down == 0){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
62 puts("X");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
63 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
64 else{
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
65 puts("*");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
66 }
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
67
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
68 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
69
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
70 //Render cursor
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
71 DocTop();
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
72 for(int i = 0;i != X;i++){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
73 printf("");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
74
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
75 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
76 for(int i = 0;i != Y;i++){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
77 puts("");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
78 }
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
79 puts("&");
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
80
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
81
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
82
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
83 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
84
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
85 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
86 * Description - This function compiles instructions for CNC machines.
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
87 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
88 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
89 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
90 void Compile(){
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
91 char * filename;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
92 char * file;
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
93 int choice;
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
94
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
95 puts("Select your format\n1. RAW GCODE");
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
96 scanf("%d",&choice);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
97
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
98
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
99 puts("Enter the filename");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
100 scanf("%s",filename);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
101
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
102 if(choice == 1){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
103 //Set the miller
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
104 strcat(file,UNITS);
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
105 strcat(file,"G0 X0 Y0 Z0");
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
106 //Meat of instructions
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
107 for(int i = 0;i != numpoints;i++){
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
108 //Compose
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
109 char * instruction;
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
110 strcat(instruction,"G0 X");
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
111 strcat(instruction,itoa(points[i].X));
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
112 strcat(instruction," Y");
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
113 strcat(instruction,itoa(points[i].Y));
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
114 strcat(instruction," Z");
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
115 strcat(instruction,itoa(DEEPNESS));
4
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
116 //Write to string
0ed615367b10 Automated Vimcurial commmit
VilyaemKenyaz
parents: 3
diff changeset
117 strcat(file,instruction);
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
118 }
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
119 //Finish
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
120 strcat(file,"G0, X0, Y0, Z0");
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
121 WriteFile(filename,file);
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
122 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
123
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
124 puts("Finished Compiling");
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
125
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
126 }
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
127
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
128
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
129 /*********************************************
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
130 * Description - Main function
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
131 * Author - William King
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
132 * Date - Sep 08 2023
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
133 * *******************************************/
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
134 void main(int argc, char* argv[]){
5
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
135 while(1){
3879c1178448 Automated Vimcurial commmit
VilyaemKenyaz
parents: 4
diff changeset
136 Render();
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
137 scanf("%c",&action);
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
138 switch(action){
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
139 case 'a': points[numpoints].X = X;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
140 points[numpoints].Y = Y;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
141 points[numpoints].down = down;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
142 numpoints++;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
143 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
144 case 'h':
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
145
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
146 if(X < 200 - step){
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
147 X += step;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
148 }
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
149 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
150 case 'j':
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
151 if(X > step){
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
152 Y += step;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
153 }
1
47e1b1039d7b Automated Vimcurial commmit
VilyaemKenyaz
parents: 0
diff changeset
154 break;
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
155 case 'k':
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
156 if(Y < 0){
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
157 Y -= step;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
158 }
2
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
159 break;
1b0ebe86b44c Automated Vimcurial commmit
VilyaemKenyaz
parents: 1
diff changeset
160 case 'l':
6
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
161 if(Y > 200){
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
162 X -= step;
ec82c868b8b0 Automated Vimcurial commmit
VilyaemKenyaz
parents: 5
diff changeset
163 }
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 }