#include <jni.h>
#include <stdio.h>
#include <wiringPi.h>
#include "Lector.h"


#define buzzerPin 0  	//define the buzzerPin
#define buttonPin 1		//define the buttonPin
#define RedLed 28		//define the red led
#define GreenLed 29		//define the green led
 
JNIEXPORT void JNICALL
Java_Lector_beepSetup(JNIEnv *env, jobject obj){
	printf("Iniciando Loop de beep...\n");

    printf("Program is starting ... \n");
	
	wiringPiSetup();
	
	pinMode(buzzerPin, OUTPUT); 
	
	pinMode(RedLed, OUTPUT);
	
	pinMode(GreenLed, OUTPUT);

	
}

JNIEXPORT void JNICALL
Java_Lector_beepHandle(JNIEnv *env, jobject obj, jdouble sensor_value){
	if(sensor_value < 5){ //object is near of the sensor
		digitalWrite(buzzerPin, LOW);   //Turn on buzzer 
		digitalWrite(RedLed, HIGH);
		digitalWrite(GreenLed, LOW);
		printf("Value : %lf\n", sensor_value);
			
	}
	else {				//button is released 
		digitalWrite(buzzerPin, HIGH);   //Turn off buzzer
		digitalWrite(RedLed, LOW);
		digitalWrite(GreenLed, HIGH);
		printf("Value : %lf\n", sensor_value);
	}
}
