• Benvenuti su RaspberryItaly!
Benvenuto ospite! Login Login con Facebook Registrati Login with Facebook


Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5

[-]
Tags
script avvio dei all avviare filmati

avviare script all'avvio dei filmati
#1
ciao,

ho questi 2 script Python (estensione .py) che mi azionano un relè 

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
ch25 = 25
GPIO.setup(ch25, GPIO.OUT)
GPIO.output(ch25, False)
print "set pin low"

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
ch25 = 25
GPIO.setup(ch25, GPIO.OUT)
GPIO.output(ch25, True)
print "Set pin High"

qualcuno saprebbe dirmi come posso far si che vengano richiamati quando avvio/fermo i video?
lo scopo è spegnere le luci nella stanza e dar tensione al circuito per l'Ambilight su Openelec

Grazie
Risposta
#2
mmm a naso direi che conviene (non so come si faccia ma è un indizio) controllare i pid in esecuzione per cercare quello del player che ti fa vedere il video.

quando lo trova imposta il pin in "low", viceversa quando non lo vede.



Coltiva linux, che windows si pianta da solo! (cit.)
Risposta
#3
Ci sono quasi...
diciamo che così funziona a metà, cioè quando il video si avvia il gpio 25 passa da 0 a 1
ma ci sono perennemente messaggi che mi indicano cosa sta facendo lo script
ammetto che ho fatto un bricolage di codici trovati in giro magari qualcuno riesce a mettermi un po' a posto lo script

grazie
Codice:
import xbmc
import xbmcgui
import subprocess
import os
import time

# at XBMC boot, set the pin low, which turns on the relay
xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_low.py')
xbmc.executebuiltin('Notification(Play Indicator script started...,,5000,/script.hellow.world.png)')
pin_state = 0
r_sleep_min = 10 #minutes after playback has ended that the GPIO pin changes state
lastcheck = time.time() # get the XBMC current time

while(1):
 xbmc.executebuiltin('Notification(While Loop started...,,1000,/script.hellow.world.png)')
 i_time = xbmc.getGlobalIdleTime()   #get user idle time - Returns the elapsed XBMC user idle time in seconds as an integer.
 r_sleep = r_sleep_min * 60 #convert sec to minutes
 
 if (i_time < r_sleep):
   xbmc.executebuiltin('Notification(Idle State running, Check for isPlaying...,5000,/script.hellow.world.png)')
   #xbmc.sleep(5000)
   if (xbmc.Player().isPlaying() == 1):
       xbmc.executebuiltin('Notification(Idle State and pin was high but media playing...,setting pin Low,5000,/script.hellow.world.png)')
       xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_low.py')
       pin_state = 0
       #xbmc.sleep(5000)

   elif ((time.time() - lastcheck) > r_sleep):
     if (pin_state == 1):
       pass # Do nothing, pin is high and Relay is off
     else:
       xbmc.executebuiltin('Notification(Idle and Nothing Playing, Setting Pin High,5000,/script.hellow.world.png)')
       xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_high.py')
       pin_state = 1

 xbmc.sleep(5000) #5 sec check intervals
Risposta
#4
se non ricordo male la sintassi...

Codice:
python programma.py > /dev/null &

in pratica (se ho scritto bene) l'output del terminale viene scritto nel nulla (/dev/null)
il & è per farlo andare in background



Coltiva linux, che windows si pianta da solo! (cit.)
Risposta
#5
scusa non ho capito, devo avviare lo script da linea di comando?
perchè ora parte all'avvio di Openelec

si chiama autoexec.py e si trova in /storage/.kodi/userdata
Risposta
#6
allora devi cercare qualcuno che ti levi le notifiche dallo script.
non so come si faccia, mi spiace, ma vedo un po' di "notification", sicuramente sono quelli.



Coltiva linux, che windows si pianta da solo! (cit.)
Risposta
#7
Shocked 
Funziona!!!

ho fatto qualche modifica qua e là e adesso funziona!!!!
per nascondere i messaggi a schermo basta mettere un cancelletto all'inizio della riga 

di seguito lo script funzionante se a qualcuno un giorno servisse Wink

Codice:
import xbmc
import xbmcgui
import subprocess
import os
import time

# at XBMC boot, set the pin low, which turns on the relay
xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_high.py')
xbmc.executebuiltin('Notification(Play Indicator script started...,,5000,/script.hellow.world.png)')
pin_state = 0
r_sleep_min = 0 #minutes after playback has ended that the GPIO pin changes state
lastcheck = time.time() # get the XBMC current time

while(1):
 #xbmc.executebuiltin('Notification(While Loop started...,,1000,/script.hellow.world.png)')
 i_time = xbmc.getGlobalIdleTime()   #get user idle time - Returns the elapsed XBMC user idle time in seconds as an integer.
 r_sleep = r_sleep_min * 60 #convert sec to minutes
 
 if ((time.time() - lastcheck) > r_sleep):
   #xbmc.executebuiltin('Notification(Idle State running, Check for isPlaying...,5000,/script.hellow.world.png)')
   #xbmc.sleep(5000)
   if (xbmc.Player().isPlaying() == 1):
       #xbmc.executebuiltin('Notification(Idle State and pin was high but media playing...,setting pin Low,5000,/script.hellow.world.png)')
       xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_low.py')
       pin_state = 0
       #xbmc.sleep(5000)

   elif ((time.time() - lastcheck) > r_sleep):
     if (pin_state == 1):
       pass # Do nothing, pin is high and Relay is off
     else:
       #xbmc.executebuiltin('Notification(Idle and Nothing Playing, Setting Pin High,5000,/script.hellow.world.png)')
       xbmc.executescript('special://home/userdata/scripts/GPIO_setpin_high.py')
       pin_state = 1

 xbmc.sleep(5000) #5 sec check intervals
Risposta
#8
Ottimo! Smile

Inviato con Tapatalk col mio Honor4X



Coltiva linux, che windows si pianta da solo! (cit.)
Risposta
  


Vai al forum:


Navigazione: 1 Ospite(i)
Forum con nuovi Post
Forum senza nuovi post
Forum bloccato
Forum Redirect