Fixup PiSRF node for latest Bookworm

to close #1078
This commit is contained in:
Dave Conway-Jones 2024-08-11 22:00:36 +01:00
parent 900339e2ba
commit df6eae9ee9
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643
5 changed files with 45 additions and 21 deletions

View File

@ -1,7 +1,8 @@
#!/bin/bash
python_cmd='python3'
# Fallback to Python 2, if Python 3 is not available
command -v python3 > /dev/null || python_cmd='python'
BASEDIR=$(dirname $0)
exec $python_cmd -u $BASEDIR/nrsrf.py $@
$python_cmd -u $BASEDIR/nrsrf.py $@

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pisrf",
"version" : "0.3.0",
"version" : "0.4.0",
"description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder",
"dependencies" : {
},
@ -18,7 +18,7 @@
},
"author": {
"name": "Dave Conway-Jones",
"email": "ceejay@vnet.ibm.com",
"email": "dceejay@gmail.com",
"url": "http://nodered.org"
}
}

View File

@ -1,33 +1,41 @@
module.exports = function(RED) {
"use strict";
var util = require("util");
var spawn = require('child_process').spawn;
var fs = require('fs');
var execSync = require('child_process').execSync;
//var fs = require('fs');
var testCommand = __dirname + '/testgpio';
var gpioCommand = __dirname + '/nrsrf';
var allOK = true;
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1 && cpuinfo.indexOf(": Raspberry Pi") === -1) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio") && !fs.existsSync("/usr/share/doc/python3-rpi.gpio")) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
allOK = false;
}
}
catch(err) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
execSync(testCommand);
} catch(err) {
allOK = false;
RED.log.warn("rpi-srf : "+RED._("rpi-gpio.errors.ignorenode"));
}
// try {
// var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
// if (cpuinfo.indexOf(": Raspberry Pi") === -1) {
// RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
// allOK = false;
// }
// else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio") && !fs.existsSync("/usr/share/doc/python3-rpi.gpio")) {
// RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
// allOK = false;
// }
// else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
// RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
// allOK = false;
// }
// }
// catch(err) {
// RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
// allOK = false;
// }
function PiSrfNode(n) {
RED.nodes.createNode(this, n);
this.topic = n.topic;
@ -83,6 +91,7 @@ module.exports = function(RED) {
node.on("close", function(done) {
if (node.child != null) {
node.child.kill('SIGKILL');
setTimeout(function() { if (done) { done(); } }, 50);
}
wfi(done);
});

8
hardware/PiSrf/testgpio Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
python_cmd='python3'
# Fallback to Python 2, if Python 3 is not available
command -v python3 > /dev/null || python_cmd='python'
BASEDIR=$(dirname $0)
$python_cmd -u $BASEDIR/testgpio.py $@

6
hardware/PiSrf/testgpio.py Executable file
View File

@ -0,0 +1,6 @@
import sys
try:
import RPi.GPIO as GPIO
sys.exit(0)
except ImportError:
sys.exit(1)