blob: e901e7faadc16f4f6831b715e2fc3ae917bfc014 [file] [log] [blame]
Phil Howard26c7fe32016-02-27 16:03:10 +00001/*
2 * lowPower.c:
3 * Check the Pi's LOW-Power signal.
4 *
5 * This is a demonstration program that could be turned into some sort
6 * of logger via e.g. syslog - however it's also probably something
7 * that might be better handled by a future kernel - who knows.
8 *
9 * Copyright (c) 2014 Gordon Henderson.
10 ***********************************************************************
11 * This file is part of wiringPi:
12 * https://projects.drogon.net/raspberry-pi/wiringpi/
13 *
14 * wiringPi is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * wiringPi is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
26 ***********************************************************************
27 */
28
29#include <stdio.h>
30#include <time.h>
31#include <wiringPi.h>
32
33
34#define LOW_POWER 35
35
36/*
37 * lowPower:
38 * This is an ISR that waits for the low-power signal going low and
39 * prints the result.
40 *********************************************************************************
41 */
42
43void lowPower (void)
44{
45 time_t t ;
46
47 time (&t) ;
48 printf ("%s: LOW POWER DETECTED\n", ctime (&t)) ;
49}
50
51
52/*
53 *********************************************************************************
54 * main
55 *********************************************************************************
56 */
57
58int main (void)
59{
60 wiringPiSetupGpio () ; // GPIO mode as it's an internal pin
61
62 wiringPiISR (LOW_POWER, INT_EDGE_FALLING, &lowPower) ;
63
64 for (;;)
65 delay (1000) ;
66
67 return 0 ;
68}