forked from rszimm/sprinklers_pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprinklers_pi.cpp
66 lines (59 loc) · 1.24 KB
/
sprinklers_pi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// sprinklers_pi.cpp
// Main entry point
// Author: Richard Zimmerman
// Copyright (c) 2013 Richard Zimmerman
//
#include "core.h"
#include "settings.h"
#include <unistd.h>
#include <signal.h>
bool bTermSignal = false;
void signal_callback_handler(int signum)
{
printf("Caught signal %d\n",signum);
bTermSignal = true;
}
int main(int argc, char **argv)
{
// Register signal handlers
signal(SIGTERM, signal_callback_handler);
signal(SIGINT, signal_callback_handler);
char * logfile = 0;
int c = -1;
while ((c = getopt(argc, argv, "?L:Vv")) != -1)
switch (c)
{
case 'L':
logfile = optarg;
break;
case 'V':
case 'v':
fprintf(stderr, "Version %s\n", VERSION);
return 0;
break;
case '?':
if (optopt == 'L')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else
fprintf (stderr, "Usage: %s [ -L(LOGFILE) ]'.\n", argv[0]);
return 1;
default:
return 1;
}
if (logfile)
{
if (freopen(logfile, "a", stdout) == 0)
{
trace("FILE OUTPUT to %s FAILED!\n", logfile);
return 1;
}
}
trace("Starting v%s..\n", VERSION);
while (!bTermSignal)
{
mainLoop();
usleep(1000); // sleep for 1 ms
}
trace("Exiting.\n");
return 0;
}