Skip to content

Commit

Permalink
Bug fix on shutdown beeps
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleborgo committed Jan 2, 2022
1 parent 5aeeb18 commit b3dde65
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# ShutdownButtonLEDBuzzer

This plugin implements a shutdown physical button for
the Rasperry. It offers also a status LED to know when
This OctoPrint plugin implements a shutdown physical button
for the Rasperry Pi. It offers also a status LED to know when
OctoPrint is ready and a buzzer to signal the startup and
the shutdown.
the shutdown. Remember that these signals may vary of few
seconds.

## Setup

Expand All @@ -15,12 +16,15 @@ or manually using this URL:

## Circuit

- Button: by default directly on pin 26 since pull-up is enabled
via software.
- LED: by default on pin 6
- Buzzer: by default on pin 12
The circuit hereafter exposed is just the one set by default,
since the plugin allows to edit each of these pin:

They can be changed in the settings page.
- Button: by default directly on pin GPIO26
- LED: by default on pin GPIO6
- Buzzer: by default on pin GPIO12

In case one of these features is not needed, it can be
deactivated by the apposite settings section.

![circuit](docs/circuit.png)

Expand All @@ -33,8 +37,6 @@ accessible in the apposite OctoPrint section in setting:
![settings2](docs/settings2.png)
![settings3](docs/settings3.png)

The offered three features can be disabled independently.

## License

This software is distributed on GPLv3.0, more information
Expand Down
2 changes: 1 addition & 1 deletion create_zip.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
zip -r ShutdownButtonLEDBuzzer.zip ./octoprint_shutdownbuttonledbuzzer/ ./translations/ ./docs/ babel.cfg MANIFEST.in README.md LICENSE:md requirements.txt setup.py
zip -r ShutdownButtonLEDBuzzer.zip ./octoprint_shutdownbuttonledbuzzer/ ./translations/ ./docs/ babel.cfg MANIFEST.in README.md LICENSE.md requirements.txt setup.py
20 changes: 11 additions & 9 deletions octoprint_shutdownbuttonledbuzzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8

