예제 #1
0
        /// <summary>
        /// Looks at the queue that has calibration requests and handles
        /// them in the order they were received
        /// </summary>
        private void calibrationHandlerThread()
        {
            while (!_exitThread)
            {
                Log.Debug("Waiting for item");
                var obj = calibrationQueue.Dequeue();
                Log.Debug("Got item");

                if (obj is String)
                {
                    return;
                }

                if (obj is ActuatorEx)
                {
                    _calibratingActuatorEx = obj as ActuatorEx;
                    Log.Debug("Before start calib");
                    var actuator = _calibratingActuatorEx;
                    actuator.StartCalibration();
                    Log.Debug("after start calib");

                    Log.Debug("Waiting for calib for " + actuator.SourceActuator.Name);

                    actuator.WaitForCalibration();
                }
            }
        }
예제 #2
0
 /// <summary>
 /// The actuator should invoke this function to indicate end
 /// of calibration.
 /// </summary>
 /// <param name="source">actuator being calibrated</param>
 /// <param name="errorMessage">any error during calibration?</param>
 /// <param name="enableConfigure">should the "configure" be enabled</param>
 public void OnEndCalibration(IActuator source, String errorMessage = "", bool enableConfigure = true)
 {
     Log.Debug("Entered ActuatorManger.EndCalibration");
     if (isCalibratingActuator(source))
     {
         calibratingActuatorEx.OnEndCalibration(errorMessage, enableConfigure);
         Log.Debug("SETTING CALIBRATINGACUTAOTRX to NULL");
         calibratingActuatorEx = null;
     }
 }
예제 #3
0
        /// <summary>
        /// The actuator should invoke this function to indicate end
        /// of calibration.
        /// </summary>
        /// <param name="source">actuator being calibrated</param>
        /// <param name="errorMessage">any error during calibration?</param>
        /// <param name="enableConfigure">should the "configure" be enabled</param>
        public void OnEndCalibration(IActuator source, String errorMessage = "", bool enableConfigure = true)
        {
            Log.Debug();
            Log.Debug("Calling isCalibratingActuator");

            if (isCalibratingActuator(source))
            {
                _calibratingActuatorEx.OnEndCalibration(errorMessage, enableConfigure);

                Log.Debug("Setting calibratingActuatorEx to null");
                _calibratingActuatorEx = null;
            }
        }
예제 #4
0
        /// <summary>
        /// Invoked when calibration is canceled for the
        /// specified actuator
        /// </summary>
        /// <param name="source">source actuator</param>
        public void OnCalibrationCanceled(IActuator source)
        {
            source.OnCalibrationCanceled();

            Log.Debug("Entered ActuatorManger.OnCalibrationCanceled");
            if (isCalibratingActuator(source))
            {
                source.OnCalibrationCanceled();

                _calibratingActuatorEx.OnEndCalibration();
                _calibratingActuatorEx = null;
            }
        }
예제 #5
0
        public void OnCalibrationCanceled(IActuator source)
        {
            source.OnCalibrationCanceled();

            Log.Debug("Entered ActuatorManger.OnCalibrationCanceled");
            if (isCalibratingActuator(source))
            {
                source.OnCalibrationCanceled();

                calibratingActuatorEx.OnEndCalibration();
                calibratingActuatorEx = null;

                //Debug.WriteLine("CANCELED!! SETTING CALIBRATINGACUTAOTRX to NULL");
                //calibratingActuatorEx = null;
            }
        }
