OK, I've uploaded a zip file of the add-on to my box account -
here.
You should be able to install it simply by downloading and then using "install from zip file" in Kodi and then pointing it at the downloaded file. It's very rough-and-ready as I only wrote it for my own usage, so haven't bothered to make it pretty or fancy.
Anyway it's set up as a services add-on, so should run at Kodi start-up by default. Hardware-wise, it's set up to take the GPIO inputs on GPIO 17, 27, 22, 6, 13 and 19 (board pins 11,13,15, 31, 33, 35 respectively) although you can change that in the script. The pins are set as inputs using the internal pull-up resistors to make them high, and then the buttons pull them low to give input. Basically the associated circuitry just has one switch per input, with one side connected to the relevant GPIO pin and the other to ground. It would probably be better to use external pull-up resistors, but on the board I'm going to be using I haven't got the space to wire them up (I'm going to be using a
ProtoZero board, hence the naming). I'm also going to add an IR receiver diode to the board for a complete solution (I already use one on three jumper cable wires, this will be a more physically robust solution).
As I said before I'm very much a beginner at Python scripting so things may well not be optimised, but they do seem to work in my testing so far. If you (or anyone else) has suggestions for improvements or corrections then I'm happy to hear and learn
But hopefully it should get you started on things.
I'm not sure if you'll need the sys import and append at the start if you're using OSMC. The OpenElec add-on for RPi.GPIO does need them - maybe Sam can comment there?
Anyway the files are reproduced below. They're fairly simple, but if anything isn't clear let me know. Feel free to use them as you want, either as a basis of something more complex or as they are.
buttons.py
Code:
#!/usr/bin/python
import sys
sys.path.append('/storage/.kodi/addons/python.RPi.GPIO/lib')
import RPi.GPIO as GPIO
import xbmc
upPin = 17 # board pin 11
downPin = 27 # board pin 13
leftPin = 22 # board pin 15
rightPin = 6 # board pin 31
selectPin = 13 # board pin 33
shiftPin = 19 # board pin 35
def up_callback(channel):
if(GPIO.input(shiftPin)):
xbmc.executebuiltin("Action(Up)")
else:
xbmc.executebuiltin("Action(Back)")
def down_callback(channel):
if(GPIO.input(shiftPin)):
xbmc.executebuiltin("Action(Down)")
else:
xbmc.executebuiltin("Action(Info)")
def left_callback(channel):
if(GPIO.input(shiftPin)):
xbmc.executebuiltin("Action(Left)")
else:
xbmc.executebuiltin("Action(Stop)")
def right_callback(channel):
if(GPIO.input(shiftPin)):
xbmc.executebuiltin("Action(Right)")
else:
xbmc.executebuiltin("Action(PlayPause)")
def select_callback(channel):
if(GPIO.input(shiftPin)):
xbmc.executebuiltin("Action(Select)")
else:
xbmc.executebuiltin("Action(ContextMenu)")
class Main:
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(upPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(downPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(leftPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(rightPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(selectPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(shiftPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(upPin, GPIO.FALLING, callback=up_callback, bouncetime=300)
GPIO.add_event_detect(downPin, GPIO.FALLING, callback=down_callback, bouncetime=300)
GPIO.add_event_detect(leftPin, GPIO.FALLING, callback=left_callback, bouncetime=300)
GPIO.add_event_detect(rightPin, GPIO.FALLING, callback=right_callback, bouncetime=300)
GPIO.add_event_detect(selectPin, GPIO.FALLING, callback=select_callback, bouncetime=300)
monitor=xbmc.Monitor()
while not monitor.abortRequested():
if monitor.waitForAbort(1):
break
GPIO.cleanup([upPin,downPin,leftPin,rightPin,selectPin,shiftPin])
if (__name__ == "__main__"):
Main()
addon.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.protozero.buttons" name="Zero Buttons" version="1.0.0" provider-name="DarrenHill">
<requires>
<import addon="xbmc.python" version="2.20.0"/>
</requires>
<extension library="buttons.py" point="xbmc.service" start="login"/>
<extension point="xbmc.addon.metadata">
<summary lang="en">ProtoZero Buttons</summary>
<description lang="en">Driver script for GPIO buttons</description>
<disclaimer lang="en">This plugin requires hardware buttons connected by GPIO.</disclaimer>
<platform>all</platform>
</extension>
</addon>