コード例 #1
0
        /// <summary>
        /// Stop后有问题,暂时不可用关闭,要关闭要重启站点
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Stop()
        {
            ishw = "stop";
            sensor?.Dispose();
            sensor = null;
            await _chatHub.Clients.All.SendAsync("ReceiveMessage", "71", "红外遥控器关闭");

            return(Content("红外遥控器关闭"));
        }
コード例 #2
0
        /// <summary>
        /// Tests the infrared sensor HX1838.
        /// </summary>
        public static void TestInfraredSensor()
        {
            Console.Clear();
            "Send a signal...".Info("IR");
            var inputPin = Pi.Gpio[BcmPin.Gpio25]; // BCM Pin 25 or Physical pin 22 on the right side of the header.
            var sensor   = new InfraredSensor(inputPin, true);

            sensor.DataAvailable += (s, e) =>
            {
                Console.Clear();
                var necData = InfraredSensor.NecDecoder.DecodePulses(e.Pulses);
                if (necData != null)
                {
                    $"NEC Data: {BitConverter.ToString(necData).Replace("-", " "),12}    Pulses: {e.Pulses.Length,4}    Duration(us): {e.TrainDurationUsecs,6}    Reason: {e.FlushReason}".Warn("IR");

                    if (InfraredSensor.NecDecoder.IsRepeatCode(e.Pulses))
                    {
                        return;
                    }
                }
                else
                {
                    if (e.Pulses.Length >= 4)
                    {
                        var debugData = InfraredSensor.DebugPulses(e.Pulses);
                        $"RX    Length: {e.Pulses.Length,5}; Duration: {e.TrainDurationUsecs,7}; Reason: {e.FlushReason}".Warn("IR");
                        debugData.Info("IR");
                    }
                    else
                    {
                        $"RX (Garbage): {e.Pulses.Length,5}; Duration: {e.TrainDurationUsecs,7}; Reason: {e.FlushReason}".Error("IR");
                    }
                }

                ExitMessage.WriteLine();
            };

            while (true)
            {
                var input = Console.ReadKey(true).Key;
                if (input != ConsoleKey.Escape)
                {
                    continue;
                }

                break;
            }

            sensor.Dispose();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Jo0/raspberryio
        /// <summary>
        /// Tests the infrared sensor HX1838.
        /// </summary>
        public static void TestInfraredSensor()
        {
            var inputPin = Pi.Gpio[P1.Gpio23]; // BCM Pin 23 or Physical pin 16 on the right side of the header.
            var sensor   = new InfraredSensor(inputPin, true);
            var emitter  = new InfraredEmitter(Pi.Gpio[P1.Gpio18]);

            sensor.DataAvailable += (s, e) =>
            {
                var necData = InfraredSensor.NecDecoder.DecodePulses(e.Pulses);
                if (necData != null)
                {
                    $"NEC Data: {BitConverter.ToString(necData).Replace("-", " "),12}    Pulses: {e.Pulses.Length,4}    Duration(us): {e.TrainDurationUsecs,6}    Reason: {e.FlushReason}".Warn("IR");

                    if (InfraredSensor.NecDecoder.IsRepeatCode(e.Pulses))
                    {
                        return;
                    }

                    // Test repeater signal
                    var outputPulses = InfraredEmitter.NecEncoder.Encode(necData);

                    emitter.Send(outputPulses);
                    var debugData = InfraredSensor.DebugPulses(outputPulses);
                    $"TX       Length: {outputPulses.Length,5}".Warn("IR");
                    debugData.Info("IR");
                }
                else
                {
                    if (e.Pulses.Length >= 4)
                    {
                        var debugData = InfraredSensor.DebugPulses(e.Pulses);
                        $"RX    Length: {e.Pulses.Length,5}; Duration: {e.TrainDurationUsecs,7}; Reason: {e.FlushReason}".Warn("IR");
                        debugData.Info("IR");
                    }
                    else
                    {
                        $"RX (Garbage): {e.Pulses.Length,5}; Duration: {e.TrainDurationUsecs,7}; Reason: {e.FlushReason}".Error("IR");
                    }
                }
            };

            Console.ReadLine();
            sensor.Dispose();
        }