2022-12-18 22:46:19 +01:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
2023-01-06 21:23:44 +01:00
|
|
|
from twin_threading import thread_cmd_start, thread_cmd_stop, thread_cmd_end # Multithreading
|
|
|
|
import twin_serial # Liaison série
|
2022-12-18 22:46:19 +01:00
|
|
|
import time
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-19 17:28:29 +01:00
|
|
|
# volrou_lib.py
|
2022-12-18 22:46:19 +01:00
|
|
|
# @title: Bibliothèque utilisateur du volet roulant
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
2023-01-01 17:34:01 +01:00
|
|
|
# @copyright: Copyright (C) 2022-2023 Philippe Roy
|
2022-12-18 22:46:19 +01:00
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
# Récupérer la scène UPBGE
|
2022-12-18 22:46:19 +01:00
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
# Récupérer le brochage du jumeau réel
|
|
|
|
from volrou import pin_config
|
2022-12-18 22:46:19 +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
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-23 14:30:13 +01:00
|
|
|
# Voyant
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour allumer le voyant témoin mode automatique
|
|
|
|
def voy_auto (order):
|
|
|
|
scene.objects['Led auto']['activated']=order
|
2022-12-18 22:46:19 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Actionneurs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Ordre pour le moteur pour monter le volet
|
|
|
|
def mot_m (order):
|
|
|
|
scene.objects['Moteur']['up']=order
|
|
|
|
|
|
|
|
# Ordre pour le moteur pour descendre le volet
|
|
|
|
def mot_d (order):
|
|
|
|
scene.objects['Moteur']['down']=order
|
2022-12-18 22:46:19 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Capteurs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du capteur fin de course volet en haut
|
|
|
|
def fdc_h ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Microrupteur haut']['activated'] or scene.objects['Microrupteur haut']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du capteur fin de course volet en bas
|
2023-01-01 17:34:01 +01:00
|
|
|
def fdc_b():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Microrupteur bas']['activated'] or scene.objects['Microrupteur bas']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2022-12-24 03:10:30 +01:00
|
|
|
# Compte-rendu du capteur de luminosité
|
2023-01-08 19:55:18 +01:00
|
|
|
# FIXME : valeur numérique
|
2022-12-24 03:10:30 +01:00
|
|
|
def lum():
|
|
|
|
return scene.objects['Recepteur LDR']['activated']
|
|
|
|
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
# Boutons poussoirs
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du bouton monter volet
|
|
|
|
def bp_m ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp monter']['activated'] or scene.objects['Bp monter']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-23 14:30:13 +01:00
|
|
|
|
|
|
|
# Compte-rendu du bouton arrêt volet
|
|
|
|
def bp_a ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp arret']['activated'] or scene.objects['Bp arret']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-23 14:30:13 +01:00
|
|
|
|
|
|
|
# Compte-rendu du bouton descendre volet
|
|
|
|
def bp_d ():
|
2023-01-08 19:55:18 +01:00
|
|
|
if scene.objects['Bp descendre']['activated'] or scene.objects['Bp descendre']['activated_real']:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2022-12-18 22:46:19 +01:00
|
|
|
|
2022-12-23 14:30:13 +01:00
|
|
|
# Compte-rendu du bouton mode automatique
|
|
|
|
def bp_auto ():
|
|
|
|
return scene.objects['Bp auto']['activated']
|
2022-12-18 22:46:19 +01:00
|
|
|
|
|
|
|
###############################################################################
|
2023-01-06 21:23:44 +01:00
|
|
|
# Jumeau
|
|
|
|
###############################################################################
|
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
# Créer une broche
|
|
|
|
def jumeau_get_pin(board, name, brochage):
|
|
|
|
for pin in brochage :
|
|
|
|
if pin ==name:
|
|
|
|
# print (pin_config[pin][0][0]+':'+str(brochage[pin])+':'+pin_config[pin][0][1])
|
|
|
|
return board.get_pin(pin_config[pin][0][0]+':'+str(brochage[pin])+':'+pin_config[pin][0][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:
|
|
|
|
for pin in pin_config :
|
|
|
|
scene.objects[pin_config[pin][1][0]][pin_config[pin][1][1]] = jumeau_get_pin(board, pin, brochage)
|
|
|
|
|
|
|
|
# Désactiver le jumelage
|
|
|
|
def jumeau_stop ():
|
|
|
|
twin_serial.close(scene.objects['System']['board'])
|
2023-01-06 21:23:44 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Cycle
|
2022-12-18 22:46:19 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2023-01-06 21:23:44 +01:00
|
|
|
# Temporisation
|
2022-12-18 22:46:19 +01:00
|
|
|
def tempo (duree):
|
|
|
|
time.sleep(duree)
|
2023-01-06 21:23:44 +01:00
|
|
|
|
2023-01-08 19:55:18 +01:00
|
|
|
# Arrêt
|
|
|
|
def stop():
|
|
|
|
if scene.objects['System']['twins']:
|
|
|
|
twin_serial.close(scene.objects['System']['board'])
|
|
|
|
time.sleep(1)
|
|
|
|
thread_cmd_stop()
|
|
|
|
|
|
|
|
# Fin naturelle
|
2023-01-06 21:23:44 +01:00
|
|
|
def end():
|
|
|
|
if scene.objects['System']['twins']:
|
2023-01-08 19:55:18 +01:00
|
|
|
twin_serial.close(scene.objects['System']['board'])
|
|
|
|
time.sleep(1)
|
2023-01-06 21:23:44 +01:00
|
|
|
thread_cmd_end()
|
|
|
|
|
|
|
|
def fin():
|
|
|
|
end()
|
|
|
|
|
|
|
|
def quit():
|
|
|
|
end()
|