Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Adding on_settings_migrate() to add the 2 new default options to older
Browse files Browse the repository at this point in the history
configurations.  This should fix all the KeyErrors people are seeing.

Set the pigpiod pwm dutycycle to range from 0-100 so that it matches
RPi.GPIO.

The startup pwm value should be 0 or 100. This should fix the
ValueError users were seeing.

Removed some of the debugging cruft I had added trying to fix the
original bugs, but I didn't have an actual printer around to test
with.
  • Loading branch information
precision committed Apr 1, 2018
1 parent 583c940 commit a34eebb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions octoprint_LEDStripControl/__init__.py
Expand Up @@ -51,16 +51,18 @@ def start(self, dutycycle):
self._dutycycle = dutycycle
self._logger.debug(u"PiGPIOpin: start() pin: %s" % self._pin)
if self._pigpiod.connected:
self._pigpiod.set_PWM_range(self._pin, 100) # emulate RPi.GPIO
self._pigpiod.set_PWM_dutycycle(self._pin, dutycycle)

def stop(self):
self._logger.debug(u"PiGPIOpin: stop() pin: %s" % self._pin)
if self._pigpiod.connected:
self._pigpiod.set_PWM_range(self._pin, 100) # emulate RPi.GPIO
self._pigpiod.set_PWM_dutycycle(self._pin, 0)

def ChangeDutyCycle(self, dutycycle):
self._logger.debug(u"PiGPIOpin: ChangeDutyCycle() pin: %s" % self._pin)
self.start(float(dutycycle))
self.start(dutycycle)

class LEDStripControlPlugin(octoprint.plugin.AssetPlugin,
octoprint.plugin.SettingsPlugin,
Expand All @@ -76,7 +78,7 @@ def _setup_pin(self, pin):
self._logger.debug(u"_setup_pin(%s)" % (pin,))
if pin:
p = None
startup = 255.0 if self._settings.get_boolean(['on_startup']) else 0.0
startup = 100.0 if self._settings.get_boolean(['on_startup']) else 0.0

if self._pigpiod is None:
self._pigpiod = pigpio.pi()
Expand All @@ -92,18 +94,15 @@ def _setup_pin(self, pin):
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
p = GPIO.PWM(pin, 100)
p.start(float(startup))
p.start(startup)
return p

def _unregister_leds(self):
self._logger.debug(u"_unregister_leds()")
for i in ('r', 'g', 'b', 'w'):
try:
if self._leds[i]:
self._leds[i].ChangeDutyCycle(0)
self._leds[i].stop()
except KeyError:
pass
if self._leds[i]:
self._leds[i].ChangeDutyCycle(0)
self._leds[i].stop()

if not self._settings.get_boolean(['pigpiod']) and GPIO:
GPIO.cleanup()
Expand Down Expand Up @@ -152,12 +151,10 @@ def HandleM150(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs

return None,

return None,

##~~ SettingsPlugin mixin

def get_settings_version(self):
return 1
return 2

def get_template_configs(self):
return [
Expand All @@ -181,6 +178,13 @@ def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
self._register_leds()

def on_settings_migrate(self, target, current=None):
self._logger.debug(u"LEDStripControl on_settings_migrate()")
if current == 1:
# add the 2 new values included
self._settings.set(['w'], self.get_settings_defaults()["w"])
self._settings.set(['on_startup'], self.get_settings_defaults()["on_startup"])

##~~ Softwareupdate hook

def get_update_information(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -18,7 +18,7 @@
plugin_identifier = "LEDStripControl"
plugin_package = "octoprint_LEDStripControl"
plugin_name = "OctoPrint-LEDStripControl"
plugin_version = "0.3.5"
plugin_version = "0.3.6"
plugin_description = """OctoPrint plugin for controling RGB LED Strips via local GPIO pins"""
plugin_author = "Uriah Welcome"
plugin_author_email = "uriah@google.com"
Expand Down

0 comments on commit a34eebb

Please sign in to comment.