#include #include //#define DBG #define STARTTIME 10 #define STOPTIME 3 #define SDBUTTON 25 void DoShutdown() { #ifdef DBG printf("Exec shutdown!!\n"); #endif system ("shutdown -h now"); } int main() { int starttimer=STARTTIME; int stoptimer=STOPTIME; int enablef=0; int val; if (wiringPiSetupGpio() == -1) return 1; pinMode (SDBUTTON , INPUT ); while(1) { val = digitalRead(SDBUTTON); if (enablef==0) { // まだイネーブルになっていない場合。 if (val == 0) { starttimer--; } else { starttimer=STARTTIME; } if ( starttimer == 0) { enablef = 1;} } else { // イネーブルになった後。 if (val == 1) { stoptimer--; } else { stoptimer=STOPTIME; } if ( stoptimer == 0 ) { DoShutdown(); return 0; } } #ifdef DBG printf("enablef:%d starttimer:%d stotimer:%d\n", enablef,starttimer,stoptimer); #endif sleep(1); } }