Skip to content

Commit

Permalink
Fix for #77 - Broken update on PC/x86
Browse files Browse the repository at this point in the history
  • Loading branch information
sco01 committed Oct 7, 2019
1 parent 06ac329 commit 7441290
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
40 changes: 23 additions & 17 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
import psutil
import sys
import os
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
import Adafruit_DHT

try: #Check to see if we are on an RPI or not
import RPi.GPIO as gpio
on_rpi = True
except (ImportError, RuntimeError):
on_rpi = False

if on_rpi == True:
import Adafruit_DHT




from octoprint.events import Events, eventManager

Expand All @@ -35,18 +44,17 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin,
dht_sensor_type = None

def adafruitDhtGetStats(self):
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
if self.dht_sensor_type == "DHT11":
sensor = Adafruit_DHT.DHT11
elif self.dht_sensor_type == "DHT22":
sensor = Adafruit_DHT.DHT22
else: return
pin = self.dht_sensor_pin
try:
self.ambient_humidity, self.ambient_temperature = Adafruit_DHT.read_retry(sensor, pin)
except RuntimeError as e:
print("Reading from DHT failure: ", e.args)
if on_rpi == True: #This will only work on an actual RPi
if self.dht_sensor_type == "DHT11":
sensor = Adafruit_DHT.DHT11
elif self.dht_sensor_type == "DHT22":
sensor = Adafruit_DHT.DHT22
else: return
pin = self.dht_sensor_pin
try:
self.ambient_humidity, self.ambient_temperature = Adafruit_DHT.read_retry(sensor, pin)
except RuntimeError as e:
print("Reading from DHT failure: ", e.args)

def psUtilGetStats(self):
#temp_average = 0
Expand Down Expand Up @@ -106,7 +114,6 @@ def on_event(self, event, payload):
averageLayerDurationInSeconds=payload.get('averageLayerDurationInSeconds')))

if event == "PrintStarted":
self._logger.info("Print Started: " + payload.get("name", ""))
del self.layer_times[:]
del self.layer_labels[:]
self. extruded_filament = 0.0
Expand Down Expand Up @@ -183,7 +190,6 @@ def process_gcode(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwa
elif gcode == "M117":
if not cmd.startswith("M117 INDICATOR-Layer"):
self.printer_message = cmd.strip("M117 ")
self._logger.info("*********** Message: " + self.printer_message)
else: return

elif gcode in ("M82", "G90"):
Expand Down
1 change: 1 addition & 0 deletions octoprint_dashboard/templates/dashboard_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<text class="dashboardGauge" font-size="14" x="50%" y="65%" dominant-baseline="middle" text-anchor="middle" fill="#08c">Job</text>
</svg>
</div>
<span>&nbsp;&nbsp;&nbsp;</span>
<!-- Layer Progress Circle-->
<div class="dashboardProgressContainer dashboardLayerProgressContainer" data-bind="visible: printerStateModel.isPrinting() && settingsViewModel.settings.plugins.dashboard.showLayerProgress() && (settingsViewModel.settings.plugins.dashboard.gaugetype() == 'circle'), DashboardContextMenu: jobMenu, css: { dashboardLayerProgressInline: settingsViewModel.settings.plugins.dashboard.showProgress() && settingsViewModel.settings.plugins.dashboard.showLayerProgress() }">
<svg class="current" width="120" height="120" viewBox="0 0 120 120">
Expand Down
22 changes: 14 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plugin_name = "OctoPrint-Dashboard"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.10.0"
plugin_version = "1.10.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand All @@ -35,13 +35,19 @@
plugin_license = "AGPLv3"

# Any additional requirements besides OctoPrint should be listed here
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
plugin_requires = ["psutil", "Adafruit_DHT"]
else:
plugin_requires = ["psutil"]
else:
plugin_requires = ["psutil"]
#if sys.platform.startswith("linux"):
# if os.uname()[1].startswith("octopi"):
# plugin_requires = ["psutil", "Adafruit_DHT"]
# else:
# plugin_requires = ["psutil"]
#else:
# plugin_requires = ["psutil"]

try:
import RPi.GPIO as gpio
plugin_requires = ["psutil", "Adafruit_DHT"] #RPi.GPIO loads, so we should be on an RPi and can load Adafruit_DHT
except (ImportError, RuntimeError):
plugin_requires = ["psutil"] #We're on some other platform.

### --------------------------------------------------------------------------------------------------------------------
### More advanced options that you usually shouldn't have to touch follow after this point
Expand Down

0 comments on commit 7441290

Please sign in to comment.