Exemplo n.º 1
0
        /// <summary>
        /// Learn an IR Command.
        /// </summary>
        /// <param name="learnTimeout">How long to wait before aborting learn.</param>
        /// <param name="learned">Newly learned IR Command.</param>
        /// <returns>Learn status.</returns>
        public override LearnStatus Learn(int learnTimeout, out IrCode learned)
        {
            DebugWriteLine("Learn()");

            learned       = null;
            _learningCode = new IrCode();

            SetInputPort(InputPort.Learning);

            int learnStartTick = Environment.TickCount;

            _readThreadMode = ReadThreadMode.Learning;

            // Wait for the learning to finish ...
            while (_readThreadMode == ReadThreadMode.Learning && Environment.TickCount < learnStartTick + learnTimeout)
            {
                Thread.Sleep(PacketTimeout);
            }

            DebugWriteLine("End Learn");

            ReadThreadMode modeWas = _readThreadMode;

            _readThreadMode = ReadThreadMode.Receiving;
            SetInputPort(InputPort.Receive);

            LearnStatus status = LearnStatus.Failure;

            switch (modeWas)
            {
            case ReadThreadMode.Learning:
                status = LearnStatus.Timeout;
                break;

            case ReadThreadMode.LearningFailed:
                status = LearnStatus.Failure;
                break;

            case ReadThreadMode.LearningDone:
                DebugDump(_learningCode.TimingData);
                if (_learningCode.FinalizeData())
                {
                    learned = _learningCode;
                    status  = LearnStatus.Success;
                }
                break;
            }

            _learningCode = null;
            return(status);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an IrCode object from Pronto format file bytes.
        /// </summary>
        /// <param name="data">IR file bytes.</param>
        /// <returns>New IrCode object.</returns>
        private static IrCode FromProntoData(byte[] data)
        {
            string code = Encoding.ASCII.GetString(data);

            string[] stringData = code.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            ushort[] prontoData = new ushort[stringData.Length];
            for (int i = 0; i < stringData.Length; i++)
            {
                prontoData[i] = ushort.Parse(stringData[i], NumberStyles.HexNumber);
            }

            IrCode newCode = Pronto.ConvertProntoDataToIrCode(prontoData);

            if (newCode != null)
            {
                newCode.FinalizeData();
            }
            // Seems some old files have excessively long delays in them .. this might fix that problem ...

            return(newCode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an IrCode object from old IR file bytes.
        /// </summary>
        /// <param name="data">IR file bytes.</param>
        /// <returns>New IrCode object.</returns>
        private static IrCode FromOldData(byte[] data)
        {
            List <int> timingData = new List <int>();

            int len = 0;

            for (int index = 0; index < data.Length; index++)
            {
                byte curByte = data[index];

                if ((curByte & 0x80) != 0)
                {
                    len += (curByte & 0x7F);
                }
                else
                {
                    len -= curByte;
                }

                if ((curByte & 0x7F) != 0x7F)
                {
                    timingData.Add(len * 50);
                    len = 0;
                }
            }

            if (len != 0)
            {
                timingData.Add(len * 50);
            }

            IrCode newCode = new IrCode(timingData.ToArray());

            newCode.FinalizeData();
            // Seems some old files have excessively long delays in them .. this might fix that problem ...

            return(newCode);
        }
Exemplo n.º 4
0
    /// <summary>
    /// Learn an IR Command.
    /// </summary>
    /// <param name="learnTimeout">How long to wait before aborting learn.</param>
    /// <param name="learned">Newly learned IR Command.</param>
    /// <returns>Learn status.</returns>
    public override LearnStatus Learn(int learnTimeout, out IrCode learned)
    {
      DebugWriteLine("Learn()");

      RestartReadThread(ReadThreadMode.Learning);

      learned = null;
      _learningCode = new IrCode();

      int learnStartTick = Environment.TickCount;

      // Wait for the learning to finish ...
      while (_readThreadMode == ReadThreadMode.Learning && Environment.TickCount < learnStartTick + learnTimeout)
        Thread.Sleep(PacketTimeout);

      DebugWriteLine("End Learn");

      ReadThreadMode modeWas = _readThreadMode;

      RestartReadThread(ReadThreadMode.Receiving);

      LearnStatus status = LearnStatus.Failure;

      switch (modeWas)
      {
        case ReadThreadMode.Learning:
          status = LearnStatus.Timeout;
          break;

        case ReadThreadMode.LearningFailed:
          status = LearnStatus.Failure;
          break;

        case ReadThreadMode.LearningDone:
          DebugDump(_learningCode.TimingData);
          if (_learningCode.FinalizeData())
          {
            learned = _learningCode;
            status = LearnStatus.Success;
          }
          break;
      }

      _learningCode = null;
      return status;
    }
Exemplo n.º 5
0
    /// <summary>
    /// Creates an IrCode object from old IR file bytes.
    /// </summary>
    /// <param name="data">IR file bytes.</param>
    /// <returns>New IrCode object.</returns>
    private static IrCode FromOldData(byte[] data)
    {
      List<int> timingData = new List<int>();

      int len = 0;

      for (int index = 0; index < data.Length; index++)
      {
        byte curByte = data[index];

        if ((curByte & 0x80) != 0)
          len += (curByte & 0x7F);
        else
          len -= curByte;

        if ((curByte & 0x7F) != 0x7F)
        {
          timingData.Add(len * 50);
          len = 0;
        }
      }

      if (len != 0)
        timingData.Add(len * 50);

      IrCode newCode = new IrCode(timingData.ToArray());
      newCode.FinalizeData();
      // Seems some old files have excessively long delays in them .. this might fix that problem ...

      return newCode;
    }