Esempio n. 1
0
def main():
    print("Waiting for boot signal")
    print(s.read())
    print("Writing sway command")
    s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72])))
    print(s.read())
    # print("Reading motor encoders")
    # s.write("".join(map(chr, [0x55, 0x1, 0x12])))
    # print(["0x%.02x " % ord(x) for x in s.read(12)])
    server = OSCServer( ("192.168.123.75", 10000) )
    server.timeout = 0
    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/rotate", rotate_callback )
    server.addMsgHandler( "/bf", bf_callback )
    
    try:
        while 1:
            server.handle_request()
    except KeyboardInterrupt:
        pass


    server.close()
def main():
    global server
    
    connected = False

    while not connected:
        try:
            server = OSCServer( ("10.101.203.74", 10000) )
            server.timeout = 0
            run = True
            connected = True

        except: 
            print "OSC Server no encontrado"
            time.sleep(5)

    GPIO.setmode(GPIO.BCM)
    m = Motor([17,18,27,22])

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/base", base_move )
    server.addMsgHandler( "/altura", altura_move )

    while(True):
        each_frame()
        try:
            m.rpm = 10
            m.move_to(rotateBase)
            # m.move_to(0)

        except KeyboardInterrupt:
            GPIO.cleanup()   
            print "Saliendo..."
            exit()
Esempio n. 3
0
def main():
    print("Waiting for boot signal")
    print(s.read())
    print("Writing sway command")
    s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72]))) # equivalent to .join['U', '\x00', '\x03', '\x00', '\x02', 'H']
    # between every elements in the list, put ""
    # that will convert it as one string ''Ux00x03x00x02H''
    print(s.read())
    # print("Reading motor encoders")
    # s.write("".join(map(chr, [0x55, 0x1, 0x12])))
    # print(["0x%.02x " % ord(x) for x in s.read(12)])
    server = OSCServer( ("192.168.123.75", 10000) )
    server.timeout = 0
    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler( "/rotate", rotate_callback )
    server.addMsgHandler( "/bf", bf_callback )
    
    try:
        while 1:
            server.handle_request()
    except KeyboardInterrupt:
        pass


    server.close()
Esempio n. 4
0
def setupServer():
  global server
  server = OSCServer( (HOST_NAME, PORT_NUM) )
  server.timeout = 0
  server.handle_timeout = types.MethodType(handle_timeout, server)
  server.addMsgHandler( "/dmx", user_callback )
  print(server)
Esempio n. 5
0
def server_start(port=7110):
    global server
    server = OSCServer ( ("localhost", 7110))
    server.timeout = 0

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/sco", handle_score)
    server.addMsgHandler("/cc", handle_cc)
    server.addMsgHandler("/quit", quit_callback)
    server.addMsgHandler("default", default_callback)
Esempio n. 6
0
def server_start(port=7110):
    global server
    server = OSCServer(("localhost", 7110))
    server.timeout = 0

    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/sco", handle_score)
    server.addMsgHandler("/cc", handle_cc)
    server.addMsgHandler("/quit", quit_callback)
    server.addMsgHandler("default", default_callback)
Esempio n. 7
0
def main():

	if len(sys.argv)>1:
		OSC_ADDRESS = str(sys.argv[1])
	else:
		OSC_ADDRESS = OSC_ADDRESS_DEFAULT

	if len(sys.argv)>2:
		OSC_PORT = int(sys.argv[2])
	else:
		OSC_PORT = OSC_PORT_DEFAULT

	if len(sys.argv)>3:
		WIFI_INT = str(sys.argv[3])
	else:
		WIFI_INT = WIFI_INT_DEFAULT

	#creates directory to store sounds
	if not os.path.exists(sounddir):
		os.makedirs(sounddir)
	print("Sound directory: ",sounddir)

	#example of use of pyosc,
	#see: https://github.com/ptone/pyosc/blob/master/examples/knect-rcv.py
	#we use here the WiFi interface provided on device en0
	ipcmd = "ipconfig getifaddr %s"%WIFI_INT
	print(ipcmd)
	ipaddress = os.popen(ipcmd).read().rstrip()
	print("IP address: ",ipaddress)
	server = OSCServer((ipaddress, OSC_PORT))
	server.timeout = 0
	global run
	run = True

	print("Listening to OSC address",OSC_ADDRESS,"on port",OSC_PORT)

	#python's way to add a method to an instance of a class
	server.handle_timeout = types.MethodType(handle_timeout, server)

	server.addMsgHandler(OSC_ADDRESS, user_callback)

	#sound query engine
	try:
		while run:
			#sleep(1)
			#call user script
			each_frame(server)
	except KeyboardInterrupt: #to quit program
		print("\n")
		pass
	server.close()
