Пример #1
0
        private void SerializeAnalyzers(XmlWriter writer, ObservableDictionary <IAnalyzer, ObservableDictionary <string, string> > analyzers)
        {
            writer.WriteStartElement("analyzers");
            foreach (IAnalyzer analyzer in analyzers.Keys)
            {
                writer.WriteStartElement("analyzer");

                if (analyzer is IAccelerometerAnalyzer)
                {
                    writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(analyzer as IAccelerometerAnalyzer));
                }
                else if (analyzer is IBalanceBoardAnalyzer)
                {
                    writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(analyzer as IBalanceBoardAnalyzer));
                }
                else if (analyzer is IEmgSignalAnalyzer)
                {
                    writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(analyzer as IEmgSignalAnalyzer));
                }
                else
                {
                    writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(analyzer as ISkeletonAnalyzer));
                }

                writeParams(writer, analyzers[analyzer]);

                writer.WriteEndElement();
            }
            writer.WriteEndElement();
        }
Пример #2
0
        private void SerializeDeviceAnalyzers(XmlWriter writer, string deviceName)
        {
            bool sectionStarted = false;


            if (_inputAnalyzers.Count == 0)
            {
                // THIS IS TEMPORARY SOLUTION TO SAVE C3D ANALYZER FOR DEVICE AS DEFAULT
                writer.WriteStartElement("analyzers");
                writer.WriteStartElement("analyzer");
                writer.WriteAttributeString("file", "C3DSerializer.dll");
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            else
            {
                foreach (InputAnalyzer a in _inputAnalyzers)
                {
                    if (a.Device.Name == deviceName)
                    {
                        if (!sectionStarted)
                        {
                            writer.WriteStartElement("analyzers");
                            sectionStarted = true;
                        }
                        writer.WriteStartElement("analyzer");
                        if (a.Analyzer is ISkeletonAnalyzer)
                        {
                            writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(a.Analyzer as ISkeletonAnalyzer));
                        }
                        else if (a.Analyzer is IAccelerometerAnalyzer)
                        {
                            writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(a.Analyzer as IAccelerometerAnalyzer));
                        }
                        else if (a.Analyzer is IBalanceBoardAnalyzer)
                        {
                            writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(a.Analyzer as IBalanceBoardAnalyzer));
                        }
                        else if (a.Analyzer is IEmgSignalAnalyzer)
                        {
                            writer.WriteAttributeString("file", InputAnalyzerManager.GetAnalyzerModuleName(a.Analyzer as IEmgSignalAnalyzer));
                        }

                        if (a.Parameters.Keys.Count > 0)
                        {
                            writeParams(writer, a.Parameters);
                        }
                        writer.WriteEndElement();
                    }
                }


                if (sectionStarted)
                {
                    writer.WriteEndElement();
                }
            }
        }
Пример #3
0
        private void ConfigureDevices(XPathNavigator navigator, Dictionary <string, IDevice> devices)
        {
            XPathNodeIterator deviceIt = navigator.Select("/Configuration/devices/device[@name]");

            while (deviceIt.MoveNext())
            {
                // parsing of attributes
                string deviceName = deviceIt.Current.GetAttribute("name", "");
                ObservableDictionary <string, string> parametersGroup = ParseParams(deviceIt.Current);

                if (!devices.ContainsKey(deviceName))
                {
                    string strDevices = "";
                    foreach (string str in devices.Keys)
                    {
                        strDevices += (str == "" ? "" : ",") + str;
                    }
                    UIThread.ShowMessage("", "Device " + deviceName + " was not found on this computer!\n " +
                                         devices.Count + " devices installed. \n(" + strDevices + ")");
                    continue;
                }

                IDevice d = devices[deviceName];
                if (!d.IsLoaded)
                {
                    try
                    {
                        d.LoadDriver(parametersGroup);
                    }
                    catch (InitializationFailedException ex)
                    {
                        //   MessageBox.Show(ex.Message, "ConfigureDevices: Unable to load driver", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        UIThread.ShowMessage("", ex.Message);
                        continue;
                    }
                }
                _deviceParameters.Add(deviceName, parametersGroup);

                if (Configuration.RegisteredInputs.Count == 0)
                {
                    continue;
                }

                ObservableDictionary <string, ObservableDictionary <string, string> > parameters = ParseAnalyzersParams(deviceIt.Current);
                foreach (string analyzerFile in parameters.Keys)
                {
                    if (d.GamingInput is ISkeletonInput)
                    {
                        ISkeletonAnalyzer analyzer = InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile);
                        if (analyzer == null)
                        {
                            Console.Error.WriteLine("ERROR: Analyzer " + analyzerFile + " could not be loaded!!!");
                        }
                        else
                        {
                            _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, analyzer));
                        }
                    }
                    else if (d.GamingInput is IAccelerometerInput)
                    {
                        _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetAccelerometerAnalyzer(analyzerFile)));
                    }
                    else if (d.GamingInput is IBalanceBoardInput)
                    {
                        _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetBalanceBoardAnalyzer(analyzerFile)));
                    }
                    else if (d.GamingInput is IEmgSensorInput)
                    {
                        _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetEmgSignalAnalyzer(analyzerFile)));
                    }
                }
            }
        }
