コード例 #1
0
        public HalloweenFlying(
            Dimmer3 eyes,
            ThroughputDevice fogStairsPump1,
            ThroughputDevice fogStairsPump2,
            StrobeColorDimmer3 fogStairsLight1,
            StrobeColorDimmer3 fogStairsLight2,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsatingLow.ConnectTo(eyes);

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(eyes);

                    pulsatingLow.Start(token: this.controlToken);
                }
                else
                {
                    pulsatingLow.Stop();
                    UnlockDevices();
                }
            });

            PowerOn
            .RunAction(ins =>
            {
                pulsatingLow.Stop();

                eyes.SetBrightness(1);
                audioPlayer.PlayEffect("Who is that knocking.wav");

                ins.WaitFor(S(2.5));

                fogStairsPump1.SetThroughput(0.4);
                fogStairsLight1.SetColor(Color.Purple, 1.0);

                fogStairsPump2.SetThroughput(0.4);
                fogStairsLight2.SetColor(Color.Purple, 1.0);

                ins.WaitFor(S(1.0));

                fogStairsPump1.SetThroughput(0);
                fogStairsPump2.SetThroughput(0);

                ins.WaitFor(S(1.0));
                fogStairsLight1.SetBrightness(0);
                fogStairsLight2.SetBrightness(0);
            })
            .TearDown(ins =>
            {
                pulsatingLow.Start(token: this.controlToken);
            });
        }
コード例 #2
0
        public HalloweenFrankGhost(
            IReceivesColor light,
            DigitalOutput2 air,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsatingLow.ConnectTo(light);
            levelsPlayback.Output.Controls(b => light.SetBrightness(b, this.controlToken));

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(air, light);

                    air.SetValue(true, this.controlToken);
                    light.SetColor(Color.Red, this.controlToken);
                    pulsatingLow.Start(token: this.controlToken);
                }
                else
                {
                    pulsatingLow.Stop();

                    UnlockDevices();
                }
            });

            PowerOn
            .SetLoop(true)
            .SetMaxRuntime(S(60))
            .SetUp(ins =>
            {
                pulsatingLow.Stop();
            })
            .RunAction(ins =>
            {
                audioPlayer.PlayEffect("Thriller2.wav", levelsPlayback);
                // The control token is optional since it's passed in via the Subroutine
                light.SetColor(Color.Purple);
                var cts = levelsPlayback.Start(this.controlToken);

                ins.WaitFor(S(45));
                cts.Cancel();
            })
            .TearDown(ins =>
            {
                light.SetColor(Color.Red);
                pulsatingLow.Start(token: this.controlToken);
            });

            PowerOff.RunAction(ins =>
            {
                audioPlayer.PlayEffect("Happy Halloween.wav", 0.15);
                ins.WaitFor(S(5));
            });
        }
コード例 #3
0
ファイル: NRF24L01.cs プロジェクト: ohyubun/windows-iot-demo
        /// <summary>
        /// Set Output Power
        /// </summary>
        /// <param name="power">Output Power</param>
        public void SetOutputPower(OutputPower power)
        {
            ce.Write(GpioPinValue.Low);

            byte[] value = new byte[1];
            sensor.TransferSequential(new byte[] { R_REGISTER + RF_SETUP }, value);

            byte setting = (byte)(value[0] & (~0x06) | ((byte)power << 1));

            sensor.Write(new byte[] { W_REGISTER + RF_SETUP, setting });

            ce.Write(GpioPinValue.High);
        }
コード例 #4
0
        public HalloweenSpiderDrop(
            IReceivesBrightness eyesLight,
            IReceivesBrightness smallSpiderEyes,
            DigitalOutput2 drop,
            DigitalOutput2 venom,
            StrobeDimmer3 strobeLight,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsating.ConnectTo(smallSpiderEyes);

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(drop, venom, eyesLight, strobeLight, smallSpiderEyes);

                    pulsating.Start(token: this.controlToken);
                }
                else
                {
                    pulsating.Stop();
                    UnlockDevices();
                }
            });

            PowerOn.RunAction(ins =>
            {
                pulsating.Stop();
                audioPlayer.PlayNewEffect("348 Spider Hiss.wav", 0, 1);
                eyesLight.SetBrightness(1);
                drop.SetValue(true);
                ins.WaitFor(S(0.2));
                strobeLight.SetBrightnessStrobeSpeed(1, 1);
                venom.SetValue(true);
                ins.WaitFor(S(2.0));
                venom.SetValue(false);
                strobeLight.SetBrightnessStrobeSpeed(0, 0);
                ins.WaitFor(S(2.0));
            })
            .TearDown(ins =>
            {
                drop.SetValue(false);
                venom.SetValue(false);
                eyesLight.SetBrightness(0);
                strobeLight.SetBrightnessStrobeSpeed(0, 0);
                pulsating.Start(token: this.controlToken);
                ins.WaitFor(S(1.0));
            });
        }