Esempio n. 8
0
def frame(savePath):
    print 'getting osc'
    # funny python's way to add a method to an instance of a class
    server = OSCServer(("192.168.1.209", 12000))
    server.timeout = 0
    run = True
    server.handle_timeout = types.MethodType(handle_timeout, server)
    server.addMsgHandler("/acc", acc_callback)
    server.addMsgHandler("/e", eul_callback)
    server.addMsgHandler("/raw", raw_callback)
    while True:
        each_frame(server)
        #print 'hello'
        sleep(0.001)
    return
Esempio n. 9
0
def main(opts):
    server = OSCServer((opts.ip_addres, int(opts.port)))
    server.handle_timeout = types.MethodType(handle_timeout, server)
    server.addMsgHandler("/user", user_callback)
    server.addMsgHandler("/quit", quit_callback)
    log_post('INFO: listening on to %s:%s' % (opts.ip_addres, opts.port))
    spinner_ = spinner()
    while run:
        each_frame(server)

        sys.stdout.write(spinner_.next())
        sys.stdout.flush()
        sleep(0.5)
        sys.stdout.write('\b')

    server.close()
Esempio n. 10
0
def main(hostname="localhost",port="8000"):
    server = OSCServer((hostname, int(port)))
    server.timeout = 0
    run = True
    global message_count
    message_count = 0

    # this method of reporting timeouts only works by convention
    # that before calling handle_request() field .timed_out is 
    # set to False
    def handle_timeout(self):
        self.timed_out = True

    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    def user_callback(path, tags, args, source):
        log("%s %s\n" % (path, args))
        global message_count
        message_count += 1

    def quit_callback(path, tags, args, source):
        #global run
        run = False

    server.addMsgHandler( "default", user_callback )
    server.addMsgHandler( "/quit", quit_callback )

    # user script that's called by the game engine every frame
    def each_frame():
        log("Messages received: %s\n" % message_count)
        # clear timed_out flag
        server.timed_out = False
        # handle all pending requests then return
        while not server.timed_out:
            server.handle_request()

    # simulate a "game engine"
    print "Server running at %s:%s" % (hostname, port)
    while run:
        # do the game stuff:
        sleep(1)
        # call user script
        each_frame()

    server.close()
Esempio n. 11
0
def main(hostname="localhost", port="8000"):
    server = OSCServer((hostname, int(port)))
    server.timeout = 0
    run = True
    global message_count
    message_count = 0

    # this method of reporting timeouts only works by convention
    # that before calling handle_request() field .timed_out is
    # set to False
    def handle_timeout(self):
        self.timed_out = True

    # funny python's way to add a method to an instance of a class
    import types
    server.handle_timeout = types.MethodType(handle_timeout, server)

    def user_callback(path, tags, args, source):
        log("%s %s\n" % (path, args))
        global message_count
        message_count += 1

    def quit_callback(path, tags, args, source):
        #global run
        run = False

    server.addMsgHandler("default", user_callback)
    server.addMsgHandler("/quit", quit_callback)

    # user script that's called by the game engine every frame
    def each_frame():
        log("Messages received: %s\n" % message_count)
        # clear timed_out flag
        server.timed_out = False
        # handle all pending requests then return
        while not server.timed_out:
            server.handle_request()

    # simulate a "game engine"
    print "Server running at %s:%s" % (hostname, port)
    while run:
        # do the game stuff:
        sleep(1)
        # call user script
        each_frame()

    server.close()
Esempio n. 12
0
  print "Player started", args
  # global running
  # running = True

def remote_files_callback(path, tags, args, source):
  print "Player has these files:", args