예제 #6
0
파일: Actuators.cs 프로젝트: weberjavi/acat
        /// <summary>
        /// Parses the "Actuators" root element in the XML file and
        /// create a list of actuators. Also loads the attributes for
        /// each actuator
        /// </summary>
        /// <param name="configFile">Name of the XML config file</param>
        /// <returns></returns>
        public bool Load(IEnumerable <String> extensionDirs, String configFile, bool recursive = true)
        {
            addKeyboardActuatorToCache();

            foreach (string dir in extensionDirs)
            {
                String extensionDir = dir + "\\" + ActuatorManager.ActuatorsRootDir;
                loadActuatorTypesIntoCache(extensionDir, recursive);
            }

            var doc = new XmlDocument();

            if (!File.Exists(configFile))
            {
                return(false);
            }

            doc.Load(configFile);

            var actuatorNodes = doc.SelectNodes("/ACAT/Actuators/Actuator");

            if (actuatorNodes == null)
            {
                return(false);
            }

            // enumerate all the actuator nodes, create an object and add it
            // to the collection only if the enabled attribute is set
            foreach (XmlNode node in actuatorNodes)
            {
                try
                {
                    bool   enabled = XmlUtils.GetXMLAttrBool(node, "enabled", false);
                    String id      = XmlUtils.GetXMLAttrString(node, "id");
                    String name    = XmlUtils.GetXMLAttrString(node, "name");
                    if (enabled && !String.IsNullOrEmpty(id))
                    {
                        Guid guid;
                        if (Guid.TryParse(id, out guid))
                        {
                            if (_actuatorsTypeCache.ContainsKey(guid))
                            {
                                var type = _actuatorsTypeCache[guid];
                                if (type != null)
                                {
                                    // allow the actuator to load its info from the XML file
                                    var assembly = Assembly.LoadFrom(type.Assembly.Location);
                                    var actuator = (IActuator)assembly.CreateInstance(type.FullName);
                                    if (actuator != null)
                                    {
                                        actuator.Load(node);
                                        actuator.Name = name;
                                        var actuatorEx = new ActuatorEx(actuator);
                                        _actuatorsEx.Add(actuatorEx);
                                        _actuators.Add(actuator);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }

            return(true);
        }
예제 #7
0
파일: Actuators.cs 프로젝트: glwu/acat
        /// <summary>
        /// Parses the "Actuators" root element in the XML file and
        /// create a list of actuators. Also loads the attributes for
        /// each actuator
        /// </summary>
        /// <param name="configFile">Name of the XML config file</param>
        /// <returns></returns>
        public bool Load(IEnumerable<String> extensionDirs, String configFile, bool recursive = true)
        {
            addKeyboardActuatorToCache();

            foreach (string dir in extensionDirs)
            {
                String extensionDir = dir + "\\" + ActuatorManager.ActuatorsRootDir;
                loadActuatorTypesIntoCache(extensionDir, recursive);
            }

            var doc = new XmlDocument();

            if (!File.Exists(configFile))
            {
                return false;
            }

            doc.Load(configFile);

            var actuatorNodes = doc.SelectNodes("/ACAT/Actuators/Actuator");

            if (actuatorNodes == null)
            {
                return false;
            }

            // enumerate all the actuator nodes, create an object and add it
            // to the collection only if the enabled attribute is set
            foreach (XmlNode node in actuatorNodes)
            {
                try
                {
                    bool enabled = XmlUtils.GetXMLAttrBool(node, "enabled", false);
                    String id = XmlUtils.GetXMLAttrString(node, "id");
                    String name = XmlUtils.GetXMLAttrString(node, "name");
                    if (enabled && !String.IsNullOrEmpty(id))
                    {
                        Guid guid;
                        if (Guid.TryParse(id, out guid))
                        {
                            if (_actuatorsTypeCache.ContainsKey(guid))
                            {
                                var type = _actuatorsTypeCache[guid];
                                if (type != null)
                                {
                                    // allow the actuator to load its info from the XML file
                                    var assembly = Assembly.LoadFrom(type.Assembly.Location);
                                    var actuator = (IActuator)assembly.CreateInstance(type.FullName);
                                    if (actuator != null)
                                    {
                                        actuator.Load(node);
                                        actuator.Name = name;
                                        var actuatorEx = new ActuatorEx(actuator);
                                        _actuatorsEx.Add(actuatorEx);
                                        _actuators.Add(actuator);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }

            return true;
        }
예제 #8
0
        /// <summary>
        /// Loads actuator settigns from the settings file.
        /// Walks through the extensions dirs, looks for actuators in there
        /// and caches the Types of the actuators.
        /// Configures the actuators with the settings from the settings file.
        /// Also if any acutators were discovered that are not in the settings file,
        /// adds them to the settings file and saves it.
        /// </summary>
        /// <param name="extensionDirs">directories to walk through</param>
        /// <param name="configFile">name of the actuators settings file</param>
        /// <param name="loadAll">whether to load even the disabled actuators</param>
        /// <returns>true on success</returns>
        public bool Load(IEnumerable <String> extensionDirs, String configFile, bool loadAll = false)
        {
            addKeyboardActuatorToCache();

            foreach (string dir in extensionDirs)
            {
                String extensionDir = dir + "\\" + ActuatorManager.ActuatorsRootDir;
                loadActuatorTypesIntoCache(extensionDir);
            }

            if (!File.Exists(configFile))
            {
                return(false);
            }

            ActuatorConfig.ActuatorSettingsFileName = configFile;
            Config = ActuatorConfig.Load();

            // walk through the settings file create and configure
            // actuators
            foreach (var actuatorSetting in Config.ActuatorSettings)
            {
                try
                {
                    bool enabled = (loadAll) || actuatorSetting.Enabled;
                    if (enabled && (actuatorSetting.Id != Guid.Empty))
                    {
                        if (!_actuatorsTypeCache.ContainsKey(actuatorSetting.Id))
                        {
                            continue;
                        }

                        var type = _actuatorsTypeCache[actuatorSetting.Id];
                        if (type != null)
                        {
                            var assembly = Assembly.LoadFrom(type.Assembly.Location);
                            var actuator = (IActuator)assembly.CreateInstance(type.FullName);
                            if (actuator != null)
                            {
                                actuator.OnRegisterSwitches();
                                actuator.Load(actuatorSetting.SwitchSettings);
                                actuator.Enabled = actuatorSetting.Enabled;
                                var actuatorEx = new ActuatorEx(actuator);
                                _actuatorsEx.Add(actuatorEx);
                                _actuators.Add(actuator);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }

            // now go through all the actuators that are not in the
            // settings file and add them to the settings file

            bool isDirty = false;

            foreach (var actuatorType in _actuatorsTypeCache.Values)
            {
                var attr = DescriptorAttribute.GetDescriptor(actuatorType);
                if (attr != null && attr.Id != Guid.Empty)
                {
                    var actuatorSetting = Config.Find(attr.Id);
                    if (actuatorSetting != null)
                    {
                        continue;
                    }

                    try
                    {
                        var assembly = Assembly.LoadFrom(actuatorType.Assembly.Location);
                        var actuator = (IActuator)assembly.CreateInstance(actuatorType.FullName);
                        if (actuator != null)
                        {
                            var actuatorEx = new ActuatorEx(actuator);
                            _actuatorsEx.Add(actuatorEx);
                            _actuators.Add(actuator);

                            actuatorSetting = new ActuatorSetting(attr.Name, attr.Id);
                            Config.ActuatorSettings.Add(actuatorSetting);

                            actuator.OnRegisterSwitches();
                            actuator.Load(actuatorSetting.SwitchSettings);

                            isDirty = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                    }
                }
            }

            if (isDirty)
            {
                Config.Save();
            }

            return(true);
        }
예제 #9
0
        /// <summary>
        /// Looks at the queue that has calibration requests and handles
        /// them in the order they were received
        /// </summary>
        private void calibrationHandlerThread()
        {
            while (!_exitThread)
            {
                Log.Debug("Waiting for item");
                var obj = calibrationQueue.Dequeue();
                Log.Debug("Got item");

                if (obj is String)
                {
                    return;
                }

                if (obj is ActuatorEx)
                {
                    calibratingActuatorEx = obj as ActuatorEx;
                    Log.Debug("Before start calib");
                    var actuator = calibratingActuatorEx;
                    calibratingActuatorEx.StartCalibration();
                    Log.Debug("after start calib");

                    Log.Debug("Waiting for calib for " + actuator.SourceActuator.Name);

                    actuator.WaitForCalibration();
                }
            }
        }
예제 #10
0
 /// <summary>
 /// The actuator should invoke this function to indicate end
 /// of calibration. 
 /// </summary>
 /// <param name="source">actuator being calibrated</param>
 /// <param name="errorMessage">any error during calibration?</param>
 /// <param name="enableConfigure">should the "configure" be enabled</param>
 public void OnEndCalibration(IActuator source, String errorMessage = "", bool enableConfigure = true)
 {
     Log.Debug("Entered ActuatorManger.EndCalibration");
     if (isCalibratingActuator(source))
     {
         calibratingActuatorEx.OnEndCalibration(errorMessage, enableConfigure);
         Log.Debug("SETTING CALIBRATINGACUTAOTRX to NULL");
         calibratingActuatorEx = null;
     }
 }
예제 #11
0
        public void OnCalibrationCanceled(IActuator source)
        {
            source.OnCalibrationCanceled();

            Log.Debug("Entered ActuatorManger.OnCalibrationCanceled");
            if (isCalibratingActuator(source))
            {
                source.OnCalibrationCanceled();

                calibratingActuatorEx.OnEndCalibration();
                calibratingActuatorEx = null;

                //Debug.WriteLine("CANCELED!! SETTING CALIBRATINGACUTAOTRX to NULL");
                //calibratingActuatorEx = null;
            }
        }