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