<commit_before>#!/usr/bin/env python
##################################################################
#               <NAME>   M Y   P R A Y E R 
#
# Gestion du Servo : http://razzpisampler.oreilly.com/ch05.html
#
# Il faut que la cam soit au moins a 25 cm du galet.
##################################################################
from raspiomix import Raspiomix
import RPi.GPIO as GPIO
import time, datetime, picamera, requests, ConfigParser, os
import LMPLed

debug_mode = False

CONFIG_FILE = "config/lmp.conf"

# Lecture du fichier de configuration
cfg = ConfigParser.ConfigParser()
cfg.read(CONFIG_FILE)

# Urls Serveur
url_upload = cfg.get('server', 'url_upload')

# Temps d'attente du scenario
wait_before_pic  		 = cfg.getfloat('client', 'wait_before_pic')
wait_after_pic   		 = cfg.getfloat('client', 'wait_after_pic')
wait_after_open  		 = cfg.getfloat('client', 'wait_after_open')
wait_after_close 		 = cfg.getfloat('client', 'wait_after_close')
wait_init_motor  		 = cfg.getfloat('client', 'wait_init_motor')
wait_after_cycle 		 = cfg.getfloat('client', 'wait_after_cycle')
wait_before_cleanup_gpio = cfg.getfloat('client', 'wait_before_cleanup_gpio')

# Temps d'animation de leds
fade_in_time  = cfg.getfloat('leds', 'fade_in_time')
fade_out_time = cfg.getfloat('leds', 'fade_out_time')
wait_time     = cfg.getfloat('leds', 'wait_time')

# Variables de seuil pour la detection
seuil_detection_trappe = cfg.getfloat('sensor_calibration', 'seuil_detection_trappe')
seuil_detection_main   = cfg.getfloat('sensor_calibration', 'seuil_detection_main')
# seuil_detection_galet  = cfg.getfloat('sensor_calibration', 'seuil_detection_galet')

last_detection_value = seuil_detection_trappe

# Carte Raspiomix
r = Raspiomix()
GPIO.setmode(GPIO.BOARD)
# Pilotage servo
GPIO.setup(r.IO0, GPIO.OUT) # Mode board = 12, GPIO18
# Capteur presence galet, capteur sur entree analogique 0
ir_sensor = 0
# Pilotage Servo-moteur
motor = GPIO.PWM(r.IO0, 50)

control_button = 35 #r.IO4
# Bouton marche/arret/reboot
GPIO.setup(control_button, GPIO.IN, pull_up_down = GPIO.PUD_UP) 
mode_commande_actif = False
timestamp_commande = 0.0

# Repertoire des images
img_dir = cfg.get('client', 'img_dir')
# Etape courante 
state = 'wait'
#
waiting_led_launched = False

# Pilotage des LEDS ###########################################################
leds = LMPLed.LMPLed() # LEDS driver
leds.setColor(leds.WHITE)
###############################################################################
#
# Logging de debug
#
def debug_log(s):
	if debug_mode:
		print s

#
# Shutdown function
#
def shutdown(option):
	debug_log("sudo shutdown -" + option + " now")
	os.system("sudo shutdown -" + option + " now")

