Exemplo n.º 1
0
 /// <summary><see cref="object.ToString"/></summary>
 public override string ToString()
 {
     return(GetType().Name
            + "\n\t" + nameof(Model) + ": " + Model.File.Name
            + "\n\t" + nameof(InputChannels) + ": " + string.Join(", ", InputChannels.ToArray())
            + "\n\t" + nameof(OutputChannels) + ": " + string.Join(", ", OutputChannels.ToArray()));
 }
Exemplo n.º 2
0
        public ThisPCStats()
        {
            this.DeviceName = "This PC Stats";
            CPU_Ussage      = new InputChannelTypes.JoyAxis("CPU Ussage", "Percentage of total CPU in use")
            {
                min_Value = 0, max_Value = 1
            };
            Memory_Ussage = new InputChannelTypes.JoyAxis("Memory Used", "Memory used in MB")
            {
                min_Value = 0, max_Value = 0
            };
            Memory_Percent = new InputChannelTypes.JoyAxis("Memory Percentage", "Percentage of total memory in use")
            {
                min_Value = 0, max_Value = 1
            };
            Memory_Total = new InputChannelTypes.JoyAxis("Total Memory", "Total system memory in MB")
            {
                min_Value = 0, max_Value = 0
            };
            Battery_Percent = new InputChannelTypes.JoyAxis("Battery Percentage", "Percentage of battery remaining")
            {
                min_Value = 0, max_Value = 1
            };

            InputChannels.Add(CPU_Ussage);
            InputChannels.Add(Memory_Ussage);
            InputChannels.Add(Memory_Total);
            InputChannels.Add(Memory_Percent);
            InputChannels.Add(Battery_Percent);

            MonitoringThread = new Thread(monitoringThread);
            MonitoringThread.Start();
        }
Exemplo n.º 3
0
        public override void CreateChannels()
        {
            for (var i = 0; i < StandardInputChannelsCount; i++)
            {
                if (InputChannels.ContainsKey(i))
                {
                    continue;
                }

                var channel = new FyyingInputChannel(i);
                channel.Parent = this;
                //channel.ValueChanged += (obj, args) => { OnChannelValueChanged(args); };

                InputChannels.Add(i, channel);
            }

            for (var i = 0; i < StandardOutputChannelsCount; i++)
            {
                if (OutputChannels.ContainsKey(i))
                {
                    continue;
                }

                var channel = new FyyingOutputChannel(i);
                channel.Parent = this;
                //channel.ValueChanged += (obj, args) => { OnChannelValueChanged(args); };

                OutputChannels.Add(i, channel);
            }
        }
Exemplo n.º 4
0
 internal void GetSignalNameList()
 {
     _model.InputSignals = InputChannels.Select(x => x.PMUName + "_" + x.SignalName).ToList();
     if (_model is CorrelationCoefficient && _model.InputSignals.Count() != 2)
     {
         throw new Exception("Correlation coefficient signature calculation needs exact 2 input signals.");
     }
 }
 internal void GetSignalNameList()
 {
     if (_model is PMUflagFilt)
     {
         _model.InputSignals = InputChannels.Select(x => x.PMUName).ToList();
     }
     else
     {
         _model.InputSignals = InputChannels.Select(x => x.PMUName + "_" + x.SignalName).ToList();
     }
 }
Exemplo n.º 6
0
        public string EncodeParameter()
        {
            string res = string.Empty;

            res += InWidth.ToString() + " ";
            res += InHeight.ToString() + " ";
            res += InputChannels.ToString() + " ";
            res += OutWidth.ToString() + " ";
            res += OutHeight.ToString() + " ";
            res += OutputChannels.ToString() + " ";
            EncodeParameterCore(ref res);
            return(res);
        }
