Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Added possibility to configure displaynames of temperatures #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions octoprint_navbartemp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __init__(self):
self.isRaspi = False
self.debugMode = False # to simulate temp on Win/Mac
self.displayRaspiTemp = True
self.bedTempDisplayName = "Bed:"
self.hotendTempDisplayName = "Hotend:"
self.raspiTempDisplayName = "Raspi:"
self._checkTempTimer = None

def on_after_startup(self):
Expand All @@ -40,17 +43,17 @@ def on_after_startup(self):
elif match.group(1) == 'BCM2709':
self._logger.debug("Pi 2")
self.isRaspi = True
elif match.group(1) == 'BCM2835':
self._logger.debug("Pi 3")
self.isRaspi = True
elif match.group(1) == 'BCM2835':
self._logger.debug("Pi 3")
self.isRaspi = True

if self.isRaspi and self.displayRaspiTemp:
self._logger.debug("Let's start RepeatedTimer!")
self.startTimer(30.0)
elif self.debugMode:
self.isRaspi = True
if self.displayRaspiTemp:
self.startTimer(5.0)
elif self.debugMode:
self.isRaspi = True
if self.displayRaspiTemp:
self.startTimer(5.0)

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

Expand Down Expand Up @@ -86,12 +89,20 @@ def randrange_float(start, stop, step):

##~~ SettingsPlugin
def get_settings_defaults(self):
return dict(displayRaspiTemp = self.displayRaspiTemp)
return dict(displayRaspiTemp = self.displayRaspiTemp, displayNames = dict(
bed = self.bedTempDisplayName,
hotend = self.hotendTempDisplayName,
raspi = self.raspiTempDisplayName
)
)

def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)

self.displayRaspiTemp = self._settings.get(["displayRaspiTemp"])
self.bedTempDisplayName = self._settings.get(["displayNames.bedTempDisplayName"])
self.hotendTempDisplayName = self._settings.get(["displayNames.hotendTempDisplayName"])
self.raspiTempDisplayName = self._settings.get(["displayNames.raspiTempDisplayName"])

if self.displayRaspiTemp:
interval = 5.0 if self.debugMode else 30.0
Expand All @@ -106,12 +117,9 @@ def on_settings_save(self, data):

##~~ TemplatePlugin API
def get_template_configs(self):
if self.isRaspi:
return [
dict(type="settings", template="navbartemp_settings_raspi.jinja2")
]
else:
return []
return [
dict(type="settings", template="navbartemp_settings.jinja2")
]

##~~ AssetPlugin API
def get_assets(self):
Expand Down
14 changes: 12 additions & 2 deletions octoprint_navbartemp/static/js/navbartemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ $(function() {
self.isRaspi = ko.observable(false);

self.formatBarTemperature = function(toolName, actual, target) {
var output = toolName + ": " + _.sprintf("%.1f°C", actual);
var displayName = "";

if (toolName == "Tool" || toolName == "End" || toolName == "Hotend" || toolName == "Hot End") {
displayName = self.settings.displayNames.hotend;
} else if (toolName == "Bett" || toolName == "Bed") {
displayName = self.settings.displayNames.bed;
} else {
displayName = toolName + ":";
}

var output = _.sprintf("%s %.1f°C", displayName, actual);

if (target) {
var sign = (target >= actual) ? " \u21D7 " : " \u21D8 ";
Expand All @@ -34,7 +44,7 @@ $(function() {
self.isRaspi(true);
}

self.raspiTemp(_.sprintf("Raspi: %.1f°C", data.raspitemp));
self.raspiTemp(_.sprintf("%s %.1f°C", self.settings.displayNames.raspi, data.raspitemp));
};
}

Expand Down
30 changes: 30 additions & 0 deletions octoprint_navbartemp/templates/navbartemp_settings.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h4>Configuration</h4>

<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="settings-navbartemp-bedtemp-displayname">Bed Temp Displayname:</label>
<div class="controls">
<input type="text" name="settings-navbartemp-bedtemp-displayname" data-bind="value: settings.displayNames.bed"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="settings-navbartemp-hotendtemp-displayname">Hotend Displayname:</label>
<div class="controls">
<input type="text" name="settings-navbartemp-hotendtemp-displayname" data-bind="value: settings.displayNames.hotend"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="settings-navbartemp-display"></label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.displayRaspiTemp"> Display internal temperature
</label>
</div>
</div>
<div class="control-group" data-bind="visible: settings.displayRaspiTemp">
<label class="control-label" for="settings-navbartemp-raspitemp-displayname">RasPi Displayname:</label>
<div class="controls">
<input type="text" name="settings-navbartemp-raspitemp-displayname" data-bind="value: settings.displayNames.raspi"/>
</div>
</div>
</form>
12 changes: 0 additions & 12 deletions octoprint_navbartemp/templates/navbartemp_settings_raspi.jinja2

This file was deleted.