Skip to content

Commit

Permalink
Displays RaspberryPi temperature even when disconnected from printer
Browse files Browse the repository at this point in the history
  • Loading branch information
imrahil committed Jun 25, 2015
1 parent 146a14d commit 95c77c3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
29 changes: 16 additions & 13 deletions octoprint_navbartemp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NavBarPlugin(octoprint.plugin.StartupPlugin,

def __init__(self):
self.isRaspi = False
self.debugMode = False # to simulate temp on Win/Mac

def on_after_startup(self):
if sys.platform == "linux2":
Expand All @@ -38,9 +39,10 @@ def on_after_startup(self):
self._logger.debug("Let's start RepeatedTimer!")
t = RepeatedTimer(30.0, self.checkRaspiTemp)
t.start()
# else:
# t = RepeatedTimer(5.0, self.checkRaspiTemp)
# t.start()
elif self.debugMode:
self.isRaspi = True
t = RepeatedTimer(5.0, self.checkRaspiTemp)
t.start()

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

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

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

# if sys.platform == "linux2":
p = run("/opt/vc/bin/vcgencmd measure_temp", stdout=Capture())
p = p.stdout.text
# else:
# import random
#
# def randrange_float(start, stop, step):
# return random.randint(0, int((stop - start) / step)) * step + start
#
# p = "temp=%s'C" % randrange_float(5, 60, 0.1)
if sys.platform == "linux2":
p = run("/opt/vc/bin/vcgencmd measure_temp", stdout=Capture())
p = p.stdout.text
elif self.debugMode:
import random

def randrange_float(start, stop, step):
return random.randint(0, int((stop - start) / step)) * step + start

p = "temp=%s'C" % randrange_float(5, 60, 0.1)

self._logger.debug("response from sarge: %s" % p)

match = re.search('=(.*)\'', p)
Expand Down
2 changes: 1 addition & 1 deletion octoprint_navbartemp/static/css/navbartemp.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion octoprint_navbartemp/static/less/navbartemp.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@text-color-dark: #333333;
@text-color: contrast(@base, @text-color-dark, @text-color-light);

.nav>li>span>p {
.nav>li>p, .nav>li>div>p {
.navbar-inner-text(@base);
}
}
Expand Down
6 changes: 3 additions & 3 deletions octoprint_navbartemp/templates/navbartemp_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<span data-bind="visible: navBarTempModel.isOperational()">
<p class="nav navbar-text" data-bind="html: raspiTemp"></p>
<p class="nav navbar-text" data-bind="html: raspiTemp, visible: isRaspi"></p>
<div data-bind="visible: navBarTempModel.isOperational()" class="nav">
<!-- ko foreach: navBarTempModel.tools -->
<p class="nav navbar-text" data-bind="template: { name: 'navbartemp-template' }"></p>
<!-- /ko -->
<p class="nav navbar-text" data-bind="template: { name: 'navbartemp-template', data: navBarTempModel.bedTemp }, visible: navBarTempModel.hasBed"></p>
</span>
</div>

<script type="text/html" id="navbartemp-template">
<span data-bind="html: formatBarTemperature(name(), actual(), target())"></span>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
plugin_identifier = "navbartemp"
plugin_package = "octoprint_%s" % plugin_identifier
plugin_name = "OctoPrint-NavbarTemp"
plugin_version = "0.5"
plugin_version = "0.6"
plugin_description = "Displays temperatures on navbar"
plugin_author = "Jarek Szczepanski"
plugin_author_email = "imrahil@imrahil.com"
Expand Down

0 comments on commit 95c77c3

Please sign in to comment.