Ejemplo n.º 1
0
        /// <summary>
        /// Adds a pattern of pulses and blanks to the output buffer
        /// </summary>
        /// <param name="codec">The codec used for the buffer composition</param>
        internal void Append(InfraredCodecBase codec)
        {
            //check whether the last accessed codec is the same
            if (this._lastCodec != codec)
            {
                //reset the buffer counter
                this._outputCount = 0;
                this._lastCodec   = codec;
            }

            //calculate the new count of the outgoing data
            int newCount = this._outputCount + codec.TotalPulseCount;

            //resize the output buffer, if won't fit the newer data
            if (this._outputBuffer.Length < newCount)
            {
                var buffer = new ushort[newCount + 100];
                Array.Copy(
                    this._outputBuffer,
                    buffer,
                    this._outputBuffer.Length);

                this._outputBuffer = buffer;
            }

            /**
             * N = TotalPulseCount
             * offset:  0   +1   +2   +3    ...    N-2  N-1   N
             *      ---------------------------------------------
             *      ##|    |    |    |    |       |    |    |###
             *      ---------------------------------------------
             *        ____________  logic bit  ______________
             **/
            const ushort Blank = 0;

            int blankFirst = this._outputCount + codec.InitialPulseCount;
            int blankLast  = newCount - codec.FinalPulseCount - 1;

            //append pulses and blanks to the buffer
            while (this._outputCount < newCount)
            {
                ushort pattern = (this._outputCount >= blankFirst && this._outputCount <= blankLast)
                    ? Blank
                    : codec.PulseMask;

                this._outputBuffer[_outputCount++] = pattern;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send the overall output buffer composed so far
        /// </summary>
        /// <param name="codec">The codec used for the buffer composition</param>
        internal void Send(InfraredCodecBase codec)
        {
            //open the SPI using the specified configuration
            using (var spi = new SPI(codec.Config))
            {
                //enable the physical transmitter driver
                this._enable.Write(true);

                //shift out the whole buffer
                spi.WriteRead(
                    this._outputBuffer,
                    0,
                    this._outputCount,
                    null,
                    0,
                    0,
                    0);

                //shut down the physical driver
                this._enable.Write(false);
            }

            this._lastCodec = null;
        }