2017-01-19 14:43:08 +01:00
|
|
|
from ivy.std_api import IvyBindMsg, IvySendMsg, IvyMainLoop
|
|
|
|
|
2017-01-19 15:14:44 +01:00
|
|
|
from LibCommon import myIvy
|
2017-01-19 14:43:08 +01:00
|
|
|
from threading import Timer
|
|
|
|
|
|
|
|
|
|
|
|
class automate:
|
|
|
|
list_color = {'rouge': 'red', 'bleu': 'blue', 'vert': 'green', 'jaune': 'yellow'}
|
|
|
|
state = 0
|
|
|
|
timer = None
|
|
|
|
|
|
|
|
def __init__(self):
|
2017-01-19 11:51:42 +01:00
|
|
|
self.timer = None
|
2017-01-19 14:43:08 +01:00
|
|
|
self.form = None
|
|
|
|
self.xy = None
|
|
|
|
self.color = None
|
|
|
|
|
|
|
|
def new_geste(self, agent, *larg):
|
2017-01-19 11:51:42 +01:00
|
|
|
print("new_geste " + str(larg))
|
|
|
|
print("state = " + str(self.state))
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 14:43:08 +01:00
|
|
|
if self.state == 0:
|
|
|
|
self.__reinit_timer()
|
|
|
|
self.form = larg[0]
|
|
|
|
self.state = 1
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 11:51:42 +01:00
|
|
|
print("endstate = " + str(self.state))
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
def new_click(self, agent, *larg):
|
2017-01-19 11:51:42 +01:00
|
|
|
print("new click " + str(larg))
|
|
|
|
print("state = " + str(self.state))
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 14:43:08 +01:00
|
|
|
if self.state == 1:
|
|
|
|
self.__reinit_timer()
|
|
|
|
self.xy = (larg[0], larg[1])
|
|
|
|
self.state = 2
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 14:43:08 +01:00
|
|
|
elif self.state == 3:
|
|
|
|
self.__reinit_timer()
|
|
|
|
self.xy = (larg[0], larg[1])
|
|
|
|
self.state = 1
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 11:51:42 +01:00
|
|
|
print("endstate = " + str(self.state))
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
def new_vocal_couleur(self, agent, *larg):
|
2017-01-19 11:51:42 +01:00
|
|
|
print("new vocal couleur " + str(larg))
|
|
|
|
print("state = " + str(self.state))
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 11:51:42 +01:00
|
|
|
if self.state == 1 and larg[0].split(" ")[0] in self.list_color and int(larg[0].split(",")[1][0:2]) > 85:
|
|
|
|
print(larg[0].split(" ")[0])
|
2017-01-19 14:43:08 +01:00
|
|
|
self.__reinit_timer()
|
2017-01-19 11:51:42 +01:00
|
|
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
2017-01-19 14:43:08 +01:00
|
|
|
self.state = 3
|
2017-01-19 12:17:59 +01:00
|
|
|
|
2017-01-19 14:43:08 +01:00
|
|
|
elif self.state == 2:
|
|
|
|
self.__reinit_timer()
|
|
|
|
self.color = larg[0]
|
|
|
|
self.state = 1
|
2017-01-19 11:51:42 +01:00
|
|
|
print("endstate = " + str(self.state))
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
def new_vocal_action(self, agent, *larg):
|
2017-01-19 11:51:42 +01:00
|
|
|
print("new vocal action" + str(larg))
|
|
|
|
print("state = " + str(self.state))
|
|
|
|
if self.state == 1 and larg[0].split(" ")[0] == "ici":
|
2017-01-19 14:43:08 +01:00
|
|
|
self.__reinit_timer()
|
|
|
|
self.__maybe_send_create()
|
|
|
|
self.state = 1
|
2017-01-19 11:51:42 +01:00
|
|
|
print("endstate = " + str(self.state))
|
|
|
|
|
|
|
|
def all(self, agent, *larg):
|
|
|
|
print("all " + str(larg))
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
def timeout(self):
|
|
|
|
if self.state == 1:
|
|
|
|
self.state = 0
|
|
|
|
if self.state in [1, 2]:
|
|
|
|
self.state = 1
|
|
|
|
|
|
|
|
def __reinit_timer(self):
|
2017-01-19 11:51:42 +01:00
|
|
|
pass
|
|
|
|
"""if self.timer:
|
|
|
|
self.timer.cancel()
|
|
|
|
self.timer = Timer(5, self.timeout)
|
|
|
|
self.timer.start()"""
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
def __maybe_send_create(self):
|
|
|
|
if None not in [self.form, self.xy, self.color]:
|
2017-01-19 11:51:42 +01:00
|
|
|
print("Send Forme")
|
2017-01-19 14:43:08 +01:00
|
|
|
IvySendMsg("MULTIMODAL forme={} x={} y={} couleur={}".format(self.form, self.xy[0], self.xy[1], self.color))
|
|
|
|
self.xy = None
|
|
|
|
self.color = None
|
|
|
|
|
|
|
|
|
|
|
|
class MyIvyMultiModale(myIvy.MyIvy):
|
|
|
|
a = automate()
|
|
|
|
|
|
|
|
def _createbind(self):
|
2017-01-19 11:51:42 +01:00
|
|
|
IvyBindMsg(self.a.all, '(.*)')
|
|
|
|
IvyBindMsg(self.a.new_geste, '^Geste forme=(.*)')
|
2017-01-19 14:43:08 +01:00
|
|
|
IvyBindMsg(self.a.new_click, '^PALETTE x=(.*) y=(.*)')
|
2017-01-19 11:51:42 +01:00
|
|
|
IvyBindMsg(self.a.new_vocal_couleur, '^sra5 Parsed=VOCAL couleur=(.*)')
|
|
|
|
IvyBindMsg(self.a.new_vocal_action, '^sra5 Parsed=VOCAL action=(.*)')
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
|
2017-01-19 15:14:44 +01:00
|
|
|
MyIvyMultiModale("MultiModal", "127.255.255.255:2010")
|
2017-01-19 14:43:08 +01:00
|
|
|
|
|
|
|
IvyMainLoop()
|