diff --git a/portail_coulissant/porcou_cmd.py b/portail_coulissant/porcou_cmd.py index 720c0f9..981009a 100644 --- a/portail_coulissant/porcou_cmd.py +++ b/portail_coulissant/porcou_cmd.py @@ -29,7 +29,13 @@ from porcou_lib import * # Bibliothèque portail coulissant ############################################################################### # Brochage du portail coulissant -brochage={} +carte = None +brochage={ + 'bp_ext' : 2,'bp_int' : 3, + 'fdc_o' : 4,'fdc_f' : 5, + 'mot_o' : 6,'mot_f' : 7, + 'gyr' : 8, + 'ir_emett' : 9,'ir_recept' : 10} ############################################################################### # Fonctions @@ -41,10 +47,9 @@ brochage={} def commandes(): - # Ecrire votre code ici ... - # jumeau() - gyr(True) # Activer le gyrophare - # ir_emet(True) + # jumeau(carte, brochage) + jumeau(brochage) + gyr(True) while True: pass @@ -59,4 +64,4 @@ def commandes(): if __name__=='start': thread_cmd_start(commandes) if __name__=='stop': - thread_cmd_stop() + stop() diff --git a/portail_coulissant/porcou_lib.py b/portail_coulissant/porcou_lib.py index b71426c..686d3a6 100644 --- a/portail_coulissant/porcou_lib.py +++ b/portail_coulissant/porcou_lib.py @@ -1,6 +1,8 @@ import bge # Bibliothèque Blender Game Engine (UPBGE) from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading +# rom twin_serial import open, close # Liaison série import twin_serial # Liaison série +# import twin_serial # Liaison série import time ############################################################################### @@ -16,19 +18,19 @@ import time scene = bge.logic.getCurrentScene() # Carte du jumeau numérique -board = None -board_it = None # Iterator (input) +# board = None +# board_it = None # Iterator (input) # Brochage du jumeau numérique -bp_int_pin = None -bp_ext_pin = None -fdc_o_pin = None -fdc_f_pin = None -ir_emett_pin = None -ir_recept_pin = None -mot_o_pin = None -mot_f_pin = None -gyr_pin = None +# bp_int_pin = None +# bp_ext_pin = None +# fdc_o_pin = None +# fdc_f_pin = None +# ir_emett_pin = None +# ir_recept_pin = None +# mot_o_pin = None +# mot_f_pin = None +# gyr_pin = None # UPBGE constants JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED @@ -101,8 +103,9 @@ def bp_int (): # Jumeau ############################################################################### -def jumeau (): - twin_serial.open() +def jumeau (brochage): + scene.objects['System']['board']=twin_serial.open() + print ("jumeau : ", scene.objects['System']['board']) ############################################################################### # Cycle @@ -112,10 +115,18 @@ def jumeau (): def tempo (duree): time.sleep(duree) -# Fin +# Arrêt +def stop(): + if scene.objects['System']['twins']: + twin_serial.close(scene.objects['System']['board']) + time.sleep(0.5) + thread_cmd_stop() + +# Fin naturelle def end(): if scene.objects['System']['twins']: - twin_serial.close() + twin_serial.close(scene.objects['System']['board']) + time.sleep(0.5) thread_cmd_end() def fin(): diff --git a/portail_coulissant/portail_coulissant-17.blend b/portail_coulissant/portail_coulissant-17.blend index d791e55..8f0e495 100644 Binary files a/portail_coulissant/portail_coulissant-17.blend and b/portail_coulissant/portail_coulissant-17.blend differ diff --git a/twin.py b/twin.py index 86bb47a..af8f545 100644 --- a/twin.py +++ b/twin.py @@ -141,19 +141,20 @@ def cmd_init(): scene.objects['ResetView-Hl'].setVisible(False,False) scene.objects['Doc-cmd-Hl'].setVisible(False,False) scene.objects['About-cmd-Hl'].setVisible(False,False) - # scene.objects['Twins-icon'].setVisible(False,True) # UI : Text, ... scene.objects['Cmd-text']['Text']="" scene.objects['Cmd-text'].setVisible(True,False) scene.objects['Twins-text']['Text']="Connection fermée." - # scene.objects['Twins-text'].setVisible(False,False) # Windows windows=("Doc", "Doc_chap-general", "Doc_chap-system", "Doc_chap-python", "About") for window in windows: scene.objects[window].setVisible(False,True) + # Jumeau + scene.objects['System']['twins'] = False + ## # Highlight des commandes ## diff --git a/twin_about.py b/twin_about.py index f94bd62..eaac2f5 100644 --- a/twin_about.py +++ b/twin_about.py @@ -101,7 +101,8 @@ def close(cont): # scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud']) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay - scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text'] + bpy.context.view_layer.update() # Bug de mise à jour + # scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text'] scene.objects['About'].setVisible(False,True) ## diff --git a/twin_config.xml b/twin_config.xml index 7500901..f74adeb 100644 --- a/twin_config.xml +++ b/twin_config.xml @@ -1,7 +1,7 @@ - 1411 - 794 + 1318 + 741 1 \ No newline at end of file diff --git a/twin_doc.py b/twin_doc.py index 3a6356d..24b17ce 100644 --- a/twin_doc.py +++ b/twin_doc.py @@ -318,9 +318,6 @@ def close(cont): scene.objects["Doc_text-"+card].setVisible(False,True) else: text_dynamic_hide() - # scene.objects['Twins-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay - # scene.objects['Twins-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay - # scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text'] ## # Highlight diff --git a/twin_serial.py b/twin_serial.py index 3a7e87e..e48ddfc 100644 --- a/twin_serial.py +++ b/twin_serial.py @@ -19,7 +19,9 @@ from serial.tools.list_ports import comports # Détection du port automatique # UPBGE scene scene = bge.logic.getCurrentScene() -board = None +# Carte du jumeau numérique +# board = None +# board_it = None # Iterator (input) ## # Recherche automatique du port @@ -83,7 +85,6 @@ def devices(): # def jumeau(pins): def open(): - global board # UI : étape 1 scene.objects['Twins-text']['Text'] = "Connection en cours ..." @@ -129,7 +130,8 @@ def open(): # mot_o_pin = board_io('d:'+str(es_dict['mot_o'])+':o') # Ouvrir le portail (moteur sens trigo) # mot_f_pin = board_io('d:'+str(es_dict['mot_f'])+':o') # Fermer le portail (moteur sens horaire # ir_emett_pin = board_io('d:'+str(es_dict['ir_emett'])+':o') # Emetteur pour le capteur barrage IR - return True + return (board) + # return True # def board_io(da,pin,io): # if pin_def is not None: @@ -141,8 +143,7 @@ def open(): # Fermeture de la communication série ## -def close(): - global board +def close(board): scene.objects['Twins-text']['Text'] = "Connection fermée." board.exit() # Fermer proprement la communication avec la carte scene.objects['System']['twins'] = False diff --git a/twin_threading.py b/twin_threading.py index d5b6415..8251a9f 100644 --- a/twin_threading.py +++ b/twin_threading.py @@ -3,7 +3,6 @@ import threading # Multithreading import trace import sys import time -import twin_serial # Liaison série ############################################################################### # twin_threading.py @@ -104,8 +103,6 @@ def thread_cmd_start(fct): thread_start(threads_cmd, "commands", fct) def thread_cmd_stop(): - if scene.objects['System']['twins']: - twin_serial.close() thread_stop(threads_cmd, "commands") def thread_cmd_end():