Skip to content

Commit 08fdf89

Browse files
authored
Merge pull request #44 from madgrizzle/homeRework
Home rework
2 parents 0b0858b + d398514 commit 08fdf89

28 files changed

+716
-184
lines changed

Actions/actions.py

Lines changed: 117 additions & 79 deletions
Large diffs are not rendered by default.

Background/LogStreamer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __main__ import socketio
2+
3+
import time
4+
5+
6+
class LogStreamer:
7+
app = None
8+
9+
def start(self, _app):
10+
self.app = _app
11+
self.app.data.console_queue.put("starting log streamer")
12+
13+
with self.app.app_context():
14+
while True:
15+
time.sleep(0.001)
16+
while (
17+
not self.app.data.alog_streamer_queue.empty() or not self.app.data.log_streamer_queue.empty()): # if there is new data to be read
18+
if not self.app.data.alog_streamer_queue.empty():
19+
message = self.app.data.alog_streamer_queue.get()
20+
if message != "":
21+
socketio.emit("message", {"log": "alog", "data": message, "dataFormat": "text"},
22+
namespace="/MaslowCNCLogs", )
23+
if not self.app.data.log_streamer_queue.empty():
24+
message = self.app.data.log_streamer_queue.get()
25+
if message != "":
26+
socketio.emit("message", {"log": "log", "data": message, "dataFormat": "text"},
27+
namespace="/MaslowCNCLogs", )
28+
29+

Background/UIProcessor.py

Lines changed: 69 additions & 44 deletions
Large diffs are not rendered by default.

Background/messageProcessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def start(self):
1717
# check for available update file
1818
if time.time()-self.data.lastChecked > 60*60:
1919
self.data.lastChecked = time.time()
20-
self.data.actions.checkForLatestPyRelease()
20+
self.data.releaseManager.checkForLatestPyRelease()
2121
while (
2222
not self.data.message_queue.empty()
2323
): # if there is new data to be read

Connection/nonVisibleWidgets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from Background.WebMCPProcessor import ConsoleProcessor
1818
from Background.webcamVideoStream import WebcamVideoStream
1919
from Boards.boardManager import BoardManager
20+
from ReleaseManager.releaseManager import ReleaseManager
2021

2122
class NonVisibleWidgets(MakesmithInitFuncs):
2223
"""
@@ -40,6 +41,7 @@ class NonVisibleWidgets(MakesmithInitFuncs):
4041
camera = WebcamVideoStream()
4142
gpioActions = GPIOActions()
4243
boardManager = BoardManager()
44+
releaseManager = ReleaseManager()
4345

4446
def setUpData(self, data):
4547
"""
@@ -69,6 +71,7 @@ def setUpData(self, data):
6971
data.camera = self.camera
7072
data.gpioActions = self.gpioActions
7173
data.boardManager = self.boardManager
74+
data.releaseManager = self.releaseManager
7275

7376
if hasattr(sys, '_MEIPASS'):
7477
data.platform = "PYINSTALLER"
@@ -122,6 +125,7 @@ def setUpData(self, data):
122125
self.gpioActions.setup()
123126
self.boardManager.setUpData(data)
124127
self.boardManager.initializeNewBoard()
128+
self.releaseManager.setUpData(data)
125129

126130
#set up kinematics with current settings
127131
self.holeyKinematics.initializeSettings()

Connection/serialPortThread.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ def sendNextLine(self):
110110
line = self.data.gcode[self.data.gcodeIndex]
111111
filtersparsed = re.sub(r'\(([^)]*)\)', '', line) # replace mach3 style gcode comments with newline
112112
line = re.sub(r';([^.]*)?', '',filtersparsed) # replace standard ; initiated gcode comments with newline
113+
# put gcode home shift here
114+
115+
113116
if not line.isspace(): # if all spaces, don't send. likely a comment.
117+
line = self.data.gcodeFile.moveLine(line)
114118
self._write(line)
115119
if line.find("G20") != -1:
116120
if self.data.units != "INCHES":

