Skip to content

Commit 476f061

Browse files
authored
Merge pull request #7 from svenstaro/patch-1
Make sure default ALT0 hardware PWM pin mode isn't overwritten
2 parents 4cbbef5 + a6c68a7 commit 476f061

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: octoprint_LightControls/__init__.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,26 @@ def gpio_startup(self, pin, settings):
121121
if pin in self.Lights:
122122
self.gpio_cleanup(pin)
123123

124-
GPIO.setup(self._gpio_get_pin(pin), GPIO.OUT)
125124
try:
126125
self.Lights[pin] = copy.deepcopy(settings)
127126
if settings["ispwm"]:
128127
if self._is_hw_pwm_pin(self._gpio_get_pin(pin)):
129128
try:
130129
self.Lights[pin]["pwm"] = HardwarePWM(self._get_hw_pwm_channel(self._gpio_get_pin(pin)), int(settings["frequency"]))
131-
self._logger.debug("Setup HW PWM succeded!")
130+
self._logger.debug("Setup hardware PWM succeded!")
132131
except Exception as e:
133-
self._logger.error("Tried to setup pin {} as Hardware PWM on channel {}, but failed:".format(pin, self._get_hw_pwm_channel(self._gpio_get_pin(pin))))
132+
self._logger.error("Tried to setup pin {} as hardware PWM on channel {}, but failed:".format(pin, self._get_hw_pwm_channel(self._gpio_get_pin(pin))))
134133
self._logger.error(e)
135-
self._logger.warning("Setting up as Soft PWM instead...")
134+
self._logger.warning("Setting up as software PWM instead...")
135+
self._logger.warning("If your LEDs appear to be flickering, look into hardware PWM.")
136+
GPIO.setup(self._gpio_get_pin(pin), GPIO.OUT)
136137
self.Lights[pin]["pwm"] = GPIO.PWM(self._gpio_get_pin(pin), int(settings["frequency"]))
137138
else:
139+
GPIO.setup(self._gpio_get_pin(pin), GPIO.OUT)
138140
self.Lights[pin]["pwm"] = GPIO.PWM(self._gpio_get_pin(pin), int(settings["frequency"]))
139141
self.Lights[pin]["pwm"].start(100 if self.Lights[pin]["inverted"] else 0)
140142
else:
143+
GPIO.setup(self._gpio_get_pin(pin), GPIO.OUT)
141144
GPIO.output(self._gpio_get_pin(pin), 1 if self.Lights[pin]["inverted"] else 0)
142145

143146
self.Lights[pin]["value"] = 0

0 commit comments

Comments
 (0)