mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Fermeture de la liaison propre
This commit is contained in:
parent
ea3a95dc36
commit
e968972cbe
@ -29,7 +29,13 @@ from porcou_lib import * # Bibliothèque portail coulissant
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Brochage du 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
|
# Fonctions
|
||||||
@ -41,10 +47,9 @@ brochage={}
|
|||||||
|
|
||||||
def commandes():
|
def commandes():
|
||||||
|
|
||||||
# Ecrire votre code ici ...
|
# jumeau(carte, brochage)
|
||||||
# jumeau()
|
jumeau(brochage)
|
||||||
gyr(True) # Activer le gyrophare
|
gyr(True)
|
||||||
# ir_emet(True)
|
|
||||||
while True:
|
while True:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -59,4 +64,4 @@ def commandes():
|
|||||||
if __name__=='start':
|
if __name__=='start':
|
||||||
thread_cmd_start(commandes)
|
thread_cmd_start(commandes)
|
||||||
if __name__=='stop':
|
if __name__=='stop':
|
||||||
thread_cmd_stop()
|
stop()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||||
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
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 twin_serial # Liaison série
|
||||||
import time
|
import time
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -16,19 +18,19 @@ import time
|
|||||||
scene = bge.logic.getCurrentScene()
|
scene = bge.logic.getCurrentScene()
|
||||||
|
|
||||||
# Carte du jumeau numérique
|
# Carte du jumeau numérique
|
||||||
board = None
|
# board = None
|
||||||
board_it = None # Iterator (input)
|
# board_it = None # Iterator (input)
|
||||||
|
|
||||||
# Brochage du jumeau numérique
|
# Brochage du jumeau numérique
|
||||||
bp_int_pin = None
|
# bp_int_pin = None
|
||||||
bp_ext_pin = None
|
# bp_ext_pin = None
|
||||||
fdc_o_pin = None
|
# fdc_o_pin = None
|
||||||
fdc_f_pin = None
|
# fdc_f_pin = None
|
||||||
ir_emett_pin = None
|
# ir_emett_pin = None
|
||||||
ir_recept_pin = None
|
# ir_recept_pin = None
|
||||||
mot_o_pin = None
|
# mot_o_pin = None
|
||||||
mot_f_pin = None
|
# mot_f_pin = None
|
||||||
gyr_pin = None
|
# gyr_pin = None
|
||||||
|
|
||||||
# UPBGE constants
|
# UPBGE constants
|
||||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||||
@ -101,8 +103,9 @@ def bp_int ():
|
|||||||
# Jumeau
|
# Jumeau
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
def jumeau ():
|
def jumeau (brochage):
|
||||||
twin_serial.open()
|
scene.objects['System']['board']=twin_serial.open()
|
||||||
|
print ("jumeau : ", scene.objects['System']['board'])
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Cycle
|
# Cycle
|
||||||
@ -112,10 +115,18 @@ def jumeau ():
|
|||||||
def tempo (duree):
|
def tempo (duree):
|
||||||
time.sleep(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():
|
def end():
|
||||||
if scene.objects['System']['twins']:
|
if scene.objects['System']['twins']:
|
||||||
twin_serial.close()
|
twin_serial.close(scene.objects['System']['board'])
|
||||||
|
time.sleep(0.5)
|
||||||
thread_cmd_end()
|
thread_cmd_end()
|
||||||
|
|
||||||
def fin():
|
def fin():
|
||||||
|
Binary file not shown.
5
twin.py
5
twin.py
@ -141,19 +141,20 @@ def cmd_init():
|
|||||||
scene.objects['ResetView-Hl'].setVisible(False,False)
|
scene.objects['ResetView-Hl'].setVisible(False,False)
|
||||||
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
||||||
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
||||||
# scene.objects['Twins-icon'].setVisible(False,True)
|
|
||||||
|
|
||||||
# UI : Text, ...
|
# UI : Text, ...
|
||||||
scene.objects['Cmd-text']['Text']=""
|
scene.objects['Cmd-text']['Text']=""
|
||||||
scene.objects['Cmd-text'].setVisible(True,False)
|
scene.objects['Cmd-text'].setVisible(True,False)
|
||||||
scene.objects['Twins-text']['Text']="Connection fermée."
|
scene.objects['Twins-text']['Text']="Connection fermée."
|
||||||
# scene.objects['Twins-text'].setVisible(False,False)
|
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
windows=("Doc", "Doc_chap-general", "Doc_chap-system", "Doc_chap-python", "About")
|
windows=("Doc", "Doc_chap-general", "Doc_chap-system", "Doc_chap-python", "About")
|
||||||
for window in windows:
|
for window in windows:
|
||||||
scene.objects[window].setVisible(False,True)
|
scene.objects[window].setVisible(False,True)
|
||||||
|
|
||||||
|
# Jumeau
|
||||||
|
scene.objects['System']['twins'] = False
|
||||||
|
|
||||||
##
|
##
|
||||||
# Highlight des commandes
|
# Highlight des commandes
|
||||||
##
|
##
|
||||||
|
@ -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.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-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['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)
|
scene.objects['About'].setVisible(False,True)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<data>
|
<data>
|
||||||
<screen>
|
<screen>
|
||||||
<width>1411</width>
|
<width>1318</width>
|
||||||
<height>794</height>
|
<height>741</height>
|
||||||
<quality>1</quality>
|
<quality>1</quality>
|
||||||
</screen>
|
</screen>
|
||||||
</data>
|
</data>
|
@ -318,9 +318,6 @@ def close(cont):
|
|||||||
scene.objects["Doc_text-"+card].setVisible(False,True)
|
scene.objects["Doc_text-"+card].setVisible(False,True)
|
||||||
else:
|
else:
|
||||||
text_dynamic_hide()
|
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
|
# Highlight
|
||||||
|
@ -19,7 +19,9 @@ from serial.tools.list_ports import comports # Détection du port automatique
|
|||||||
# UPBGE scene
|
# UPBGE scene
|
||||||
scene = bge.logic.getCurrentScene()
|
scene = bge.logic.getCurrentScene()
|
||||||
|
|
||||||
board = None
|
# Carte du jumeau numérique
|
||||||
|
# board = None
|
||||||
|
# board_it = None # Iterator (input)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Recherche automatique du port
|
# Recherche automatique du port
|
||||||
@ -83,7 +85,6 @@ def devices():
|
|||||||
|
|
||||||
# def jumeau(pins):
|
# def jumeau(pins):
|
||||||
def open():
|
def open():
|
||||||
global board
|
|
||||||
|
|
||||||
# UI : étape 1
|
# UI : étape 1
|
||||||
scene.objects['Twins-text']['Text'] = "Connection en cours ..."
|
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_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
|
# 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
|
# 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):
|
# def board_io(da,pin,io):
|
||||||
# if pin_def is not None:
|
# if pin_def is not None:
|
||||||
@ -141,8 +143,7 @@ def open():
|
|||||||
# Fermeture de la communication série
|
# Fermeture de la communication série
|
||||||
##
|
##
|
||||||
|
|
||||||
def close():
|
def close(board):
|
||||||
global board
|
|
||||||
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
scene.objects['Twins-text']['Text'] = "Connection fermée."
|
||||||
board.exit() # Fermer proprement la communication avec la carte
|
board.exit() # Fermer proprement la communication avec la carte
|
||||||
scene.objects['System']['twins'] = False
|
scene.objects['System']['twins'] = False
|
||||||
|
@ -3,7 +3,6 @@ import threading # Multithreading
|
|||||||
import trace
|
import trace
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import twin_serial # Liaison série
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# twin_threading.py
|
# twin_threading.py
|
||||||
@ -104,8 +103,6 @@ def thread_cmd_start(fct):
|
|||||||
thread_start(threads_cmd, "commands", fct)
|
thread_start(threads_cmd, "commands", fct)
|
||||||
|
|
||||||
def thread_cmd_stop():
|
def thread_cmd_stop():
|
||||||
if scene.objects['System']['twins']:
|
|
||||||
twin_serial.close()
|
|
||||||
thread_stop(threads_cmd, "commands")
|
thread_stop(threads_cmd, "commands")
|
||||||
|
|
||||||
def thread_cmd_end():
|
def thread_cmd_end():
|
||||||
|
Loading…
Reference in New Issue
Block a user