From ee584783513f12efa651118c7182261962b5fd8f Mon Sep 17 00:00:00 2001 From: pastapojken <6597735+pastapojken@users.noreply.github.com> Date: Mon, 21 Sep 2020 13:18:02 +0200 Subject: [PATCH] Python 3 compatibility, version bump --- extras/hardwarepwm.md | 5 +- octoprint_hardwarepwm/__init__.py | 107 +++++++++--------- .../static/js/hardwarepwm.js | 2 +- setup.py | 8 +- 4 files changed, 63 insertions(+), 59 deletions(-) diff --git a/extras/hardwarepwm.md b/extras/hardwarepwm.md index 7db78ba..45e1c02 100644 --- a/extras/hardwarepwm.md +++ b/extras/hardwarepwm.md @@ -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 @@ -31,6 +31,9 @@ featuredimage: /assets/img/plugins/hardwarepwm/settingsPage.png compatibility: + compatibility: + - python: ">=2.7,<4" + octoprint: - 1.2.0 diff --git a/octoprint_hardwarepwm/__init__.py b/octoprint_hardwarepwm/__init__.py index bba44b0..7079c9f 100755 --- a/octoprint_hardwarepwm/__init__.py +++ b/octoprint_hardwarepwm/__init__.py @@ -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() @@ -52,53 +52,53 @@ 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) @@ -106,13 +106,14 @@ def set_pwm(self): __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 + } diff --git a/octoprint_hardwarepwm/static/js/hardwarepwm.js b/octoprint_hardwarepwm/static/js/hardwarepwm.js index 1c8ef48..fa4f430 100644 --- a/octoprint_hardwarepwm/static/js/hardwarepwm.js +++ b/octoprint_hardwarepwm/static/js/hardwarepwm.js @@ -1,7 +1,7 @@ /* * View model for OctoPrint-Hardwarepwm * - * Author: Dario Rostirolla + * Author: Daria Rostirolla * License: AGPLv3 */ $(function() { diff --git a/setup.py b/setup.py index dc67ca9..b25dc31 100644 --- a/setup.py +++ b/setup.py @@ -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" @@ -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 )