Mercurial Hosting > harelet
changeset 19:8fe0b5711413
Added BasedTremGrx and Dvorak
author | VilyaemKenyaz |
---|---|
date | Wed, 27 Sep 2023 01:47:28 -0400 |
parents | 7bf25e90a1de |
children | 0555050bada0 |
files | .README.md.swp FIRST.SBP README.md basedfilelib.h basedtermgrx.h c.ksh examples/FIRST.SBP examples/LINE examples/LINE.GCODE examples/SQUARE examples/SQUARE.GCODE harelet harelet.c hareletdvrk linuxconio.h |
diffstat | 15 files changed, 390 insertions(+), 348 deletions(-) [+] |
line wrap: on
line diff
--- a/FIRST.SBP Tue Sep 26 23:19:42 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -'OpenSBP file written by Harelet -'Harelet, written by William King -'No responsibilty is taken for any damages to any equipment - -'Starting -SO, 1,1 -Pause 2 -SA, -&ZUP = 0.25 -MH - -'Bulk of instructions -J2 55 25 -JZ,&ZUP -J2 55 25 -JZ,&ZUP -J2 25 25 -JZ,&ZUP - -J2,0,0 -SO, 1,0 -'All done. Wait for user. -PAUSE \ No newline at end of file
--- a/README.md Tue Sep 26 23:19:42 2023 -0400 +++ b/README.md Wed Sep 27 01:47:28 2023 -0400 @@ -1,30 +1,48 @@ # Harelet A simple CNC CAD program for milling machines -You may export RAW gcode or Superhare machines -To configure some settings edit the definitions in +You may export RAW gcode or for Shopbot machines (OpenSBP) +To configure settings edit the definitions in the source code and recompile easily by executing the -compile script. By default the units are imperial. +compile script. By default the units are Imperial. --- ## USAGE -Vim keys (HJKL). +All controls are lowercase. +Vim keys to move(HJKL). + k + h l + j H Left J Down K Up L Right + A to add a point at the current cursor's position Q to exit D to set cursor down or raised -C to compile GCODE +C to compile instructions for a machine, you will be prompted for a filename + +S to change step size, how far the cursor moves at a time + +## DVORAK + +Harelet has built in Dvorak support, compile with -dvorak. + +Keys for QWERTY to DVORAK -S to change step size - - - +, - Up +A - Left +O - Down +E - Right +X - Exit +p - Set DWN +Y - Compile +. - Set step size +Space - Add point
--- a/basedfilelib.h Tue Sep 26 23:19:42 2023 -0400 +++ b/basedfilelib.h Wed Sep 27 01:47:28 2023 -0400 @@ -1,6 +1,9 @@ -// Based File Library -// -// Makes File I/O two functions, more like TempleOS, instead of *nix. +/********************************************* +* Description - BasedFileLib makes file I/O less like *nix and more like +* TempleOS +* Author - William King +* Date - Sep 25 2023 +* *******************************************/ #define MAX_LINES 100000 #define MAXLENGTH 512
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/basedtermgrx.h Wed Sep 27 01:47:28 2023 -0400 @@ -0,0 +1,199 @@ +/********************************************* + * Description - Based Term Grx + * Modified for use with Harelet. + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ + +#include <string.h> + +//Always have a 2:1 ratio if you want a square picture +//Terminals are vertically stretched +#define RESX 98 +#define RESY 48 + +//Center X & Y +#define CX 49 +#define CY 24 + +//Colours +#define BLACK "\x1b[30m" +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define WHITE "\x1b[37m" + +#define IBLACK "\x1b[30;1m" +#define IRED "\x1b[31;1m" +#define IGREEN "\x1b[32;1m" +#define IYELLOW "\x1b[33;1m" +#define IBLUE "\x1b[34;1m" +#define IMAGENTA "\x1b[35;1m" +#define ICYAN "\x1b[36;1m" +#define IWHITE "\x1b[37;1m" + +#define BGC_BLACK "\x1b[40m" +#define BGC_RED "\x1b[41m" +#define BGC_GREEN "\x1b[42m" +#define BGC_YELLOW "\x1b[43m" +#define BGC_BLUE "\x1b[44m" +#define BGC_MAGENTA "\x1b[45m" +#define BGC_CYAN "\x1b[46m" +#define BGC_WHITE "\x1b[47m" + +#define BGC_IBLACK "\x1b[40;1m" +#define BGC_IRED "\x1b[41;1m" +#define BGC_IGREEN "\x1b[42;1m" +#define BGC_IYELLOW "\x1b[43;1m" +#define BGC_IBLUE "\x1b[44;1m" +#define BGC_IMAGENTA "\x1b[45;1m" +#define BGC_ICYAN "\x1b[46;1m" +#define BGC_IWHITE "\x1b[47;1m" + +char screen[RESY][RESX]; + + +/********************************************* + * Description - Clear the screen + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ +void ClrScr(){ + //printf("\x1b[2J"); + for(int i = 0; i != 32;i++) + puts(""); + + for(int i = 0; i != RESY; i++){ + + for(int j = 0; j != RESX; j++){ + + screen[i][j] = ' '; + + } + + + } + + +} + +/********************************************* + * Description - Render all the cells to the screen, splashing + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ +void Splash(){ + puts(""); + for(int i = 0; i != RESY; i++){ + + for(int j = 0; j != RESX; j++){ + + printf("%c",screen[j][i]); + + } + + puts(""); + + } + + +} + +/********************************************* + * Description - Put a character onto the screen + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ +void DrawChar(int x, int y, char content){ + //Make sure it's in the screen + assert(x <= RESX && y <= RESY); + + screen[x][y] = content; +} + +/********************************************* + * Description - Put a string onto the screen + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ +void DrawString(int x, int y, char str[128]){ + + //Make sure origin is in the screen + assert(x <= RESX || y <= RESY); + + //Make sure the string wont run off the screen + assert(x + strlen(str) <= RESX); + + for(int i; i != strlen(str);i++){ + + DrawChar(x+i,y,str[i]); + + } + + +} + + +/********************************************* + * Description - Draw a square + * Author - William King + * Date - Sep 13 2023 + * *******************************************/ +void DrawSquare(int x, int y, int length, char fill){ + + //Make sure shape is not ridiculous + assert(x <= RESX && y <= RESY); + assert(x+length <= RESX && y+length <= RESY); + + for(int i = 0; i != length;i++){ + + int j = 0; + while (j != 0){ + DrawChar(x+j,y+i,fill); + j++; + } + + } + + +} + + +/********************************************* +* Description - Fill the entire screen with a character +* Author - William King +* Date - Sep 15 2023 +* *******************************************/ +void DrawFill(char fill){ + for(int i = 0; i != RESY; i++){ + for(int j = 0; j != RESX; j++){ + screen[i][j] = fill; + + } + } + +} + + + +/********************************************* +* Description - Set the colour +* Author - William King +* Date - Sep 13 2023 +* *******************************************/ +void SetColour(char * colour){ + printf("%s",colour); +} + + +/********************************************* +* Description - Reset the colour +* Author - William King +* Date - Sep 13 2023 +* *******************************************/ +void ResetColour(char * colour){ + printf("\x1b[0m"); +}
--- a/c.ksh Tue Sep 26 23:19:42 2023 -0400 +++ b/c.ksh Wed Sep 27 01:47:28 2023 -0400 @@ -1,6 +1,8 @@ #!/bin/sh clear rm harelet -tcc harelet.c -g -o harelet +rm hareletdvrk +tcc harelet.c -o harelet +tcc harelet.c -o hareletdvrk -D DVORAK doas cp harelet /usr/bin/ gdb harelet
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/FIRST.SBP Wed Sep 27 01:47:28 2023 -0400 @@ -0,0 +1,23 @@ +'OpenSBP file written by Harelet +'Harelet, written by William King +'No responsibilty is taken for any damages to any equipment + +'Starting +SO, 1,1 +Pause 2 +SA, +&ZUP = 0.25 +MH + +'Bulk of instructions +J2 55 25 +JZ,&ZUP +J2 55 25 +JZ,&ZUP +J2 25 25 +JZ,&ZUP + +J2,0,0 +SO, 1,0 +'All done. Wait for user. +PAUSE \ No newline at end of file
--- a/examples/LINE Tue Sep 26 23:19:42 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -G20 -G0 X0 Y0 Z0 -G0 X 100 Y 40 Z 5 -G0 X 100 Y 40 Z 5 -G0 X 135 Y 25 Z 5 -G0 X0 Y0 Z0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/LINE.GCODE Wed Sep 27 01:47:28 2023 -0400 @@ -0,0 +1,6 @@ +G20 +G0 X0 Y0 Z0 +G0 X 100 Y 40 Z 5 +G0 X 100 Y 40 Z 5 +G0 X 135 Y 25 Z 5 +G0 X0 Y0 Z0
--- a/examples/SQUARE Tue Sep 26 23:19:42 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -G21 -G0 x 0 Y 0 Z 0 -G0 X 100 Y 25 Z 5 -G0 X 100 Y 35 Z 5 -G0 X 115 Y 25 Z 5 -G0 X 115 Y 35 Z 5 -G0 X 100 Y 25 Z 5 -G0 X 100 Y 35 Z 5 -G0 X 115 Y 25 Z 5 -G0 X 115 Y 35 Z 5 -G0 X 100 Y 25 Z 5 -G0 X 100 Y 35 Z 5 -G0 X 115 Y 25 Z 5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/SQUARE.GCODE Wed Sep 27 01:47:28 2023 -0400 @@ -0,0 +1,13 @@ +G21 +G0 x 0 Y 0 Z 0 +G0 X 100 Y 25 Z 5 +G0 X 100 Y 35 Z 5 +G0 X 115 Y 25 Z 5 +G0 X 115 Y 35 Z 5 +G0 X 100 Y 25 Z 5 +G0 X 100 Y 35 Z 5 +G0 X 115 Y 25 Z 5 +G0 X 115 Y 35 Z 5 +G0 X 100 Y 25 Z 5 +G0 X 100 Y 35 Z 5 +G0 X 115 Y 25 Z 5
--- a/harelet.c Tue Sep 26 23:19:42 2023 -0400 +++ b/harelet.c Wed Sep 27 01:47:28 2023 -0400 @@ -7,27 +7,16 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> #include "basedfilelib.h" - -#ifdef __linux__ -#include "linuxconio.h" -#endif - -#ifdef _WIN32 -#include <windows.h>> -#include <conio.h> -#endif +#include "basedtermgrx.h" #define DEEPNESS 5 #define MAXPOINT 4096 #define UNITS "G20\n" #define SPEED 20 -#define SBPUP "JZ &ZUP\n" -#define SBPDWN 0.0625 - - typedef struct{ unsigned int X; unsigned int Y; @@ -36,8 +25,8 @@ point points[MAXPOINT]; -unsigned int X = 100; -unsigned int Y = 25; +unsigned int X = 5; +unsigned int Y = 5; unsigned int step = 5; unsigned int down = 0; unsigned int numpoints = 0; @@ -45,11 +34,23 @@ /********************************************* -* Description - Convert integers to strings, makes -* source code more pretty. -* Author - William King -* Date - Sep 26 2023 -* *******************************************/ + * Description - Warn the user about something + * Author - William King + * Date - Sep 27 2023 + * *******************************************/ +void Warn(char * s){ + printf("WARNING:"); + puts(s); + putchar('\a'); + getchar(); +} + +/********************************************* + * Description - Convert integers to strings, makes + * source code more pretty. + * Author - William King + * Date - Sep 26 2023 + * *******************************************/ char * IntToString(int num){ char * s; sprintf(s,"%d",num); @@ -62,37 +63,27 @@ * Date - Sep 08 2023 * *******************************************/ void Render(){ - clrscr(); - gotoxy(0,3); + ClrScr(); puts("HARELET A CAD PROGRAM BY VILYAEM KENYAZ, PEEP SOFTWARE 2023"); printf("Number of Points: %d X: %d Y: %d STEPSIZE: %d DWN?: %d\n",numpoints,X,Y,step,down); //Render points - for(int i = 0;i != MAXPOINT;i++){ - gotoxy(0,50); - - gotoxy(points[i].X,points[i].Y); + if(numpoints > 0){ + for(int i = 0;i != numpoints;i++){ + if(points[i].down == 0){ + DrawChar(points[i].X,points[i].Y,'U'); - if(points[i].down == 0){ - printf("X"); + } + else{ + DrawChar(points[i].X,points[i].Y,'D'); + } } - else{ - printf("*"); - } - - } //Render cursor - - gotoxy(X,Y); - - puts("&"); + DrawChar(X,Y,'&'); - //Move cursor to top of document, so its not trailing the cadcursor - gotoxy(0,0); - - + Splash(); } @@ -108,7 +99,6 @@ char buffer[64]; unsigned int choice; - clrscr(); puts("Select your format\n1. RAW GCODE\n2. OPENSBP"); scanf("%d",&choice); @@ -125,14 +115,10 @@ //Compose char instruction[64]; strcat(instruction,"G0 X "); - //Convert X to string - sprintf(buffer,"%d",points[i].X); - strcat(instruction,buffer); + strcat(instruction,IntToString(points[i].X)); strcat(instruction," Y "); - //Convert Y to string - sprintf(buffer,"%d",points[i].Y); - strcat(instruction,buffer); - if(points[i].down = 1){ + strcat(instruction,IntToString(points[i].Y)); + if(points[i].down == 1){ strcat(instruction," Z 5\n"); } else{ @@ -147,11 +133,11 @@ WriteFile(filename,file); } else if(choice == 2){ - // Setup the miller - 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"); + // Setup the miller + 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"); - for(int i = 0;i != numpoints;i++){ - + for(int i = 0;i != numpoints;i++){ + char instruction[64]; strcat(instruction,"J2 "); @@ -166,27 +152,22 @@ else{ strcat(instruction,"JZ,&ZUP\n"); } - strcat(file,instruction); - } + } - //Finished, add instructions to wait for the user - strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE"); + //Finished, add instructions to wait for the user + strcat(file,"\nJ2,0,0\nSO, 1,0\n'All done. Wait for user.\nPAUSE"); - WriteFile(filename,file); + WriteFile(filename,file); } else{ - - puts("Invalid compiliation format"); - scanf(""); - - + Warn("Invalid compiliation format"); } puts("Finished compiling instructions"); - scanf(""); + getchar(); } @@ -197,27 +178,33 @@ * Date - Sep 08 2023 * *******************************************/ void main(int argc, char* argv[]){ - clrscr(); while(1){ Render(); +#ifndef DVORAK switch(getchar()){ case 'h': - X -= step; + if(X - step >= 2){ + X -= step; + } break; case 'j': - Y += step; + if(Y + step < RESY - step){ + Y += step; + } break; case 'k': - Y -= step; + if(Y - step >= 2){ + Y -= step; + } break; case 'l': - X += step; + if(X + step < RESX - step){ + X += step; + } break; - case 's': - puts("New stepsize"); + puts("New stepsize:"); scanf("%d",&step); - break; case 'a': @@ -234,18 +221,69 @@ down = 1; } break; - case 'c': Compile(); break; case 'q': - clrscr(); + ClrScr(); exit(0); break; default: - putchar('\a'); break; } +#endif +#ifdef DVORAK + switch(getchar()){ + case 'a': + if(X - step >= 2){ + X -= step; + } + break; + case 'o': + if(Y + step < RESY - step){ + Y += step; + } + break; + case ',': + if(Y - step >= 2){ + Y -= step; + } + break; + case 'e': + if(X + step < RESX - step){ + X += step; + } + break; + case '.': + puts("New stepsize:"); + scanf("%d",&step); + break; + + case ' ': + points[numpoints].X = X; + points[numpoints].Y = Y; + points[numpoints].down = down; + numpoints++; + break; + case 'p': + if(down == 1){ + down = 0; + } + else{ + down = 1; + } + break; + case 'y': + Compile(); + break; + case 'q': + ClrScr(); + exit(0); + break; + default: + break; + } +#endif } exit(0);
--- a/linuxconio.h Tue Sep 26 23:19:42 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,218 +0,0 @@ -#ifndef CONIO_H -#define CONIO_H - -#include <termios.h> -#include <unistd.h> -#include <stdio.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> - -#define cprintf printf -#define cscanf scanf -#define cgets gets - -#define CLEAR "\x1b[2J" -#define SET11 "\x1b[1;1f" -#define CURSOR_UP "\x1b[1A" -#define ERASE_LINE "\x1b[2K" -#define BLINK_SLOW "\x1b[5m" -#define BLINK_RAPID "\x1b[6m" -#define CC_CLEAR "\x1b[0m" - -#define BLACK "\x1b[30m" -#define RED "\x1b[31m" -#define GREEN "\x1b[32m" -#define YELLOW "\x1b[33m" -#define BLUE "\x1b[34m" -#define MAGENTA "\x1b[35m" -#define CYAN "\x1b[36m" -#define WHITE "\x1b[37m" - -#define IBLACK "\x1b[30;1m" -#define IRED "\x1b[31;1m" -#define IGREEN "\x1b[32;1m" -#define IYELLOW "\x1b[33;1m" -#define IBLUE "\x1b[34;1m" -#define IMAGENTA "\x1b[35;1m" -#define ICYAN "\x1b[36;1m" -#define IWHITE "\x1b[37;1m" - -#define BGC_BLACK "\x1b[40m" -#define BGC_RED "\x1b[41m" -#define BGC_GREEN "\x1b[42m" -#define BGC_YELLOW "\x1b[43m" -#define BGC_BLUE "\x1b[44m" -#define BGC_MAGENTA "\x1b[45m" -#define BGC_CYAN "\x1b[46m" -#define BGC_WHITE "\x1b[47m" - -#define BGC_IBLACK "\x1b[40;1m" -#define BGC_IRED "\x1b[41;1m" -#define BGC_IGREEN "\x1b[42;1m" -#define BGC_IYELLOW "\x1b[43;1m" -#define BGC_IBLUE "\x1b[44;1m" -#define BGC_IMAGENTA "\x1b[45;1m" -#define BGC_ICYAN "\x1b[46;1m" -#define BGC_IWHITE "\x1b[47;1m" - -static struct termios oldterm, newterm; - -void initTermios(int echo) -{ - tcgetattr(0, &oldterm); - newterm = oldterm; - newterm.c_lflag &= ~ICANON; - newterm.c_lflag &= echo ? ECHO : ~ECHO; - tcsetattr(0, TCSANOW, &newterm); -} -void resetTermios(void) -{ - tcsetattr(0, TCSANOW, &oldterm); -} - -int getch_(int echo) -{ - int ch; - initTermios(echo); - ch = getchar(); - resetTermios(); - return ch; -} - -void cagxy(unsigned int x, unsigned int y) -{ - printf("%s\x1b[%d;%df", CLEAR, y, x); -} - -void clrscr() -{ - printf("%s%s",CLEAR, SET11); -} - -int getch(void) -{ - return getch_(0); -} - -int getche(void) -{ - return getch_(1); -} - -void gotox(unsigned int x) -{ - printf("\x1b[%dG", x); -} - -void gotoxy(unsigned int x, unsigned int y) -{ - printf("\x1b[%d;%df", y, x); -} - -void nocursor() -{ - printf("\x1b[?25l"); -} - -void reset_video() -{ - printf("\x1b[0m"); -} - -void showcursor() -{ - printf("\x1b[?25h"); -} - -void textcolor(char *color) -{ - printf("%s",color); -} - -void textbackground(char color[11]) -{ - char col[11]; - strcpy(col,color); - col[2]='4'; - printf("%s",col); -} - -void delline() -{ - printf("%s%s", ERASE_LINE, CURSOR_UP); -} - -void clreol() -{ - printf("%s",CLEAR); -} -int putch(const char c) -{ - printf("%c",c); - return (int)c; -} - -int cputs(const char*str) -{ - printf(str); - return 0; -} - - -int wherexy(int *x, int *y) -{ - printf("\033[6n"); - if(getch() != '\x1B') return 0; - if(getch() != '\x5B') return 0; - int in; - int ly = 0; - while((in = getch()) != ';') - ly = ly * 10 + in - '0'; - int lx = 0; - while((in = getch()) != 'R') - lx = lx * 10 + in - '0'; - *x = lx; - *y = ly; -} -int wherex() -{ - int x=0,y=0; - wherexy(&x, &y); - return x; -} - -int wherey() -{ - int x=0,y=0; - wherexy(&x, &y); - return y; -} - -int kbhit() -{ - struct termios oldt, newt; - int ch; - int oldf; - - tcgetattr(STDIN_FILENO, &oldt); - newt = oldt; - newt.c_lflag &= ~(ICANON | ECHO); - tcsetattr(STDIN_FILENO, TCSANOW, &newt); - oldf = fcntl(STDIN_FILENO, F_GETFL, 0); - fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); - - ch = getchar(); - - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - fcntl(STDIN_FILENO, F_SETFL, oldf); - - if(ch != EOF) - { - ungetc(ch, stdin); - return 1; - } - return 0; -} -#endif -