コード例 #5
0
        public HalloweenMrPumpkin(
            Dimmer3 light,
            DigitalOutput2 air,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsatingLow.ConnectTo(light);
            levelsPlayback.Output.Controls(b => light.SetBrightness(b, this.controlToken));

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(air, light);

                    air.SetValue(true, this.controlToken);
                    pulsatingLow.Start(token: this.controlToken);
                }
                else
                {
                    pulsatingLow.Stop();
                    UnlockDevices();
                }
            });

            PowerOn
            .RunAction(ins =>
            {
                pulsatingLow.Stop();

                audioPlayer.PlayEffect("125919__klankbeeld__horror-what-are-you-doing-here-cathedral.wav", levelsPlayback);
                levelsPlayback.Start(this.controlToken);

                ins.WaitFor(S(8));
            })
            .TearDown(ins =>
            {
                pulsatingLow.Start(token: this.controlToken);
            });
        }
コード例 #6
0
        public FireProjector(
            DigitalOutput2 fire,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            this.inputTrigger1.Subscribe(x =>
            {
                if (x)
                {
                    if (this.inputTriggerBlock.Value)
                    {
                        this.log.Verbose("{Name} has been triggered on 1, but is blocked", Name);
                    }
                    else
                    {
                        if (Power)
                        {
                            this.log.Verbose("Trigger 1 for {Name}", Name);
                            Executor.Current.Execute(this.sub1);
                        }
                    }
                }
            });

            this.inputTrigger2.Subscribe(x =>
            {
                if (x)
                {
                    if (this.inputTriggerBlock.Value)
                    {
                        this.log.Verbose("{Name} has been triggered on 2, but is blocked", Name);
                    }
                    else
                    {
                        if (Power)
                        {
                            this.log.Verbose("Trigger 2 for {Name}", Name);
                            Executor.Current.Execute(this.sub2);
                        }
                    }
                }
            });

            this.inputTriggerBlock.Subscribe(x =>
            {
                this.log.Verbose("Trigger block for {Name} changed to {TriggerBlock}", Name, x);
            });

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(fire);
                }
                else
                {
                    UnlockDevices();
                }
            });

            sub1.RunAction(ins =>
            {
                fire.SetValue(true, this.controlToken);
                ins.WaitFor(S(0.5));
            })
            .TearDown(ins =>
            {
                fire.SetValue(false, this.controlToken);
            });

            sub2.RunAction(ins =>
            {
                fire.SetValue(true, this.controlToken);
                ins.WaitFor(S(2.0));
            })
            .TearDown(ins =>
            {
                fire.SetValue(false, this.controlToken);
            });
        }
コード例 #7
0
        public HalloweenRocker(
            DigitalOutput2 rockingMotor,
            DigitalOutput2 ladyEyes,
            StrobeColorDimmer3 strobeLight,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsatingRocking.ConnectTo(strobeLight, Utils.Data(DataElements.Color, Color.HotPink));

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(rockingMotor, ladyEyes, strobeLight);
                    audioPlayer.SetBackgroundVolume(0.2);
                    audioPlayer.PlayBackground();
                    sub.Run();
                }
                else
                {
                    audioPlayer.PauseBackground();
                    UnlockDevices();
                    Exec.Cancel(sub);
                }
            });

            sub
                .SetUp(ins =>
                {
                    ladyEyes.SetValue(true, this.controlToken);
                    rockingMotor.SetValue(true, this.controlToken);
                })
                .RunAction(ins =>
                {
                    while (!ins.IsCancellationRequested)
                    {
                        isRockingLadyTalking = true;
                        audioPlayer.PlayEffect("A conversation with Mother.wav");
                        ins.WaitFor(S(42), true);
                        isRockingLadyTalking = false;

                        ins.WaitFor(S(15.0));
                    }
                })
                .TearDown(ins =>
                {
                    audioPlayer.PauseFX();
                    ladyEyes.SetValue(false, this.controlToken);
                    rockingMotor.SetValue(false, this.controlToken);
                });

            PowerOn.RunAction(ins =>
                {
                    pulsatingRocking.Start(token: this.controlToken);
                    if (!isRockingLadyTalking)
                    {
                        switch (random.Next(3))
                        {
                            case 0:
                                audioPlayer.PlayEffect("032495843-old-woman-cough.wav");
                                break;

                            case 1:
                                audioPlayer.PlayEffect("049951942-grampy-old-woman-cackle.wav");
                                break;

                            case 2:
                                audioPlayer.PlayEffect("053851373-old-ungly-female-laughter.wav");
                                break;
                        }
                    }

                    ins.WaitFor(S(7));
                })
                .TearDown(ins =>
                {
                    pulsatingRocking.Stop();
                });
        }
