#include #include #include #include #include #include /* Ripped off from http://excamera.com/articles/21/parallel.html, modified 18/7/05 wharrop (check the licence of ripped off code before including this in any products) /dev/ppi0 must be r/w'able by the user who runs this program This program take a command line int, and "pushes the power button" for that length of time. (if you have the right hardware) */ static int ppi_fd; static void init(void) { char port[] = "/dev/ppi0"; ppi_fd = open(port, O_RDWR); if (ppi_fd < 0) { perror(port); exit(1); } } static void deinit(void) { close(ppi_fd); } static void do_out(uint8_t outval, useconds_t delay_us) { uint8_t tmp; /* put our data on the line */ ioctl(ppi_fd, PPISDATA, &outval); /* get ctrl register */ ioctl(ppi_fd, PPIGCTRL, &tmp); /* set strobe */ tmp |= STROBE; ioctl(ppi_fd, PPISCTRL, &tmp); /* sleep with strobe held */ usleep(delay_us); /* unset strobe */ tmp &= ~STROBE; ioctl(ppi_fd, PPISCTRL, &tmp); /* set data to 0 */ ioctl(ppi_fd, PPISDATA, 0x00); } void usage(const char *name) { printf("\nUsage: %s [delay]\n\n", name); printf(" - select the data pin (0 through 7) to operate on\n"); printf(" [delay] - optional delay (in fractional seconds) to wait before clearing output (default = 1s)\n\n"); exit(1); } int main(int argc, char *argv[]) { float delay_s; int pin, delay_us; switch (argc) { case 2: pin = strtol(argv[1], NULL, 0); delay_s = 1.0; break; case 3: pin = strtol(argv[1], NULL, 0); delay_s = strtof(argv[2], NULL); break; default: usage(argv[0]); break; } if (pin < 0 || pin > 7) usage(argv[0]); delay_us = (int)(delay_s * 1000000); if (delay_us < 0) usage(argv[0]); init(); printf("Sending 0x%02x to parallel port for %0.3fs\n", 0xFF & (1 << pin), delay_s); do_out(0xFF & (1 << pin), delay_us); deinit(); return 0; }