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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* Copyright 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 class Config : KeyFile {
public Config() throws Error {
if(!load_from_file("microcopter.cfg", KeyFileFlags.NONE)) {
throw new FileError.FAILED("Could not load configuration file");;
}
}
public MotorController get_motor_controller() throws Error {
string name = get_string("config", "motorcontroller");
string path = Path.build_path("/", Environment.get_variable("PWD"), "actuators", "motor", "%s.so".printf(name));
var plugin = new PluginLoader<MotorController>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public Gyroscope get_gyroscope() throws Error {
string name = get_string("config", "gyroscope");
string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "gyroscope", "%s.so".printf(name));
var plugin = new PluginLoader<Gyroscope>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public Barometer get_barometer() throws Error {
string name = get_string("config", "barometer");
string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "barometer", "%s.so".printf(name));
var plugin = new PluginLoader<Barometer>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public Accelerometer get_accelerometer() throws Error {
string name = get_string("config", "accelerometer");
string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "accelerometer", "%s.so".printf(name));
var plugin = new PluginLoader<Accelerometer>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public Compass get_compass() throws Error {
string name = get_string("config", "compass");
string path = Path.build_path("/", Environment.get_variable("PWD"), "sensors", "compass", "%s.so".printf(name));
var plugin = new PluginLoader<Compass>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public CopterModel get_model() throws Error {
string name = get_string("config", "model");
string path = Path.build_path("/", Environment.get_variable("PWD"), "ctrl", "models", "%s.so".printf(name));
var plugin = new PluginLoader<CopterModel>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
public Receiver get_receiver() throws Error {
string name = get_string("config", "receiver");
string path = Path.build_path("/", Environment.get_variable("PWD"), "receiver", "%s.so".printf(name));
var plugin = new PluginLoader<Receiver>(path);
if(!plugin.load())
throw new KeyFileError.INVALID_VALUE("Could not load Plugin");
var result = plugin.new_object();
result.init(this);
return result;
}
}
|