comparison harelet.c @ 19:8fe0b5711413

Added BasedTremGrx and Dvorak
author VilyaemKenyaz
date Wed, 27 Sep 2023 01:47:28 -0400
parents 7bf25e90a1de
children 0555050bada0
comparison
equal deleted inserted replaced
18:7bf25e90a1de 19:8fe0b5711413
5 * *******************************************/ 5 * *******************************************/
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <assert.h>
10 11
11 #include "basedfilelib.h" 12 #include "basedfilelib.h"
12 13 #include "basedtermgrx.h"
13 #ifdef __linux__
14 #include "linuxconio.h"
15 #endif
16
17 #ifdef _WIN32
18 #include <windows.h>>
19 #include <conio.h>
20 #endif
21 14
22 #define DEEPNESS 5 15 #define DEEPNESS 5
23 #define MAXPOINT 4096 16 #define MAXPOINT 4096
24 #define UNITS "G20\n" 17 #define UNITS "G20\n"
25 #define SPEED 20 18 #define SPEED 20
26
27 #define SBPUP "JZ &ZUP\n"
28 #define SBPDWN 0.0625
29
30 19
31 typedef struct{ 20 typedef struct{
32 unsigned int X; 21 unsigned int X;
33 unsigned int Y; 22 unsigned int Y;
34 unsigned int down; 23 unsigned int down;
35 }point; 24 }point;
36 25
37 point points[MAXPOINT]; 26 point points[MAXPOINT];
38 27
39 unsigned int X = 100; 28 unsigned int X = 5;
40 unsigned int Y = 25; 29 unsigned int Y = 5;
41 unsigned int step = 5; 30 unsigned int step = 5;
42 unsigned int down = 0; 31 unsigned int down = 0;
43 unsigned int numpoints = 0; 32 unsigned int numpoints = 0;
44 char action; 33 char action;
45 34
46 35
47 /********************************************* 36 /*********************************************
48 * Description - Convert integers to strings, makes 37 * Description - Warn the user about something
49 * source code more pretty. 38 * Author - William King
50 * Author - William King 39 * Date - Sep 27 2023
51 * Date - Sep 26 2023 40 * *******************************************/
52 * *******************************************/ 41 void Warn(char * s){
42 printf("WARNING:");
43 puts(s);
44 putchar('\a');
45 getchar();
46 }
47
48 /*********************************************
49 * Description - Convert integers to strings, makes
50 * source code more pretty.
51 * Author - William King
52 * Date - Sep 26 2023
53 * *******************************************/
53 char * IntToString(int num){ 54 char * IntToString(int num){
54 char * s; 55 char * s;
55 sprintf(s,"%d",num); 56 sprintf(s,"%d",num);
56 return s; 57 return s;
57 } 58 }
60 * Description - Renders the screen 61 * Description - Renders the screen
61 * Author - William King 62 * Author - William King
62 * Date - Sep 08 2023 63 * Date - Sep 08 2023
63 * *******************************************/ 64 * *******************************************/
64 void Render(){ 65 void Render(){
65 clrscr(); 66 ClrScr();
66 gotoxy(0,3);
67 puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023"); 67 puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023");
68 printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down); 68 printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down);
69 69
70 //Render points 70 //Render points
71 for(int i = 0;i != MAXPOINT;i++){ 71 if(numpoints > 0){
72 gotoxy(0,50); 72 for(int i = 0;i != numpoints;i++){
73 73 if(points[i].down == 0){
74 gotoxy(points[i].X,points[i].Y); 74 DrawChar(points[i].X,points[i].Y,'U');
75 75
76 if(points[i].down == 0){ 76 }
77 printf("X"); 77 else{
78 } 78 DrawChar(points[i].X,points[i].Y,'D');
79 else{ 79 }
80 printf("*"); 80 }
81 }
82
83
84 } 81 }
85 82
86 //Render cursor 83 //Render cursor
87 84 DrawChar(X,Y,'&');
88 gotoxy(X,Y); 85
89 86 Splash();
90 puts("&");
91
92 //Move cursor to top of document, so its not trailing the cadcursor
93 gotoxy(0,0);
94
95
96 87
97 } 88 }
98 89
99 /********************************************* 90 /*********************************************
100 * Description - This function compiles instructions for CNC machines. 91 * Description - This function compiles instructions for CNC machines.
106 char filename[64]; 97 char filename[64];
107 char file[8192]; 98 char file[8192];
108 char buffer[64]; 99 char buffer[64];
109 unsigned int choice; 100 unsigned int choice;
110 101
111 clrscr();
112 puts("Select your format\n1. RAW GCODE\n2. OPENSBP"); 102 puts("Select your format\n1. RAW GCODE\n2. OPENSBP");
113 scanf("%d",&choice); 103 scanf("%d",&choice);
114 104
115 105
116 puts("Enter the filename"); 106 puts("Enter the filename");
123 //Meat of instructions 113 //Meat of instructions
124 for(int i = 0;i != numpoints;i++){ 114 for(int i = 0;i != numpoints;i++){
125 //Compose 115 //Compose
126 char instruction[64]; 116 char instruction[64];
127 strcat(instruction,"G0 X "); 117 strcat(instruction,"G0 X ");
128 //Convert X to string 118 strcat(instruction,IntToString(points[i].X));
129 sprintf(buffer,"%d",points[i].X);
130 strcat(instruction,buffer);
131 strcat(instruction," Y "); 119 strcat(instruction," Y ");
132 //Convert Y to string 120 strcat(instruction,IntToString(points[i].Y));
133 sprintf(buffer,"%d",points[i].Y); 121 if(points[i].down == 1){
134 strcat(instruction,buffer);
135 if(points[i].down = 1){
136 strcat(instruction," Z 5\n"); 122 strcat(instruction," Z 5\n");
137 } 123 }
138 else{ 124 else{
139 strcat(instruction," Z 0\n"); 125 strcat(instruction," Z 0\n");
140 } 126 }
145 //Finish 131 //Finish
146 strcat(file,"G0 X0 Y0 Z0\n"); 132 strcat(file,"G0 X0 Y0 Z0\n");
147 WriteFile(filename,file); 133 WriteFile(filename,file);
148 } 134 }
149 else if(choice == 2){ 135 else if(choice == 2){
150 // Setup the miller 136 // Setup the miller
151 strcat(file,"'OpenSBP file written by Harelet\n'Harelet, written by William King\n'No responsibilty is taken for any damages to any equipment\n\n'Starting\nSO, 1,1\nPause 2\nSA,\n&ZUP = 0.25\nMH\n\n'Bulk of instructions\n"); 137 strcat(file,"'OpenSBP file written by Harelet\n'Harelet, written by William King\n'No responsibilty is taken for any damages to any equipment\n\n'Starting\nSO, 1,1\nPause 2\nSA,\n&ZUP = 0.25\nMH\n\n'Bulk of instructions\n");
152 138
153 for(int i = 0;i != numpoints;i++){ 139 for(int i = 0;i != numpoints;i++){
154 140
155 char instruction[64]; 141 char instruction[64];
156 142
157 strcat(instruction,"J2 "); 143 strcat(instruction,"J2 ");
158 strcat(instruction,IntToString(points[i].X)); 144 strcat(instruction,IntToString(points[i].X));
159 strcat(instruction," "); 145 strcat(instruction," ");
164 strcat(instruction,"MZ -0,0625\n"); 150 strcat(instruction,"MZ -0,0625\n");
165 } 151 }
166 else{ 152 else{
167 strcat(instruction,"JZ,&ZUP\n"); 153 strcat(instruction,"JZ,&ZUP\n");
168 } 154 }
169
170 155
171 strcat(file,instruction); 156 strcat(file,instruction);
172 } 157 }
173 158
174 //Finished, add instructions to wait for the user 159 //Finished, add instructions to wait for the user
175 strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE"); 160 strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE");
176 161
177 WriteFile(filename,file); 162 WriteFile(filename,file);
178 163
179 } 164 }
180 else{ 165 else{
181 166 Warn("Invalid compiliation format");
182 puts("Invalid compiliation format");
183 scanf("");
184
185
186 } 167 }
187 168
188 puts("Finished compiling instructions"); 169 puts("Finished compiling instructions");
189 scanf(""); 170 getchar();
190 171
191 } 172 }
192 173
193 174
194 /********************************************* 175 /*********************************************
195 * Description - Main function 176 * Description - Main function
196 * Author - William King 177 * Author - William King
197 * Date - Sep 08 2023 178 * Date - Sep 08 2023
198 * *******************************************/ 179 * *******************************************/
199 void main(int argc, char* argv[]){ 180 void main(int argc, char* argv[]){
200 clrscr();
201 while(1){ 181 while(1){
202 Render(); 182 Render();
183 #ifndef DVORAK
203 switch(getchar()){ 184 switch(getchar()){
204 case 'h': 185 case 'h':
205 X -= step; 186 if(X - step >= 2){
187 X -= step;
188 }
206 break; 189 break;
207 case 'j': 190 case 'j':
208 Y += step; 191 if(Y + step < RESY - step){
192 Y += step;
193 }
209 break; 194 break;
210 case 'k': 195 case 'k':
211 Y -= step; 196 if(Y - step >= 2){
197 Y -= step;
198 }
212 break; 199 break;
213 case 'l': 200 case 'l':
214 X += step; 201 if(X + step < RESX - step){
215 break; 202 X += step;
216 203 }
204 break;
217 case 's': 205 case 's':
218 puts("New stepsize"); 206 puts("New stepsize:");
219 scanf("%d",&step); 207 scanf("%d",&step);
220
221 break; 208 break;
222 209
223 case 'a': 210 case 'a':
224 points[numpoints].X = X; 211 points[numpoints].X = X;
225 points[numpoints].Y = Y; 212 points[numpoints].Y = Y;
232 } 219 }
233 else{ 220 else{
234 down = 1; 221 down = 1;
235 } 222 }
236 break; 223 break;
237
238 case 'c': 224 case 'c':
239 Compile(); 225 Compile();
240 break; 226 break;
241 case 'q': 227 case 'q':
242 clrscr(); 228 ClrScr();
243 exit(0); 229 exit(0);
244 break; 230 break;
245 default: 231 default:
246 putchar('\a'); 232 break;
247 break; 233 }
248 } 234 #endif
235 #ifdef DVORAK
236 switch(getchar()){
237 case 'a':
238 if(X - step >= 2){
239 X -= step;
240 }
241 break;
242 case 'o':
243 if(Y + step < RESY - step){
244 Y += step;
245 }
246 break;
247 case ',':
248 if(Y - step >= 2){
249 Y -= step;
250 }
251 break;
252 case 'e':
253 if(X + step < RESX - step){
254 X += step;
255 }
256 break;
257 case '.':
258 puts("New stepsize:");
259 scanf("%d",&step);
260 break;
261
262 case ' ':
263 points[numpoints].X = X;
264 points[numpoints].Y = Y;
265 points[numpoints].down = down;
266 numpoints++;
267 break;
268 case 'p':
269 if(down == 1){
270 down = 0;
271 }
272 else{
273 down = 1;
274 }
275 break;
276 case 'y':
277 Compile();
278 break;
279 case 'q':
280 ClrScr();
281 exit(0);
282 break;
283 default:
284 break;
285 }
286 #endif
249 } 287 }
250 288
251 exit(0); 289 exit(0);
252 } 290 }