Skip to content

Commit 95c77c3

Browse files
committed
Displays RaspberryPi temperature even when disconnected from printer
1 parent 146a14d commit 95c77c3

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

octoprint_navbartemp/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class NavBarPlugin(octoprint.plugin.StartupPlugin,
1616

1717
def __init__(self):
1818
self.isRaspi = False
19+
self.debugMode = False # to simulate temp on Win/Mac
1920

2021
def on_after_startup(self):
2122
if sys.platform == "linux2":
@@ -38,9 +39,10 @@ def on_after_startup(self):
3839
self._logger.debug("Let's start RepeatedTimer!")
3940
t = RepeatedTimer(30.0, self.checkRaspiTemp)
4041
t.start()
41-
# else:
42-
# t = RepeatedTimer(5.0, self.checkRaspiTemp)
43-
# t.start()
42+
elif self.debugMode:
43+
self.isRaspi = True
44+
t = RepeatedTimer(5.0, self.checkRaspiTemp)
45+
t.start()
4446

4547
self._logger.debug("is Raspberry Pi? - %s" % self.isRaspi)
4648

@@ -49,16 +51,17 @@ def checkRaspiTemp(self):
4951

5052
self._logger.debug("Checking Raspberry Pi internal temperature")
5153

52-
# if sys.platform == "linux2":
53-
p = run("/opt/vc/bin/vcgencmd measure_temp", stdout=Capture())
54-
p = p.stdout.text
55-
# else:
56-
# import random
57-
#
58-
# def randrange_float(start, stop, step):
59-
# return random.randint(0, int((stop - start) / step)) * step + start
60-
#
61-
# p = "temp=%s'C" % randrange_float(5, 60, 0.1)
54+
if sys.platform == "linux2":
55+
p = run("/opt/vc/bin/vcgencmd measure_temp", stdout=Capture())
56+
p = p.stdout.text
57+
elif self.debugMode:
58+
import random
59+
60+
def randrange_float(start, stop, step):
61+
return random.randint(0, int((stop - start) / step)) * step + start
62+
63+
p = "temp=%s'C" % randrange_float(5, 60, 0.1)
64+
6265
self._logger.debug("response from sarge: %s" % p)
6366

6467
match = re.search('=(.*)\'', p)

octoprint_navbartemp/static/css/navbartemp.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

octoprint_navbartemp/static/less/navbartemp.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@text-color-dark: #333333;
88
@text-color: contrast(@base, @text-color-dark, @text-color-light);
99

10-
.nav>li>span>p {
10+
.nav>li>p, .nav>li>div>p {
1111
.navbar-inner-text(@base);
1212
}
1313
}

octoprint_navbartemp/templates/navbartemp_navbar.jinja2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<span data-bind="visible: navBarTempModel.isOperational()">
2-
<p class="nav navbar-text" data-bind="html: raspiTemp"></p>
1+
<p class="nav navbar-text" data-bind="html: raspiTemp, visible: isRaspi"></p>
2+
<div data-bind="visible: navBarTempModel.isOperational()" class="nav">
33
<!-- ko foreach: navBarTempModel.tools -->
44
<p class="nav navbar-text" data-bind="template: { name: 'navbartemp-template' }"></p>
55
<!-- /ko -->
66
<p class="nav navbar-text" data-bind="template: { name: 'navbartemp-template', data: navBarTempModel.bedTemp }, visible: navBarTempModel.hasBed"></p>
7-
</span>
7+
</div>
88

99
<script type="text/html" id="navbartemp-template">
1010
<span data-bind="html: formatBarTemperature(name(), actual(), target())"></span>

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
plugin_identifier = "navbartemp"
77
plugin_package = "octoprint_%s" % plugin_identifier
88
plugin_name = "OctoPrint-NavbarTemp"
9-
plugin_version = "0.5"
9+
plugin_version = "0.6"
1010
plugin_description = "Displays temperatures on navbar"
1111
plugin_author = "Jarek Szczepanski"
1212
plugin_author_email = "imrahil@imrahil.com"

0 commit comments

Comments
 (0)