Skip to content

Instantly share code, notes, and snippets.

@zeszyt
Created November 8, 2011 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeszyt/1347980 to your computer and use it in GitHub Desktop.
Save zeszyt/1347980 to your computer and use it in GitHub Desktop.
WRAP reboot
#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