From 036e68dd999646b8635ab6c59ef022d26b237d8f Mon Sep 17 00:00:00 2001 From: josh Date: Tue, 29 May 2007 22:21:13 +0000 Subject: [PATCH] initial import git-svn-id: svn://anubis/misc/parport-bare@2 bd8a9e45-a331-0410-811e-c64571078777 --- Makefile | 5 ++++ led.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Makefile create mode 100644 led.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..98c56c6 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ + +all: led + +led: led.c + gcc -o $@ $< diff --git a/led.c b/led.c new file mode 100644 index 0000000..aab1de3 --- /dev/null +++ b/led.c @@ -0,0 +1,80 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +}