Siren.c 1.44 KB
#include <jni.h>
#include <stdio.h>
#include "model_SirenJNI.h"
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>          
#include <sys/stat.h>           
#include <asm/ioctl.h>
#include <linux/parport.h>
#include <linux/ppdev.h>

#define DEVICE "/dev/parport0"

JNIEXPORT void JNICALL Java_model_SirenJNI_sirenOn(JNIEnv *env, jobject obj) {

	
	 int fd = open(DEVICE, O_WRONLY | O_NOCTTY | O_NDELAY);
        if (fd < 0) {
               // fprintf(stderr, "can not open %s\n", DEVICE);
                return;
        }

        if(ioctl(fd, PPCLAIM)) {
                perror("PPCLAIM");
                close(fd);
                return;
        }

        unsigned char data = 255;

               if (ioctl(fd, PPWDATA, &data) < 0)
                        perror("ioctl()");
           

        ioctl(fd, PPRELEASE);
        close(fd);



     return;
}


JNIEXPORT void JNICALL Java_model_SirenJNI_sirenOff (JNIEnv *env, jobject obj) {

	    int fd = open(DEVICE, O_WRONLY | O_NOCTTY | O_NDELAY);
        if (fd < 0) {
               // fprintf(stderr, "can not open %s\n", DEVICE);
                return;
        }

        if(ioctl(fd, PPCLAIM)) {
                perror("PPCLAIM");
                close(fd);
                return;
        }

        unsigned char data = 0;

               if (ioctl(fd, PPWDATA, &data) < 0)
                        perror("ioctl()");
           

        ioctl(fd, PPRELEASE);
        close(fd);

     return;
}