Ejemplo 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;

            //calculates the equivalent SPI frequency
            //note that an "unshort" 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(
                Pins.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_Devices.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;
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            //create the infrared transmitter driver
            var irtx = new InfraredTransmitter(Pins.GPIO_PIN_D8);

            //create the codec to be used
            var codec = new InfraredCodecRC5(irtx);

            codec.ExtendedMode = true;

            //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);
            };

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

            btn_dir.OnInterrupt += (a_, b_, dt_) =>
            {
                codec.Send(Address, Direction);
            };

            Thread.Sleep(Timeout.Infinite);
        }
Ejemplo n.º 3
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;
 }
 /// <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)
 {
 }