From c11e5e1ba4b31257431bf01b021c766656f376f6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 30 Dec 2023 17:34:06 +0100 Subject: [PATCH] - added settings externalized into settings.py (not for the executable version yet) -Changed depency to the pip package version from submodule -Updated requirements.txt --- cnc_gerbil.py | 25 ++++++++++++------------- dist/settings.py | 22 ++++++++++++++++++++++ gcode_machine | 1 - gerbil | 1 - requirements.txt | 2 ++ settings.py | 22 ++++++++++++++++++++++ 6 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 dist/settings.py delete mode 160000 gcode_machine delete mode 160000 gerbil create mode 100644 settings.py diff --git a/cnc_gerbil.py b/cnc_gerbil.py index f9d69c1..ce61ba9 100644 --- a/cnc_gerbil.py +++ b/cnc_gerbil.py @@ -3,7 +3,8 @@ import time from tkinter import Button, Label, Variable, IntVar, Canvas, Frame, Listbox, Entry, Radiobutton, Tk, constants, LEFT from tkinter import filedialog as fd import os -from gerbil.gerbil import Gerbil +from grbl_streamer import GrblStreamer +import settings class touchCNC: def __init__(self, root): @@ -313,8 +314,7 @@ class touchCNC: def grblConnect2(self, baudrate=115200, max_retries=5, retry_interval=3): retry_count = 0 - locations = ['/dev/ttyUSB0', '/dev/ttyACM0', '/dev/ttyUSB1', '/dev/ttyACM1', '/dev/ttyACM2', '/dev/ttyACM3', - '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3'] + locations = settings.portlist # Configure logging logging.basicConfig(level=logging.DEBUG) @@ -409,13 +409,13 @@ class touchCNC: def get_grbl_command(self, CMD): if CMD == 'M3': - return 'M3 S1000' if self.states['M3'] == '1' else 'M5' + return settings.spindle_on if self.states['M3'] == '1' else settings.spindle_off elif CMD == 'M8': - return CMD if self.states[CMD] == '1' else 'M9' + return settings.cooling_on if self.states[CMD] == '1' else settings.cooling_off elif CMD == 'G10': - return 'G10 P0 L20 X0 Y0 Z0' + return settings.toolchange elif CMD == '32': return '$32=0' if self.states['32'] == '1' else '$32=1' @@ -428,7 +428,7 @@ class touchCNC: def openGCODE(self): filetypes = (('GCODE', '*.nc'), ('All files', '*.*')) if not self.file_list: - GCODE = fd.askopenfilename(title='Open a file', initialdir='/home/', filetypes=filetypes) + GCODE = fd.askopenfilename(title='Open a file', initialdir=settings.basepath, filetypes=filetypes) else: GCODE = self.load_gcode_from_listbox() @@ -471,7 +471,7 @@ class touchCNC: def openDir(self): self.file_list = [] self.path_list = [] - directory = fd.askdirectory(title='Open a Folder', initialdir='/home/') + directory = fd.askdirectory(title='Open a Folder', initialdir=settings.basepath) allowed_extensions = {'nc', 'GCODE'} # Use a set for efficient membership testing if directory: @@ -602,7 +602,7 @@ class DrawonTable: self.mill_table.delete('all') self.mill_table.create_rectangle(50, 50, 350, 350, fill='white') - self.mill_table.create_text(200, 25, text='Fräsbereich 300mm x 300mm') + self.mill_table.create_text(200, 25, text=settings.table_text) for x in range(50, 350, 50): self.mill_table.create_text(x, 400 - x, text=x - 50) @@ -616,16 +616,15 @@ class DrawonTable: if __name__ == "__main__": root = Tk() root.title('touchCNC') - root.geometry('1024x600+0+0') + root.geometry(settings.resolution) root.grid_propagate(True) root.resizable(False, False) # 17203b - root.attributes('-fullscreen', False) + root.attributes('-fullscreen', settings.set_fullscreen) root.tk_setPalette(background='#4B4A67', foreground='black', activeBackground='#F99417', activeForeground='lightgrey') - app = touchCNC(root) - grbl = Gerbil(app.gui_callback) + grbl = GrblStreamer(app.gui_callback) grbl.hash_state_requested = True grbl.gcode_parser_state_requested = True diff --git a/dist/settings.py b/dist/settings.py new file mode 100644 index 0000000..e07059a --- /dev/null +++ b/dist/settings.py @@ -0,0 +1,22 @@ + +# The resolution of your SBC-screen +resolution = '1024x600+0+0' + +# When running on SBC with touch set to: True +set_fullscreen = False + +# Platform dependent +portlist = ['/dev/ttyUSB0', '/dev/ttyACM0', '/dev/ttyUSB1', '/dev/ttyACM1', '/dev/ttyACM2', '/dev/ttyACM3', + '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3'] +# Where the file dialog points to. Ideally some Nextcloud folder or Samba share etc. +basepath = '/home/' + +# Machine commands +spindle_on = 'M3S1000' +spindle_off = 'M5' +cooling_on = 'M8' +cooling_off = 'M9' +toolchange = 'G10 P0 L20 X0 Y0 Z0' + +# Table Info Text +table_text = 'Fräsbereich 300mm x 300mm' diff --git a/gcode_machine b/gcode_machine deleted file mode 160000 index 624f71a..0000000 --- a/gcode_machine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 624f71ae1549b13a94aec5c58b9bb0337346225f diff --git a/gerbil b/gerbil deleted file mode 160000 index 78aa148..0000000 --- a/gerbil +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 78aa148f0ae98c7dc686eeeb47e2040f40486dab diff --git a/requirements.txt b/requirements.txt index 5702cc8..1f3f394 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ altgraph==0.17.4 +gcode-machine==1.0.3 +grbl-streamer==1.0.3 numpy==1.26.2 pyserial==3.5 diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..e07059a --- /dev/null +++ b/settings.py @@ -0,0 +1,22 @@ + +# The resolution of your SBC-screen +resolution = '1024x600+0+0' + +# When running on SBC with touch set to: True +set_fullscreen = False + +# Platform dependent +portlist = ['/dev/ttyUSB0', '/dev/ttyACM0', '/dev/ttyUSB1', '/dev/ttyACM1', '/dev/ttyACM2', '/dev/ttyACM3', + '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3'] +# Where the file dialog points to. Ideally some Nextcloud folder or Samba share etc. +basepath = '/home/' + +# Machine commands +spindle_on = 'M3S1000' +spindle_off = 'M5' +cooling_on = 'M8' +cooling_off = 'M9' +toolchange = 'G10 P0 L20 X0 Y0 Z0' + +# Table Info Text +table_text = 'Fräsbereich 300mm x 300mm'