DataStructures/data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Data:
3838
Version Updater
3939
'''
4040
lastChecked = -1
41-
pyInstallCurrentVersion = 0.913
41+
pyInstallCurrentVersion = 0.914
4242
pyInstallUpdateAvailable = False
4343
pyInstallUpdateBrowserUrl = ""
4444
pyInstallUpdateVersion = 0
@@ -139,6 +139,8 @@ class Data:
139139
message_queue = LoggingQueue(logger)
140140
ui_controller_queue = queue.Queue()
141141
ui_queue1 = UIQueue()
142+
alog_streamer_queue = queue.Queue(1000) # used for sending log to client screen.. limit to 1000 "items"
143+
log_streamer_queue = queue.Queue(1000) # used for sending log to client screen.. limit to 1000 "items"
142144
console_queue = queue.Queue() # used for printing to terminal
143145
mcp_queue = queue.Queue () # used for sending messages to WebMCP(if enabled)
144146
webMCPActive = False # start false until WebMCP connects

DataStructures/logger.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ def resetIdler(self):
5858
def setLoggingTimeout(self, timeOut):
5959
self.loggingTimeout = timeOut
6060

61+
def addToMessageBuffer(self,message):
62+
self.messageBuffer += message
63+
self.data.log_streamer_queue.put(message)
64+
65+
def addToaMessageBuffer(self,message):
66+
self.amessageBuffer += message
67+
self.data.alog_streamer_queue.put(message)
68+
6169
def writeToLog(self, message):
6270

6371
"""
@@ -75,26 +83,26 @@ def writeToLog(self, message):
7583
dateTime = datetime.datetime.fromtimestamp(currentTime).strftime('%Y-%m-%d %H:%M:%S')
7684
if self.loggingTimeout > 0 and self.data.uploadFlag == 0 and currentTime-self.idler > self.loggingTimeout:
7785
if not self.suspendLogging:
78-
self.messageBuffer += logTime + ": " + "Logging suspended due to user idle time > "+str(self.loggingTimeout)+" seconds\n"
86+
self.addToMessageBuffer(logTime + ": " + "Logging suspended due to user idle time > "+str(self.loggingTimeout)+" seconds\n")
7987
self.suspendLogging = True
8088
else:
8189
if self.suspendLogging:
82-
self.messageBuffer += logTime + ": " + "Logging resumed due to user activity\n"
90+
self.addToMessageBuffer(logTime + ": " + "Logging resumed due to user activity\n")
8391
self.suspendLogging = False
8492

8593
if message[0] != "<" and message[0] != "[":
8694
try:
8795
tmessage = message.rstrip('\r\n')
88-
self.amessageBuffer += logTime+": " + tmessage+"\n"
96+
self.addToaMessageBuffer(logTime+": " + tmessage+"\n")
8997
if not self.suspendLogging:
90-
self.messageBuffer += logTime+": " + tmessage+"\n"
98+
self.addToMessageBuffer(logTime+": " + tmessage+"\n")
9199
except:
92100
pass
93101
else:
94102
try:
95103
if not self.suspendLogging:
96104
tmessage = message.rstrip('\r\n')
97-
self.messageBuffer += logTime+": "+ tmessage+"\n"
105+
self.addToMessageBuffer(logTime+": "+ tmessage+"\n")
98106
except:
99107
pass
100108

File/gcodeFile.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def saveFile(self, fileName, directory):
5656
gfile = open(fileToWrite, "w+")
5757
print(fileToWrite)
5858
for line in self.data.gcode:
59-
newLine = self.data.gcodeFile.moveLine(line, True, homeX, homeY)
60-
gfile.write(newLine+'\n')
59+
gfile.write(line+'\n')
6160
#gfile = open(directory+fileName, "w+")
6261
#gfile.writelines(map(lambda s: s+ '\n', self.data.gcode))
6362
print("Closing File")
@@ -73,7 +72,9 @@ def saveFile(self, fileName, directory):
7372

7473

7574
def loadUpdateFile(self, gcode=""):
76-
#print(gcode)
75+
gcodeLoad = False
76+
if gcode=="":
77+
gcodeLoad = True
7778
if self.data.units == "MM":
7879
self.canvasScaleFactor = self.MILLIMETERS
7980
else:
@@ -174,6 +175,7 @@ def loadUpdateFile(self, gcode=""):
174175
return False
175176
self.updateGcode()
176177
self.data.gcodeFile.isChanged = True
178+
self.data.actions.sendGCodePositionUpdate(self.data.gcodeIndex, recalculate=True)
177179
return True
178180

179181
def isClose(self, a, b):
@@ -248,12 +250,7 @@ def drawLine(self, gCodeLine, command):
248250
self.addPoint3D(xTarget, yTarget, zTarget)
249251

250252
else:
251-
if (
252-
len(self.line3D) == 0
253-
or self.line3D[-1].dashed
254-
or self.line3D[-1].type != "line"
255-
):
256-
253+
if (len(self.line3D) == 0 or self.line3D[-1].dashed or self.line3D[-1].type != "line"): #test123
257254
self.line3D.append( Line() )
258255
self.line3D[-1].type = "line"
259256
self.addPoint3D(self.xPosition, self.yPosition, self.zPosition)
@@ -393,22 +390,13 @@ def clearGcodeFile(self):
393390

394391

395392

396-
def moveLine(self, gCodeLine, dehome = False, homeX=0, homeY=0):
393+
def moveLine(self, gCodeLine):
397394

398395
originalLine = gCodeLine
399-
if dehome:
400-
shiftX = -homeX
401-
shiftY = -homeY
402-
else:
403-
shiftX = self.data.gcodeShift[0]
404-
shiftY = self.data.gcodeShift[1]
405-
406-
#print("original:"+gCodeLine)
407-
#first check for full comment lines
396+
shiftX = self.data.gcodeShift[0]
397+
shiftY = self.data.gcodeShift[1]
408398
if len(gCodeLine) > 0:
409399
if gCodeLine[0] == '(' or gCodeLine[0] == ';':
410-
#comment lines
411-
#print("comment:"+originalLine)
412400
return originalLine
413401
#next check for comment after line and if exist, split on first occurrence and retain the comment portion
414402
findexA = gCodeLine.find('(')
@@ -425,7 +413,6 @@ def moveLine(self, gCodeLine, dehome = False, homeX=0, homeY=0):
425413
#print("comment:"+comment)
426414
gCodeLine = gCodeLine[:findex]
427415

428-
429416
#This test should always pass so taking it out
430417
#if gCodeLine.find("(") == -1 and gCodeLine.find(";") == -1:
431418
if True:
@@ -495,9 +482,6 @@ def loadNextLine(self):
495482
"""
496483

497484
try:
498-
self.data.gcode[self.lineNumber] = self.moveLine(
499-
self.data.gcode[self.lineNumber]
500-
) # move the line if the gcode has been moved
501485
fullString = self.data.gcode[self.lineNumber]
502486
except:
503487
return # we have reached the end of the file
@@ -622,10 +606,12 @@ def updateGcode(self):
622606
else:
623607
scaleFactor = 1/25.4;
624608
#before, gcode shift = home X
625-
#self.xPosition = self.data.gcodeShift[0] * scaleFactor
626-
#self.yPosition = self.data.gcodeShift[1] * scaleFactor
627-
self.xPosition = float(self.data.config.getValue("Advanced Settings", "homeX")) * scaleFactor
628-
self.yPosition = float(self.data.config.getValue("Advanced Settings", "homeY")) * scaleFactor
609+
#old #self.xPosition = self.data.gcodeShift[0] * scaleFactor
610+
#old #self.yPosition = self.data.gcodeShift[1] * scaleFactor
611+
#self.xPosition = float(self.data.config.getValue("Advanced Settings", "homeX")) * scaleFactor #test123
612+
#self.yPosition = float(self.data.config.getValue("Advanced Settings", "homeY")) * scaleFactor #test123
613+
self.xPosition = 0
614+
self.yPosition = 0
629615
self.zPosition = 0
630616

631617
self.prependString = "G00 "

ReleaseManager/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)