Esempio n. 1
0
        public override void Run()
        {
            RequireRx();

            RaspberryIRDotNet.IReadOnlyPulseSpaceDurationList leadInDurations = LearnExpectedLeadInDurations();
            int unitDuration = LearnExpectedUnitDuration(leadInDurations);
            int unitCount    = LearnExpectedUnitCount(leadInDurations, unitDuration);

            Console.WriteLine("IR parameters learnt. Now ready to learn individual buttons.");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            var key1 = LearnKey("1", leadInDurations, unitDuration, unitCount);
            var key2 = LearnKey("2", leadInDurations, unitDuration, unitCount);

            Console.WriteLine("IR codes learnt. Now press 1 or 2 on the Pi's keyboard to transmit those IR codes.");

            RequireTx();

            using (var sender = new RaspberryIRDotNet.TX.PulseSpaceTransmitter_ManualOpenClose()
            {
                TransmissionDevice = DemoConfig.GetTxDevice()
            })
            {
                sender.Open();
                while (true)
                {
                    var choice = Console.ReadKey();
                    if (choice.Key == ConsoleKey.Escape)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Escape pressed, quitting.");
                        return;
                    }
                    else if (choice.KeyChar == '1')
                    {
                        sender.Send(key1);
                    }
                    else if (choice.KeyChar == '2')
                    {
                        sender.Send(key2);
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Press 1, 2 or escape.");
                    }
                }
            }
        }
Esempio n. 2
0
 private void OnRx(RaspberryIRDotNet.IReadOnlyPulseSpaceDurationList buffer)
 {
     if (_roundTo.HasValue)
     {
         var roundedBuffer = buffer.Copy(_roundTo.Value);
         if (roundedBuffer.Any(x => x <= 0))
         {
             /// The rounding process has produced a zero. Either <see cref="_roundTo"/> has been set to the wrong value, or this was background noise.
             /// We need to drop it because if we try to transmit this we will get an error since zero length PULSES/SPACES are not valid.
             Console.Write("-");
             return;
         }
         _sender.Send(buffer.Copy(_roundTo.Value));
     }
     _sender.Send(buffer);
     Console.Write("+");
 }
Esempio n. 3
0
        private int LearnExpectedUnitDuration(RaspberryIRDotNet.IReadOnlyPulseSpaceDurationList leadInDurations)
        {
            var learner = new RaspberryIRDotNet.RX.UnitDurationLearner()
            {
                CaptureDevice          = DemoConfig.GetRxDevice(),
                LeadInPatternDurations = leadInDurations,
            };

            SetUpRxFeedback(learner);

            Console.WriteLine("This step will try to learn the unit duration of the IR message.");
            WriteKeyPressInstructions("any key", true);

            int duration = learner.LearnUnitDuration();

            Console.WriteLine();
            Console.WriteLine($"Done, unit duration is: {duration} microseconds.");
            Breather();
            return(duration);
        }
Esempio n. 4
0
        private RaspberryIRDotNet.IRPulseMessage LearnKey(string keyName, RaspberryIRDotNet.IReadOnlyPulseSpaceDurationList leadInDurations, int unitDuration, int unitCount)
        {
            var recorder = new RaspberryIRDotNet.RX.IRMessageLearn()
            {
                CaptureDevice           = DemoConfig.GetRxDevice(),
                UnitDurationMicrosecs   = unitDuration,
                MessageMinimumUnitCount = unitCount,
                MessageMaximumUnitCount = unitCount
            };

            recorder.SetLeadInPatternAsMicrosecs(leadInDurations);

            SetUpRxFeedback(recorder);
            WriteKeyPressInstructions($"the '{keyName}' key", false);

            var result = recorder.LearnMessage();

            Console.WriteLine("Key captured.");
            Breather();
            return(result);
        }
Esempio n. 5
0
        private int LearnExpectedUnitCount(RaspberryIRDotNet.IReadOnlyPulseSpaceDurationList leadInDurations, int unitDuration)
        {
            var counter = new RaspberryIRDotNet.RX.IRUnitCounter()
            {
                CaptureDevice         = DemoConfig.GetRxDevice(),
                UnitDurationMicrosecs = unitDuration,
            };

            counter.SetLeadInPatternAsMicrosecs(leadInDurations);

            SetUpRxFeedback(counter);

            Console.WriteLine("This step will try to learn how many units each IR message is.");
            WriteKeyPressInstructions("any key", true);

            int unitCount = counter.CaptureAndGetMostCommonUnitCount();

            Console.WriteLine();
            Console.WriteLine("Done, unit count is " + unitCount);
            Breather();
            return(unitCount);
        }