Ejemplo n.º 1
0
L298N::L298N(int in1, int in2, int in3, int in4, int ena, int enb) {
	_valid = true; //innocent until proven guilty
	
	/*if (checkGPIOexport(in1) || checkGPIOexport(in2) || checkGPIOexport(in3) || checkGPIOexport(in4)) {
		//Problem with one of the GPIOs
		_valid = false;
	}
	
	if (checkPWMdev(ena) || checkPWMdev(enb)) {
		//Problem with one of the PWM devices in /dev
		_valid = false;
	}*/
	
	/*if (setGPIOout(in1) || setGPIOout(in2) || setGPIOout(in3) || setGPIOout(in4)) {
		//couldn't set gpio to output
		_valid = false;
	}
	
	_fd1 = openGPIO(in1);
	if (_fd1 == -1) {
		_valid = false;
	}
	
	_fd2 = openGPIO(in2);
	if (_fd2 == -1) {
		close(_fd1);
		_valid = false;
	}
	
	_fd3 = openGPIO(in3);
	if (_fd3 == -1) {
		_valid = false;
	}
	
	_fd4 = openGPIO(in4);
	if (_fd4 == -1) {
		_valid = false;
	}*/
	
	_in1 = new GPIO(in1, 1, 1);
	_in2 = new GPIO(in2, 1, 0);
	_in3 = new GPIO(in3, 1, 1);
	_in4 = new GPIO(in4, 1, 0);
	
	_fda = openPWM(ena);
	if (_fda == -1) {
		_valid = false;
	}
	
	_fdb = openPWM(enb);
	if (_fdb == -1) {
		_valid = false;
	}
	
	//set initial "safe" condition
	set(1, 0, 1, 0, 0, 0);
}
Ejemplo n.º 2
0
int main(void)

{
        int fileHandleGPIO_LED;
        int fileHandleGPIO_PROXY;
        int i=0;

        puts("Starting proximity reader on Galileo board.");
        fileHandleGPIO_PROXY = openGPIO(GP_PROXY, GPIO_DIRECTION_IN);
        if(ERROR ==  fileHandleGPIO_PROXY)
        {
        		puts("Unable to open toggle Proximity port #8");
        		return(-1);
        }
        fileHandleGPIO_LED = openGPIO(GP_LED, GPIO_DIRECTION_OUT);

        if(ERROR ==  fileHandleGPIO_LED)

        {
        		puts("Unable to open toggle LED port #13");
        		return(-1);

        }


        //Switch off the LED before starting.
        writeGPIO(fileHandleGPIO_LED, 0);

        //set PWM parameters
        openPWM(GP_PWM);
        setPWMPeriod(1000000,GP_PWM);
        enablePWM(1,GP_PWM);
		setPWMDutyCycle(0,GP_PWM);


        //Start an infinite loop to keep polling for proximity info
        int proxyValue = 0;
        while(1==1)
        {
			proxyValue = readGPIO(fileHandleGPIO_PROXY,GP_PROXY);
			if(proxyValue == 1)
			{
				if(duty_cycle == 500000)
				{
					duty_cycle = 200000;
		        	writeGPIO(fileHandleGPIO_LED, 0);
				}
				else
				{
					duty_cycle = 500000;
		        	writeGPIO(fileHandleGPIO_LED, 1);
				}
				setPWMDutyCycle(duty_cycle,GP_PWM);
			}
			else
			{
				duty_cycle = 50000;
				setPWMDutyCycle(0,GP_PWM);
	        	writeGPIO(fileHandleGPIO_LED, 0);
			}
        	usleep(1000*400);
        }


        closeGPIO(GP_LED, fileHandleGPIO_LED);
        closeGPIO(GP_PROXY, fileHandleGPIO_PROXY);
        closePWM(GP_PWM);

        puts("Finished BURGLER ALARM on Galileo board.");
        return 0;
}