Beispiel #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>
        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);
                }
            }
        }
Beispiel #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>
        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);
                }
            }
        }
        public AssessmentResult(string path, string realPath, DeviceFeatures features, uint?minTimeout, uint?maxTimeout, uint?currentTimeout)
        {
            Path     = path;
            RealPath = realPath;
            Features = features;

            MinimumReceiveTimeout = minTimeout;
            MaximumReceiveTimeout = maxTimeout;
            CurrentReceiveTimeout = currentTimeout;
        }
Beispiel #4
0
        /// <summary>
        /// Open the IR device and begin reading.
        /// </summary>
        protected void CaptureFromDevice()
        {
            if (!System.Threading.Monitor.TryEnter(_capturingLocker))
            {
                throw new InvalidOperationException("Capture already in progress.");
            }
            try
            {
                OnBeforeRawCapture();

                if (string.IsNullOrWhiteSpace(CaptureDevice))
                {
                    throw new ArgumentNullException(nameof(CaptureDevice), $"The capture device must be set.");
                }

                using (var irDevice = _fileSystem.OpenRead(CaptureDevice))
                {
                    DeviceFeatures deviceFeatures = _utility.GetFeatures(irDevice);
                    CheckDevice(irDevice, deviceFeatures);

                    if (TimeoutMicrosecs >= 0)
                    {
                        _utility.SetRxTimeout(irDevice, TimeoutMicrosecs);
                    }
                    byte[] buffer = new byte[4];
                    while (true)
                    {
                        int readCount = irDevice.Stream.Read(buffer, 0, buffer.Length); // Note if "modprobe -r gpio_ir_recv" is used to unload the driver while this is reading then we get an IOException.
                        if (readCount != 4)
                        {
                            throw new System.IO.IOException($"Read {readCount} bytes instead of the expected 4.");
                        }

                        Mode2PacketType packetType = (Mode2PacketType)buffer[3];
                        buffer[3] = 0;

                        Lazy <int> number = new Lazy <int>(() => BitConverter.ToInt32(buffer));

                        if (!OnReceivePacket(packetType, number))
                        {
                            return;
                        }
                    }
                }
            }
            finally
            {
                System.Threading.Monitor.Exit(_capturingLocker);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Assess a single IR device.
        /// </summary>
        /// <param name="path">Example: /dev/lirc0</param>
        /// <exception cref="System.IO.FileNotFoundException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        /// <exception cref="NotAnIRDeviceException"></exception>
        /// <exception cref="UnauthorizedAccessException"></exception>
        public AssessmentResult AssessDevice(string path)
        {
            string fullPath = _fileSystem.GetFullPath(path);

            using (var irDevice = _fileSystem.OpenRead(fullPath))
            {
                DeviceFeatures features = _utility.GetFeatures(irDevice); /// If this is not an IR device then expect a <see cref="NotAnIRDeviceException"/> exception from this.

                string realPath = _fileSystem.GetRealPath(fullPath);

                uint?minTimeOut     = null;
                uint?maxTimeOut     = null;
                uint?currentTimeOut = null;
                if (features.CanReceive()) // Only try this query for receive devices since it is not applicable to transmit devices so is very unlikely to work.
                {
                    minTimeOut     = GetIoCtlValueIfImplemented(irDevice, LircConstants.LIRC_GET_MIN_TIMEOUT);
                    maxTimeOut     = GetIoCtlValueIfImplemented(irDevice, LircConstants.LIRC_GET_MAX_TIMEOUT);
                    currentTimeOut = GetIoCtlValueIfImplemented(irDevice, LircConstants.LIRC_GET_REC_TIMEOUT);
                }

                return(new AssessmentResult(fullPath, realPath, features, minTimeOut, maxTimeOut, currentTimeOut));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Open the IR device. Dispose the object this returns to close it.
        /// </summary>
        protected FileSystem.IOpenFile OpenDevice()
        {
            if (string.IsNullOrWhiteSpace(TransmissionDevice))
            {
                throw new ArgumentNullException(nameof(TransmissionDevice), $"The transmission device must be set.");
            }

            var irDevice = _fileSystem.OpenWrite(TransmissionDevice);

            try
            {
                DeviceFeatures deviceFeatures = _utility.GetFeatures(irDevice);
                CheckDevice(irDevice, deviceFeatures);
                ApplySettings(irDevice);
            }
            catch
            {
                irDevice.Dispose();
                throw;
            }

            return(irDevice);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new default set of application parameters with the passed name and version.
        /// </summary>
        /// <param name="name">The name of the application.</param>
        /// <param name="version">The version of the application.</param>
        public AppParameters(string name, AppVersion version)
        {
            Name    = name;
            Version = version;

            // Logger defaults
            DefaultLoggerTag        = name;
            UseThreadedLogging      = true;
            LogFileBaseName         = "application";
            LogFileTimestamp        = true;
            LogFileHistorySize      = 5;
            LogFileDirectory        = "logs";
            DefaultLoggingFormatter = null;
            DefaultLoggingPolicy    = null;
            LibraryMessageMask      = LoggingLevel.Standard;

            // Graphics defaults
            EnableValidationLayers  = false;
            EnabledGraphicsFeatures = default;
            StrictGraphicsFeatures  = true;

            // Content defaults
            GlobalContentPath = "data/Content.cpak";
        }
Beispiel #8
0
 public static bool CanReceive(this DeviceFeatures f) => LIRC_CAN_REC((uint)f);
Beispiel #9
0
 public static bool CanSend(this DeviceFeatures f) => LIRC_CAN_SEND((uint)f);