Пример #4
0
        private void ConfigureBindings(XPathNavigator navigator, Dictionary <string, IDevice> devices)
        {
            XPathNodeIterator bindingIt = navigator.Select(
                "/Configuration/bindings/binding[@device and @point and @sensitivity]");

            while (bindingIt.MoveNext())
            {
                string deviceName = bindingIt.Current.GetAttribute("device", "");

                if (!devices.ContainsKey(deviceName))
                {
                    UIThread.ShowMessage("", "Device " + deviceName + " was not found on this computer!");
                    continue;
                }

                IDevice device = devices[deviceName];
                if (!device.IsLoaded)
                {
                    try
                    {
                        device.LoadDriver(null);
                    }
                    catch (InitializationFailedException ex)
                    {
                        // MessageBox.Show(ex.Message, "ConfigureBindings: Unable to load driver", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                }

                IGamingInput gamingInput = device.GamingInput;
                InputBinding binding     = null;

                string point = bindingIt.Current.GetAttribute("point", "");
                if (Configuration.GetHandle(point) == null)
                {
                    continue;
                }

                if (device.GamingInput is ISkeletonInput)
                {
                    binding = ConfigureSkeleton(navigator, bindingIt, (ISkeletonInput)device.GamingInput);
                    ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams =
                        ParseAnalyzersParams(bindingIt.Current);
                    foreach (string analyzerFile in analyzersParams.Keys)
                    {
                        if (binding is SkeletonBinding)
                        {
                            (binding as SkeletonBinding).AddAnalyzer(
                                InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile), analyzersParams[analyzerFile]);
                        }
                        else if (binding is AbsoluteSkeletonBinding)
                        {
                            (binding as AbsoluteSkeletonBinding).AddAnalyzer(
                                InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile), analyzersParams[analyzerFile]);
                        }
                    }
                }
                else if (gamingInput is IAccelerometerInput)
                {
                    binding = ConfigureAccelerometer(navigator, bindingIt, (IAccelerometerInput)device.GamingInput);
                    ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams =
                        ParseAnalyzersParams(bindingIt.Current);
                    foreach (string analyzerFile in analyzersParams.Keys)
                    {
                        if (binding is AccelerometerBinding)
                        {
                            (binding as AccelerometerBinding).AddAnalyzer(
                                InputAnalyzerManager.GetAccelerometerAnalyzer(analyzerFile), analyzersParams[analyzerFile]);
                        }
                    }
                }
                else if (gamingInput is IBalanceBoardInput)
                {
                    binding = ConfigureBalanceBoard(navigator, bindingIt, (IBalanceBoardInput)device.GamingInput);
                    ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams =
                        ParseAnalyzersParams(bindingIt.Current);

                    //
                    //  TODO add balance board analyzers processing
                    //
                    //foreach (string analyzerFile in analyzersParams.Keys)
                    //{
                    //    if (binding is BalanceBoardBinding)
                    //        (binding as BalanceBoardBinding).AddAnalyzer(
                    //            AnalysisManager.GetBAccelerometerAnalyzer(analyzerFile), analyzersParams[analyzerFile]);
                    //}
                }
                else if (gamingInput is IEmgSensorInput)
                {
                    binding = ConfigureEmgSensor(navigator, bindingIt, (IEmgSensorInput)device.GamingInput);
                    //ObservableDictionary<string, ObservableDictionary<string, string>> analyzerParams =
                    //                                    ParseAnalyzersParams(bindingIt.Current);
                }


                if (binding != null)
                {
                    this.AddOrReplace(binding);
                }
            }
        }