if __name__ == "__main__":
  try:
    sys.excepthook = log_uncaught_exceptions

    notifications = OSCServer( (args.notifierip, args.notifierport) )
    notifications.timeout = 0.1
    # funny python's way to add a method to an instance of a class
    notifications.handle_timeout = types.MethodType(handle_timeout, notifications)

    # RPi.GPIO Layout verwenden (wie Pin-Nummern)
    GPIO.setmode(GPIO.BOARD)

    for _button in button_map:
      GPIO.setup(_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # PUD_DOWN, because we use a pull down resistor, use RISING in next line then!
      GPIO.add_event_detect(_button, GPIO.RISING, callback=button_press, bouncetime=args.bouncetime)

    client.connect( (args.ip, args.port) )
    notifications.addMsgHandler( "/stopped", remote_stopped_callback )
    notifications.addMsgHandler( "/playing", remote_started_callback )
    notifications.addMsgHandler( "/files", remote_files_callback )

    print "StaalPiPlayer Button Client ready!"
    print "\tListening for player with:",notifications
Esempio n. 13
0
import sys
from time import sleep

server = OSCServer( ("localhost", 5005) )
server.timeout = 0
run = True

# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True

# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)

def user_callback(path, tags, args, source):
    # which user will be determined by path:
    # we just throw away all slashes and join together what's left
    user = ''.join(path.split("/"))
    # tags will contain 'ffff'
    # args is a OSCMessage with data
    # source is where the message came from (in case you need to reply)
    print ("Now do something with ", user, args[0], args[1], args[2], args[3])

def quit_callback(path, tags, args, source):
    # don't do this at home (or it'll quit blender)
    global run
    run = False
Esempio n. 14
0
		threading.Thread.__init__(self)
		self.threadID = threadID
		self.name = name
	def run(self):
		print "Starting " + self.name
		testStrip() 

# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is 
# set to False
def handle_timeout(self):
	self.timed_out = True

# funny python's way to add a method to an instance of a class
import types
lockerServer.handle_timeout = types.MethodType(handle_timeout, lockerServer)

# recommended for auto-disabling motors on shutdown!
def turnOffSolenoid():
	locker.getMotor(1).run(Adafruit_MotorHAT.RELEASE)

def clearStrip():
	for pixel in range(totalPixels):
		strip.setPixelColor(pixel, 0x000000)
	strip.show()

def testStrip():
	while True:
		global color
		global prevColor
		time.sleep(0.001)
Esempio n. 15
0
                  'myuidw43536')

# next make an outlet
outlet = StreamOutlet(info)


# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True


# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)


def user_callback(path, tags, args, source):
    # which user will be determined by path:
    # we just throw away all slashes and join together what's left
    #print "hello"
    msg = args[0]
    print msg
    outlet.push_sample([str(msg)])


server.addMsgHandler("/OSC-Marker-Stream", user_callback)


def quit_callback(path, tags, args, source):
    def run(self):
        print "Starting " + self.name
        serialComms()


# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True


# funny python's way to add a method to an instance of a class
import types

columnServer.handle_timeout = types.MethodType(handle_timeout, columnServer)


def clearStrip():
    for pixel in range(totalPixels):
        strip.setPixelColor(pixel, 0x000000)
    strip.show()


def displayColumn():
    while True:
        global color
        global prevColor
        time.sleep(0.001)
        if prevColor != color:
            #print str(color)
