Last active
September 27, 2017 19:33
Star
You must be signed in to star a gist
clase para rpi watchdog
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
#ifndef rpiWatchdog_h | |
#define rpiWatchdog_h | |
#include <linux/watchdog.h> | |
#include <sys/ioctl.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
class piWatchdog | |
{ | |
public: | |
int deviceHandle; | |
int timeFeed; | |
bool iniciado = false; | |
void setupWatchdog(){ | |
if ((deviceHandle = open("/dev/watchdog", O_RDWR | O_NOCTTY)) < 0) { | |
printf("Error: Couldn't open watchdog device! %d\n", deviceHandle); | |
}else{ | |
printf("watchdog OK.\n"); | |
int timeout = 15; | |
ioctl(deviceHandle, WDIOC_SETTIMEOUT, &timeout); | |
ioctl(deviceHandle, WDIOC_GETTIMEOUT, &timeout); | |
printf("The watchdog timeout is %d seconds.\n\n", timeout); | |
iniciado = true; | |
} | |
timeFeed = ofGetElapsedTimeMillis(); | |
} | |
void feedWatchdog(){ | |
if(iniciado){ | |
if(ofGetElapsedTimeMillis() - timeFeed > 8000){ | |
printf("Feeding the dog with a heartbeat.\n"); | |
ioctl(deviceHandle, WDIOC_KEEPALIVE, 0); | |
timeFeed = ofGetElapsedTimeMillis(); | |
} | |
} | |
} | |
void exitWatchdog(){ | |
printf("Disable watchdog.\n"); | |
write(deviceHandle, "V", 1); | |
close(deviceHandle); | |
} | |
/* data */ | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ejemplo de uso