diff --git a/portail_coulissant/porcou.py b/portail_coulissant/porcou.py index 3ee31cc..f9f23be 100644 --- a/portail_coulissant/porcou.py +++ b/portail_coulissant/porcou.py @@ -86,6 +86,7 @@ def init(cont): scene.objects['Recepteur IR']['description']="Capteur barrage IR (absence d\"obstacle) : ir_recep()" system_init() # Initialisation du système + scene.objects['System']['plot_proc'] = None # Initialisation du processus plot def get_pin_config(): return pin_config diff --git a/portail_coulissant/porcou_cmd.py b/portail_coulissant/porcou_cmd.py index 4098cc7..53621bc 100644 --- a/portail_coulissant/porcou_cmd.py +++ b/portail_coulissant/porcou_cmd.py @@ -51,11 +51,12 @@ def commandes(): # mot_f(False) # gyr(False) - # Ecrire votre code ici ... - gyr(True) # Activer le gyrophare - plot() + plot(['Led']) while True: - pass + gyr(True) + tempo(0.25) + gyr(False) + tempo(0.25) fin() # A garder diff --git a/portail_coulissant/porcou_lib.py b/portail_coulissant/porcou_lib.py index 4017c6b..3b9721d 100644 --- a/portail_coulissant/porcou_lib.py +++ b/portail_coulissant/porcou_lib.py @@ -106,7 +106,7 @@ def stop(): if scene.objects['System']['twins']: serial_close(scene.objects['System']['board']) time.sleep(1) - scene.objects['System']['plot']=False + scene.objects['System']['plot_draw']=False thread_cmd_stop() # Fin naturelle @@ -114,7 +114,7 @@ def end(): if scene.objects['System']['twins']: serial_close(scene.objects['System']['board']) time.sleep(1) - scene.objects['System']['plot']=False + scene.objects['System']['plot_draw']=False thread_cmd_end() def fin(): @@ -128,18 +128,52 @@ def quit(): ############################################################################### # 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 + + # 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']=True -# Envoi des données (Pipe) +# Communication avec Qt5 def plot_maj(cont): if cont.sensors['Plot'].positive : - time_send = str(scene.objects['System']['plot_time'])+'\n' - if scene.objects['System']['plot_proc'].poll()==None: - # scene.objects['System']['plot_proc'].communicate(input=time_send.encode())[0] # Bloquant - scene.objects['System']['plot_proc'].stdin.write(time_send) - else: - print ("Stop") - scene.objects['System']['plot']=False + + # Affichage du graphique + if scene.objects['System']['plot_draw']: + + # Préparation du message + # FIXME : ajouter les valeurs réelles et valeurs numériques ('activated_real') + 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() diff --git a/portail_coulissant/portail_coulissant-17.blend b/portail_coulissant/portail_coulissant-17.blend index 49fcf14..ccb2ac7 100644 Binary files a/portail_coulissant/portail_coulissant-17.blend and b/portail_coulissant/portail_coulissant-17.blend differ