-
Notifications
You must be signed in to change notification settings - Fork 3
/
light2300.c
81 lines (70 loc) · 1.89 KB
/
light2300.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* open2300 - light2300.c
*
* Version 1.10
*
* Control WS2300 weather station
*
* Copyright 2003-2005, Kenneth Lavrsen
* This program is published under the GNU General Public license
*/
#include "rw2300.h"
/********************************************************************
* print_usage prints a short user guide
*
* Input: none
*
* Output: prints to stdout
*
* Returns: exits program
*
********************************************************************/
void print_usage(void)
{
printf("\n");
printf("light2300 - Control background light of a WS-2300 weather station\n");
printf("Version %s (C)2003-2004 Kenneth Lavrsen.\n", VERSION);
printf("This program is released under the GNU General Public License (GPL)\n\n");
printf("Usage:\n");
printf("Turn light off: light2300 off config_filename\n");
printf("Turn light on: light2300 on config_filename\n");
exit(0);
}
/********** MAIN PROGRAM ************************************************
*
* Control background light of a WS-2300 weather station
* and writes the data to a log file.
*
* Just run the program without parameters for usage.
*
* It takes two parameters. The first is the log filename with path
* The second is the config file name with path
* If this parameter is omitted the program will look at the default paths
* See the open2300.conf-dist file for info
*
***********************************************************************/
int main(int argc, char *argv[])
{
WEATHERSTATION ws2300;
struct config_type config;
if (argc < 2 || argc > 3)
{
print_usage();
}
get_configuration(&config, argv[2]);
ws2300 = open_weatherstation(config.serial_device_name);
/* Get on or off */
if (strcmp(argv[1],"on") == 0)
{
light(ws2300,1);
}
else if (strcmp(argv[1],"off") == 0)
{
light(ws2300,0);
}
else
{
print_usage();
}
close_weatherstation(ws2300);
return (0);
}