Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemotePi 3.2.2 #359

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions remotepi/i18n/strings_de.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"REMOTEPI":{
"PLUGIN_NAME":"RemotePi",
"ERR_RECONF14":"Rekonfiguration von GPIO 14 fehlgeschlagen: ",
"ERR_CONF14":"Konfiguration von GPIO 14 fehlgeschlagen: ",
"ERR_CONF15":"Konfiguration von GPIO 15 fehlgeschlagen: ",
"ERR_RECONF_GPIO":"Fehler bei der Rekonfiguration von GPIO ",
"ERR_CONF_GPIO":"Fehler bei der Konfiguration von GPIO ",
"ERR_WRITE":"Fehler beim Schreiben von ",
"ERR_READ":"Fehler beim Lesen von ",
"PI5_WARN_MSG":"<b>WARNUNG!</b><br><br>WARNUNG! RemotePi-Boards wurden nicht für den Raspberry Pi 5 entwickelt. Der Strombedarf von Pi 5-basierten Systemen kann die Leistungsfähigkeit des RemotePi-Boards übersteigen und es möglicherweise beschädigen.",
"REBOOT_MSG":"Ein Neustart ist erforderlich, damit die Änderung wirksam wird.",
"NO_CHANGES":"Keine zu speichernde Änderung.",
"PLUGIN_CONFIGURATION":"RemotePi Konfiguration",
Expand Down
6 changes: 3 additions & 3 deletions remotepi/i18n/strings_en.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"REMOTEPI":{
"PLUGIN_NAME":"RemotePi",
"ERR_RECONF14":"Reconfiguring GPIO 14 failed: ",
"ERR_CONF14":"Configuring GPIO 14 failed: ",
"ERR_CONF15":"Configuring GPIO 15 failed: ",
"ERR_RECONF_GPIO":"Error reconfiguring GPIO ",
"ERR_CONF_GPIO":"Error configuring GPIO ",
"ERR_WRITE":"Error writing ",
"ERR_READ":"Error reading ",
"PI5_WARN_MSG":"<b>WARNING!</b><br><br>RemotePi boards were not developed for the Raspberry Pi 5. The power requirements of Pi 5 based systems may exceed what the RemotePi board can handle and possibly damage it.",
"REBOOT_MSG":"A reboot is required for the change to take effect.",
"NO_CHANGES":"No changes to save.",
"PLUGIN_CONFIGURATION":"RemotePi Configuration",
Expand Down
6 changes: 3 additions & 3 deletions remotepi/i18n/strings_fr.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"REMOTEPI":{
"PLUGIN_NAME":"RemotePi",
"ERR_RECONF14":"La reconfiguration du GPIO 14 a échoué: ",
"ERR_CONF14":"La configuration de GPIO 14 a échoué: ",
"ERR_CONF15":"La configuration de GPIO 15 a échoué: ",
"ERR_RECONF_GPIO":"Erreur de reconfiguration de GPIO ",
"ERR_CONF_GPIO":"Erreur de configuration de GPIO ",
"ERR_WRITE":"Erreur d'écriture ",
"ERR_READ":"Erreur de lecture ",
"PI5_WARN_MSG":"<b>ATTENTION!</b><br><br>Les cartes RemotePi n'ont pas été développées pour le Raspberry Pi 5. Les besoins en énergie des systèmes basés sur le Pi 5 peuvent dépasser ce que la carte RemotePi peut supporter et éventuellement l'endommager.",
"REBOOT_MSG":"Un redémarrage est nécéssaire pour prendre en charge les nouveaux réglages",
"NO_CHANGES":"Aucune modification à enregistrer.",
"PLUGIN_CONFIGURATION":"Configuration de RemotePi",
Expand Down
85 changes: 56 additions & 29 deletions remotepi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const libQ = require('kew');
const fs = require('fs-extra');
const { exec } = require('child_process');
const path = require('path');
const os = require('os');
const { Gpio } = require('onoff');
Expand Down Expand Up @@ -37,7 +38,7 @@ remotepi.prototype.onVolumioShutdown = function () {
try {
if (!hwShutdown) {
self.logger.info(self.pluginName + ': Shutdown initiated by UI');
// Execute shutdown signal sequence on GPIO15 respectively GPIO473 on Pi 5
// Execute shutdown signal sequence on GPIO15
initShutdown.writeSync(1);
msleep(125);
initShutdown.writeSync(0);
Expand All @@ -49,7 +50,7 @@ remotepi.prototype.onVolumioShutdown = function () {
self.logger.info(self.pluginName + ': Shutdown initiated by hardware knob or IR remote control');
}
try {
// Reconfigure GPIO14 respectively GPIO472 on Pi 5 as output with initial "high" level allowing the RemotePi
// Reconfigure GPIO14 as output with initial "high" level allowing the RemotePi
// to recognize when the shutdown process on the RasPi has been finished
shutdownCtrl.unwatchAll();
shutdownCtrl.setEdge('none');
Expand Down Expand Up @@ -99,35 +100,38 @@ remotepi.prototype.onStart = function () {
self.commandRouter.broadcastMessage('openModal', responseData);
self.config.set('pi5WarnACK', true);
}
shutdownCtrlGPIO = pi5 ? 472 : 14;
initShutdownGPIO = pi5 ? 473 : 15;
try {
// As the RemotePi signals a shutdown event (hardware knob or IR receiver) to the RasPi by setting the level
// on the pin of GPIO14 respectively GPIO472 on Pi 5 to "high" configure GPIO14 (GPIO472) as input and watch it
shutdownCtrl = new Gpio(shutdownCtrlGPIO, 'in', 'rising');
shutdownCtrl.watch((err, value) => {
if (err) {
self.logger.error(self.pluginName + ': Error watching GPIO ' + shutdownCtrlGPIO + ': ' + err);
} else if (value === 1) {
hwShutdown = true;
return self.commandRouter.shutdown();
self.getGpioOffset()
.then(gpioOffset => {
shutdownCtrlGPIO = gpioOffset + 14;
initShutdownGPIO = gpioOffset + 15;
try {
// As the RemotePi signals a shutdown event (hardware knob or IR receiver) to the RasPi by setting the level
// on the pin of GPIO14 to "high" configure GPIO14 as input and watch it
shutdownCtrl = new Gpio(shutdownCtrlGPIO, 'in', 'rising');
shutdownCtrl.watch((err, value) => {
if (err) {
self.logger.error(self.pluginName + ': Error watching GPIO ' + shutdownCtrlGPIO + ': ' + err);
} else if (value === 1) {
hwShutdown = true;
return self.commandRouter.shutdown();
}
});
} catch (e) {
self.logger.error(self.pluginName + ': Error configuring GPIO ' + shutdownCtrlGPIO + ': ' + e);
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('REMOTEPI.PLUGIN_NAME'), self.commandRouter.getI18nString('REMOTEPI.ERR_CONF_GPIO') + shutdownCtrlGPIO + ': ' + e);
throw new Error();
}
try {
initShutdown = new Gpio(initShutdownGPIO, 'out');
} catch (e) {
shutdownCtrl.unexport();
self.logger.error(self.pluginName + ': Error configuring GPIO ' + initShutdownGPIO + ': ' + e);
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('REMOTEPI.PLUGIN_NAME'), self.commandRouter.getI18nString('REMOTEPI.ERR_CONF_GPIO') + initShutdownGPIO + ': ' + e);
throw new Error();
}
self.modBootConfig(self.config.get('gpio_configuration') ? self.config.get('enable_gpio17') : '');
defer.resolve();
});
} catch (e) {
self.logger.error(self.pluginName + ': Error configuring GPIO ' + shutdownCtrlGPIO + ': ' + e);
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('REMOTEPI.PLUGIN_NAME'), self.commandRouter.getI18nString('REMOTEPI.ERR_CONF_GPIO') + shutdownCtrlGPIO + ': ' + e);
throw new Error();
}
try {
initShutdown = new Gpio(initShutdownGPIO, 'out');
} catch (e) {
shutdownCtrl.unexport();
self.logger.error(self.pluginName + ': Error configuring GPIO ' + initShutdownGPIO + ': ' + e);
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('REMOTEPI.PLUGIN_NAME'), self.commandRouter.getI18nString('REMOTEPI.ERR_CONF_GPIO') + initShutdownGPIO + ': ' + e);
throw new Error();
}
self.modBootConfig(self.config.get('gpio_configuration') ? self.config.get('enable_gpio17') : '');
defer.resolve();
})
.fail(() => defer.reject());
return defer.promise;
Expand Down Expand Up @@ -240,6 +244,29 @@ remotepi.prototype.detectPi5 = function () {
return defer.promise;
};

remotepi.prototype.getGpioOffset = function () {
const self = this;
const defer = libQ.defer();

exec('/usr/bin/sudo /bin/chmod o+rx /sys/kernel/debug', { uid: 1000, gid: 1000 }, (error, stdout, stderr) => {
if (error !== null) {
self.logger.error(self.pluginName + ': Error setting file permissions for /sys/kernel/debug: ' + error);
defer.reject(error);
} else {
fs.readFile('/sys/kernel/debug/gpio', 'utf8', (err, data) => {
if (err !== null) {
self.logger.info(self.pluginName + ': GPIO offset cannot be determined: ' + err);
defer.reject(err);
} else {
data = parseInt(data.match(/^\sgpio-\d+\s+\(ID_SD/m)[0].split(/gpio-/)[1].split(/\s+\(ID_SD/)[0]);
defer.resolve(data);
}
});
}
});
return defer.promise;
};

remotepi.prototype.modBootConfig = function (gpio17) {
const self = this;
const defer = libQ.defer();
Expand Down
2 changes: 1 addition & 1 deletion remotepi/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ apt-get update || { echo "Running apt-get update failed"; exit 3; }
apt-get -y install build-essential || { echo "Installing build-essential failed"; exit 3; }

echo "Installing module \"onoff\""
npm install --prefix "$PLUGIN_DIR" onoff@^6.0.0 || { echo "Installing module \"onoff\" failed"; exit 3; }
sudo -u volumio npm install --prefix "$PLUGIN_DIR" onoff@^6.0.0 || { echo "Installing module \"onoff\" failed"; exit 3; }
4 changes: 2 additions & 2 deletions remotepi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remotepi",
"version": "3.2.1",
"version": "3.2.2",
"description": "The plugin enables support for RemotePi boards.",
"main": "index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"buster"
],
"details": "The plugin enables support for RemotePi boards for Raspberry Pi 4, Pi 3 B+, Pi 3, Pi 2, B+ and B.<br><br>With the plugin the RemotePi board will manage cutting the power after Volumio has been shut down via the GUI or the RemotePi board's hardware knob has been pressed or a infrared power off signal (learned-in to the RemotePi board) has been received.",
"changelog": "Fixed incorrect line feed handling when modifying \"/boot/userconfig.txt\"; added Pi5 detection and warning"
"changelog": "Prepare gpio number handling for kernel 6.6+"
},
"engines": {
"node": ">=8",
Expand Down