initial import
git-svn-id: svn://anubis/misc/parport-bare@2 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
7fefc66899
commit
036e68dd99
80
led.c
Normal file
80
led.c
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/parport.h>
|
||||
#include <linux/ppdev.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define WAIT 100000
|
||||
|
||||
int running = 1;
|
||||
|
||||
void signalHandler(int sig)
|
||||
{
|
||||
running = 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd;
|
||||
int result;
|
||||
|
||||
signal(SIGINT, signalHandler);
|
||||
|
||||
fd = open("/dev/parport0", O_RDWR);
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("Could not open parallel port");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Claiming parallel port\n");
|
||||
if (ioctl(fd, PPCLAIM, NULL))
|
||||
{
|
||||
perror("Could not claim the parallel port!");
|
||||
close(fd);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int mode = IEEE1284_MODE_BYTE;
|
||||
if (ioctl(fd, PPSETMODE, &mode))
|
||||
{
|
||||
perror("Could not set mode");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int dir = 0x00;
|
||||
if (ioctl(fd, PPDATADIR, &dir))
|
||||
{
|
||||
perror("Could not set parallel port direction");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 4;
|
||||
}
|
||||
|
||||
char dataH = 0xFF;
|
||||
char dataL = 0x00;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
ioctl(fd, PPWDATA, &dataH);
|
||||
usleep(WAIT);
|
||||
if (!running)
|
||||
break;
|
||||
ioctl(fd, PPWDATA, &dataL);
|
||||
usleep(WAIT);
|
||||
if (!running)
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Releasing parallel port\n");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user