def main(stdcr):

    stdscr = curses.initscr()
    stdscr.nodelay(1)

    activeLight = False
    activeVideoOn = False
    activeVideoOff = False

    lastButtonCar = 1
    sentButtonCar = 0
    timerButtonCar = 0

    connected = False

    raspberryAddress = '192.168.0.197', 7100
    milluminAddress = '192.168.1.21', 5000
    milluminAddress2 = '192.168.1.22', 5000

    while not connected:

        try:
            server = OSCServer(raspberryAddress)
            server.timeout = 0

            # Creamos el objeto "Cliente"
            client = OSCClient()
            client2 = OSCClient()

            # Realizamos la conexion
            # client.connect( milluminAddress )
            # client2.connect( milluminAddress2 )

            connected = True

        except:
            print("No se encuentra el servidor OSC. Reintentando...")
            time.sleep(5)

    # funny python's way to add a method to an instance of a class
    server.handle_timeout = types.MethodType(handle_timeout, server)

    server.addMsgHandler("/1/lightPlus", callback_lightOn)
    server.addMsgHandler("/1/lightMinus", callback_lightOff)
    server.addMsgHandler("/1/videoOn1", callback_videoOn1)
    server.addMsgHandler("/1/videoOn1eng", callback_videoOn1eng)
    server.addMsgHandler("/1/videoOn2", callback_videoOn2)
    server.addMsgHandler("/1/videoOn2eng", callback_videoOn2eng)
    server.addMsgHandler("/1/videoOn3", callback_videoOn3)
    server.addMsgHandler("/1/videoOn4", callback_videoOn4)
    server.addMsgHandler("/1/videoStop", callback_videoStop)

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.OUT)  ## GPIO 17 como salida (bajar luz)
    GPIO.setup(27, GPIO.OUT)  ## GPIO 27 como salida (subir luz)
    GPIO.setup(
        22, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  ## GPIO 23 como entrada (boton iniciar show)

    time_stamp = time.time() - 30

    # simulate a "game engine"
    while True:

        while not connected:
            try:
                server = OSCServer(raspberryAddress)
                server.timeout = 0

                # Creamos el objeto "Cliente"
                client = OSCClient()
                client2 = OSCClient()

                # Realizamos la conexion
                client.connect(milluminAddress)
                client2.connect(milluminAddress2)

                connected = True

            except:
                # print("No se encuentra el servidor OSC. Reintentando...")
                stdscr.addstr(
                    "No se encuentra el servidor OSC. Reintentando..." + ' ')
                stdscr.refresh()
                # return curser to start position
                stdscr.move(0, 0)
                time.sleep(5)

        try:
            stdscr.move(0, 0)
            c = stdscr.getch()
            if c != -1:
                # print numeric value
                stdscr.addstr(str(c) + ' ')
                stdscr.refresh()
                # return curser to start position
                stdscr.move(0, 0)

            # do the game stuff:
            if activeLight:
                GPIO.output(17, False)

            else:
                GPIO.output(17, True)

            # print GPIO.input(22)

            if (GPIO.input(22) == 0) and (lastButtonCar == 1):

                timerButtonCar = time.time()
                lastButtonCar = 0
                # print "Inicio Pulso"

            elif (GPIO.input(22) == 0) and (lastButtonCar
                                            == 0) and (not sentButtonCar):

                delta = time.time() - timerButtonCar

                if delta > 1.0:
                    msg = OSCMessage()
                    msg.setAddress("/millumin/action/launchorStopColumn")
                    msg.append(9.0)
                    #client.send(msg) # now we dont need to tell the client the address anymore
                    #client2.send(msg) # now we dont need to tell the client the address anymore
                    sentButtonCar = True
                    # print "Lanzando mapping coche"
                    stdscr.addstr("Lanzando mapping coche..." + ' ')
                    stdscr.refresh()
                    # return curser to start position
                    stdscr.move(0, 0)

            elif (GPIO.input(22) == 1) and (lastButtonCar == 0):

                timerButtonCar = time.time()
                lastButtonCar = 1
                # print "Fin pulso"

            elif (GPIO.input(22) == 1) and (lastButtonCar
                                            == 1) and (sentButtonCar):

                if (time.time() - timerButtonCar > 1.0):

                    # print "Reseteando boton de coche"
                    sentButtonCar = False

            each_frame(server)

        except KeyboardInterrupt:

            #client.close()
            #client2.close()
            server.close()
            GPIO.cleanup()
Esempio n. 18
0
    def run(self):
        print "Starting " + self.name
        testStrip()


# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
    self.timed_out = True


# funny python's way to add a method to an instance of a class
import types
lockerServer.handle_timeout = types.MethodType(handle_timeout, lockerServer)


# recommended for auto-disabling motors on shutdown!
def turnOffSolenoid():
    locker.getMotor(1).run(Adafruit_MotorHAT.RELEASE)


def clearStrip():
    for pixel in range(totalPixels):
        strip.setPixelColor(pixel, 0x000000)
    strip.show()


def testStrip():
    while True:
Esempio n. 19
0
oscserver_run = True

# Add a method `handle_timeout` to an instance of OSCServer.
#
# tThis method of reporting timeouts only works by convention
# that before calling handle_request() the field .timed_out is
# set to False.
import types


def handle_timeout(self):
    self.timed_out = True


SERVER.handle_timeout = types.MethodType(handle_timeout, SERVER)


def quit_callback(path, tags, args, source):
    global oscserver_run
    oscserver_run = False


def user_callback(path, tags, args, source):
    """
    :path: react only to /run
    :tags: ignored
    :args: OSCMessage with data.
    :source: where the message came from.
    """
    global process_run
		threading.Thread.__init__(self)
		self.threadID = threadID
		self.name = name
	def run(self):
		print "Starting " + self.name
		serialComms()

# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is 
# set to False
def handle_timeout(self):
	self.timed_out = True

# funny python's way to add a method to an instance of a class
import types
columnServer.handle_timeout = types.MethodType(handle_timeout, columnServer)

def clearStrip():
	for pixel in range(totalPixels):
		strip.setPixelColor(pixel, 0x000000)
	strip.show()

def displayColumn():
	while True:
		global color
		global prevColor
		time.sleep(0.001)
		if prevColor != color:	
			#print str(color)
			for pixel in range(totalPixels):
				strip.setPixelColor(pixel, color)	#Assign Color to pixel