Created
June 14, 2012 10:28
-
-
Save jplattel/2929482 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import pusher | |
# Serial Port | |
print 'Setting up serialport' | |
s = serial.Serial('/dev/tty.Bluetooth_Bee_V2-DevB') | |
# Websocket | |
#print 'Creating Websocket' | |
#from websocket import create_connection | |
#ws = create_connection('ws://localhost:9000') | |
# Pusher services | |
print 'Setting up Pusher' | |
p = pusher.Pusher(app_id='22213', key='89ec1e5e6c8ea8499c18', secret='e17cd79f30370aefdf96') | |
# Creating history | |
c_volume = ['0'] | |
c_function = ['0'] | |
c_autobeats = ['0'] | |
while True: | |
signal = s.readline() | |
# Volume Function | |
if signal[:6] == 'volume': | |
i_volume = str(signal.split(' ')[1].replace('\r\n','')) | |
# check for changes | |
if i_volume != c_volume[-1]: | |
if int(c_volume[-1]) + 5 < int(i_volume): | |
print "Volume changed: " + i_volume | |
#ws.send('volume:' + str(i_volume)) | |
p['runlabs'].trigger('volume', {'volume': str(i_volume)}) | |
elif int(c_volume[-1]) - 5 > int(i_volume): | |
print "Volume changed: " + i_volume | |
#ws.send('volume:' + str(i_volume)) | |
p['runlabs'].trigger('volume', {'volume': str(i_volume)}) | |
else: | |
pass | |
# append to history | |
c_volume.append(i_volume) | |
# Button Function | |
elif signal[:8] == 'function': | |
i_function = str(signal.split(' ')[1].replace('\r\n','')) | |
if i_function != c_function[-1]: | |
print "Function changed: " + i_function | |
#ws.send(i_function) | |
p['runlabs'].trigger('func', {'func': str(i_function)}) | |
c_function.append(i_function) | |
# Autobeats Function | |
elif signal[:9] == 'autobeats': | |
i_autobeats = str(signal.split(' ')[1].replace('\r\n','')) | |
if i_autobeats != c_autobeats[-1]: | |
print "Autobeats: " + i_autobeats | |
#ws.send(i_autobeats) | |
p['runlabs'].trigger('autobeats', {'autobeats': str(i_autobeats)}) | |
c_autobeats.append(i_autobeats) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment