コード例 #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;
        }
コード例 #2
0
 /// <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)
 {
 }
コード例 #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;
 }