Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Written By kenkeiras <kenkeiras@gmail.com>
- # This program is free software. It comes without any warranty, to
- # the extent permitted by applicable law. You can redistribute it
- # and/or modify it under the terms of the Do What The Fuck You Want
- # To Public License, Version 2, as published by Sam Hocevar. See
- # http://sam.zoy.org/wtfpl/COPYING for more details.
- import sys, time, os
- from pymote import *
- # Muestra los dispositivos disponibles
- def show_devices():
- # Escanea buscando dispositivos nuevos
- nearby_devices = bluetooth.discover_devices()
- # Dispositivos encontrados
- print len(nearby_devices), "device(s) found"
- # Por cada uno encontrado
- for bdaddr in nearby_devices:
- print "-", bluetooth.lookup_name(bdaddr ), "[", bdaddr, "]"
- # Obtiene la dirección de un dispositivo
- def get_addr(name):
- address = None
- # Escanea buscando dispositivos
- nearby_devices = bluetooth.discover_devices()
- # Por cada uno encontrado
- for bdaddr in nearby_devices:
- # Y se encontró, ya está
- if (name == bluetooth.lookup_name( bdaddr )):
- address = bdaddr
- break
- return address
- # Obtiene la próxima remesa de datos
- def next_bunch(f, l):
- return f.read(l)
- tapper = 0
- # Da un poco de color con los leds
- def tapLeds(dev):
- global tapper
- dev.toogle_led(tapper)
- tapper = (tapper + 1) % 4
- if (len(sys.argv) < 3):
- print >>sys.stderr, "Uso:", sys.argv[0],"<dispositivo> <pista.wav>"
- else:
- f = open(sys.argv[2], "rb")
- print "Obteniendo dirección..."
- bdaddr = get_addr(sys.argv[1])
- if (bdaddr == None):
- print >>sys.stderr,"Dispositivo no encontrado"
- exit(1)
- else:
- print "Conectando..."
- ctrl = pymote(bdaddr)
- print "Reproduciendo..."
- # Cantidad de frames que se pueden enviar de una vez
- width = 20
- i = 0
- j = os.path.getsize(sys.argv[2])
- framerate = 1500.
- while True:
- # Se muestran los segundos reproducidos / totales
- sys.stdout.write("\r" + str(int(i / framerate)) + "/" + \
- str(int(j / framerate)))
- sys.stdout.flush()
- # Se obtienen los próximos datos
- b = next_bunch(f, width)
- if (len(b) < 1):
- break
- # Se envían
- ctrl.send_audio(b)
- # Cada segundo cambian los leds :)
- if ((i % int(framerate)) == 0 ):
- tapLeds(ctrl)
- i += width
- # Se espera a que sea el momento de envíar los próximos frames
- time.sleep(width / framerate)
- print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement