mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Communication entre Blender et Qt5 (point d'étape)
This commit is contained in:
parent
9dba4ac24e
commit
af09b80de2
@ -86,6 +86,7 @@ def init(cont):
|
|||||||
scene.objects['Recepteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()"
|
scene.objects['Recepteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()"
|
||||||
|
|
||||||
system_init() # Initialisation du système
|
system_init() # Initialisation du système
|
||||||
|
scene.objects['System']['plot_proc'] = None # Initialisation du processus plot
|
||||||
|
|
||||||
def get_pin_config():
|
def get_pin_config():
|
||||||
return pin_config
|
return pin_config
|
||||||
|
@ -51,11 +51,12 @@ def commandes():
|
|||||||
# mot_f(False)
|
# mot_f(False)
|
||||||
# gyr(False)
|
# gyr(False)
|
||||||
|
|
||||||
# Ecrire votre code ici ...
|
plot(['Led'])
|
||||||
gyr(True) # Activer le gyrophare
|
|
||||||
plot()
|
|
||||||
while True:
|
while True:
|
||||||
pass
|
gyr(True)
|
||||||
|
tempo(0.25)
|
||||||
|
gyr(False)
|
||||||
|
tempo(0.25)
|
||||||
|
|
||||||
fin() # A garder
|
fin() # A garder
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ def stop():
|
|||||||
if scene.objects['System']['twins']:
|
if scene.objects['System']['twins']:
|
||||||
serial_close(scene.objects['System']['board'])
|
serial_close(scene.objects['System']['board'])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
scene.objects['System']['plot']=False
|
scene.objects['System']['plot_draw']=False
|
||||||
thread_cmd_stop()
|
thread_cmd_stop()
|
||||||
|
|
||||||
# Fin naturelle
|
# Fin naturelle
|
||||||
@ -114,7 +114,7 @@ def end():
|
|||||||
if scene.objects['System']['twins']:
|
if scene.objects['System']['twins']:
|
||||||
serial_close(scene.objects['System']['board'])
|
serial_close(scene.objects['System']['board'])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
scene.objects['System']['plot']=False
|
scene.objects['System']['plot_draw']=False
|
||||||
thread_cmd_end()
|
thread_cmd_end()
|
||||||
|
|
||||||
def fin():
|
def fin():
|
||||||
@ -128,18 +128,52 @@ def quit():
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Lancement du grapheur
|
# Lancement du grapheur
|
||||||
def plot():
|
def plot(data):
|
||||||
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
|
# subprocess.run([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], , stdin=subprocess.PIPE) # Process bloquant
|
||||||
|
|
||||||
|
# Terminer le processus précédent
|
||||||
|
if scene.objects['System']['plot_proc'] is not None:
|
||||||
|
if scene.objects['System']['plot_proc'].poll()==None:
|
||||||
|
scene.objects['System']['plot_proc'].terminate()
|
||||||
|
scene.objects['System']['plot_draw'] = True
|
||||||
|
scene.objects['System']['plot_time'] = 0
|
||||||
|
scene.objects['System']['plot_data'] = data # FIXME : conversion mémonique -> 3D
|
||||||
scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], stdin=subprocess.PIPE, encoding = 'utf8')
|
scene.objects['System']['plot_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "twin_plot.py")], stdin=subprocess.PIPE, encoding = 'utf8')
|
||||||
scene.objects['System']['plot']=True
|
scene.objects['System']['plot']=True
|
||||||
|
|
||||||
# Envoi des données (Pipe)
|
# Communication avec Qt5
|
||||||
def plot_maj(cont):
|
def plot_maj(cont):
|
||||||
if cont.sensors['Plot'].positive :
|
if cont.sensors['Plot'].positive :
|
||||||
time_send = str(scene.objects['System']['plot_time'])+'\n'
|
|
||||||
if scene.objects['System']['plot_proc'].poll()==None:
|
# Affichage du graphique
|
||||||
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Bloquant
|
if scene.objects['System']['plot_draw']:
|
||||||
scene.objects['System']['plot_proc'].stdin.write(time_send)
|
|
||||||
else:
|
# Préparation du message
|
||||||
print ("Stop")
|
# FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real')
|
||||||
scene.objects['System']['plot']=False
|
msg=str(scene.objects['System']['plot_time'])
|
||||||
|
for obj in scene.objects['System']['plot_data']:
|
||||||
|
if scene.objects[obj]['activated']:
|
||||||
|
msg = msg+",1"
|
||||||
|
else:
|
||||||
|
msg = msg+",0"
|
||||||
|
msg = msg+"\n"
|
||||||
|
|
||||||
|
# Envoi (Pipe)
|
||||||
|
if scene.objects['System']['plot_proc'].poll()==None:
|
||||||
|
# scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Communication bloquante
|
||||||
|
scene.objects['System']['plot_proc'].stdin.write(msg)
|
||||||
|
else:
|
||||||
|
print ("Stop")
|
||||||
|
scene.objects['System']['plot']=False
|
||||||
|
scene.objects['System']['plot_draw'] =False
|
||||||
|
scene.objects['System']['plot_proc'].terminate()
|
||||||
|
|
||||||
|
# Arret de l'affichage du graphique
|
||||||
|
else :
|
||||||
|
if scene.objects['System']['plot_proc'].poll()==None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print ("Stop")
|
||||||
|
scene.objects['System']['plot']=False
|
||||||
|
scene.objects['System']['plot_draw'] =False
|
||||||
|
scene.objects['System']['plot_proc'].terminate()
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user