Created
November 8, 2011 15:08
-
-
Save zeszyt/1347980 to your computer and use it in GitHub Desktop.
WRAP reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/gpio.h> | |
#include <sys/ioctl.h> | |
#include <sys/reboot.h> | |
#include <err.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#define _PATH_DEV_GPIO "/dev/gpio0" | |
char *device = _PATH_DEV_GPIO; | |
int devfd = -1; | |
int quiet = 0; | |
int pinread(int); | |
main() | |
{ | |
if ((devfd = open(device, O_RDWR)) == -1) | |
err(1, "%s", device); | |
while (pinread(40) == 1) { | |
sleep(3); | |
} | |
reboot(3); | |
} | |
int | |
pinread(int pin) | |
{ | |
struct gpio_pin_op op; | |
bzero(&op, sizeof(op)); | |
op.gp_pin = pin; | |
if (ioctl(devfd, GPIOPINREAD, &op) == -1) | |
err(1, "GPIOPINREAD"); | |
return op.gp_value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment