Esempio n. 1
0
def waiting(ifname):
    metro = sl_metro.Metro(0.5)
    is_waiting = True

    while is_waiting:
        if metro.update():
            if param(ifname) == False:
                print "waiting for IP"
            else:
                is_waiting = False
                print "Got ip is : ", param(ifname)
                time.sleep(3)
Esempio n. 2
0
import thread_event as tev
import event
import sl_metro

metro = sl_metro.Metro(1.0)
metro2 = sl_metro.Metro(1.0)
metro3 = sl_metro.Metro(1.5)


# Make callback functions
def foo():
    while True:
        if metro3.update():
            print "    [foo()::EVENT LOOP]:"


def bar(val1, val2):
    while True:
        if metro2.update():
            print "    [bar()::EVENT LOOP]:", val1, " , ", val2


# Connect events and callbacks
event.add("/foo", foo)
event.add("/bar", bar)

tev.bang("/foo")
tev.bang("/bar", 137, 1.38)
while True:
    if metro.update():
        print "[MAIN LOOP]"
Esempio n. 3
0
def call1(val1, val2):
    print "[Call1] args=", val1, ",", val2, "2sec"


def call2():
    print "[Call2] 4SEC", "4sec"
    timer.end()
    suicide.run()


#add the function as event
event.add("/call1", call1)
event.add("/call2", call2)

#Create Metro
metro = sl_metro.Metro(0.5)

#create timer with event name and args
timer = timer_event.Timer_event(2.0, "/call1", 137, 13.8)
timer2 = timer_event.Timer_event(
    4.0, "/call2")  #a event without argments is also ok.

#start waiting the involing the event
print "Set timer event named call1 after 2sec and call2 after 4sec."
try:
    while True:
        if metro.update():
            print "Waiting timer ..."

except KeyboardInterrupt:
    timer.end()
Esempio n. 4
0
# if you want to use this library from outside of sonilab folder, should import as follows,
# from sonilab import sl_metro, sl_osc_send, osc_receive, event
# enjoy !!

import sl_metro, sl_osc_send, osc_receive, event

metro = sl_metro.Metro(1.0)
sender = sl_osc_send.slOscSend("127.0.0.1" , 57137)
receiver = osc_receive.OscReceive(57137)


def osc_received (vals):
    print "OSC RECEIVED :: arg[0] = " + str(vals[0]) + " | arg[1] = "  + str(vals[1])

event.add("/test" , osc_received)
receiver.setup("/foo")


try :
    while True:
        if metro.update():
            print "OK"
            sender.send("/test", 137, 1.37)

except KeyboardInterrupt :
    receiver.terminate()
Esempio n. 5
0
import delay, event, sl_metro

#Finishing flag
finished = False

#metro
metro = sl_metro.Metro(0.5)
metro2 = sl_metro.Metro(3.0)


#Make call back functions for timer involing
def foo():
    global finished
    print "[Threaded event]"


def bar(*args):
    print "[is invoked. ", " with ", str(args[0]), ",", str(args[1]), ",", str(
        args[2]), "seconds delay.]"
    assert args[0] == 1
    assert args[1] == 2.0
    assert args[2] == 3.0


def bar2(val1, val2, val3):
    print "[STAY foolish.]", "::", val1, " + ", val2, "+", val3, "=", val1 + val2 + val3
    assert val1 == 1
    assert val2 == 0.3
    assert val3 == 0.07

Esempio n. 6
0
import sl_blink_pattern, sl_metro

blinker = sl_blink_pattern.SlBlinkPattern(100)
metro = sl_metro.Metro(1)

metro.set(blinker.bang())
count = 0
while True:
    if metro.update():
        print(blinker.update())
        count = count + 1
        if count > 10:
            metro.set(blinker.bang())
            count = 0

# for var in range(30):
#     if metro.update():
#         print(blinker.update())
#
# metro.set(blinker.bang())
# for var in range(30):
#     if metro.update():
#         print(blinker.update())
#
# metro.set(blinker.bang())
# for var in range(30):
#     if metro.update():
#         print(blinker.update())