Exemplo n.º 7
0
        public ScDs3Device(int deviceNum, RootHub rootHub)
        {
            this.rootHub    = rootHub;
            this.deviceNum  = deviceNum;
            this.DeviceName = "Dualshock 3 controller " + deviceNum + 1;
            this.StatusIcon = Properties.Resources._128.ToImageSource();

            InputChannels.Add(deviceClass.Circle);
            InputChannels.Add(deviceClass.Cross);
            InputChannels.Add(deviceClass.Square);
            InputChannels.Add(deviceClass.Triangle);

            InputChannels.Add(deviceClass.vCircle);
            InputChannels.Add(deviceClass.vCross);
            InputChannels.Add(deviceClass.vSquare);
            InputChannels.Add(deviceClass.vTriangle);

            InputChannels.Add(deviceClass.LSx);
            InputChannels.Add(deviceClass.LSy);
            InputChannels.Add(deviceClass.RSx);
            InputChannels.Add(deviceClass.RSy);

            InputChannels.Add(deviceClass.L1);
            InputChannels.Add(deviceClass.L2);
            InputChannels.Add(deviceClass.L3);
            InputChannels.Add(deviceClass.R1);
            InputChannels.Add(deviceClass.R2);
            InputChannels.Add(deviceClass.R3);

            InputChannels.Add(deviceClass.PS);
            InputChannels.Add(deviceClass.Select);
            InputChannels.Add(deviceClass.Start);

            InputChannels.Add(deviceClass.DUp);
            InputChannels.Add(deviceClass.DDown);
            InputChannels.Add(deviceClass.DLeft);
            InputChannels.Add(deviceClass.DRight);

            OutputChannels.Add(deviceClass.BigRumble);
            OutputChannels.Add(deviceClass.SmallRumble);
            OutputChannels.Add(deviceClass.LightBar);

            (rootHub.Pad[deviceNum] as UsbDevice).Report += RootHub_USBReport;
        }
        public override void RemoveSignal(SignalViewModel signal)
        {
            if (_model is Filter)
            {
                InputChannels.Remove(signal);
                OutputChannels.Remove(signal);
            }
            else
            {//need to remove the output signal depends on type of customization
                switch (Name)
                {
                case "Subtraction":
                    break;

                default:
                    break;
                }
            }
        }
 public override void AddSignal(SignalViewModel signal)
 {
     if (_model is Filter)
     {
         InputChannels.Add(signal); // Override baseclass function
         OutputChannels.Add(signal);
     }
     else
     {
         switch (Name)
         {
         //case "Status Flags":
         //case "Zeros":
         //case "Missing":
         //case "Nominal Voltage":
         //case "Nominal Frequency":
         //    break;
         case "Subtraction":
             // Set parameter
             SetFocusedTextBox(signal);     // if step is a customization, need to make up the output signal from input signal depends on type of customizaion
             break;
         }
     }
 }