#
# traiter l'action du bouton
#
# 1 appuie : reboot
# 2 appuies en moins d'une seconde : Shutdown
#
def treat_button_action(channel):
	global mode_commande_actif, timestamp_commande
	if mode_commande_actif == False:
		# Faire clignoter la LED de la trappe en ROUGE (mode commande)
		leds.command(1.0)
		# Attendre un deuxieme appuie sur le bouton pour arreter le systeme
		mode_commande_actif = True
		timestamp_commande = datetime.datetime.now();
		debug_log ("Command mode activated at" + str(timestamp_commande))
		# Remonter la pin du bouton a 1
		GPIO.setup(control_button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
	else:
		# Le mode comande est actif, on traite la commande
		timeDiff = datetime.datetime.now() - timestamp_commande
		if timeDiff.total_seconds() < 2:
			# shutdown
			debug_log("Shutdown lauched...")
			# Fixer la LED de la trappe en VERT pendant 1 seconde
			leds.shutdown()
			option = "h"
		else:
			# Sinon Reboot du systeme
			debug_log("Reboot lauched...")
			# Fixer la LED de la trappe en ROUGE pendant une seconde
			leds.reboot()
			option = "r"
		mode_commande_actif = False
		timestamp_commande = 0
		shutdown(option)
	leds.update()

# Interrution sur changement de front du bouton  
GPIO.add_event_detect(control_button, GPIO.FALLING, callback = treat_button_action, bouncetime = 50)  

# 
# Petite fonction de Wait pour le debug
#
def waiting(sometime):
	# debug_log ("waiting for (%f) sec." % sometime)
	time.sleep(sometime)<commit_msg>suppress temporarly command button interruption<commit_after>#!/usr/bin/env python
##################################################################
#               L I G H T   M Y   P R A Y E R 
#
# Gestion du Servo : http://razzpisampler.oreilly.com/ch05.html
#
# Il faut que la cam soit au moins a 25 cm du galet.
##################################################################
from raspiomix import Raspiomix
import RPi.GPIO as GPIO
import time, datetime, picamera, requests, ConfigParser, os
import LMPLed

debug_mode = False

CONFIG_FILE = "config/lmp.conf"

# Lecture du fichier de configuration
cfg = ConfigParser.ConfigParser()
cfg.read(CONFIG_FILE)

# Urls Serveur
url_upload = cfg.get('server', 'url_upload')

# Temps d'attente du scenario
wait_before_pic  		 = cfg.getfloat('client', 'wait_before_pic')
wait_after_pic   		 = cfg.getfloat('client', 'wait_after_pic')
wait_after_open  		 = cfg.getfloat('client', 'wait_after_open')
wait_after_close 		 = cfg.getfloat('client', 'wait_after_close')
wait_init_motor  		 = cfg.getfloat('client', 'wait_init_motor')
wait_after_cycle 		 = cfg.getfloat('client', 'wait_after_cycle')
wait_before_cleanup_gpio = cfg.getfloat('client', 'wait_before_cleanup_gpio')

# Temps d'animation de leds
fade_in_time  = cfg.getfloat('leds', 'fade_in_time')
fade_out_time = cfg.getfloat('leds', 'fade_out_time')
wait_time     = cfg.getfloat('leds', 'wait_time')

# Variables de seuil pour la detection
seuil_detection_trappe = cfg.getfloat('sensor_calibration', 'seuil_detection_trappe')
seuil_detection_main   = cfg.getfloat('sensor_calibration', 'seuil_detection_main')
# seuil_detection_galet  = cfg.getfloat('sensor_calibration', 'seuil_detection_galet')

last_detection_value = seuil_detection_trappe

# Carte Raspiomix
r = Raspiomix()
GPIO.setmode(GPIO.BOARD)
# Pilotage servo
GPIO.setup(r.IO0, GPIO.OUT) # Mode board = 12, GPIO18
# Capteur presence galet, capteur sur entree analogique 0
ir_sensor = 0
# Pilotage Servo-moteur
motor = GPIO.PWM(r.IO0, 50)

control_button = 35 #r.IO4
# Bouton marche/arret/reboot
GPIO.setup(control_button, GPIO.IN, pull_up_down = GPIO.PUD_UP) 
mode_commande_actif = False
timestamp_commande = 0.0

# Repertoire des images
img_dir = cfg.get('client', 'img_dir')
# Etape courante 
state = 'wait'
#
waiting_led_launched = False

# Pilotage des LEDS ###########################################################
leds = LMPLed.LMPLed() # LEDS driver
leds.setColor(leds.WHITE)
###############################################################################
#
# Logging de debug
#
def debug_log(s):
	if debug_mode:
		print s

#
# Shutdown function
#
def shutdown(option):
	debug_log("sudo shutdown -" + option + " now")
	os.system("sudo shutdown -" + option + " now")

#
# traiter l'action du bouton
#
# 1 appuie : reboot
# 2 appuies en moins d'une seconde : Shutdown
#
def treat_button_action(channel):
	global mode_commande_actif, timestamp_commande
	if mode_commande_actif == False:
		# Faire clignoter la LED de la trappe en ROUGE (mode commande)
		leds.command(1.0)
		# Attendre un deuxieme appuie sur le bouton pour arreter le systeme
		mode_commande_actif = True
		timestamp_commande = datetime.datetime.now();
		debug_log ("Command mode activated at" + str(timestamp_commande))
		# Remonter la pin du bouton a 1
		GPIO.setup(control_button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
	else:
		# Le mode comande est actif, on traite la commande
		timeDiff = datetime.datetime.now() - timestamp_commande
		if timeDiff.total_seconds() < 2:
			# shutdown
			debug_log("Shutdown lauched...")
			# Fixer la LED de la trappe en VERT pendant 1 seconde
			leds.shutdown()
			option = "h"
		else:
			# Sinon Reboot du systeme
			debug_log("Reboot lauched...")
			# Fixer la LED de la trappe en ROUGE pendant une seconde
			leds.reboot()
			option = "r"
		mode_commande_actif = False
		timestamp_commande = 0
		shutdown(option)
	leds.update()

# Interrution sur changement de front du bouton  
##### Seems not to be effective ??? BUGGY BUGGY !
##### GPIO.add_event_detect(control_button, GPIO.FALLING, callback = treat_button_action, bouncetime = 50)  

# 
# Petite fonction de Wait pour le debug
#
def waiting(sometime):
	# debug_log ("waiting for (%f) sec." % sometime)
	time.sleep(sometime)
{'fraction_non_alphanumeric': 0.1632022805558855, 'fraction_numerical': 0.006889179237439126, 'mean_word_length': 5.110304789550073, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '438174', 'n_tokens_mistral': 3102, 'n_tokens_neox': 2902, 'n_words': 722}