"""
Copyright (C) 2021 Daniele Borgo
Copyright (C) 2022 Daniele Borgo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,7 +43,7 @@
PI_SHUTDOWN_COMMAND = "sudo shutdown -h now"
I2C_STATUS_COMMAND = "raspi-config nonint get_i2c"
SPI_STATUS_COMMAND = "raspi-config nonint get_spi"
SERVICE_ENABLE_OUT = "0"
SERVICE_ENABLED_OUTPUT = "0"


class ShutdownButtonLEDBuzzerPlugin(
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(self):
def on_after_startup(self):
self.__load_settings()
self.__setup()
self._logger.info('ShutdownButtonLEDBuzzerPlugin ready')
self._logger.info('Plugin ready')

def __load_settings(self):
# Avoid errors in case of memory saved data corruption
Expand Down Expand Up @@ -111,7 +111,7 @@ def __setup(self):
GPIO.add_event_detect(
self.__button_pin,
GPIO.FALLING,
callback=lambda param: self.__shutdown()
callback=lambda param: self.__shutdown_for_button()
)

# Set the status LED
Expand All @@ -130,7 +130,7 @@ def __setup(self):
else:
self.__buzzer = None

def __shutdown(self):
def __shutdown_for_button(self):
if not self.__shutdown_lock.acquire(blocking=False):
return

Expand Down Expand Up @@ -160,9 +160,11 @@ def __close_button(self):
GPIO.remove_event_detect(self.__button_pin)

def on_shutdown(self):
self.__emit_beep(self.__beeps_on_shutdown)
self.__close_component(self.__buzzer)
self.__beep_thread_pool.shutdown(wait=False)
self.__close_button()
# LED is not turned off since it has to indicate the Raspberry GPIO shutdown
self.__emit_beep_for_pool(self.__beeps_on_shutdown)
self.__close_component(self.__buzzer)
self._logger.info("Plugin closed")

def get_settings_defaults(self):
Expand Down Expand Up @@ -210,7 +212,7 @@ def __get_spi_status():
def __get_service_status(command: str):
try:
out = subprocess.run(command.split(), capture_output=True).stdout.decode("utf-8").strip()
return "enabled" if (out == SERVICE_ENABLE_OUT) else "disabled"
return "enabled" if (out == SERVICE_ENABLED_OUTPUT) else "disabled"
except FileNotFoundError:
return "undefined"

Expand All @@ -224,7 +226,7 @@ def get_assets(self):
# core UI here.
return {
"js": ["js/ShutdownButtonLEDBuzzer.js"],
"less": ["less/ShutdownButtonLEDBuzzer.less"],
# "less": ["less/ShutdownButtonLEDBuzzer.less"],
"css": ["css/ShutdownButtonLEDBuzzer.css"]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
/*
* View model for OctoPrint-ShutdownButtonLEDBuzzer
* Copyright (C) 2022 Daniele Borgo
*
* Author: Daniele Borgo
* License: GPLv3
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

$(function() {
function ShutdownbuttonledbuzzerViewModel(parameters) {
function ShutdownButtonLEDBuzzerViewModel(parameters) {
let self = this;

self.settingsViewModel = parameters[0];

self.i2c_status = ko.observable("_")
self.spi_status = ko.observable("-")
self.updated_hour = ko.observable("-")
self.i2c_status = ko.observable("_");
self.spi_status = ko.observable("-");
self.updated_hour = ko.observable("-");

self.set_hour = function (){
let date = new Date($.now())
self.updated_hour(date.toLocaleDateString() + " " + date.toLocaleTimeString())
let date = new Date($.now());
self.updated_hour(date.toLocaleDateString() + " " + date.toLocaleTimeString());
}

self.refresh = function (){
self.updated_hour("Updating...")
self.i2c_status("Loading...")
self.spi_status("Loading...")
self.updated_hour("Updating...");
self.i2c_status("Loading...");
self.spi_status("Loading...");

$.ajax({
url: API_BASEURL + "plugin/shutdownbuttonledbuzzer",
Expand All @@ -34,23 +44,23 @@ $(function() {
command: "services_status"
})
}).done(function (data) {
self.i2c_status(data.i2c_status)
self.spi_status(data.spi_status)
self.i2c_status(data.i2c_status);
self.spi_status(data.spi_status);
}).fail(function () {
self.i2c_status("Error in retrieving")
self.spi_status("Error in retrieving")
self.i2c_status("Error in retrieving");
self.spi_status("Error in retrieving");
}).always(function () {
self.set_hour()
self.set_hour();
});
}

self.onStartupComplete = function () {
self.refresh()
self.refresh();
}
}

OCTOPRINT_VIEWMODELS.push({
construct: ShutdownbuttonledbuzzerViewModel,
construct: ShutdownButtonLEDBuzzerViewModel,
dependencies: [ "settingsViewModel" ],
elements: [ "#settings_plugin_shutdownbuttonledbuzzer" ]
});
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
plugin_license = "GPLv3"

# Any additional requirements besides OctoPrint should be listed here
plugin_requires = ["OctoPrint>=1.7.2", "gpiozero>=1.6.2", "RPi.GPIO>=0.7.0"]
plugin_requires = ["OctoPrint>=1.7.2", "gpiozero>=1.6.2", "RPi.GPIO>=0.7.0", "flask>=1.1.4"]

# --------------------------------------------------------------------------------------------------------------------
# More advanced options that you usually shouldn't have to touch follow after this point
Expand All @@ -60,7 +60,7 @@
# plugin_requires = ["someDependency==dev"]
# additional_setup_parameters = {"dependency_links":
# ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
additional_setup_parameters = {"python_requires": ">=3, <4"}
additional_setup_parameters = {}

########################################################################################################################

Expand Down

0 comments on commit b3dde65

Please sign in to comment.