/*2011-01-03T15:23:41-01:00*/

/********************************************************************
 * bouton_poussoir_lumineux_cov.c
 * 
 * generated by: plcgen 2.1.201
 ********************************************************************/

#include "cb_comp.h"
#include "cb_covs.h"
#include "iec_1131.h"

#include "bouton_poussoir_lumineux.h"


/**************************** Variables *****************************/

CB_Index bouton_poussoir_lumineux__num = 0;
CB_Mem_Bool *bouton_poussoir_lumineux_lumineux;
CB_Mem_Bool *bouton_poussoir_lumineux_bp;
CB_Mem_Float *bouton_poussoir_lumineux_compteurTemps;
CB_Mem_Bool *bouton_poussoir_lumineux_action;
CB_Mem_Float *bouton_poussoir_lumineux_dureeImpulsion;
CB_Mem_Bool *bouton_poussoir_lumineux_logiqueBp;

/**************************** Variables *****************************/

#define lumineux (bouton_poussoir_lumineux_lumineux->CB_current_value)
#define bp (bouton_poussoir_lumineux_bp->CB_current_value)
#define compteurTemps (bouton_poussoir_lumineux_compteurTemps->CB_current_value)
#define action (bouton_poussoir_lumineux_action->CB_current_value)
#define dureeImpulsion (bouton_poussoir_lumineux_dureeImpulsion->CB_current_value)
#define logiqueBp (bouton_poussoir_lumineux_logiqueBp->CB_current_value)


/************************ Components offsets ************************/


/********************* Initialization function **********************/

int _bibliotheque_epo__bouton_poussoir_lumineux_init(void)
{
	(self.Float+1)->CB_current_value = 5.0; /*dureeImpulsion*/
	(self.Bool+1)->CB_current_value = 1; /*logiqueBp*/
	self.Bool+=2;
	self.Float+=2;


	return 0;
}


/************************ Behavior function *************************/

int bibliotheque_epo__bouton_poussoir_lumineux(void)
{
	static char *__comp_name = "bibliotheque_epo.bouton_poussoir_lumineux";
	if (exec_term_node(self_num)) {

		/*********************** Internals variables ************************/

		bouton_poussoir_lumineux_compteurTemps = self.Float+0;
		bouton_poussoir_lumineux_action = self.Bool+0;
		bouton_poussoir_lumineux_dureeImpulsion = self.Float+1;
		bouton_poussoir_lumineux_logiqueBp = self.Bool+1;

		/********************* Pre-conditions execution *********************/

		/*no Pre-conditions*/

		/************************ Behavior execution ************************/

		{
			if (action) {
				cov_control_struct(__comp_name, self_num, INCODE, 11, IFTHEN);
				compteurTemps = compteurTemps + CLOCK_PERIOD / 1000000.0;
				if (compteurTemps > dureeImpulsion) {
					cov_control_struct(__comp_name, self_num, INCODE, 13, IFTHEN);
					action = 0;
					compteurTemps = 0.0;
				}
				else {
					cov_control_struct(__comp_name, self_num, INCODE, 13, IFELSE);
				}
			}
			else {
				cov_control_struct(__comp_name, self_num, INCODE, 11, IFELSE);
			}
			bp = action ^ !logiqueBp;
		}

		CB_post_bool(bouton_poussoir_lumineux_bp);

		/******************** Post-conditions execution *********************/

		/*no Post-conditions*/
	}

	/*************************** self update ****************************/

	self.Bool += 2;
	self.Float += 2;

	return 0;
}

