Skip to content

Commit 50073b9

Browse files
authored
Merge pull request #49 from LazeMSS/develop
0.0.1.4
2 parents 1b8cd54 + 9847477 commit 50073b9

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

octoprint_toptemp/__init__.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os.path
1010
from os import path
1111

12-
12+
import glob
1313
import sys
1414
import flask
1515
import subprocess
@@ -32,7 +32,7 @@ def __init__(self):
3232
self.customHistory = {}
3333

3434
# List of cpu temp methods found
35-
self.cpuTemps = {}
35+
self.tempCmds = {}
3636

3737
self.psutilCPUHasRun = False
3838

@@ -198,14 +198,14 @@ def on_settings_initialized(self):
198198
# # type can be cmd, gcIn, gcOut
199199
# self.defaultsCustom = {'cmd':'','name':'','interval': 25, 'type':'cmd', 'isTemp' : True}
200200

201-
for key in self.cpuTemps:
202-
if self.cpuTemps[key][1] != False:
201+
for key in self.tempCmds:
202+
if self.tempCmds[key][1] != False:
203203
self.debugOut("Adding default CPU temp")
204204
# Make template
205205
temp = self._merge_dictionaries(self.tempTemplate.copy(),self.defaultsCustom.copy())
206206
# Assign
207207
newCust = {'cu0':temp}
208-
newCust['cu0']['cmd'] = self.cpuTemps[key][0]
208+
newCust['cu0']['cmd'] = self.tempCmds[key][0]
209209
newCust['cu0']['name'] = 'CPU temperature'
210210
newCust['cu0']['type'] = 'cmd'
211211
newCust['cu0']['isTemp'] = True
@@ -412,13 +412,13 @@ def buildPsuUtil(self):
412412
# check the available methods for finding CPU temp on the hw platform
413413
# ----------------------------------------------------------------------------------------------------------------
414414
def checkCpuTempMethods(self):
415-
self.cpuTemps = {}
415+
self.tempCmds = {}
416416

417417
self.debugOut("Building cpu methods!")
418418

419419
# build list for linux
420420
if sys.platform.startswith("linux"):
421-
self.cpuTemps = {
421+
self.tempCmds = {
422422
'/opt/vc/bin/vcgencmd' :
423423
[
424424
'/opt/vc/bin/vcgencmd measure_temp|cut -d "=" -f2|cut -d"\'" -f1',
@@ -442,24 +442,37 @@ def checkCpuTempMethods(self):
442442
# try and find thermal class by looking cpu-thermal temp
443443
code, out, err = self.runcommand("for i in /sys/class/thermal/thermal_zone*; do if grep -qi cpu-thermal $i/type && test -f $i/temp ; then echo $i/temp;exit 0; fi; done; exit 1")
444444
if not code and not err:
445-
self.cpuTemps[out] = ["awk '{print $0/1000}' "+out,'CPU thermal zone',None]
445+
self.tempCmds[out] = ["awk '{print $0/1000}' "+out,'CPU thermal zone',None]
446+
447+
# look for DS18B20 devices
448+
DS18B20s = glob.glob('/sys/bus/w1/devices/28-*')
449+
if DS18B20s:
450+
for DS18B20 in DS18B20s:
451+
#check slave is present /w1_slave
452+
dsslave = os.path.join(DS18B20,'w1_slave')
453+
if os.path.isfile(dsslave):
454+
dsbase = os.path.basename(DS18B20)
455+
# check for crc
456+
code, out, err = self.runcommand("grep -iqP \"crc=(.*)YES\" "+dsslave)
457+
if not code and not err:
458+
self.tempCmds[DS18B20] = ["awk -F'[ =]' '$10==\"t\"{printf(\"%.2f\\n\",$11/1000)}' "+dsslave,'DS18B20 sensor ('+dsbase+')' ,None]
446459

447460
# check all methods found
448-
for key in self.cpuTemps:
461+
for key in self.tempCmds:
449462
if (path.exists(key)):
450-
self._logger.debug(self.cpuTemps[key])
451-
code, out, err = self.runcommand(self.cpuTemps[key][0])
463+
# self._logger.debug(self.tempCmds[key])
464+
code, out, err = self.runcommand(self.tempCmds[key][0])
452465
out = out.rstrip("\n")
453466
if code or err:
467+
#self._logger.debug("ERROR 1:-------------------------------------------------------------%s %s",err,code)
454468
pass
455-
#self._logger.debug("ERROR 1:-------------------------------------------------------------%s %s",err,code)
456469
else:
457470
if out.replace('.','',1).isdigit():
458-
self.cpuTemps[key][2] = float(out)
459-
# self._logger.debug("OK-------------------------------------------------------------%s",out)
471+
#self._logger.debug("OK-------------------------------------------------------------%s",out)
472+
self.tempCmds[key][2] = float(out)
460473
else:
474+
# self._logger.debug("ERROR 2:-------------------------------------------------------------%s",out)
461475
pass
462-
#self._logger.debug("ERROR 2:-------------------------------------------------------------%s",out)
463476
else:
464477
self._logger.debug("Not found:-------------------------------------------------------------%s",key)
465478

@@ -712,7 +725,7 @@ def on_api_command(self, command, data):
712725
self.buildPsuUtil()
713726

714727
self.debugOut("Sending options")
715-
return flask.jsonify({'cmds' : self.cpuTemps,'psutil' : self.psutilList})
728+
return flask.jsonify({'cmds' : self.tempCmds,'psutil' : self.psutilList})
716729

717730
# Get history data
718731
if command == "getCustomHistory":

octoprint_toptemp/static/js/TopTemp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ $(function() {
241241
if (calc == null || calc == false || $.trim(calc) == ""){
242242
return val;
243243
}
244-
return eval(calc.replace("X",val));
244+
return eval(calc.replace(/x/ig,val));
245245
}
246246

247247
// Get updated data from the "feeds"
@@ -700,7 +700,7 @@ $(function() {
700700
}else{
701701
$('#settings_plugin_toptemp .UICShowIconPicker').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){
702702
new PNotify({
703-
title: 'Instal UI Customizer',
703+
title: 'Install UI Customizer',
704704
text: 'In order to use the icon picker please install the UI Customizer plugin.<br><a target="_new" href="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/LazeMSS/OctoPrint-UICustomizer/">More...</a>',
705705
type: "notice",
706706
hide: false

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "Top Temp"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "0.0.1.3"
17+
plugin_version = "0.0.1.4"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module

0 commit comments

Comments
 (0)