diff --git a/recipes/computercontroller/script.py b/recipes/computercontroller/script.py index 97e774ba..1191df5a 100644 --- a/recipes/computercontroller/script.py +++ b/recipes/computercontroller/script.py @@ -10,36 +10,44 @@ arch = java.lang.System.getProperty('sun.arch.data.model').lower() def shutdown(): - if(system=="Windows 7"): + if((system=="Windows 7") or (system=="Windows 8")): # shutdown pc returncode = subprocess.call("shutdown -s -f -t 0", shell=True) elif(system=="Mac OS X"): # sleep osx # nodel process must have sudo rights to shutdown command returncode = subprocess.call("sudo shutdown -h now", shell=True) + else: + print 'unknown system: ' + system def mute(): - if(system=="Windows 7"): + if((system=="Windows 7") or (system=="Windows 8")): returncode = subprocess.call("nircmd"+arch+".exe mutesysvolume 1", shell=True) elif(system=="Mac OS X"): returncode = subprocess.call("osascript -e 'set volume output muted true'", shell=True) + else: + print 'unknown system: ' + system def unmute(): - if(system=="Windows 7"): + if((system=="Windows 7") or (system=="Windows 8")): returncode = subprocess.call("nircmd"+arch+".exe mutesysvolume 0", shell=True) print returncode elif(system=="Mac OS X"): returncode = subprocess.call("osascript -e 'set volume output muted false'", shell=True) + else: + print 'unknown system: ' + system def set_volume(vol): - if(system=="Windows 7"): + if((system=="Windows 7") or (system=="Windows 8")): winvol = (65535/100)*vol returncode = subprocess.call("nircmd"+arch+".exe setsysvolume "+str(winvol), shell=True) elif(system=="Mac OS X"): returncode = subprocess.call("osascript -e 'set volume output volume "+str(vol)+"'", shell=True) # raspberry pi volume: "amixer cset numid=1 -- 20%" # returncode = subprocess.call("amixer cset numid=1 -- "+str(vol)+"%", shell=True) - + else: + print 'unknown system: ' + system + # Local actions this Node provides def local_action_TurnOff(arg = None): """{"title":"Turn off","desc":"Turns this computer off.","group":"Power"}""" diff --git a/recipes/raspberrypi/script.py b/recipes/raspberrypi/script.py new file mode 100644 index 00000000..5e4d5c88 --- /dev/null +++ b/recipes/raspberrypi/script.py @@ -0,0 +1,43 @@ +# Copyright (c) 2014Museum Victoria +# This software is released under the MIT license (see license.txt for details) + +'''This node provides raspberry pi controls.''' + +import subprocess + +def shutdown(): + returncode = subprocess.call("sudo shutdown -h now", shell=True) + +def mute(): + returncode = subprocess.call("sudo amixer cset numid=2 0", shell=True) + +def unmute(): + returncode = subprocess.call("sudo amixer cset numid=2 1", shell=True) + +def set_volume(vol): + returncode = subprocess.call("sudo amixer cset numid=1 "+str(vol)+"%", shell=True) + +# Local actions this Node provides +def local_action_TurnOff(arg = None): + """{"title":"Turn off","desc":"Turns this computer off.","group":"Power"}""" + print 'Action TurnOff requested' + shutdown() + +def local_action_mute(arg = None): + """{"title":"Mute","desc":"Mute this computer.","group":"Volume"}""" + print 'Action Mute requested' + mute() + +def local_action_unmute(arg = None): + """{"title":"Unmute","desc":"Un-mute this computer.","group":"Volume"}""" + print 'Action Unmute requested' + unmute() + +def local_action_SetVolume(arg = None): + """{"title":"Set volume","desc":"Set volume.","schema":{"title":"Level","type":"integer","required":"true"},"group":"Volume"}""" + print 'Action SetVolume requested - '+str(arg) + set_volume(arg) + +def main(arg = None): + # Start your script here. + print 'Nodel script started.'