Esempio n. 1
0
        /// <summary>
        /// Base class constructor for any infrared oriented codec
        /// </summary>
        /// <param name="transmitter">A valid infrared transmitter reference</param>
        /// <param name="frequency">The carrier frequency to be used</param>
        /// <param name="pulseDuty">The desired pulse-duty cycle</param>
        /// <remarks>
        /// The pulse duty-cycle is meant to be expressed as a value from 0.0 to 1.0,
        /// and is the ratio between the duration of the high-level and the pulse period
        /// </remarks>
        protected InfraredCodecBase(
            InfraredTransmitter transmitter,
            float frequency,
            float pulseDuty)
        {
            this.Transmitter = transmitter;

            //calculates the actual period for pushing out one
            //ushort value, interleave including
            float t_carrier = 1 / frequency;
            float t_ushort  = t_carrier - 2e-3f; // subtrai 2us (porque?)

            //calculates the equivalent SPI frequency
            //note that an "ushort" is 16 bits
            uint spi_freq = (uint)(16.0f / t_ushort);

            //prevent a frequency too low: seems that Netduino hangs
            //when the frequency is below a certain value
            if (spi_freq < 300)
            {
                throw new Exception();
            }

            this.Config = new SPI.Configuration(
                Cpu.Pin.GPIO_NONE,  // SS-pin (not used)
                true,               // SS-pin active state (not used)
                0,                  // The setup time for the SS port (not used)
                0,                  // The hold time for the SS port (not used)
                true,               // The idle state of the clock (not used)
                true,               // The sampling clock edge (not used)
                spi_freq,           // The SPI clock rate in KHz
                SPI.SPI_module.SPI1 // The used SPI bus (refers to a MOSI MISO and SCLK pinset)
                );

            //calculate the pulse mask
            int mask = 1;

            for (int i = 1; i <= 16; i++)
            {
                if ((i / 16.0f) < pulseDuty)
                {
                    mask = (mask << 1) | 1;
                }
                else
                {
                    break;
                }
            }

            this.PulseMask = (ushort)mask;
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new instance of codec
 /// </summary>
 /// <param name="transmitter">A valid reference for the transmitter to be used</param>
 public InfraredCodecNec(InfraredTransmitter transmitter)
     : base(transmitter, CarrierFrequency, PulseDuty)
 {
     this.TotalPulseCount = 64;
 }
 /// <summary>
 /// Create a new instance of codec
 /// </summary>
 /// <param name="transmitter">A valid reference for the transmitter to be used</param>
 public InfraredCodecSonySIRC(InfraredTransmitter transmitter)
     : base(transmitter, CarrierFrequency, PulseDuty)
 {
 }
Esempio n. 4
0
        public static void Main()
        {
            ////define the button for decrement speed
            //var btn_dec = new InterruptPort(
            //    Pins.GPIO_PIN_D0,
            //    true,
            //    Port.ResistorMode.PullUp,
            //    Port.InterruptMode.InterruptEdgeLow
            //    );

            //btn_dec.OnInterrupt += (a_, b_, dt_) =>
            //{
            //    codec.Send(Address, SpeedDown);
            //};

            ////define the button for increment speed
            //var btn_inc = new InterruptPort(
            //    Pins.GPIO_PIN_D1,
            //    true,
            //    Port.ResistorMode.PullUp,
            //    Port.InterruptMode.InterruptEdgeLow
            //    );

            //btn_inc.OnInterrupt += (a_, b_, dt_) =>
            //{
            //    codec.Send(Address, SpeedUp);
            //};


            //create the infrared transmitter driver
            var irtx = new InfraredTransmitter(Pins.GPIO_PIN_D8);

            //create the codec to be used
            var codec = new InfraredCodecNEC(irtx);
            //codec.ExtendedMode = true;

            //define button for sending IR command
            var btn_dir = new InterruptPort(
                Pins.GPIO_PIN_D2,
                true,
                Port.ResistorMode.PullUp,
                Port.InterruptMode.InterruptEdgeLow
                );

            btn_dir.OnInterrupt += (a_, b_, dt_) =>
            {
                Debug.Print("sending ...");
                codec.Send(0xFF, 0xE0);
            };

            //Thread.Sleep(Timeout.Infinite);

            // send non-stop sequence

            int i = 0;

            //int[] x = {0xE0, 0xEA, 0x0E, 0x15};
            //int[] x = { 0xFF, 0xFF, 0xFF, 0xFF };
            //int[] x = { 0x0D, 0x1F, 0x0D, 0x1F };
            int[] x = { 0xF2, 0xE3, 0xEA, 0xE0 }; // on, yellow, white, off

            while (true)
            {
                //codec.Send(0x00, x[i++]);
                //codec.Send(x[i++], 0x00);
                Debug.Print("... cmd " + i);
                codec.Send(0x00, i++);
                i = i % 256;
                Thread.Sleep(2000);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Create a new instance of codec
 /// </summary>
 /// <param name="transmitter">A valid reference for the transmitter to be used</param>
 public InfraredCodecRC5(InfraredTransmitter transmitter)
     : base(transmitter, CarrierFrequency, PulseDuty)
 {
     //the RC-5 protocol fixes a well-defined duration for any logic bit
     this.TotalPulseCount = 64;
 }