コード例 #8
0
        /// <summary>
        /// 终测命令
        /// </summary>
        private void ExecuteTest()
        {
            bool          isSaveData = false;
            StringBuilder strBuild   = new StringBuilder();

            IsTestEnable = false;
            try
            {
                //另一线程执行该方法
                Thread thread = new Thread(() =>
                {
                    //SN
                    if (!string.IsNullOrEmpty(SN))
                    {
                        TestingPara.SN = SN;
                    }
                    //GPIB通信
                    if (IsReady)
                    {
                        double ini  = IniAtt;
                        double span = 0.2;
                        double voltage;
                        double saturation = 0;
                        //Hp8156A.Open();
                        Mp2100A.AutoScale();
                        Aq6317B.SetSingle();

                        //Supply Current
                        SupplyCurrent             = AgE3631A.GetCurrent();
                        TestingPara.SupplyCurrent = SupplyCurrent.ToString("F3");
                        //OutputPower
                        OutputPower             = Hp8153A.ReadPower("2");
                        TestingPara.OutputPower = OutputPower.ToString("F3");

                        //SD_Desserted SD_High
                        for (int i = 0; i <= 40; i++)
                        {
                            Hp8156A.SetAtt(ini.ToString());
                            Thread.Sleep(300);
                            voltage = Ag34401A.GetVoltage();
                            Thread.Sleep(100);
                            if (i == 0 && voltage >= 2.0)
                            {
                                MessageBox.Show("初始即为高电压,请检查设备连接!", "系统提示");
                                return;
                            }
                            if (voltage >= 2.0)
                            {
                                SdDesserted = ini;
                                TestingPara.SD_Desserted = SdDesserted.ToString();
                                SDHigh = voltage;
                                TestingPara.SD_High = SDHigh.ToString("F3");
                                //SdDesserted SdHigh
                                strBuild.Append(string.Format("SdDesserted:{0}", SdDesserted));
                                strBuild.Append(string.Format("SdHigh:{0}", SDHigh));
                                DisplayInfo = strBuild.ToString();
                                break;
                            }
                            else
                            {
                                ini += span;
                                if (i == 40)
                                {
                                    strBuild.Append("获取SdDesserted失败!");
                                    DisplayInfo = strBuild.ToString();
                                }
                            }
                        }
                        ;
                        //SD_Asserted,SD_Low
                        for (int i = 0; i <= 30; i++)
                        {
                            Hp8156A.SetAtt(ini.ToString());
                            Thread.Sleep(200);
                            voltage = Ag34401A.GetVoltage();
                            Thread.Sleep(100);
                            if (voltage < 0.5)
                            {
                                SdAsserted = ini;
                                TestingPara.SD_Asserted = SdAsserted.ToString();
                                SDLow = voltage;
                                TestingPara.SD_Low = SDLow.ToString();
                                strBuild.Append(string.Format("SdAsserted:{0}", SdAsserted));
                                strBuild.Append(string.Format("SdLow:{0}", SDLow));
                                DisplayInfo = strBuild.ToString();
                                break;
                            }
                            else
                            {
                                ini -= span;
                                if (i == 30)
                                {
                                    strBuild.Append("获取SdAsserted失败");
                                    DisplayInfo = strBuild.ToString();
                                }
                            }
                        }
                        //Hysteresis
                        Hysteresis             = SdDesserted = SdAsserted;
                        TestingPara.Hysteresis = Hysteresis.ToString();
                        #region MP2100
                        Hp8156A.SetAtt(IniAtt.ToString());
                        //Exit.Ratio
                        ExtiRatio = Mp2100A.GetExRatio();
                        TestingPara.ExtioRatio = ExtiRatio.ToString("F3");
                        strBuild.Append(string.Format("Extinction Ratio:{0}", ExtiRatio));
                        DisplayInfo = strBuild.ToString();
                        //Crossing
                        CrossingRate         = Mp2100A.GetCrossing();
                        TestingPara.Crossing = CrossingRate.ToString("F3");
                        strBuild.Append(string.Format("CrossingRate:{0}", CrossingRate));
                        DisplayInfo = strBuild.ToString();
                        //MaskMargin
                        MaskMargin             = Mp2100A.GetMaskMargin();
                        TestingPara.MaskMargin = MaskMargin.ToString("F3");
                        strBuild.Append(string.Format("Mask Margin:{0}", MaskMargin));
                        DisplayInfo = strBuild.ToString();
                        //Jitter
                        Jitter             = Mp2100A.GetJitter();
                        TestingPara.Jitter = Jitter.ToString("F3");
                        strBuild.Append(string.Format("Jitter:{0}", Jitter));
                        DisplayInfo = strBuild.ToString();
                        Thread.Sleep(2000);
                        //OSA
                        string osaData = Aq6317B.GetData();
                        string[] data  = osaData.Split(',');
                        //CenterWavelength
                        if (double.TryParse(data[1].Trim(), out double data1))
                        {
                            CenterWavelength = data1;
                        }
                        else
                        {
                            CenterWavelength = 0;
                        }
                        TestingPara.CenterWavelength = CenterWavelength.ToString();
                        //SMSR
                        if (double.TryParse(data[4].Trim(), out double data4))
                        {
                            SMSR = data4;
                        }
                        else
                        {
                            SMSR = 0;
                        }
                        TestingPara.SMSR = SMSR.ToString();
                        //WavelengthDiff
                        if (double.TryParse(data[0].Trim(), out double data0))
                        {
                            DifferenceWavelength = data0;
                        }
                        else
                        {
                            DifferenceWavelength = 0;
                        }
                        TestingPara.WavelengthDiff = DifferenceWavelength.ToString();

                        strBuild.AppendLine(string.Format("中心波长:{0}", CenterWavelength));
                        strBuild.AppendLine(string.Format("Δλ:{0}", DifferenceWavelength));
                        strBuild.AppendLine(string.Format("SMSR:{0}", SMSR));
                        DisplayInfo = strBuild.ToString();
                        //Sensitivity
                        Sensitivity             = Math.Round(GetSensitivity(), 2);
                        TestingPara.Sensitivity = Sensitivity.ToString();
                        strBuild.Append(string.Format("Sensitivity:{0}", Sensitivity));
                        DisplayInfo = strBuild.ToString();
                        #endregion
                        Thread.Sleep(300);

                        //Saturation
                        //测试饱和度 设置 衰减
                        Hp8156A.SetAtt(AttInSaturation);
                        Thread.Sleep(3000);
                        for (int i = 0; i < 5; i++)
                        {
                            Thread.Sleep(300);
                            double r = Mp2100A.GetErrorRate();
                            if (r >= 0)
                            {
                                saturation = Math.Log10(r);
                                if (saturation > -9)
                                {
                                    Saturation = false;
                                    break;
                                }
                            }
                            else
                            {
                                MessageBox.Show("读取眼图仪误码率发生错误", "系统设置");
                                break;
                            }
                            Saturation = true;
                        }
                        TestingPara.Saturation = Saturation;
                        strBuild.Append(string.Format("Saturation:{0}", Saturation));
                        DisplayInfo = strBuild.ToString();

                        //TxDisable
                        Thread.Sleep(200);
                        Hp8156A.Close();
                        P3202.SetVolage("1", "2.0");
                        Thread.Sleep(3000);
                        double txDisablePower = Hp8153A.ReadPower("2");
                        strBuild.Append(string.Format("Power@TxDisable:{0}", txDisablePower));
                        DisplayInfo = strBuild.ToString();
                        if (txDisablePower < -20.0 || Math.Log10(txDisablePower) > 10)
                        {
                            TxDisable             = true;
                            TestingPara.TxDisable = true;
                        }
                        P3202.SetVolage("1", "0.8");
                        isSaveData = true;
                    }
                    else
                    {
                        MessageBox.Show("设备初始化未完成,将无法进行GPIB测试", "系统提示");
                    }
                    //IIC通信参数
                    if (IsPortReady)
                    {
                        I2CTest();
                        isSaveData = true;
                    }
                    else
                    {
                        MessageBox.Show("串口初始化未完成", "系统提示");
                    }
                    if (isSaveData)
                    {
                        //将数据存储到本地
                        MessageBoxResult result = MessageBox.Show("测试完成,是否储存数据?", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                        if (result == MessageBoxResult.OK)
                        {
                            bool isEmpty = false;
                            if (!Directory.Exists(@"E:\Xu"))
                            {
                                Directory.CreateDirectory(@"E:\Xu");
                            }
                            using (FileStream fs = new FileStream(SavePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
                            {
                                using (StreamReader sr = new StreamReader(fs))
                                {
                                    string output = null;
                                    if ((output = sr.ReadLine()) == null)
                                    {
                                        isEmpty = true;
                                    }
                                    else
                                    {
                                        isEmpty = false;
                                    }
                                }
                            }
                            using (FileStream fs = new FileStream(SavePath, FileMode.Append, FileAccess.Write, FileShare.None))
                            {
                                using (StreamWriter sw = new StreamWriter(fs))
                                {
                                    if (isEmpty == true)
                                    {
                                        sw.WriteLine("SN,SupplyCurrent,OutputPower,ExRatio,Crossing,Jitter,MaskMargin," +
                                                     "CenterWavelength,SMSR,WavelengthDiff,TxDisable,Sensitivity,SD_Asserted,SD_Desserted," +
                                                     "Hysteresis,SD_High,SD_Low,Saturation,RxPoint1,RxPoint2,RxPoint3,TxPower," +
                                                     "Vcc,Temp,Bias,IsAwPass,Date");
                                    }
                                    sw.WriteLine(TestingPara.ToString());
                                }
                            }
                        }
                    }
                    IsTestEnable = true;
                });
                thread.IsBackground = true;
                thread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提示");
            }
        }
コード例 #9
0
        public HalloweenGrumpyCat(
            Dimmer3 light,
            DigitalOutput2 air,
            AudioPlayer audioPlayer,
            [System.Runtime.CompilerServices.CallerMemberName] string name = "")
            : base(name)
        {
            pulsatingLow.ConnectTo(light);
            pulsatingHigh.ConnectTo(light);

            OutputPower.Subscribe(x =>
            {
                if (x)
                {
                    LockDevices(air, light);

                    air.SetValue(true, this.controlToken);
                    pulsatingLow.Start(token: this.controlToken);
                }
                else
                {
                    pulsatingLow.Stop();
                    UnlockDevices();
                }
            });

            PowerOn
            .SetLoop(true)
            .SetMaxRuntime(S(20))
            .SetUp(ins =>
            {
                pulsatingLow.Stop();
                pulsatingHigh.Start(token: this.controlToken);
            })
            .RunAction(ins =>
            {
                switch (random.Next(5))
                {
                case 0:
                    audioPlayer.PlayEffect("266 Monster Growl 7.wav", 1.0, 1.0);
                    ins.WaitFor(S(2.0));
                    break;

                case 1:
                    audioPlayer.PlayEffect("285 Monster Snarl 2.wav", 1.0, 1.0);
                    ins.WaitFor(S(3.0));
                    break;

                case 2:
                    audioPlayer.PlayEffect("286 Monster Snarl 3.wav", 1.0, 1.0);
                    ins.WaitFor(S(2.5));
                    break;

                case 3:
                    audioPlayer.PlayEffect("287 Monster Snarl 4.wav", 1.0, 1.0);
                    ins.WaitFor(S(1.5));
                    break;

                default:
                    ins.WaitFor(S(3.0));
                    break;
                }
            })
            .TearDown(ins =>
            {
                //TODO: Fade out
                pulsatingHigh.Stop();
                pulsatingLow.Start(token: this.controlToken);
            });


            PowerOff
            .RunAction(ins =>
            {
                audioPlayer.PlayEffect("How you doing.wav", 0.15);
                ins.WaitFor(S(5));
            });
        }