Ejemplo n.º 1
0
        /// <summary>
        /// When the device is opened this is called to check that the device is OK (e.g. has the right capabilities, etc).
        /// </summary>
        protected virtual void CheckDevice(FileSystem.IOpenFile irDevice, DeviceFeatures deviceFeatures)
        {
            if (!deviceFeatures.CanSend())
            {
                throw new NotSupportedException("This IR device cannot send.");
            }

            if (!deviceFeatures.HasFlag(DeviceFeatures.SendModePulse))
            {
                throw new NotSupportedException("Only PULSE mode is supported for sending, but this device does not support PULSE.");
            }

            uint sendMode = _fileSystem.IoCtlReadUInt32(irDevice, LircConstants.LIRC_GET_SEND_MODE);

            if (sendMode != LircConstants.LIRC_MODE_PULSE)
            {
                // The Raspberry Pi only supports PULSE mode and so it is the default mode, but incase that changes got the option to set the mode.
                try
                {
                    _fileSystem.IoCtlWrite(irDevice, LircConstants.LIRC_SET_SEND_MODE, LircConstants.LIRC_MODE_PULSE);
                }
                catch (System.ComponentModel.Win32Exception err)
                {
                    throw new NotSupportedException("Unable to set send mode to PULSE.", err);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// When the device is opened this is called to check that the device is OK (e.g. has the right capabilities, etc).
        /// </summary>
        private void CheckDevice(FileSystem.IOpenFile irDevice, DeviceFeatures deviceFeatures)
        {
            if (!deviceFeatures.CanReceive())
            {
                throw new NotSupportedException("This IR device cannot receive.");
            }

            if (!deviceFeatures.HasFlag(DeviceFeatures.ReceiveModeMode2))
            {
                throw new NotSupportedException("Only MODE2 is supported for capture, but this device does not support MODE2.");
            }

            uint recMode = _fileSystem.IoCtlReadUInt32(irDevice, LircConstants.LIRC_GET_REC_MODE);

            if (recMode != LircConstants.LIRC_MODE_MODE2)
            {
                // The Raspberry Pi seems to always default to MODE2 when opening, but in case that changes got the option to set the mode.
                try
                {
                    _fileSystem.IoCtlWrite(irDevice, LircConstants.LIRC_SET_REC_MODE, LircConstants.LIRC_MODE_MODE2);
                }
                catch (System.ComponentModel.Win32Exception err)
                {
                    throw new NotSupportedException("Unable to set receive mode to MODE2.", err);
                }
            }
        }