Exemplo n.º 10
0
        public void Save(string location)
        {
            var mloc = new System.IO.DirectoryInfo(location);

            if (mloc.Exists)
            {
                mloc.Delete(true);
            }
            mloc.Create();
            #region ModelBaseFile Create
            string text = this.GetType().ToString() + "\n";
            text += Epoch + " " + Generation + " " + ReverseStartBlock + " " + Error + "\n";
            text += InputChannels.ToString() + " " + InputWidth.ToString() + " " + InputHeight.ToString() + "\n";
            text += "!!!!!!!!!!!!!!!>";
            string[] tmp = new string[LayerCount];
            for (int i = 0; i < LayerCount; i++)
            {
                tmp[i] = Layer[i].Encode();
            }
            foreach (var item in tmp)
            {
                text += item;
            }
            #endregion
            #region ModelParameterFile
            var ploc = new System.IO.DirectoryInfo(location + @"\parameter");
            ploc.Create();
            Tasks.ForParallel(0, LayerCount, i => { Layer[i].Variable.SaveObject(ploc); });
            #endregion
            #region ModelBaseFile Save
            using (var fs = new System.IO.StreamWriter(location + @"\" + "model" + ".mdl", false))
            {
                fs.WriteLine(text);
            }
            #endregion
        }
Exemplo n.º 11
0
        public LiveSimulation(Circuit.Schematic Simulate, Audio.Device Device, Audio.Channel[] Inputs, Audio.Channel[] Outputs)
        {
            try
            {
                InitializeComponent();

                // Make a clone of the schematic so we can mess with it.
                Circuit.Schematic clone = Circuit.Schematic.Deserialize(Simulate.Serialize(), Log);
                clone.Elements.ItemAdded   += OnElementAdded;
                clone.Elements.ItemRemoved += OnElementRemoved;
                Schematic = new SimulationSchematic(clone);
                Schematic.SelectionChanged += OnProbeSelected;

                // Build the circuit from the schematic.
                circuit = Schematic.Schematic.Build(Log);

                // Create the input and output controls.
                IEnumerable <Circuit.Component> components = circuit.Components;

                // Create audio input channels.
                for (int i = 0; i < Inputs.Length; ++i)
                {
                    InputChannels.Add(new InputChannel(i)
                    {
                        Name = Inputs[i].Name
                    });
                }

                ComputerAlgebra.Expression speakers = 0;

                foreach (Circuit.Component i in components)
                {
                    Circuit.Symbol S = i.Tag as Circuit.Symbol;
                    if (S == null)
                    {
                        continue;
                    }

                    SymbolControl tag = (SymbolControl)S.Tag;
                    if (tag == null)
                    {
                        continue;
                    }

                    // Create potentiometers.
                    Circuit.IPotControl c = i as Circuit.IPotControl;
                    if (c != null)
                    {
                        PotControl pot = new PotControl()
                        {
                            Width      = 80,
                            Height     = 80,
                            Opacity    = 0.5,
                            FontSize   = 15,
                            FontWeight = FontWeights.Bold,
                        };
                        Schematic.overlays.Children.Add(pot);
                        Canvas.SetLeft(pot, Canvas.GetLeft(tag) - pot.Width / 2 + tag.Width / 2);
                        Canvas.SetTop(pot, Canvas.GetTop(tag) - pot.Height / 2 + tag.Height / 2);

                        pot.Value         = c.PotValue;
                        pot.ValueChanged += x => { c.PotValue = x; UpdateSimulation(false); };

                        pot.MouseEnter += (o, e) => pot.Opacity = 0.95;
                        pot.MouseLeave += (o, e) => pot.Opacity = 0.5;
                    }

                    // Create Buttons.
                    Circuit.IButtonControl b = i as Circuit.IButtonControl;
                    if (b != null)
                    {
                        Button button = new Button()
                        {
                            Width      = tag.Width,
                            Height     = tag.Height,
                            Opacity    = 0.5,
                            Background = Brushes.White,
                        };
                        Schematic.overlays.Children.Add(button);
                        Canvas.SetLeft(button, Canvas.GetLeft(tag));
                        Canvas.SetTop(button, Canvas.GetTop(tag));

                        button.Click += (o, e) =>
                        {
                            // Click all the buttons in the group.
                            foreach (Circuit.IButtonControl j in components.OfType <Circuit.IButtonControl>().Where(x => x.Group == b.Group))
                            {
                                j.Click();
                            }
                            UpdateSimulation(true);
                        };

                        button.MouseEnter += (o, e) => button.Opacity = 0.95;
                        button.MouseLeave += (o, e) => button.Opacity = 0.5;
                    }

                    Circuit.Speaker output = i as Circuit.Speaker;
                    if (output != null)
                    {
                        speakers += output.V;
                    }

                    // Create input controls.
                    Circuit.Input input = i as Circuit.Input;
                    if (input != null)
                    {
                        tag.ShowText = false;

                        ComboBox combo = new ComboBox()
                        {
                            Width             = 80,
                            Height            = 24,
                            Opacity           = 0.5,
                            IsEditable        = true,
                            SelectedValuePath = "Tag",
                        };

                        foreach (InputChannel j in InputChannels)
                        {
                            combo.Items.Add(new ComboBoxItem()
                            {
                                Tag     = j,
                                Content = j.Name
                            });
                        }

                        Schematic.overlays.Children.Add(combo);
                        Canvas.SetLeft(combo, Canvas.GetLeft(tag) - combo.Width / 2 + tag.Width / 2);
                        Canvas.SetTop(combo, Canvas.GetTop(tag) - combo.Height / 2 + tag.Height / 2);

                        ComputerAlgebra.Expression V = Circuit.Component.DependentVariable(input.Name, Circuit.Component.t);
                        inputs[V] = new SignalChannel(0);

                        combo.SelectionChanged += (o, e) =>
                        {
                            if (combo.SelectedItem != null)
                            {
                                ComboBoxItem it = (ComboBoxItem)combo.SelectedItem;
                                inputs[V] = new InputChannel(((InputChannel)it.Tag).Index);
                            }
                        };

                        combo.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler((o, e) =>
                        {
                            try
                            {
                                inputs[V] = new SignalChannel(Circuit.Quantity.Parse(combo.Text, Circuit.Units.V));
                            }
                            catch (Exception)
                            {
                                // If there is an error in the expression, zero out the signal.
                                inputs[V] = new SignalChannel(0);
                            }
                        }));

                        if (combo.Items.Count > 0)
                        {
                            combo.SelectedItem = combo.Items[0];
                        }
                        else
                        {
                            combo.Text = "0 V";
                        }

                        combo.MouseEnter += (o, e) => combo.Opacity = 0.95;
                        combo.MouseLeave += (o, e) => combo.Opacity = 0.5;
                    }
                }

                // Create audio output channels.
                for (int i = 0; i < Outputs.Length; ++i)
                {
                    OutputChannel c = new OutputChannel(i)
                    {
                        Name = Outputs[i].Name, Signal = speakers
                    };
                    c.PropertyChanged += (o, e) => { if (e.PropertyName == "Signal")
                                                     {
                                                         RebuildSolution();
                                                     }
                    };
                    OutputChannels.Add(c);
                }


                // Begin audio processing.
                if (Inputs.Any() || Outputs.Any())
                {
                    stream = Device.Open(ProcessSamples, Inputs, Outputs);
                }
                else
                {
                    stream = new NullStream(ProcessSamples);
                }

                ContentRendered += (o, e) => RebuildSolution();

                Closed += (s, e) => stream.Stop();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 12
0
 internal void GetSamplingRAte()
 {
     _model.SamplingRate = InputChannels.FirstOrDefault().SamplingRate;
 }
Exemplo n.º 13
0
 public virtual void RemoveSignal(SignalViewModel signal)
 {
     InputChannels.Remove(signal);
 }
Exemplo n.º 14
0
 internal void GetSignalNameList()
 {
     _model.InputSignals = InputChannels.Select(x => x.PMUName + "_" + x.SignalName).ToList();
 }
Exemplo n.º 15
0
        public SC360_Device_Plugin(int device, SettingGroup settings)
        {
            ControllerID    = device;
            this.settings   = settings;
            this.StatusIcon = new BitmapImage(new Uri(@"pack://application:,,,/SC360;component/Resources/360.ico"));
            this.DeviceName = "Controller " + ControllerID;

            x360device myDevice = new x360device();

            InputChannels.Add(myDevice.LSx);
            InputChannels.Add(myDevice.LSy);
            InputChannels.Add(myDevice.RSx);
            InputChannels.Add(myDevice.RSy);

            InputChannels.Add(myDevice.LS);
            InputChannels.Add(myDevice.RS);

            InputChannels.Add(myDevice.LT);
            InputChannels.Add(myDevice.RT);
            InputChannels.Add(myDevice.LB);
            InputChannels.Add(myDevice.RB);

            InputChannels.Add(myDevice.DUp);
            InputChannels.Add(myDevice.DDown);
            InputChannels.Add(myDevice.DLeft);
            InputChannels.Add(myDevice.DRight);

            InputChannels.Add(myDevice.A);
            InputChannels.Add(myDevice.B);
            InputChannels.Add(myDevice.X);
            InputChannels.Add(myDevice.Y);

            InputChannels.Add(myDevice.Start);
            InputChannels.Add(myDevice.Back);
            InputChannels.Add(myDevice.Guide);

            OutputChannels.Add(myDevice.SmallRumble);
            OutputChannels.Add(myDevice.BigRumble);

            if (SC360Globals.scBus.Open() && SC360Globals.scBus.Start())
            {
                SC360Globals.scBus.Plugin(device);

                if (settings.getSetting("Low latency mode"))
                {
                    byte[] Report = new byte[28];
                    byte[] Rumble = new byte[8];

                    foreach (DeviceChannel channel in InputChannels)
                    {
                        channel.PropertyChanged += (s, e) => {
                            SC360Globals.scBus.Parse(myDevice, Report, ControllerID);
                            if (SC360Globals.scBus.Report(Report, Rumble))
                            {
                                //    if (Rumble[1] == 0x08)
                                //    {
                                //        myDevice.SmallRumble.Value = Rumble[3];
                                //        myDevice.BigRumble.Value = Rumble[4];
                                //    }
                            }
                        };
                    }
                }
                else
                {
                    ReportingThread = new Thread(() => ReportingThreadLoop(myDevice));
                    ReportingThread.Start();
                }
            }
        }
Exemplo n.º 16
0
        public LiveSimulation(Schematic Simulate, Audio.Device Device, Audio.Channel[] Inputs, Audio.Channel[] Outputs)
        {
            try
            {
                InitializeComponent();

                // Make a clone of the schematic so we can mess with it.
                var clone = Circuit.Schematic.Deserialize(Simulate.Serialize(), Log);
                clone.Elements.ItemAdded   += OnElementAdded;
                clone.Elements.ItemRemoved += OnElementRemoved;
                Schematic = new SimulationSchematic(clone);
                Schematic.SelectionChanged += OnProbeSelected;

                // Build the circuit from the schematic.
                circuit = Schematic.Schematic.Build(Log);

                // Create the input and output controls.
                IEnumerable <Circuit.Component> components = circuit.Components;

                // Create audio input channels.
                for (int i = 0; i < Inputs.Length; ++i)
                {
                    InputChannels.Add(new InputChannel(i)
                    {
                        Name = Inputs[i].Name
                    });
                }

                ComputerAlgebra.Expression speakers = 0;

                foreach (Circuit.Component i in components)
                {
                    Symbol S = i.Tag as Symbol;
                    if (S == null)
                    {
                        continue;
                    }

                    SymbolControl tag = (SymbolControl)S.Tag;
                    if (tag == null)
                    {
                        continue;
                    }

                    // Create potentiometers.
                    if (i is IPotControl potentiometer)
                    {
                        var potControl = new PotControl()
                        {
                            Width      = 80,
                            Height     = 80,
                            Opacity    = 0.5,
                            FontSize   = 15,
                            FontWeight = FontWeights.Bold,
                        };
                        Schematic.Overlays.Children.Add(potControl);
                        Canvas.SetLeft(potControl, Canvas.GetLeft(tag) - potControl.Width / 2 + tag.Width / 2);
                        Canvas.SetTop(potControl, Canvas.GetTop(tag) - potControl.Height / 2 + tag.Height / 2);

                        var binding = new Binding
                        {
                            Source = potentiometer,
                            Path   = new PropertyPath("(0)", typeof(IPotControl).GetProperty(nameof(IPotControl.PotValue))),
                            Mode   = BindingMode.TwoWay,
                            NotifyOnSourceUpdated = true
                        };

                        potControl.SetBinding(PotControl.ValueProperty, binding);

                        potControl.AddHandler(Binding.SourceUpdatedEvent, new RoutedEventHandler((o, args) =>
                        {
                            if (!string.IsNullOrEmpty(potentiometer.Group))
                            {
                                foreach (var p in components.OfType <IPotControl>().Where(p => p != potentiometer && p.Group == potentiometer.Group))
                                {
                                    p.PotValue = (o as PotControl).Value;
                                }
                            }
                            UpdateSimulation(false);
                        }));

                        potControl.MouseEnter += (o, e) => potControl.Opacity = 0.95;
                        potControl.MouseLeave += (o, e) => potControl.Opacity = 0.5;
                    }

                    // Create Buttons.
                    if (i is IButtonControl b)
                    {
                        Button button = new Button()
                        {
                            Width      = tag.Width,
                            Height     = tag.Height,
                            Opacity    = 0.5,
                            Background = Brushes.White,
                        };
                        Schematic.Overlays.Children.Add(button);
                        Canvas.SetLeft(button, Canvas.GetLeft(tag));
                        Canvas.SetTop(button, Canvas.GetTop(tag));

                        button.Click += (o, e) =>
                        {
                            b.Click();
                            // Click all the buttons in the group.
                            if (!string.IsNullOrEmpty(b.Group))
                            {
                                foreach (var j in components.OfType <IButtonControl>().Where(x => x != b && x.Group == b.Group))
                                {
                                    j.Click();
                                }
                            }
                            UpdateSimulation(true);
                        };

                        button.MouseEnter += (o, e) => button.Opacity = 0.95;
                        button.MouseLeave += (o, e) => button.Opacity = 0.5;
                    }

                    if (i is Speaker output)
                    {
                        speakers += output.Out;
                    }

                    // Create input controls.
                    if (i is Input input)
                    {
                        tag.ShowText = false;

                        ComboBox combo = new ComboBox()
                        {
                            Width             = 80,
                            Height            = 24,
                            Opacity           = 0.5,
                            IsEditable        = true,
                            SelectedValuePath = "Tag",
                        };

                        foreach (InputChannel j in InputChannels)
                        {
                            combo.Items.Add(new ComboBoxItem()
                            {
                                Tag     = j,
                                Content = j.Name
                            });
                        }

                        Schematic.Overlays.Children.Add(combo);
                        Canvas.SetLeft(combo, Canvas.GetLeft(tag) - combo.Width / 2 + tag.Width / 2);
                        Canvas.SetTop(combo, Canvas.GetTop(tag) - combo.Height / 2 + tag.Height / 2);

                        ComputerAlgebra.Expression In = input.In;
                        inputs[In] = new SignalChannel(0);

                        combo.SelectionChanged += (o, e) =>
                        {
                            if (combo.SelectedItem != null)
                            {
                                ComboBoxItem it = (ComboBoxItem)combo.SelectedItem;
                                inputs[In] = new InputChannel(((InputChannel)it.Tag).Index);
                            }
                        };

                        combo.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler((o, e) =>
                        {
                            try
                            {
                                inputs[In] = new SignalChannel(ComputerAlgebra.Expression.Parse(combo.Text));
                            }
                            catch (Exception)
                            {
                                // If there is an error in the expression, zero out the signal.
                                inputs[In] = new SignalChannel(0);
                            }
                        }));

                        if (combo.Items.Count > 0)
                        {
                            combo.SelectedItem = combo.Items[0];
                        }
                        else
                        {
                            combo.Text = "0 V";
                        }

                        combo.MouseEnter += (o, e) => combo.Opacity = 0.95;
                        combo.MouseLeave += (o, e) => combo.Opacity = 0.5;
                    }
                }

                // Create audio output channels.
                for (int i = 0; i < Outputs.Length; ++i)
                {
                    OutputChannel c = new OutputChannel(i)
                    {
                        Name = Outputs[i].Name, Signal = speakers
                    };
                    c.PropertyChanged += (o, e) => { if (e.PropertyName == "Signal")
                                                     {
                                                         RebuildSolution();
                                                     }
                    };
                    OutputChannels.Add(c);
                }


                // Begin audio processing.
                if (Inputs.Any() || Outputs.Any())
                {
                    stream = Device.Open(ProcessSamples, Inputs, Outputs);
                }
                else
                {
                    stream = new NullStream(ProcessSamples);
                }

                ContentRendered += (o, e) => RebuildSolution();

                Closed += (s, e) => stream.Stop();

                timer = new System.Timers.Timer()
                {
                    Interval  = 100,
                    AutoReset = true,
                    Enabled   = true,
                };
                timer.Elapsed += timer_Elapsed;
                timer.Start();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }