Beispiel #1
0
        /// <summary>
        /// This method detects and configures PacLed64 controllers automatically
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            foreach (int Id in PacDriveSingleton.Instance.PacLed64GetIdList())
            {
                if (!Cabinet.OutputControllers.Any(oc => oc is PacLed64 && ((PacLed64)oc).Id == Id))
                {
                    PacLed64 PL = new PacLed64();
                    PL.Id = Id;

                    if (!Cabinet.OutputControllers.Contains(PL.Name))
                    {
                        Cabinet.OutputControllers.Add(PL);

                        Log.Write("Detected and added PacLed64 Id {0} with name {1}".Build(PL.Id, PL.Name));


                        if (!!Cabinet.Toys.Any(T => T is LedWizEquivalent && (((LedWizEquivalent)T).LedWizNumber == ((PL.Id - 1) * 2) + 20 || ((LedWizEquivalent)T).LedWizNumber == ((PL.Id - 1) * 2) + 20 + 1)))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = (PL.Id - 1) * 2 + 20;
                            LWE.Name         = "{0} Equivalent 1".Build(PL.Name);
                            for (int i = 1; i <= 32; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(PL.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }
                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                            }

                            LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = (PL.Id - 1) * 2 + 20 + 1;
                            LWE.Name         = "{0} Equivalent 2".Build(PL.Name);
                            for (int i = 1; i <= 32; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(PL.Name, i + 32), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }
                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PacLed64 with Id {2}".Build(LWE.LedWizNumber, LWE.Name, PL.Id));
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method detects and configures Ultimate I/O controllers automatically
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            //Log.Write("ScheduleSettings name="+Cabinet.ScheduledSettings[0].Name+", clock="+ Cabinet.ScheduledSettings[0].ClockStart);

            //Log.Write("PacUIOAutoConfigurator.AutoConfig started");
            foreach (int Id in PacDriveSingleton.Instance.PacUIOGetIdList())
            {
                if (!Cabinet.OutputControllers.Any(oc => oc is PacUIO && ((PacUIO)oc).Id == Id))
                {
                    PacUIO PIO = new PacUIO();
                    PIO.Id = Id;

                    Log.Write("PacUIOAutoConfigurator.AutoConfig.. Detected " + PacDriveSingleton.Instance.GetProductName(Id) + "[" + PIO.Id + "], name=" + PIO.Name);

                    if (!Cabinet.OutputControllers.Contains(PIO.Name))
                    {
                        Cabinet.OutputControllers.Add(PIO);

                        Log.Write("Detected and added PacUIO Id {0} with name {1}".Build(PIO.Id, PIO.Name));

                        //+27 used to define start of directoutputconfig[27...].xml
                        if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == PIO.Id - 0 + 27))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = PIO.Id - 0 + 27;
                            LWE.Name         = "{0} Equivalent 1".Build(PIO.Name);
                            for (int i = 1; i <= 96; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(PIO.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }
                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PacUIO with Id {2}".Build(LWE.LedWizNumber, LWE.Name, PIO.Id));
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method detects and configures Pinscape output controllers automatically.
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            const int         UnitBias      = 50;
            List <int>        Preconfigured = new List <int>(Cabinet.OutputControllers.Where(OC => OC is Pinscape).Select(PS => ((Pinscape)PS).Number));
            IEnumerable <int> Numbers       = Pinscape.AllDevices().Select(d => d.UnitNo());

            foreach (int N in Numbers)
            {
                if (!Preconfigured.Contains(N))
                {
                    Pinscape p = new Pinscape(N);
                    if (!Cabinet.OutputControllers.Contains(p.Name))
                    {
                        Cabinet.OutputControllers.Add(p);
                        Log.Write("Detected and added Pinscape Controller Nr. {0} with name {1}".Build(p.Number, p.Name));

                        if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == p.Number + UnitBias))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = p.Number + UnitBias;
                            LWE.Name         = "{0} Equivalent".Build(p.Name);

                            for (int i = 1; i <= p.NumberOfOutputs; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(p.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }

                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for Pinscape Controller Nr. {2}".Build(
                                              LWE.LedWizNumber, LWE.Name, p.Number) + ", {0}".Build(p.NumberOfOutputs));
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// This method detects and configures LedWiz output controllers automatically.
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            List <int> Preconfigured = new List <int>(Cabinet.OutputControllers.Where(OC => OC is LedWiz).Select(LW => ((LedWiz)LW).Number));
            List <int> Numbers       = LedWiz.GetLedwizNumbers();

            foreach (int N in Numbers)
            {
                if (!Preconfigured.Contains(N))
                {
                    LedWiz LW = new LedWiz(N);
                    if (!Cabinet.OutputControllers.Contains(LW.Name))
                    {
                        Cabinet.OutputControllers.Add(LW);
                        Log.Write("Detected and added LedWiz Nr. {0} with name {1}".Build(LW.Number, LW.Name));


                        if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == LW.Number))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = LW.Number;
                            LWE.Name         = "{0} Equivalent".Build(LW.Name);

                            for (int i = 1; i < 33; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(LW.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }

                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for Ledwiz Nr. {2}".Build(LWE.LedWizNumber, LWE.Name, LW.Number));
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This method detects and configures a PacDrive output controller.
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            int Index = PacDriveSingleton.Instance.PacDriveGetIndex();

            if (Index >= 0)
            {
                if (!Cabinet.OutputControllers.Any(oc => oc is PacDrive))
                {
                    PacDrive PD = new PacDrive();
                    if (!Cabinet.OutputControllers.Contains(PD.Name))
                    {
                        Cabinet.OutputControllers.Add(PD);

                        Log.Write("Detected and added PacDrive");

                        if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == 19))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = 19;
                            LWE.Name         = "{0} Equivalent".Build(PD.Name);
                            for (int i = 1; i <= 16; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}.{1:00}".Build(PD.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }
                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PacDrive".Build(LWE.LedWizNumber, LWE.Name));
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets a array of bytes values re'presenting the data to be sent to the led strip.
        /// </summary>
        /// <returns></returns>
        private void SetOutputData()
        {
            if (Layers.Count > 0)
            {
                //Blend layers
                float[, ,] Value = new float[Width, Height, 3];

                foreach (KeyValuePair <int, RGBAColor[, ]> KV in Layers)
                {
                    RGBAColor[,] D = KV.Value;

                    int Nr = 0;
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int Alpha = D[x, y].Alpha.Limit(0, 255);
                            if (Alpha != 0)
                            {
                                Value[x, y, 0] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 0]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].Red.Limit(0, 255)];
                                Value[x, y, 1] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 1]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].Green.Limit(0, 255)];
                                Value[x, y, 2] = AlphaMappingTable.AlphaMapping[255 - Alpha, (int)Value[x, y, 2]] + AlphaMappingTable.AlphaMapping[Alpha, D[x, y].Blue.Limit(0, 255)];
                            }
                            Nr++;
                        }
                    }
                }

                //the following code mapps the led data to the outputs of the stripe
                //to affect output strength, modify fadingtable during overrides
                byte[] FadingTable = FadingCurve.Data;

                //wrapper object to specify output strength so we have something to modify
                Output newOutput = new Output();
                List <LedWizEquivalent> LWELedstripList = new List <LedWizEquivalent>(Cabinet.Toys.Where(OC => OC is LedWizEquivalent).Select(LW => ((LedWizEquivalent)LW)));
                LedWizEquivalent        LWE             = LWELedstripList[0];

                //wrap firstlednumber into an output number and channel strength 0-100 as output value
                newOutput.Number = FirstLedNumber;
                newOutput.Value  = 100;

                //check for table overrides
                newOutput.Value = TableOverrideSettings.Instance.getnewrecalculatedOutput(newOutput, 30, LWE.LedWizNumber - 30).Value;

                //check for scheduled setting
                newOutput.Value = ScheduledSettings.Instance.getnewrecalculatedOutput(newOutput, 30, LWE.LedWizNumber - 30).Value;

                //get fadingtable from finale percent output
                FadingTable = getfadingtablefromPercent(newOutput.Value);

                switch (ColorOrder)
                {
                case RGBOrderEnum.RBG:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;

                case RGBOrderEnum.GRB:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;

                case RGBOrderEnum.GBR:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;

                case RGBOrderEnum.BRG:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;

                case RGBOrderEnum.BGR:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;

                case RGBOrderEnum.RGB:
                default:
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            int OutputNumber = OutputMappingTable[x, y];
                            OutputData[OutputNumber]     = FadingTable[(int)Value[x, y, 0]];
                            OutputData[OutputNumber + 1] = FadingTable[(int)Value[x, y, 1]];
                            OutputData[OutputNumber + 2] = FadingTable[(int)Value[x, y, 2]];
                        }
                    }
                    break;
                }
            }



            //for (int i = 0; i < OutputData.Length-3; i+=3)
            //{
            //    if (OutputData[i] != OutputData[i + 1] || OutputData[i] != OutputData[i + 2])
            //    {
            //        Console.WriteLine("Stop");

            //    }


            //}
        }
        private Dictionary <int, Dictionary <int, IToy> > SetupCabinet(Dictionary <int, TableConfig> TableConfigDict, Cabinet Cabinet)
        {
            Dictionary <int, Dictionary <int, IToy> > ToyAssignments = new Dictionary <int, Dictionary <int, IToy> >();

            Dictionary <int, LedWizEquivalent> LedWizEquivalentDict = new Dictionary <int, LedWizEquivalent>();

            foreach (IToy T in Cabinet.Toys.Where(Toy => Toy is LedWizEquivalent).ToList())
            {
                LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T);
            }

            foreach (KeyValuePair <int, TableConfig> KV in TableConfigDict)
            {
                int LedWizNr = KV.Key;
                ToyAssignments.Add(LedWizNr, new Dictionary <int, IToy>());

                TableConfig TC = KV.Value;
                if (LedWizEquivalentDict.ContainsKey(LedWizNr))
                {
                    LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr];

                    foreach (TableConfigColumn TCC in TC.Columns)
                    {
                        IToy TargetToy = null;
                        switch (TCC.RequiredOutputCount)
                        {
                        case 3:
                            //RGB Led

                            if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2))
                            {
                                //Try to get the toy
                                try
                                {
                                    //Toy does already exist
                                    TargetToy = (IToy)Cabinet.Toys.First(Toy => Toy is IRGBAToy && ((IRGBAToy)Toy).OutputNameRed == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName&& ((IRGBAToy)Toy).OutputNameGreen == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName&& ((IRGBAToy)Toy).OutputNameBlue == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName);
                                }
                                catch
                                {
                                    //Toy does not exist. Create toyname and toy
                                    string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number);
                                    if (Cabinet.Toys.Contains(ToyName))
                                    {
                                        int Cnt = 1;
                                        while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt)))
                                        {
                                            Cnt++;
                                        }
                                        ToyName = "{0} {1}".Build(ToyName, Cnt);
                                    }
                                    TargetToy = (IToy) new RGBAToy()
                                    {
                                        Name = ToyName, OutputNameRed = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName, OutputNameGreen = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName, OutputNameBlue = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName
                                    };
                                    Cabinet.Toys.Add(TargetToy);
                                }

                                ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy);
                            }

                            break;

                        case 1:
                            //Single output

                            //Analog output
                            if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber))
                            {
                                try
                                {
                                    TargetToy = Cabinet.Toys.First(Toy => Toy is IAnalogAlphaToy && ((IAnalogAlphaToy)Toy).OutputName == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName);
                                }
                                catch
                                {
                                    //Toy does not exist. Create toyname and toy
                                    string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number);

                                    if (Cabinet.Toys.Contains(ToyName))
                                    {
                                        int Cnt = 1;
                                        while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt)))
                                        {
                                            Cnt++;
                                        }
                                        ToyName = "{0} {1}".Build(ToyName, Cnt);
                                    }
                                    TargetToy = (IToy) new AnalogAlphaToy()
                                    {
                                        Name = ToyName, OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName
                                    };
                                    Cabinet.Toys.Add(TargetToy);
                                }
                                ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy);
                            }



                            break;

                        default:
                            //Unknow value
                            Log.Warning("A illegal number ({0}) of required outputs has been found in a table config colum {0} for ledcontrol nr. {2}. Cant configure toy.".Build(TCC.RequiredOutputCount, TCC.Number, LedWizNr));
                            break;
                        }
                    }
                }
            }
            return(ToyAssignments);
        }
Beispiel #8
0
        /// <summary>
        /// This method detects and configures Sainsmart 8ch USB outputs automatically (possibly FT245RBitbangController in general?).
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            //Log.Write("FT245RBitbangControllerAutoConfigurator.AutoConfig started");

            FTDI              dummyFTDI     = new FTDI();
            uint              amountDevices = 0;
            string            callResult    = "";
            List <DeviceInfo> devicelist    = new List <DeviceInfo>();

            //fetch amount of devices, then kill instance
            callResult = dummyFTDI.GetNumberOfDevices(ref amountDevices).ToString();
            //Log.Write("FT245RBitbangControllerAutoConfigurator.AutoConfig: amount of devices detected=" + amountDevices + ", callresult=" + callResult);
            dummyFTDI.Close();
            dummyFTDI = null;

            //connect to each device using ftdi directly, snag the index and serial, then close and gc
            //do this seperate from adding instances in case multiple instances of ftdi would cause issues, as doing this too aggressive will cause locked exe / dll on exit
            for (uint i = 0; i < amountDevices; i++)
            {
                using (FTDI connectFTDI = new FTDI())
                {
                    string deviceSerial = "";
                    string deviceDesc   = "";
                    connectFTDI.OpenByIndex(i);
                    connectFTDI.GetSerialNumber(out deviceSerial);
                    connectFTDI.GetDescription(out deviceDesc);
                    devicelist.Add(new DeviceInfo(deviceSerial, deviceDesc));
                    //Log.Write("i=" + i + ", serial device=" + deviceSerial);
                    connectFTDI.Close();
                }
            }

            //next add instances of the controller to output, and all controller outputs
            for (int deviceIndex = 0; deviceIndex < devicelist.Count; deviceIndex++)
            {
                FT245RBitbangController FTDevice = new FT245RBitbangController();
                FTDevice.Name         = "FT245RBitbangController {0}".Build(deviceIndex);
                FTDevice.SerialNumber = devicelist[deviceIndex].serial;
                FTDevice.Description  = devicelist[deviceIndex].desc;
                FTDevice.Id           = deviceIndex;

                Log.Write("FT245RBitbangControllerAutoConfigurator.AutoConfig.. Detected FT245RBitbangController" + "["
                          + deviceIndex + "], name=" + FTDevice.Name
                          + ", description: " + FTDevice.Description
                          + ", serial #" + FTDevice.SerialNumber);

                if (!Cabinet.OutputControllers.Contains(FTDevice.Name))
                {
                    Cabinet.OutputControllers.Add(FTDevice);

                    Log.Write("Detected and added FT245RBitbangController Id {0} with name {1}".Build(deviceIndex, FTDevice.Name));

                    //+40 used to define start of directoutputconfig[40...].xml
                    if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == deviceIndex - 0 + 40))
                    {
                        LedWizEquivalent LWE = new LedWizEquivalent();
                        LWE.LedWizNumber = deviceIndex - 0 + 40;
                        LWE.Name         = "{0} Equivalent 1".Build(FTDevice.Name);
                        for (int outputIndex = 1; outputIndex <= 8; outputIndex++)
                        {
                            LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                            {
                                OutputName = "{0}\\{0}.{1:00}".Build(FTDevice.Name, outputIndex), LedWizEquivalentOutputNumber = outputIndex
                            };
                            LWE.Outputs.Add(LWEO);
                        }
                        if (!Cabinet.Toys.Contains(LWE.Name))
                        {
                            Cabinet.Toys.Add(LWE);
                            Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PacUIO with Id {2}".Build(LWE.LedWizNumber, LWE.Name, deviceIndex));
                        }
                    }
                }
            }
        }
Beispiel #9
0
        //public class PhilipsHueAutoConfigurator  {
        #region IAutoConfigOutputController Member

        /// <summary>
        /// This method detects and configures Philips Hue bridge controllers automatically.
        /// It is slightly different from PacUIO in that it depends on both an entry in Cabinet.xml OutputControllers.PhilipsHueController for IP and key, and to reuse that instance in this AutoConfig to populate with toys.
        /// </summary>
        /// <param name="Cabinet">The cabinet object to which the automatically detected IOutputController objects are added if necessary.</param>
        public void AutoConfig(Cabinet Cabinet)
        {
            int idCounter = 0;

            //Log.Write("ScheduleSettings name="+Cabinet.ScheduledSettings[0].Name+", clock="+ Cabinet.ScheduledSettings[0].ClockStart);


            Log.Write("PhilipsHueAutoConfigurator.AutoConfig started...note, actual connection detection will happen asynchronously, and device disabled if not succesfull (check further down in the log)");

            //check if we can reuse an instance found in cabinet.xml <outputcontrollers> list
            foreach (IOutputController OC in Cabinet.OutputControllers)
            {
                //Log.Write("PhilipsHueAutoConfigurator.AutoConfig...type=" + OC + ", name=" + OC.Name + ", type=" + OC.GetType());
                if (OC is PhilipsHueController)
                {
                    Log.Write("PhilipsHueAutoConfigurator.AutoConfig...found existing instance, adding output toys to: " + OC.Name);
                    PhilipsHueController PHC = (PhilipsHueController)OC;

                    //if we have an instance, start populating it with toys outputs
                    if (PHC != null)
                    {
                        //set id first, and reapply ip and key
                        PHC.Id        = idCounter;
                        PHC.BridgeIP  = PHC.BridgeIP;
                        PHC.BridgeKey = PHC.BridgeKey;

                        //manual testing for now, the getter/setters will apply this to active static list PhilipsHueControllerUnits[Id]
                        //PHC.BridgeIP = "10.0.1.174";
                        //PHC.BridgeKey = "ywCNFGOagGoJYtm16Kq4PS1tkGBAd3bj1ajg7uCk";
                        //Log.Write("PhilipsHueAutoConfigurator.AutoConfig... <Name> = " + Cabinet.OutputControllers.ToString());

                        PHC.ConnectHub();

                        //if instance doesn't exist, add it to controllers
                        if (!Cabinet.OutputControllers.Contains(PHC.Name))
                        {
                            Cabinet.OutputControllers.Add(PHC);
                            Log.Write("Detected and added PhilipsHueController Id {0} with name {1}".Build(PHC.Id, PHC.Name));
                        }

                        //+70 used to define start of directoutputconfig[70...].xml toys
                        if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == PHC.Id - 0 + 70))
                        {
                            LedWizEquivalent LWE = new LedWizEquivalent();
                            LWE.LedWizNumber = PHC.Id - 0 + 70;
                            LWE.Name         = "{0} Equivalent 1".Build(PHC.Name);
                            for (int i = 1; i <= 150; i++)
                            {
                                LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput()
                                {
                                    OutputName = "{0}\\{0}.{1:00}".Build(PHC.Name, i), LedWizEquivalentOutputNumber = i
                                };
                                LWE.Outputs.Add(LWEO);
                            }
                            if (!Cabinet.Toys.Contains(LWE.Name))
                            {
                                Cabinet.Toys.Add(LWE);
                                Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PhilipsHueController with Id {2}".Build(LWE.LedWizNumber, LWE.Name, PHC.Id));
                            }
                        }

                        idCounter++;
                    }
                }
            }

            //if we have an instance, start populating it with toys outputs

            /*if (PHC != null) {
             *
             *  //set id first
             *  PHC.Id = 0;
             *
             *  //manual testing for now, the getter/setters will apply this to active static list PhilipsHueControllerUnits[Id]
             *  //PHC.BridgeIP = "10.0.1.174";
             *  //PHC.BridgeKey = "ywCNFGOagGoJYtm16Kq4PS1tkGBAd3bj1ajg7uCk";
             *  //Log.Write("PhilipsHueAutoConfigurator.AutoConfig... <Name> = " + Cabinet.OutputControllers.ToString());
             *
             *  PHC.ConnectHub();
             *
             *  //if instance doesn't exist, add it to controllers
             *  if (!Cabinet.OutputControllers.Contains(PHC.Name)) {
             *      Cabinet.OutputControllers.Add(PHC);
             *      Log.Write("Detected and added PhilipsHueController Id {0} with name {1}".Build(PHC.Id, PHC.Name));
             *  }
             *
             *  //+70 used to define start of directoutputconfig[70...].xml toys
             *  if (!Cabinet.Toys.Any(T => T is LedWizEquivalent && ((LedWizEquivalent)T).LedWizNumber == PHC.Id - 0 + 70)) {
             *      LedWizEquivalent LWE = new LedWizEquivalent();
             *      LWE.LedWizNumber = PHC.Id - 0 + 70;
             *      LWE.Name = "{0} Equivalent 1".Build(PHC.Name);
             *      for (int i = 1; i <= 50; i++) {
             *          LedWizEquivalentOutput LWEO = new LedWizEquivalentOutput() { OutputName = "{0}\\{0}.{1:00}".Build(PHC.Name, i), LedWizEquivalentOutputNumber = i };
             *          LWE.Outputs.Add(LWEO);
             *      }
             *      if (!Cabinet.Toys.Contains(LWE.Name)) {
             *          Cabinet.Toys.Add(LWE);
             *          Log.Write("Added LedwizEquivalent Nr. {0} with name {1} for PhilipsHueController with Id {2}".Build(LWE.LedWizNumber, LWE.Name, PHC.Id));
             *      }
             *  }
             * }*/
        }