예제 #1
0
        /// <summary>
        /// Attempts auto-detection of the currently installed Navio board.
        /// </summary>
        /// <returns>
        /// Navio hardware model when detected, or null when failed.
        /// </returns>
        /// <remarks>
        /// Returns the existing model once initialized (it would not be safe to detect with hardware already in use).
        /// As the EEPROM ID is not accessible in Windows IoT, the FRAM device is used as
        /// the next best and safe probe for the hardware model. It is different in all current versions.
        /// In Navio 2 it doesn't exist.
        /// In Navio+ it exists at one address.
        /// In the original Navio it exists with two addresses (less RAM with high and low address split).
        /// The detection logic is thus:
        /// 1) See if the first FRAM address is available. No = Navio 2.
        /// 2) See if the second FRAM address is available. Yes = Navio, No = Navio+.
        /// TODO: Perform an additional test to really detect a Navio 2.
        /// </remarks>
        public static NavioHardwareModel?Detect()
        {
            // Return existing board model when present
            // We cannot interact with hardware which may already have been used.
            // It would either be locked exclusively, cause interferance or fail in an indetermined state.
            if (_board != null)
            {
                return(_board.Model);
            }

            // Thread-safe lock
            lock (_lock)
            {
                // Try to detect a Navio 1 or 1+ via FRAM model
                try
                {
                    // Connect to FRAM I2C device and read FRAM model
                    var framId = Mb85rcvDevice.GetDeviceId(Navio1FramDevice.I2cControllerIndex);
                    if (framId != null)
                    {
                        // Return Navio model for known FRAM IDs
                        if (framId == Navio1FramDevice.Navio1PlusDeviceId)
                        {
                            // Must be a Navio 1+
                            return(NavioHardwareModel.Navio1Plus);
                        }
                        if (framId == Navio1FramDevice.Navio1DeviceId)
                        {
                            // Must be a Navio 1
                            return(NavioHardwareModel.Navio1);
                        }

                        // Unsupported FRAM device ID
                        return(null);
                    }

                    // Try to detect a Navio 2 RCIO co-processor
                    using (var rcio = new Navio2RcioDevice())
                    {
                        // Must be a Navio 2
                        return(NavioHardwareModel.Navio2);
                    }
                }
                catch
                {
                    // No Navio hardware found
                    return(null);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        public RcioTerminalApplicationUIModel(TaskFactory uiTaskFactory)
            : base(uiTaskFactory)
        {
            // Run on background thread (necessary for C++/WinRT hardware access)
            Task.Run(() =>
            {
                // Ensure we are running on a Navio 2
                if (NavioDeviceProvider.Detect() != NavioHardwareModel.Navio2)
                {
                    throw new InvalidOperationException(Strings.UnsupportedModelError);
                }

                // Initialize RCIO
                Rcio = new Navio2RcioDevice();
            })
            .Wait();
        }