Skip to content

Commit

Permalink
Merge pull request #7 from gigibu5/version0.1.1
Browse files Browse the repository at this point in the history
Version 0.1.1
  • Loading branch information
gigibu5 authored Jan 21, 2021
2 parents 75af851 + ad8218b commit 88737e0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OctoLight
A simple plugin that adds a button to the navigation bar for toggleing a GPIO pin on the Raspberry Pi. I use it for turning ON and OFF the light on my 3D printer.
A simple plugin that adds a button to the navigation bar for toggleing a GPIO pin on the Raspberry Pi.

![WebUI interface](img/screenshoot.png)

Expand All @@ -10,6 +10,14 @@ or manually using this URL:
https://github.com/gigibu5/OctoLight/archive/master.zip

## Configuration
There is an option in the settings menu for changing the GPIO the button trigeres. **IMPORTANT:** the pins are saved in the board layout, not by GPIO naming scheme. Below is a picture of the Raspberry Pies GPIO configuration. The correct numbers are those written in gray on the picture bellow.
![Settings panel](img/settings.png)

![Raspberry Pi GPIO](img/rpi_gpio.png)
Curently, you can configure two settings:
- `Light PIN`: The pin on the Raspberry Pi that the button controls.
- Default value: 13
- The pin number is saved in the **board layout naming** scheme (gray labels on the pinout image below).
- **!! IMPORTANT !!** The Raspberry Pi can only controll the **GPIO** pins (orange labels on the pinout image below)
![Raspberry Pi GPIO](img/rpi_gpio.png)

- `Inverted output`: If true, the output will be inverted
- Usage: if you have a light, that is turned off when voltage is applied to the pin (wired in negative logic), you should turn on this option, so the light isn't on when you reboot your Raspberry Pi.
Binary file added img/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions octoprint_octolight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class OctoLightPlugin(
octoprint.plugin.StartupPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.SettingsPlugin
octoprint.plugin.SettingsPlugin,
octoprint.plugin.RestartNeedingPlugin
):

light_state = False


def get_settings_defaults(self):
return dict(
light_pin = 13,
Expand All @@ -39,7 +39,6 @@ def on_after_startup(self):
self._settings.get(["light_pin"]),
self._settings.get(["inverted_output"])
))
#self._logger.info(self._settings.get(["light_pin"]))
self._logger.info("--------------------------------------------")

# Setting the default state of pin
Expand All @@ -51,10 +50,14 @@ def on_after_startup(self):


def on_api_get(self, request):
# Sets the GPIO every time, if user changed it in the settings.
GPIO.setup(int(self._settings.get(["light_pin"])), GPIO.OUT)


self.light_state = not self.light_state
#self._logger.info(self._settings.get(["light_pin"]))
if bool(self.light_state)^bool(self._settings.get(["inverted_output"])):

# Sets the light state depending on the inverted output setting (XOR)
if self.light_state ^ self._settings.get(["inverted_output"]):
GPIO.output(int(self._settings.get(["light_pin"])), GPIO.HIGH)
else:
GPIO.output(int(self._settings.get(["light_pin"])), GPIO.LOW)
Expand Down Expand Up @@ -84,5 +87,6 @@ def get_update_information(self):
__plugin_implementation__ = OctoLightPlugin()

__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
"octoprint.plugin.softwareupdate.check_config":
__plugin_implementation__.get_update_information
}
2 changes: 1 addition & 1 deletion octoprint_octolight/templates/octolight_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<a onclick='OctoPrint.simpleApiGet("octolight")' style="font-size: 1.3em; text-shadow: 0px 0px 2px #000">&#x1F4A1;</a>
<a onclick='OctoPrint.simpleApiGet("octolight")' style="font-size: 1.3em; text-shadow: 0px 0px 2px #000; cursor: pointer; user-select: none">&#x1F4A1;</a>
2 changes: 1 addition & 1 deletion octoprint_octolight/templates/octolight_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="control-group">
<label class="control-label">{{ _('Light PIN') }}</label>
<div class="controls">
<input type="number" class="input-small" data-bind="value: settings.plugins.octolight.light_pin">
<input type="number" min="1" max="40" class="input-small" data-bind="value: settings.plugins.octolight.light_pin">
</div>

<div class="controls">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoLight"

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

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 88737e0

Please sign in to comment.