summaryrefslogtreecommitdiffstats
path: root/demo.vala
blob: 0262edb70d84ea768ea6bd2ec2708fd9eba3425e (plain)
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
/* demo.vala
 * Copyright (c) 2012, Sebastian Reichel <sre@ring0.de>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

public static int main(string[] args) {
	var station = new Weather.Station();

	if(station == null) {
		stderr.printf("weather station not found!\n");
		return 1;
	}

	var header = station.read_header();
	var data = station.read_data(header.history_data_stack);

	/* print some infos from the header */
	stdout.printf("interval: %d\n", header.sampling_interval);
	stdout.printf("stack addr: 0x%04x\n", header.history_data_stack);
	stdout.printf("stack size: %d\n\n", header.history_data_sets);

	/* print content of the current data set */
	stdout.printf("Valid: %s\n", (data.status & Weather.Status.INVALID_DATA) == 0 ? "yes" : "no");
	stdout.printf("Temperature Indoor: %.1f°C\n", data.temperature_indoor/10.0);
	stdout.printf("Humidity Indoor: %d%%\n", data.humidity_indoor);
	stdout.printf("Temperature Outdoor: %.1f°C\n", data.temperature_outdoor/10.0);
	stdout.printf("Humidity Outdoor: %d%%\n", data.humidity_outdoor);
	stdout.printf("Pressure: %.1f hPa\n", data.pressure/10.0);
	stdout.printf("Wind Direction: %s\n", data.wind_direction.to_string());
	stdout.printf("Wind Speed: %.1f m/s\n", data.avg_wind_speed/10.0);
	stdout.printf("Wind Gust: %.1f m/s\n", data.gust_wind_speed/10.0);
	stdout.printf("Total Rain: %.1f mm\n", data.rain*0.3);

	return 0;
}