From b0c8b1e83f9db2366009bc015493e4df13af4747 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 12 Feb 2016 21:27:02 +0000 Subject: [PATCH] more node-red-nodes hardware section info updates and update Pibrella to use latest nrgpio debounce thinking --- hardware/Pibrella/38-rpi-pibrella.html | 9 ++-- hardware/Pibrella/38-rpi-pibrella.js | 4 +- hardware/Pibrella/nrgpio | 1 + hardware/Pibrella/nrgpio.py | 67 +++++++++++++++++++------- hardware/Pibrella/package.json | 2 +- hardware/blink1/77-blink1.html | 2 +- hardware/blink1/package.json | 2 +- hardware/neopixel/neopixel.html | 8 +-- hardware/neopixel/package.json | 2 +- 9 files changed, 66 insertions(+), 31 deletions(-) diff --git a/hardware/Pibrella/38-rpi-pibrella.html b/hardware/Pibrella/38-rpi-pibrella.html index e6b45d19..1aeea99c 100644 --- a/hardware/Pibrella/38-rpi-pibrella.html +++ b/hardware/Pibrella/38-rpi-pibrella.html @@ -39,8 +39,8 @@ @@ -110,9 +110,10 @@ diff --git a/hardware/Pibrella/38-rpi-pibrella.js b/hardware/Pibrella/38-rpi-pibrella.js index e6122351..02677a0c 100644 --- a/hardware/Pibrella/38-rpi-pibrella.js +++ b/hardware/Pibrella/38-rpi-pibrella.js @@ -20,7 +20,7 @@ module.exports = function(RED) { var spawn = require('child_process').spawn; var fs = require('fs'); - var gpioCommand = __dirname+'/nrgpio.py'; + var gpioCommand = __dirname+'/nrgpio'; if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi //util.log("Info : Ignoring Raspberry Pibrella specific node."); @@ -90,7 +90,7 @@ module.exports = function(RED) { } if (node.pin !== undefined) { - node.child = spawn(gpioCommand, ["in",node.pin]); + node.child = spawn(gpioCommand, ["in",node.pin,"down",35]); node.running = true; node.status({fill:"green",shape:"dot",text:"OK"}); diff --git a/hardware/Pibrella/nrgpio b/hardware/Pibrella/nrgpio index 88b381a7..6a575ce6 100755 --- a/hardware/Pibrella/nrgpio +++ b/hardware/Pibrella/nrgpio @@ -1,3 +1,4 @@ +#!/bin/bash # # Copyright 2014 IBM Corp. # diff --git a/hardware/Pibrella/nrgpio.py b/hardware/Pibrella/nrgpio.py index a578283f..34a3feff 100755 --- a/hardware/Pibrella/nrgpio.py +++ b/hardware/Pibrella/nrgpio.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -# Copyright 2014 IBM Corp. +# Copyright 2014,2016 IBM Corp. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,15 +15,19 @@ # Import library functions we need import RPi.GPIO as GPIO +import struct import sys +import os +import subprocess +from time import sleep -bounce = 20 # bounce time in mS to apply +bounce = 25; if sys.version_info >= (3,0): print("Sorry - currently only configured to work with python 2.x") sys.exit(1) -if len(sys.argv) > 1: +if len(sys.argv) > 2: cmd = sys.argv[1].lower() pin = int(sys.argv[2]) GPIO.setmode(GPIO.BOARD) @@ -92,18 +96,18 @@ if len(sys.argv) > 1: elif cmd == "in": #print "Initialised pin "+str(pin)+" to IN" + bounce = int(sys.argv[4]) def handle_callback(chan): + sleep(bounce/1000) print GPIO.input(chan) - if len(sys.argv) == 4: - if sys.argv[3].lower() == "up": - GPIO.setup(pin,GPIO.IN,GPIO.PUD_UP) - elif sys.argv[3].lower() == "down": - GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN) - else: - GPIO.setup(pin,GPIO.IN) + if sys.argv[3].lower() == "up": + GPIO.setup(pin,GPIO.IN,GPIO.PUD_UP) + elif sys.argv[3].lower() == "down": + GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN) else: GPIO.setup(pin,GPIO.IN) + print GPIO.input(pin) GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce) @@ -166,12 +170,6 @@ if len(sys.argv) > 1: except: data = 0 - elif cmd == "rev": - print GPIO.RPI_REVISION - - elif cmd == "ver": - print GPIO.VERSION - elif cmd == "mouse": # catch mice button events file = open( "/dev/input/mice", "rb" ) oldbutt = 0 @@ -193,5 +191,40 @@ if len(sys.argv) > 1: file.close() sys.exit(0) + elif cmd == "kbd": # catch keyboard button events + try: + while not os.path.isdir("/dev/input/by-path"): + time.sleep(10) + infile = subprocess.check_output("ls /dev/input/by-path/ | grep -m 1 'kbd'", shell=True).strip() + infile_path = "/dev/input/by-path/" + infile + EVENT_SIZE = struct.calcsize('llHHI') + file = open(infile_path, "rb") + event = file.read(EVENT_SIZE) + while event: + (tv_sec, tv_usec, type, code, value) = struct.unpack('llHHI', event) + #if type != 0 or code != 0 or value != 0: + if type == 1: + # type,code,value + print("%u,%u" % (code, value)) + event = file.read(EVENT_SIZE) + print "0,0" + file.close() + sys.exit(0) + except: + file.close() + sys.exit(0) + +elif len(sys.argv) > 1: + cmd = sys.argv[1].lower() + if cmd == "rev": + print GPIO.RPI_REVISION + elif cmd == "ver": + print GPIO.VERSION + elif cmd == "info": + print GPIO.RPI_INFO + else: + print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}" + print " only ver (gpio version) and info (board information) accept no pin parameter." + else: - print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}" + print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}" diff --git a/hardware/Pibrella/package.json b/hardware/Pibrella/package.json index e3916a5a..3ffee2dc 100644 --- a/hardware/Pibrella/package.json +++ b/hardware/Pibrella/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-pibrella", - "version" : "0.0.9", + "version" : "0.0.10", "description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board", "dependencies" : { }, diff --git a/hardware/blink1/77-blink1.html b/hardware/blink1/77-blink1.html index af4663a1..eec5ee31 100644 --- a/hardware/blink1/77-blink1.html +++ b/hardware/blink1/77-blink1.html @@ -32,7 +32,7 @@