Skip to content

Commit

Permalink
Python 3 compatibility, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
farfalleflickan committed Sep 21, 2020
1 parent 4fd2ced commit ee58478
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 59 deletions.
5 changes: 4 additions & 1 deletion extras/hardwarepwm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ layout: plugin
id: hardwarepwm
title: OctoPrint-Hardwarepwm
description: Plugin for true hardware PWM on the Raspberry Pi
author: Dario Rostirolla
author: Daria Rostirolla
license: AGPLv3

date: 2019-02-01
Expand All @@ -31,6 +31,9 @@ featuredimage: /assets/img/plugins/hardwarepwm/settingsPage.png

compatibility:

compatibility:
- python: ">=2.7,<4"

octoprint:
- 1.2.0

Expand Down
107 changes: 54 additions & 53 deletions octoprint_hardwarepwm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@
class HardwarepwmPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.StartupPlugin,
octoprint.plugin.ShutdownPlugin,
octoprint.plugin.BlueprintPlugin,
octoprint.plugin.ShutdownPlugin,
octoprint.plugin.BlueprintPlugin,
octoprint.plugin.TemplatePlugin):

def __init__(self):
self.IOpin = 19
self.Freq = 512
self.dutyCycle = 50
self.IOpin = 19
self.Freq = 512
self.dutyCycle = 50
self.GPIO = pigpio.pi()

def startPWM(self, pin, hz, percCycle):
cycle=float(percCycle*10000)
cycle=int(percCycle*10000)
if (self.GPIO.connected):
if (pin==12 or pin==13 or pin==18 or pin==19):
self.GPIO.set_mode(pin, pigpio.ALT5)
self.GPIO.hardware_PWM(pin, hz, cycle)
else:
self._logger.error(str(pin)+" is not a hardware PWM pin.")
else:
if (pin==12 or pin==13 or pin==18 or pin==19):
self.GPIO.set_mode(pin, pigpio.ALT5)
self.GPIO.hardware_PWM(pin, hz, cycle)
else:
self._logger.error(str(pin)+" is not a hardware PWM pin.")
else:
self._logger.error("Not connected to PIGPIO")

def stopPWM(self, pin):
if (self.GPIO.connected):
self.GPIO.write(pin, 0)
self.GPIO.write(pin, 0)
else:
self._logger.error("Not connected to PIGPIO")
self._logger.error("Not connected to PIGPIO")

def shutOffPWM(self):
self.GPIO.stop()

def get_settings_defaults(self):
return dict(
IOpin=self.IOpin,
Freq=self.Freq,
dutyCycle=self.dutyCycle
)
return dict(
IOpin=self.IOpin,
Freq=self.Freq,
dutyCycle=self.dutyCycle
)

def on_after_startup(self):
self.getVars()
Expand All @@ -52,67 +52,68 @@ def on_shutdown(self):
self.shutOffPWM();

def getVars(self):
self.IOpin = float(self._settings.get(["IOpin"]))
self.Freq = float(self._settings.get(["Freq"]))
self.dutyCycle = float(self._settings.get(["dutyCycle"]))
self.IOpin = int(self._settings.get(["IOpin"]))
self.Freq = int(self._settings.get(["Freq"]))
self.dutyCycle = int(self._settings.get(["dutyCycle"]))

def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
self.stopPWM(self.IOpin)
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
self.stopPWM(self.IOpin)
self.getVars()
self.startPWM(self.IOpin, self.Freq, self.dutyCycle)

def get_assets(self):
return dict(
js=["js/hardwarepwm.js"]
)
return dict(
js=["js/hardwarepwm.js"]
)

def get_template_vars(self):
return dict(
IOpin = float(self._settings.get(["IOpin"])),
Freq = float(self._settings.get(["Freq"])),
dutyCycle = float(self._settings.get(["dutyCycle"]))
)
IOpin = int(self._settings.get(["IOpin"])),
Freq = int(self._settings.get(["Freq"])),
dutyCycle = int(self._settings.get(["dutyCycle"]))
)

def get_template_configs(self):
return [
dict(type="settings", custom_bindings=False)
]
dict(type="settings", custom_bindings=False)
]


def get_update_information(self):
return dict(
hardwarepwm=dict(
displayName="Hardwarepwm Plugin",
displayVersion=self._plugin_version,
type="github_release",
user="pastapojken",
repo="OctoPrint-Hardwarepwm",
current=self._plugin_version,
pip="https://github.com/pastapojken/OctoPrint-Hardwarepwm/archive/{target_version}.zip"
)
return dict(
hardwarepwm=dict(
displayName="Hardwarepwm Plugin",
displayVersion=self._plugin_version,
type="github_release",
user="pastapojken",
repo="OctoPrint-Hardwarepwm",
current=self._plugin_version,
pip="https://github.com/pastapojken/OctoPrint-Hardwarepwm/archive/{target_version}.zip"
)
)

@octoprint.plugin.BlueprintPlugin.route("/setPWM", methods=["POST"])
def set_pwm(self):
new_cycle = float(flask.request.json['val'])
self.dutyCycle=new_cycle
new_cycle = int(flask.request.json['val'])
self.dutyCycle=new_cycle
self._settings.set(["dutyCycle"], new_cycle)
self._settings.save()
self._settings.save()
self.getVars()
self.startPWM(self.IOpin, self.Freq, self.dutyCycle)
return flask.jsonify(success=True)



__plugin_name__ = "hardwarePWM"
__plugin_pythoncompat__ = ">=2.7,<4"

def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = HardwarepwmPlugin()

global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = HardwarepwmPlugin()

global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
2 changes: 1 addition & 1 deletion octoprint_hardwarepwm/static/js/hardwarepwm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* View model for OctoPrint-Hardwarepwm
*
* Author: Dario Rostirolla
* Author: Daria Rostirolla
* License: AGPLv3
*/
$(function() {
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

plugin_name = "OctoPrint-Hardwarepwm"

plugin_version = "0.1.1.2"
plugin_version = "0.1.1.3"

plugin_description = """Raspberry Pi Hardware PWM """

plugin_author = "Dario Rostirolla"
plugin_author = "Daria Rostirolla"

plugin_author_email = "rostirolladario@gmail.com"
plugin_author_email = "pastapojken@gmail.com"

plugin_url = "https://github.com/pastapojken/OctoPrint-Hardwarepwm"

Expand Down Expand Up @@ -49,7 +49,7 @@
url=plugin_url,
license=plugin_license,
requires=plugin_requires,
additional_packages=plugin_additional_packages,
additional_packages=plugin_additional_packages,
ignored_packages=plugin_ignored_packages,
additional_data=plugin_additional_data
)
Expand Down

0 comments on commit ee58478

Please sign in to comment.