jumeaux-numeriques/portail_coulissant/porcou_lib.py

126 lines
3.5 KiB
Python
Raw Normal View History

2022-12-11 08:40:31 +01:00
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
2022-12-11 08:40:31 +01:00
import time
###############################################################################
# porcou_lib.py
2022-12-18 22:29:06 +01:00
# @title: Bibliothèque utilisateur du portail coulissant
2022-12-11 08:40:31 +01:00
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2020-2023 Philippe Roy
2022-12-11 08:40:31 +01:00
# @license: GNU GPL
###############################################################################
scene = bge.logic.getCurrentScene()
2022-12-11 15:50:38 +01:00
# Carte du jumeau numérique
2022-12-18 06:18:30 +01:00
board = None
board_it = None # Iterator (input)
# Brochage du jumeau numérique
2022-12-18 08:39:44 +01:00
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
2022-12-18 06:18:30 +01:00
gyr_pin = None
2022-12-11 08:40:31 +01:00
2022-12-11 15:50:38 +01:00
# 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
2022-12-11 08:40:31 +01:00
###############################################################################
# Ordre pour allumer le gyrophare
def gyr (order):
# global gyr_pin
scene.objects['Led']['activated']=order
# if scene.objects['System']['twins'] :
# if ordre :
# gyr_pin.write(1)
# else:
# gyr_pin.write(0)
2022-12-11 08:40:31 +01:00
###############################################################################
# Actionneurs
###############################################################################
# Ordre pour le moteur phase ouvrir
def mot_o (order):
scene.objects['Moteur']['open']=order
2022-12-11 08:40:31 +01:00
# Ordre pour le moteur phase fermer
def mot_f (order):
scene.objects['Moteur']['close']=order
2022-12-11 08:40:31 +01:00
# Ordre pour le capteur barrage IR
def ir_emet(order):
scene.objects['Emetteur IR']['active']=order
2022-12-11 08:40:31 +01:00
2022-12-11 15:50:38 +01:00
###############################################################################
2022-12-11 08:40:31 +01:00
# Capteurs
###############################################################################
# Compte-rendu du capteur fin de course portail ouvert
2022-12-13 02:42:31 +01:00
def fdc_o ():
return scene.objects['Microrupteur fdc ouvert']['activated']
2022-12-11 08:40:31 +01:00
# Compte-rendu du capteur fin de course portail ouvert
2022-12-13 02:42:31 +01:00
def fdc_f ():
return scene.objects['Microrupteur fdc ferme']['activated']
2022-12-11 08:40:31 +01:00
# Compte-rendu du capteur barrage IR
2022-12-11 08:40:31 +01:00
def ir_recep ():
2023-01-01 14:48:27 +01:00
if scene.objects['Recepteur IR']['activated']:
return False
else:
return True
2022-12-11 08:40:31 +01:00
2022-12-11 15:50:38 +01:00
###############################################################################
2022-12-11 08:40:31 +01:00
# Boutons poussoirs
###############################################################################
# Compte-rendu du bouton pousssoir coté rue
2022-12-11 08:40:31 +01:00
def bp_ext ():
return scene.objects['Bp cote rue']['activated']
2022-12-11 08:40:31 +01:00
# Compte-rendu du bouton pousssoir coté cour
2022-12-11 08:40:31 +01:00
def bp_int ():
return scene.objects['Bp cote cour']['activated']
2022-12-11 08:40:31 +01:00
2022-12-11 15:50:38 +01:00
###############################################################################
# Jumeau
###############################################################################
def jumeau ():
twin_serial.open()
###############################################################################
# Cycle
2022-12-11 08:40:31 +01:00
###############################################################################
# Temporisation
2022-12-11 08:40:31 +01:00
def tempo (duree):
time.sleep(duree)
# Fin
def end():
if scene.objects['System']['twins']:
twin_serial.close()
thread_cmd_end()
def fin():
end()
def quit():
end()