1
|
1 /*********************************************
|
|
2 * Description - Harelet is a CAD and compiler program for CNC milling machines
|
|
3 * Author - William King
|
|
4 * Date - Sep 08 2023
|
|
5 * *******************************************/
|
|
6
|
|
7 #include <stdio.h>
|
|
8 #include <stdlib.h>
|
|
9 #include "basedfilelib.h"
|
|
10
|
|
11 #define DEEPNESS 5
|
|
12 #define MAXPOINT 4096
|
2
|
13 #define UNITS "G20"
|
|
14 #define SPEED 20
|
1
|
15
|
|
16 typedef struct{
|
|
17 unsigned int X,Y,down;
|
|
18 }point;
|
|
19
|
|
20 points[MAXPOINT];
|
|
21
|
|
22 unsigned int X,Y,step,down,numpoints;
|
|
23 char action;
|
|
24
|
|
25 /*********************************************
|
|
26 * Description - Renders the screen
|
|
27 * Author - William King
|
|
28 * Date - Sep 08 2023
|
|
29 * *******************************************/
|
|
30 void Render(){
|
|
31
|
|
32 for(int i = 0;i != MAXPOINT;i++){
|
|
33 DocTop();
|
|
34 //Move X
|
|
35 for(int j = 0;j != points[i].X;j++){
|
|
36
|
|
37 printf("");
|
|
38
|
|
39 }
|
|
40
|
|
41 //Move Y
|
|
42 for(int k = 0;k != points[i].Y;k++){
|
|
43
|
|
44 puts("");
|
|
45
|
|
46
|
|
47 }
|
|
48
|
|
49 puts("X");
|
|
50
|
|
51
|
|
52 }
|
|
53
|
|
54
|
|
55 }
|
|
56
|
|
57 /*********************************************
|
|
58 * Description - This function compiles instructions for CNC machines.
|
|
59 * Author - William King
|
|
60 * Date - Sep 08 2023
|
|
61 * *******************************************/
|
|
62 void Compile(){
|
|
63 char * filename;
|
2
|
64 char * file;
|
1
|
65 int choice;
|
|
66
|
|
67 puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
|
|
68 scanf("%d",&choice);
|
|
69
|
|
70
|
|
71 puts("Enter the filename");
|
|
72 scanf("%s",filename);
|
|
73
|
|
74 if(choice == 1){
|
2
|
75 //Set the miller
|
|
76 strcat(file,UNITS);
|
|
77
|
|
78 //Meat of instructions
|
|
79 for(int i = 0;i != numpoints;i++){
|
|
80 //Compose
|
|
81 char * instruction;
|
|
82 strcat(instruction,"G0 X");
|
|
83 strcat(instruction,sprintf("%d",points[i].X));
|
|
84 strcat(instruction," Y");
|
3
|
85 strcat(inustrction,sprintf("%d",points[i].Y));
|
|
86 strcat(instructions," Z");
|
|
87 strcat(instructions,sprintf("%d",points[i].Z));
|
2
|
88 //Write to string
|
|
89 strcat(file,instruction);
|
|
90 }
|
|
91 //Finish
|
|
92 strcat(file,"G0, X0, Y0, Z0");
|
|
93 WriteFile(filename,file);
|
1
|
94 }
|
|
95 else{
|
2
|
96 //Set the miller
|
|
97
|
1
|
98
|
2
|
99 //Meat of instructions
|
|
100
|
|
101
|
|
102 //Finish
|
1
|
103
|
|
104 }
|
|
105
|
|
106 puts("Finished Compiling");
|
|
107
|
|
108 }
|
|
109
|
|
110
|
|
111 /*********************************************
|
|
112 * Description - Main function
|
|
113 * Author - William King
|
|
114 * Date - Sep 08 2023
|
|
115 * *******************************************/
|
|
116 void main(int argc, char* argv[]){
|
|
117 scanf("%c",&action);
|
|
118 switch(action){
|
2
|
119 case 'a': points[numpoints].X = X;
|
|
120 points[numpoints].Y = Y;
|
|
121 points[numpoints].down = down;
|
|
122 numpoints++;
|
|
123 break;
|
|
124 case 'h':
|
|
125 X+=step;
|
|
126 break;
|
|
127 case 'j':
|
|
128 Y+=step;
|
1
|
129 break;
|
2
|
130 case 'k':
|
|
131 Y-=step;
|
|
132 break;
|
|
133 case 'l':
|
|
134 X-=step;
|
1
|
135 break;
|
2
|
136
|
|
137 case 's':
|
|
138 puts("Enter new step:");
|
|
139 scanf("%d",&step);
|
|
140 break;
|
|
141 default:
|
1
|
142 break;
|
|
143 }
|
|
144 exit(0);
|
|
145 }
|