mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
167 lines
5.5 KiB
Python
167 lines
5.5 KiB
Python
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
|
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
|
import twin_serial # Liaison série
|
|
import time
|
|
|
|
###############################################################################
|
|
# porcou_lib.py
|
|
# @title: Bibliothèque utilisateur du portail coulissant
|
|
# @project: Blender-EduTech
|
|
# @lang: fr
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
# @copyright: Copyright (C) 2020-2023 Philippe Roy
|
|
# @license: GNU GPL
|
|
###############################################################################
|
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
# Brochage du jumeau réel
|
|
pin_config = {
|
|
'bp_ext' : ['d','i'],
|
|
'bp_int' : ['d','i'],
|
|
'fdc_o' : ['d','i'],
|
|
'fdc_f' : ['d','i'],
|
|
'mot_o' : ['d','o'],
|
|
'mot_f' : ['d','o'],
|
|
'gyr' : ['d','o'],
|
|
'ir_emet' : ['d','o'],
|
|
'ir_recep' : ['d','i']}
|
|
|
|
# UPBGE constants
|
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
|
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
|
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
|
|
|
###############################################################################
|
|
# Gyrophare
|
|
###############################################################################
|
|
|
|
# Ordre pour allumer le gyrophare
|
|
def gyr (order):
|
|
scene.objects['Led']['activated']=order
|
|
|
|
###############################################################################
|
|
# Actionneurs
|
|
###############################################################################
|
|
|
|
# Ordre pour le moteur phase ouvrir
|
|
def mot_o (order):
|
|
scene.objects['Moteur']['open']=order
|
|
|
|
# Ordre pour le moteur phase fermer
|
|
def mot_f (order):
|
|
scene.objects['Moteur']['close']=order
|
|
|
|
# Ordre pour le capteur barrage IR
|
|
def ir_emet(order):
|
|
scene.objects['Emetteur IR']['active']=order
|
|
|
|
###############################################################################
|
|
# Capteurs
|
|
###############################################################################
|
|
|
|
# Compte-rendu du capteur fin de course portail ouvert
|
|
def fdc_o ():
|
|
if scene.objects['Microrupteur fdc ouvert']['activated'] or scene.objects['Microrupteur fdc ouvert']['activated_real']:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
# Compte-rendu du capteur fin de course portail fermé
|
|
def fdc_f ():
|
|
if scene.objects['Microrupteur fdc ferme']['activated'] or scene.objects['Microrupteur fdc ferme']['activated_real']:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
# Compte-rendu du capteur barrage IR
|
|
def ir_recep ():
|
|
if scene.objects['Recepteur IR']['activated'] or scene.objects['Recepteur IR']['activated_real']==False:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
###############################################################################
|
|
# Boutons poussoirs
|
|
###############################################################################
|
|
|
|
# Compte-rendu du bouton pousssoir coté rue
|
|
def bp_ext ():
|
|
if scene.objects['Bp cote rue']['activated'] or scene.objects['Bp cote rue']['activated_real']:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
# Compte-rendu du bouton pousssoir coté cour
|
|
def bp_int ():
|
|
if scene.objects['Bp cote cour']['activated'] or scene.objects['Bp cote cour']['activated_real']:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
###############################################################################
|
|
# Jumeau
|
|
###############################################################################
|
|
|
|
# Créer une broche
|
|
def jumeau_get_pin(board, name, brochage):
|
|
for pin in brochage :
|
|
if pin ==name:
|
|
# print (pin_config[pin][0]+':'+str(brochage[pin])+':'+pin_config[pin][1])
|
|
return board.get_pin(pin_config[pin][0]+':'+str(brochage[pin])+':'+pin_config[pin][1])
|
|
return None
|
|
|
|
# Activer le jumelage
|
|
def jumeau (brochage=None):
|
|
|
|
# Carte
|
|
board =twin_serial.open()
|
|
scene.objects['System']['board']=board
|
|
# print ("jumeau : ", scene.objects['System']['board'])
|
|
|
|
# Brochage
|
|
if brochage is not None:
|
|
scene.objects['Bp cote cour']['pin'] = jumeau_get_pin(board, 'bp_int', brochage)
|
|
scene.objects['Bp cote rue']['pin'] = jumeau_get_pin(board, 'bp_ext', brochage)
|
|
scene.objects['Microrupteur fdc ouvert']['pin'] =jumeau_get_pin(board, 'fdc_o', brochage)
|
|
scene.objects['Microrupteur fdc ferme']['pin'] =jumeau_get_pin(board, 'fdc_f', brochage)
|
|
scene.objects['Moteur']['pin_o'] = jumeau_get_pin(board, 'mot_o', brochage)
|
|
scene.objects['Moteur']['pin_f'] = jumeau_get_pin(board, 'mot_f', brochage)
|
|
scene.objects['Led']['pin'] = jumeau_get_pin(board, 'gyr', brochage)
|
|
scene.objects['Emetteur IR']['pin'] = jumeau_get_pin(board, 'ir_emet', brochage)
|
|
scene.objects['Recepteur IR']['pin'] = jumeau_get_pin(board, 'ir_recep', brochage)
|
|
|
|
# Désactiver le jumelage
|
|
def jumeau_stop ():
|
|
twin_serial.close(scene.objects['System']['board'])
|
|
|
|
###############################################################################
|
|
# Cycle
|
|
###############################################################################
|
|
|
|
# Temporisation
|
|
def tempo (duree):
|
|
time.sleep(duree)
|
|
|
|
# Arrêt
|
|
def stop():
|
|
if scene.objects['System']['twins']:
|
|
twin_serial.close(scene.objects['System']['board'])
|
|
time.sleep(1)
|
|
thread_cmd_stop()
|
|
|
|
# Fin naturelle
|
|
def end():
|
|
if scene.objects['System']['twins']:
|
|
twin_serial.close(scene.objects['System']['board'])
|
|
time.sleep(1)
|
|
thread_cmd_end()
|
|
|
|
def fin():
|
|
end()
|
|
|
|
def quit():
|
|
end()
|