jumeaux-numeriques/portail_coulissant/porcou_lib.py

137 lines
4.0 KiB
Python

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
###############################################################################
# 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()
# Carte du jumeau numérique
# 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
# 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):
# global gyr_pin
scene.objects['Led']['activated']=order
# if scene.objects['System']['twins'] :
# if ordre :
# gyr_pin.write(1)
# else:
# gyr_pin.write(0)
###############################################################################
# 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 ():
return scene.objects['Microrupteur fdc ouvert']['activated']
# Compte-rendu du capteur fin de course portail ouvert
def fdc_f ():
return scene.objects['Microrupteur fdc ferme']['activated']
# Compte-rendu du capteur barrage IR
def ir_recep ():
if scene.objects['Recepteur IR']['activated']:
return False
else:
return True
###############################################################################
# Boutons poussoirs
###############################################################################
# Compte-rendu du bouton pousssoir coté rue
def bp_ext ():
return scene.objects['Bp cote rue']['activated']
# Compte-rendu du bouton pousssoir coté cour
def bp_int ():
return scene.objects['Bp cote cour']['activated']
###############################################################################
# Jumeau
###############################################################################
def jumeau (brochage):
scene.objects['System']['board']=twin_serial.open()
print ("jumeau : ", 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(0.5)
thread_cmd_stop()
# Fin naturelle
def end():
if scene.objects['System']['twins']:
twin_serial.close(scene.objects['System']['board'])
time.sleep(0.5)
thread_cmd_end()
def fin():
end()
def quit():
end()