/* Copyright 2012, Sebastian Reichel * * 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Engine 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Gyroscope 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Barometer 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Accelerometer 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Compass 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load CopterModel 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(path); if(!plugin.load()) throw new KeyFileError.INVALID_VALUE("Could not load Receiver Plugin"); var result = plugin.new_object(); result.init(this); return result; } }