Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
justparking committed May 29, 2014
2 parents 8aceb39 + 277a200 commit 94eada6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
18 changes: 13 additions & 5 deletions recipes/computercontroller/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}"""
Expand Down
43 changes: 43 additions & 0 deletions recipes/raspberrypi/script.py
Original file line number Diff line number Diff line change
@@ -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.'

0 comments on commit 94eada6

Please sign in to comment.