From 78ca3782ae02b467c6686fca3950be62333c3192 Mon Sep 17 00:00:00 2001 From: gvolt Date: Sun, 29 Sep 2024 22:52:26 +0200 Subject: [PATCH 1/2] RemotePi 3.2.2 --- remotepi/i18n/strings_de.json | 6 +-- remotepi/i18n/strings_en.json | 6 +-- remotepi/i18n/strings_fr.json | 6 +-- remotepi/index.js | 85 +++++++++++++++++++++++------------ remotepi/package.json | 4 +- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/remotepi/i18n/strings_de.json b/remotepi/i18n/strings_de.json index 9f8823910..e01227633 100644 --- a/remotepi/i18n/strings_de.json +++ b/remotepi/i18n/strings_de.json @@ -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":"WARNUNG!

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", diff --git a/remotepi/i18n/strings_en.json b/remotepi/i18n/strings_en.json index 8dc5aaf87..e44344660 100644 --- a/remotepi/i18n/strings_en.json +++ b/remotepi/i18n/strings_en.json @@ -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":"WARNING!

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", diff --git a/remotepi/i18n/strings_fr.json b/remotepi/i18n/strings_fr.json index 9e4defd2a..37e25cba9 100644 --- a/remotepi/i18n/strings_fr.json +++ b/remotepi/i18n/strings_fr.json @@ -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":"ATTENTION!

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", diff --git a/remotepi/index.js b/remotepi/index.js index 33c73678c..82759f254 100644 --- a/remotepi/index.js +++ b/remotepi/index.js @@ -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'); @@ -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); @@ -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'); @@ -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; @@ -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(); diff --git a/remotepi/package.json b/remotepi/package.json index 4451a3e32..8c8ff6677 100644 --- a/remotepi/package.json +++ b/remotepi/package.json @@ -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": { @@ -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.

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", From 1e348edfb8faf61ec1ce40882401cdfe32d38412 Mon Sep 17 00:00:00 2001 From: gvolt Date: Sun, 27 Oct 2024 11:45:37 +0100 Subject: [PATCH 2/2] Run npm install as user "volumio" --- remotepi/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remotepi/install.sh b/remotepi/install.sh index 0d51a6cd4..456876306 100644 --- a/remotepi/install.sh +++ b/remotepi/install.sh @@ -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; }