Skip to content

Commit 9ed1a1d

Browse files
committed
added suspend indicator to logging page
1 parent 7d26ce5 commit 9ed1a1d

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

Background/LogStreamer.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,31 @@ def start(self, _app):
1616
self.app = _app
1717
self.app.data.console_queue.put("Starting Log Streamer")
1818

19+
timeSinceLastLoggerState = time.time()
1920
with self.app.app_context():
2021
while True:
2122
# this sleep function is needed to keep it non-blocking.
2223
time.sleep(0.001)
23-
while (
24-
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
24+
# if there is new data to be read
25+
loggerState = self.app.data.logger.getLoggerState()
26+
while (not self.app.data.alog_streamer_queue.empty() or not self.app.data.log_streamer_queue.empty()):
2527
# process a line from the alog queue
2628
if not self.app.data.alog_streamer_queue.empty():
2729
message = self.app.data.alog_streamer_queue.get()
2830
if message != "":
29-
socketio.emit("message", {"log": "alog", "data": message, "dataFormat": "text"},
30-
namespace="/MaslowCNCLogs", )
31+
socketio.emit("message", {"log": "alog", "data": message, "state": loggerState,
32+
"dataFormat": "text"}, namespace="/MaslowCNCLogs", )
33+
timeSinceLastLoggerState = time.time()
3134
# process a line from the log queue
3235
if not self.app.data.log_streamer_queue.empty():
3336
message = self.app.data.log_streamer_queue.get()
3437
if message != "":
35-
socketio.emit("message", {"log": "log", "data": message, "dataFormat": "text"},
36-
namespace="/MaslowCNCLogs", )
37-
38+
socketio.emit("message", {"log": "log", "data": message, "state": loggerState,
39+
"dataFormat": "text"}, namespace="/MaslowCNCLogs", )
40+
timeSinceLastLoggerState = time.time()
41+
currentTime = time.time()
42+
if currentTime - timeSinceLastLoggerState > 5:
43+
socketio.emit("message", {"log": "state", "state": loggerState, "dataFormat":"text"},
44+
namespace="/MaslowCNCLogs", )
45+
timeSinceLastLoggerState = currentTime
3846

DataStructures/logger.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def __init__(self):
5555
def resetIdler(self):
5656
self.idler = time.time()
5757

58+
def getLoggerState(self):
59+
'''
60+
Returns the state of the logger
61+
:return:
62+
'''
63+
return self.suspendLogging
64+
5865
def setLoggingTimeout(self, timeOut):
5966
self.loggingTimeout = timeOut
6067

@@ -82,7 +89,7 @@ def writeToLog(self, message):
8289
8390
"""
8491
if self.loggingTimeout == -1: #get setting for suspend time
85-
self.loggingTimeout = self.data.config.get("WebControl Settings","loggingTimeout")
92+
self.loggingTimeout = self.data.config.get("WebControl Settings", "loggingTimeout")
8693
currentTime = time.time()
8794
logTime = "{:0.2f}".format(currentTime-self.logStartTime)
8895
dateTime = datetime.datetime.fromtimestamp(currentTime).strftime('%Y-%m-%d %H:%M:%S')

static/scripts/logs.js

+25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var alogMessages = [];
33
var logMessages = [];
44
var alogEnabled = true;
55
var logEnabled = true;
6+
var loggingState = false;
67

78
$(document).ready(function(){
89
namespace = '/MaslowCNCLogs'; // change to an empty string to use the global namespace
@@ -42,11 +43,19 @@ function setListeners(){
4243
case 'alog':
4344
if (alogEnabled)
4445
processalog(msg.data);
46+
processLoggingState(msg.state);
4547
break;
4648
case 'log':
4749
if (logEnabled)
4850
processlog(msg.data);
51+
processLoggingState(msg.state);
4952
break;
53+
case 'state':
54+
if (loggingState != msg.state){
55+
processLoggingState(msg.state);
56+
break;
57+
}
58+
5059
default:
5160
console.log("!!!!!!");
5261
console.log("uncaught action:"+msg.command);
@@ -66,6 +75,8 @@ function processalog(data){
6675
$('#alogMessages').append(document.createTextNode(data));
6776
$('#alogMessages').append("<br>");
6877
$('#alogMessages').scrollBottom();
78+
79+
6980
}
7081

7182
function processlog(data){
@@ -82,6 +93,20 @@ function processlog(data){
8293
$('#logMessages').scrollBottom();
8394
}
8495

96+
function processLoggingState(data){
97+
if (data)
98+
{
99+
$("#loggingState").text("Logging Suspended");
100+
$("#loggingState").removeClass('alert-success').addClass('alert-secondary');
101+
}
102+
else
103+
{
104+
$("#loggingState").text("Logging Active");
105+
$("#loggingState").removeClass('alert-secondary').addClass('alert-success');
106+
}
107+
}
108+
109+
85110
$.fn.scrollBottom = function() {
86111
return $(this).scrollTop($(this)[0].scrollHeight);
87112
};

templates/gettingStarted.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h4>4) Set Sprockets Vertical</h4>
4040
</figure>
4141
<p>4c) Extend left chain. Press 'Extend Left Chain to xxxx mm' where xxxx is the distance set in Step 2.&nbsp; <span style="text-decoration: underline; color: #ff0000;">Warning: This is one spot where the chains can get wrapped around the sprocket.&nbsp; Grab hold of the end of the chain and apply tension to it as it feeds off the sprocket so it doesn't wrap</span>.</p>
4242
<p>4d) Extend right chain. Press 'Extend Right Chain to xxxx mm' where xxxx is the distance set in Step 2.&nbsp; <span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">Warning: Same as above.</span></span></p>
43-
<p>4e) Connect Sled.&nbsp; Connected up your sled to the extended chains.</p>
43+
<p>4e) Connect Sled.&nbsp; Connect up your sled to the extended chains.</p>
4444
<p>4f) Mark chains.&nbsp; Take a marker, nail polish, something, and mark the specific chain link that is on top of the top tooth.&nbsp; If the 'Extend Chain Distance' is a multiple of 6.35 mm, there should be a tooth perfectly vertical after extending the chains.&nbsp; Mark this because if you ever have to reset the chains, you need to know which link is this one.</p>
4545
<h4>5) Calibrate</h4>
4646
<p>5a) If using stock firwmare, go to 'Actions-&gt;Triangular Calibration.'&nbsp; If using holey calibration firmware, go to 'Actions-&gt;Holey Calibration'</p>

templates/logs.html

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
</head>
1717

1818
<div>
19+
<div class="row">
20+
<div id="loggingState" class="alert alert-success">Waiting for Status...</div>
21+
</div>
1922
<div class="row">
2023
<div class="col-6">
2124
<div class="row">

0 commit comments

Comments
 (0)