2022-06-27, 11:31
Dear all,
I in the process of modifying fairly old radios (40s…50s) to Kodi players. I try to use the old switches for control of Kodi. The current radio has a four position switch which I use for the selection of three radio stations via the Radio plugin and my music collection. The reading of the switch and switching of the programs is done via the autoexec.py
What I see is, that Kodi crashes when I urn the switch to fast. What I’m looking for is a method by which I can determine if the running switch is completed (addon loaded and running) and it is save to switch again. For the time being I try to block switch through timeouts. Here is the code of my autoexec.py:
Any help on this?
I in the process of modifying fairly old radios (40s…50s) to Kodi players. I try to use the old switches for control of Kodi. The current radio has a four position switch which I use for the selection of three radio stations via the Radio plugin and my music collection. The reading of the switch and switching of the programs is done via the autoexec.py
What I see is, that Kodi crashes when I urn the switch to fast. What I’m looking for is a method by which I can determine if the running switch is completed (addon loaded and running) and it is save to switch again. For the time being I try to block switch through timeouts. Here is the code of my autoexec.py:
python:#!/usr/bin/python
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import xbmc
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
LED = 22 #GPIO used for LED
SEL0 = 27 #Selector bit 0
SEL1 = 17 #Selector bit 1
#Selector
PreSelect = 99
Select = 0
SelBit0 = 0
SelBit1 = 0
#Zeitsperre
SinceLastSwitch = 0
# Set up GPIO 22 and turn LED off
GPIO.setup(LED, GPIO.OUT, initial=GPIO.LOW)
# Set up GPIO 27, 17 as input for selector
GPIO.setup(SEL0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SEL1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def WaitUntilRunning():
while (xbmc.getCondVisibility('Window.IsActive(notification)') == True):
#while (xbmc.Player().isPlaying() == False):
time.sleep(0.1)
def WaitUntilStopped():
while (xbmc.Player().isPlaying() == True):
time.sleep(0.1)
def LightSwitchLED():
StartAt = time.time()
Runtime = 5
NowIs = time.time()
GPIO.output(LED, GPIO.HIGH)
while ((NowIs - StartAt) < RunTime):
NowIs = time.time()
time.sleep(0.1)
GPIO.output(LED, GPIO.LOW)
def SwitchToAddon(TargetAddon, TargetNumber):
TargetString = 'Select = ' + TargetNumber + ' -- Ups!'
try:
xbmc.executebuiltin("PlayerControl(Stop)")
WaitUntilStopped()
xbmc.executebuiltin(TargetAddon)
WaitUntilRunning()
except:
xbmc.executebuiltin('Notification(%s, %s, %d)'%(TargetString, 'von ottO', 2000))
while True:
time.sleep(0.2)
Select = (GPIO.input(SEL1) * 2) + GPIO.input(SEL0)
if (Select != PreSelect):
if (SinceLastSwitch < time.time()):
PreSelect = Select
SinceLastSwitch = time.time() + 15 # Timeout für nächsten Switch
if (Select == 0):
SwitchToAddon("PlayMedia(/storage/.kodi/userdata/playlists/music/AlleMucke.m3u)", "0")
xbmc.executebuiltin("PlayerControl(RandomOn)")
elif (Select == 1):
SwitchToAddon("PlayMedia(plugin://plugin.audio.radio_de/station/2976)", "1")
elif (Select == 2):
SwitchToAddon("PlayMedia(plugin://plugin.audio.radio_de/station/2263)", "2")
elif (Select == 3):
SwitchToAddon("PlayMedia(plugin://plugin.audio.radio_de/station/1521)", "3")
else:
xbmc.executebuiltin('Notification(%s, %s, %d)'%('Select falsch - Ups!', 'von ottO', 2000))
else:
xbmc.executebuiltin('Notification(%s, %s, %d)'%('Nicht so schnell, Isabel!', 'von ottO', 1000))
time.sleep(1)
Any help on this?