Skip to content

Commit cf1ef90

Browse files
committed
started commenting.. also fixed the automatic move to vertical of sprockets..
1 parent 29797cf commit cf1ef90

File tree

5 files changed

+373
-78
lines changed

5 files changed

+373
-78
lines changed

Actions/actions.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33

44
import os
55
import sys
6-
import threading
76
import math
87
import serial.tools.list_ports
98
import glob
109
import json
1110
import time
1211
import re
1312
import zipfile
14-
#from zipfile import ZipFile
15-
import datetime
1613
from gpiozero.pins.mock import MockFactory
1714
from gpiozero import Device
18-
from github import Github
19-
import wget
20-
import subprocess
21-
from shutil import copyfile
2215

16+
'''
17+
This class does most of the heavy lifting in processing messages from the UI client.
18+
'''
2319
class Actions(MakesmithInitFuncs):
2420

2521
Device.pin_factory = MockFactory()
2622

2723
def processAction(self, msg):
24+
'''
25+
When a message comes in via the UI client it gets parsed and processed here.
26+
:param msg: json of message from UI client
27+
:return:
28+
'''
2829
try:
29-
#Commands allowed during sending gcode
30+
# Commands allowed during sending gcode. These commands won't screw something up.
3031
if msg["data"]["command"] == "createDirectory":
3132
if not self.createDirectory(msg["data"]["arg"]):
3233
self.data.ui_queue1.put("Alert", "Alert", "Error with creating directory.")
@@ -61,10 +62,10 @@ def processAction(self, msg):
6162
elif msg["data"]["command"] == "shutdown":
6263
if not self.shutdown():
6364
self.data.ui_queue1.put("Alert", "Alert", "Error with shutting down.")
64-
65-
#Commands not allowed during sending gcode
6665
elif self.data.uploadFlag:
6766
self.data.ui_queue1.put("Alert", "Alert", "Cannot issue command while sending gcode.")
67+
# Commands not allowed during sending gcode.. if you did these commands, something could screw up.
68+
# If uploadFlag was enabled (see above) then this would never be reached.
6869
elif msg["data"]["command"] == "update":
6970
if not self.data.releaseManager.update(msg["data"]["arg"]):
7071
self.data.ui_queue1.put("Alert", "Alert", "Error with updating webcontrol.")
@@ -143,8 +144,8 @@ def processAction(self, msg):
143144
elif msg["data"]["command"] == "rotateSprocket":
144145
if not self.rotateSprocket(msg["data"]["arg"], msg["data"]["arg1"]):
145146
self.data.ui_queue1.put("Alert", "Alert", "Error with setting sprocket")
146-
elif msg["data"]["command"] == "setSprocketsAutomatic":
147-
if not self.setSprocketsAutomatic():
147+
elif msg["data"]["command"] == "setSprocketAutomatic":
148+
if not self.setSprocketAutomatic():
148149
self.data.ui_queue1.put("Alert", "Alert", "Error with setting sprockets automatically")
149150
elif msg["data"]["command"] == "setSprocketsZero":
150151
if not self.setSprocketsZero():
@@ -763,7 +764,7 @@ def setSprockets(self, sprocket, degrees):
763764
self.data.console_queue.put(str(e))
764765
return False
765766

766-
def setVerticalAutomatic(self):
767+
def setSprocketAutomatic(self):
767768
# set the call back for the measurement
768769
try:
769770
self.data.measureRequest = self.getLeftChainLength
@@ -786,8 +787,8 @@ def getRightChainLength(self, dist):
786787
self.moveToVertical()
787788

788789
def moveToVertical(self):
789-
chainPitch = float(self.data.config.get("Advanced Settings", "chainPitch"))
790-
gearTeeth = float(self.data.config.get("Advanced Settings", "gearTeeth"))
790+
chainPitch = float(self.data.config.getValue("Advanced Settings", "chainPitch"))
791+
gearTeeth = float(self.data.config.getValue("Advanced Settings", "gearTeeth"))
791792
distPerRotation = chainPitch * gearTeeth
792793

793794
distL = -1 * (self.leftChainLength % distPerRotation)

Background/LogStreamer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import time
44

5+
'''
6+
This class sends logs to a browser via sockets. It monitors two log queues (log and alog) and sends the messages
7+
if data is available.
58
9+
This class is not MakesmithInitFuncs inherited, so it doesn't have direct access to the data. Therefore, it gets
10+
passed the app.
11+
'''
612
class LogStreamer:
713
app = None
814

915
def start(self, _app):
1016
self.app = _app
11-
self.app.data.console_queue.put("starting log streamer")
17+
self.app.data.console_queue.put("Starting Log Streamer")
1218

1319
with self.app.app_context():
1420
while True:
21+
# this sleep function is needed to keep it non-blocking.
1522
time.sleep(0.001)
1623
while (
1724
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

0 commit comments

Comments
 (0)