comparison harelet.c @ 12:35e6a7b53e3c

Automated Vimcurial commmit
author VilyaemKenyaz
date Tue, 12 Sep 2023 08:18:53 -0400
parents 1d4df12de9e3
children 8fe2392f2fcc
comparison
equal deleted inserted replaced
11:1d4df12de9e3 12:35e6a7b53e3c
86 * Description - This function compiles instructions for CNC machines. 86 * Description - This function compiles instructions for CNC machines.
87 * Author - William King 87 * Author - William King
88 * Date - Sep 08 2023 88 * Date - Sep 08 2023
89 * *******************************************/ 89 * *******************************************/
90 void Compile(){ 90 void Compile(){
91 91
92 char * filename; 92 char filename[32];
93 char * file; 93 char file[8192];
94 char buffer[sizeof(int)*8+1]; 94 char buffer[32];
95 int choice; 95 unsigned int choice;
96
96 clrscr(); 97 clrscr();
97 puts("Select your format\n1. RAW GCODE"); 98 puts("Select your format\n1. RAW GCODE");
98 scanf("%d",&choice); 99 scanf("%d",&choice);
99 100
100 101
101 puts("Enter the filename"); 102 puts("Enter the filename");
102 scanf("%s",filename); 103 scanf("%s",filename);
103 104 printf("Compiling %s,,,\n",filename);
104 if(choice == 1){ 105 if(choice == 1){
105 //Set the miller 106 //Set the miller
106 strcat(file,UNITS); 107 strcat(file,UNITS);
107 strcat(file,"G0 X0 Y0 Z0"); 108 strcat(file,"G0 X0 Y0 Z0");
108 //Meat of instructions 109 //Meat of instructions
109 for(int i = 0;i != numpoints;i++){ 110 for(int i = 0;i != numpoints;i++){
110 //Compose 111 //Compose
111 char * instruction; 112 char instruction[32];
112 strcat(instruction,"G0 X"); 113 strcat(instruction,"G0 X");
113 strcat(instruction,buffer); 114 strcat(instruction,buffer);
114 //Convert X to string 115 //Convert X to string
115 sprintf(buffer,"%d",&points[i].X); 116 sprintf(buffer,"%d",&points[i].X);
116 strcat(instruction," Y"); 117 strcat(instruction," Y");
117 //Convert Y to string 118 //Convert Y to string
118 sprintf(buffer,"%d",&points[i].Y); 119 sprintf(buffer,"%d",&points[i].Y);
119 strcat(instruction,buffer); 120 strcat(instruction,buffer);
120 //Convert Z to string 121 if(points[i].down = 1){
121 sprintf(buffer,"%d",5); 122 strcat(instruction," Z 5");
122 strcat(instruction," Z"); 123 }
124 else{
125 strcat(instruction," Z 0");
126 }
123 strcat(instruction,buffer); 127 strcat(instruction,buffer);
124 //Write to string 128 //Write to string
125 strcat(file,instruction); 129 strcat(file,instruction);
126 } 130 }
127 //Finish 131 //Finish
128 strcat(file,"G0, X0, Y0, Z0"); 132 strcat(file,"G0, X0, Y0, Z0");
129 WriteFile(filename,file); 133 WriteFile(filename,file);
130 } 134 }
135 else{
136
137 puts("Invalid compile format");
138
139
140 }
131 141
132 puts("Finished Compiling GCODE"); 142 puts("Finished Compiling GCODE");
133 143
134 144
135 } 145 }
136 146
137 147
138 /********************************************* 148 /*********************************************
139 * Description - Main function 149 * Description - Main function
142 * *******************************************/ 152 * *******************************************/
143 void main(int argc, char* argv[]){ 153 void main(int argc, char* argv[]){
144 clrscr(); 154 clrscr();
145 while(1){ 155 while(1){
146 Render(); 156 Render();
147 //New CONIO controls
148 switch(getchar()){ 157 switch(getchar()){
149 case 'h': 158 case 'h':
150 X -= step; 159 X -= step;
151 break; 160 break;
152 case 'j': 161 case 'j':
153 Y += step; 162 Y += step;
154 break; 163 break;
155 case 'k': 164 case 'k':
156 Y -= step; 165 Y -= step;
157 break; 166 break;
158 case 'l': 167 case 'l':
159 X += step; 168 X += step;
160 break; 169 break;
161 170
162 case 's': 171 case 's':
163 puts("New stepsize"); 172 puts("New stepsize");
164 scanf("%d",&step); 173 scanf("%d",&step);
165 174
166 break; 175 break;
167 176
168 case 'a': 177 case 'a':
169 points[numpoints].X = X; 178 points[numpoints].X = X;
170 points[numpoints].Y = Y; 179 points[numpoints].Y = Y;
171 points[numpoints].down = down; 180 points[numpoints].down = down;
172 numpoints++; 181 numpoints++;
173 break; 182 break;
174 case 'd': 183 case 'd':
175 if(down == 1){ 184 if(down == 1){
176 down = 0; 185 down = 0;
177 } 186 }
178 else{ 187 else{
179 down = 1; 188 down = 1;
180 } 189 }
181 break; 190 break;
182 191
183 case 'c': 192 case 'c':
184 Compile(); 193 Compile();
185 break; 194 break;
186 195
187 default: 196 default:
188 putchar('\a'); 197 putchar('\a');
189 break; 198 break;
190 } 199 }
191 } 200 }
192 201
193 exit(0); 202 exit(0);
194 } 203 }