jumeaux-numeriques/monte_charge/montchg_lib.py

105 lines
3.1 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
###############################################################################
# montchg_lib.py
# @title: Bibliothèque utilisateur du monte-charge
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2022-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
# FIXME
# 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
###############################################################################
# Voyants
###############################################################################
# Ordre pour allumer le voyant niveau 0
def voy_0 (order):
scene.objects['Led niveau 0']['activated']=order
# Ordre pour allumer le voyant niveau 1
def voy_1 (order):
scene.objects['Led niveau 1']['activated']=order
###############################################################################
# Actionneurs
###############################################################################
# Ordre pour le moteur phase monter
def mot_m (order):
scene.objects['Moteur']['up']=order
# Ordre pour le moteur phase descendre
def mot_d (order):
scene.objects['Moteur']['down']=order
###############################################################################
# Capteurs
###############################################################################
# Compte-rendu du capteur de présence cabine niveau 0
def pc_0 ():
return scene.objects['Microrupteur niveau 0']['activated']
# Compte-rendu du capteur de présence cabine niveau 0
def pc_1 ():
return scene.objects['Microrupteur niveau 1']['activated']
###############################################################################
# Boutons poussoirs
###############################################################################
# Compte-rendu du bouton pousssoir appel niveau 0
def ba_0 ():
return scene.objects['Bp niveau 0']['activated']
# Compte-rendu du bouton pousssoir appel niveau 1
def ba_1 ():
return scene.objects['Bp niveau 1']['activated']
###############################################################################
# Jumeau
###############################################################################
def jumeau ():
twin_serial.open()
###############################################################################
# Cycle
###############################################################################
# Temporisation
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()