Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AltitudeClick"/> class.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the AltitudeClick is inserted into.</param>
        /// <param name="clockRateI2">The <see cref="MBN.Enums.ClockRatesI2C"/> for I2C communication.</param>
        /// <param name="i2CTimeout">The universal I2C Transaction Timeout value to wait for I2C transactions to complete.</param>
        /// <exception cref="DeviceInitialisationException">A DeviceInitialisationException will be thrown if the AltitudeClick does not complete its initialization properly.</exception>
        /// <exception cref="PinInUseException">A PinInUseException will be thrown if the I2C pins are being used for non-I2C function.</exception>
        public AltitudeClick(Hardware.Socket socket, ClockRatesI2C clockRateI2, int i2CTimeout = 1000)
        {
            try
            {
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket);

                // Create the driver's I²C configuration
                _i2CConfig = new I2CDevice.Configuration(I2CAddress, (int)clockRateI2);

                _i2CTimeout = i2CTimeout;

                // Check if it's the first time an I²C device is created
                if (Hardware.I2CBus == null)
                {
                    Hardware.I2CBus = new I2CDevice(_i2CConfig);
                }

                if (!Init())
                {
                    throw new DeviceInitialisationException("The AltitudeClick has failed to initialize");
                }
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to caller.
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JoystickClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the JoystickClick module is plugged on MikroBus.Net board</param>
        /// <param name="address">The address of the module.</param>
        /// <param name="clockRateKHz">The clock rate of the I²C device. <seealso cref="ClockRatesI2C"/></param>
        public JoystickClick(Hardware.Socket socket, Byte address = 0x40, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz)
        {
            try
            {
                // Checks if needed I²C pins are available.
                Hardware.CheckPinsI2C(socket, socket.Int, socket.Rst, socket.Cs);

                // Create the driver's I²C configuration
                _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);

                _reset = new OutputPort(socket.Rst, true);
                Reset(ResetModes.Hard);

                Sensitivity = 0x3F; // Max sensitivity
                Scaling     = 0x09; // 100% scaling

                Button = new InterruptPort(socket.Cs, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
                Button.EnableInterrupt();

                PowerMode     = PowerModes.On;  // Interrupt mode
                InterruptLine = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
                TimeBase      = 3;
                ReadRegister(0x11);     // Don't care about the first data available
                InterruptLine.EnableInterrupt();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to the caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Exemple #3
0
        private readonly I2CDevice.Configuration _config;      // I²C configuration

        /// <summary>
        /// Initializes a new instance of the <see cref="ProximityClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Proximity Click board is plugged on MikroBus.Net</param>
        /// <param name="address">Address of the I²C device.</param>
        /// <param name="clockRate">Clock rate of the Proximity Click board.</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public ProximityClick(Hardware.Socket socket, Byte address = 0x13, ClockRatesI2C clockRate = ClockRatesI2C.Clock100KHz)
        {
            // Checks if needed I²C pins are available
            Hardware.CheckPinsI2C(socket, socket.Int);

            // Create the driver's I²C configuration
            _config = new I2CDevice.Configuration(address, (Int32)clockRate);
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EEpromClick"/> class.
 /// </summary>
 /// <param name="socket">The socket on which the EEpromClick module is plugged on MikroBus.Net board</param>
 /// <param name="address">The address of the module.</param>
 /// <param name="clockRateKHz">The clock rate of the I²C device. <seealso cref="ClockRatesI2C"/></param>
 /// <param name="memorySize">Optionnal size of the memory chip, in KB. Default to 8KB, as sold by MikroElektronika.</param>
 public EEpromClick(Hardware.Socket socket, Byte address = 0xA0, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz, Int32 memorySize = 8)
 {
     try
     {
         Hardware.CheckPinsI2C(socket, socket.Pwm);
         _config     = new I2CDevice.Configuration((ushort)(address >> 1), (Int32)clockRateKHz);
         _memorysize = memorySize * 1024;
     }
     catch (PinInUseException) { throw new PinInUseException(); }
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PressureClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Pressure Click board is plugged on MikroBus.Net</param>
        /// <param name="address">Address of the I²C device.</param>
        /// <param name="clockRateKHz">Clock rate of the Pressure Click board.</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public PressureClick(Hardware.Socket socket, Byte address = (0xBA >> 1), ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz)
        {
            // Checks if needed I²C pins are available
            Hardware.CheckPinsI2C(socket);

            // Create the driver's I²C configuration
            _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);
            if (!Init())
            {
                throw new DeviceInitialisationException("Device failed to initialize");
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IRThermoClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the IRThermo Click board is plugged on MikroBus.Net board</param>
        /// <param name="address">The address of the display. Default to 0x5A.</param>
        /// <param name="clockRateKHz">The clock rate of the I²C device. Default to ClockRatesI2C.Clock100KHz. <seealso cref="ClockRatesI2C"/></param>
        /// <exception cref="MBN.Exceptions.PinInUseException">Thrown if a pin is already in use by another driver.</exception>
        public IRThermoClick(Hardware.Socket socket, Byte address = 0x5A, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz)
        {
            try
            {
                Hardware.CheckPinsI2C(socket, socket.Scl, socket.Sda);

                _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HT16K33"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the HT16K33 board is plugged on MikroBus.Net board</param>
        /// <param name="address">The address of the display. Default to 0x70.</param>
        /// <param name="clockRateKHz">The clock rate of the I²C device. Default to ClockRatesI2C.Clock400KHz. <seealso cref="ClockRatesI2C"/></param>
        public HT16K33(Hardware.Socket socket, Byte address = 0x70, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock400KHz)
        {
            // Checks if needed I²C pins are available
            Hardware.CheckPinsI2C(socket, socket.Scl, socket.Sda);

            // Create the driver's I²C configuration
            _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);

            _buffer   = new Byte[11];
            PowerMode = PowerModes.On;
            ClearDisplay();
            Display(true);
            Brightness = 15;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HTU21DClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the HTU21DClick module is plugged on MikroBus.Net board</param>
        /// <param name="clockRateKHz">Optional - The clock rate of the I²C device. <seealso cref="ClockRatesI2C"/> Defaults to 400KHz.</param>
        /// <param name="timeout">OPtional - The I2C Transaction timeout before returning. Defaults to 1000 ms.</param>
        public HTU21DClick(Hardware.Socket socket, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock400KHz, int timeout = 1000)
        {
            try
            {
                Hardware.CheckPinsI2C(socket);

                _config  = new I2CDevice.Configuration(HTDU21D_WRITE_ADDRESS, (Int32)clockRateKHz);
                _timeout = timeout;

                Reset(ResetModes.Soft);
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to the caller.
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CapSenseClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the CapSense Click board is plugged on MikroBus.Net</param>
        /// <param name="address">Address of the I²C device.</param>
        /// <param name="clockRateKHz">Clock rate of the Proximity Click board.</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public CapSenseClick(Hardware.Socket socket, Byte address = 0x00, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz)
        {
            try
            {
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket);

                // Create the driver's I²C configuration
                _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);
                Init();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IlluminanceClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Illuminance Click module is plugged on MikroBus.Net board</param>
        /// <param name="address">The user selectable I2C Address of the module based on Logic Level of Jumper J1. See <see cref="I2CAddress"/> for more information.</param>
        /// <param name="clockRateKHz">The clock rate of the I²C device. <seealso cref="ClockRatesI2C"/> for more information.</param>
        /// <param name="timeout">Optional, the I2C transaction timeout in milliseconds. The default value is 1000 ms.</param>
        public IlluminanceClick(Hardware.Socket socket, I2CAddress address, ClockRatesI2C clockRateKHz, int timeout = 1000)
        {
            try
            {
                Hardware.CheckPinsI2C(socket, socket.Int);
                _config  = new I2CDevice.Configuration((ushort)address, (Int32)clockRateKHz);
                _timeout = timeout;

                if (!Init())
                {
                    throw new DeviceInitialisationException("Illuminance Click not found");
                }
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to the caller.
            catch (PinInUseException ex) { throw new PinInUseException(ex.Message); }
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccelClick"/> class.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the RTC Click board is inserted into.</param>
        /// <param name="address">Address of the module.</param>
        /// <param name="clockSpeed">The speed of the I2C Clock. See <see cref="ClockRatesI2C"/></param>
        /// <param name="autoStart">if set to <c>true</c> [automatic start].</param>
        /// <exception cref="System.SystemException">ADXL345 not detected</exception>
        public AccelClick(Hardware.Socket socket, Byte address = 0x1D, ClockRatesI2C clockSpeed = ClockRatesI2C.Clock100KHz, Boolean autoStart = false)
        {
            // Checks if needed I²C pins are available
            Hardware.CheckPinsI2C(socket, socket.Int);

            // Create the driver's I²C configuration
            _config = new I2CDevice.Configuration(address, (Int32)clockSpeed);
            if (ReadRegister((Byte)RegisterMap.DEVID) != 0xE5)
            {
                throw new SystemException("ADXL345 not detected");
            }
            _int1 = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            // Initialize our sensor
            InitSensor(autoStart);
        }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DevantechLcd03"/> class using I²C communication
        /// </summary>
        /// <param name="socket">The socket on MBN board where the Lcd is connected</param>
        /// <param name="address">I²C address (7 bits) of the LCD. </param>
        public DevantechLcd03(Hardware.Socket socket, Byte address)     // I²C mode
        {
            try
            {
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket);
                // Create the driver's I²C configuration
                _config = new I2CDevice.Configuration(address, (Int32)ClockRatesI2C.Clock100KHz);

                _isUart = false;
                Init();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Color Click board is plugged on MikroBus.Net board</param>
        /// <param name="address">The address of the display. Default to 0x29.</param>
        /// <param name="clockRateKHz">The clock rate of the I²C device. Default to ClockRatesI2C.Clock100KHz. <seealso cref="ClockRatesI2C"/></param>
        public ColorClick(Hardware.Socket socket, Byte address = 0x29, ClockRatesI2C clockRateKHz = ClockRatesI2C.Clock100KHz)
        {
            Hardware.CheckPinsI2C(socket, socket.Int, socket.An, socket.Cs, socket.Pwm);

            _config = new I2CDevice.Configuration(address, (Int32)clockRateKHz);

            Init();
            LedR = new OutputPort(socket.An, false);
            LedG = new OutputPort(socket.Cs, false);
            LedB = new OutputPort(socket.Pwm, false);
            var dataReady = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);

            dataReady.OnInterrupt += _dataReady_OnInterrupt;

            dataReady.EnableInterrupt();
        }
Exemple #14
0
        /// <summary>
        ///     Default Constructor
        /// </summary>
        /// <param name="socket">The socket that the BMP180 Module is connected into.</param>
        /// <param name="clockRate">I2CBus clock speed, either standard or high speed bus.</param>
        /// <param name="i2CTimeout">I2C Transaction timeout.</param>
        /// <param name="resetBusyPin">The CPU.Pin used internally to test is the BMP180 Module has completed reset process.</param>
        public BMP180(Hardware.Socket socket, ClockRatesI2C clockRate, int i2CTimeout, Cpu.Pin resetBusyPin = Cpu.Pin.GPIO_NONE)
        {
            try
            {
                if (resetBusyPin == Cpu.Pin.GPIO_NONE)
                {
                    resetBusyPin = socket.An;
                }
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket, resetBusyPin);

                // Create the driver's I²C configuration
                _i2CConfiguration = new I2CDevice.Configuration(0x77, (byte)clockRate);
                _i2CTimeout       = i2CTimeout;

                // Check if it's the first time an I²C device is created
                if (Hardware.I2CBus == null)
                {
                    Hardware.I2CBus = new I2CDevice(_i2CConfiguration);
                }

                // Is the BMP180 there?
                if (!IsConnected())
                {
                    throw new DeviceInitialisationException("BMP180 not found.");
                }

                // Get Calibration Data
                if (!GetCalibrationData())
                {
                    throw new DeviceInitialisationException("BMP180 GetCalibrationData failed.");
                }

                _resetBusyPin = new OutputPort(resetBusyPin, false);
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to caller
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
Exemple #15
0
        /// <summary>
        /// Initializes a new instance of the RTC2click class.
        /// </summary>
        /// <param name="socket">The socket that the RTC2 is inserted into.</param>
        /// <param name="clockKHz">The speed of the I2C Clock. See <see cref="ClockRatesI2C"/>.</param>
        /// <param name="timeout">I2C Transaction timeout.</param>
        public RTC2Click(Hardware.Socket socket, ClockRatesI2C clockKHz, int timeout)
        {
            try
            {
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket);

                _i2CTimeout       = timeout;
                _i2CConfiguration = new I2CDevice.Configuration(Registers.I2C_ADDRESS, (int)clockKHz);

                // Check if it's the first time an I²C device is created
                if (Hardware.I2CBus == null)
                {
                    Hardware.I2CBus = new I2CDevice(_i2CConfiguration);
                }
                SetSquareWave(SqwFrequency.SqwOff); // Turn off SQW output and set it to initial state off.
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
Exemple #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FMClick"/> class.
        /// </summary>
        /// <param name="socket">The socket that this module is plugged in to.</param>
        /// <param name="clockRateI2C">The <see cref="ClockRatesI2C"/> </param>
        /// <param name="i2CTimeout">The I2C Transaction Timeout Period before returning an error in I2C communication.</param>
        public FMClick(Hardware.Socket socket, ClockRatesI2C clockRateI2C, int i2CTimeout = 1000)
        {
            try
            {
                // Checks if needed I²C pins are available
                Hardware.CheckPinsI2C(socket, socket.Rst);

                _i2CTimeOut = i2CTimeout;

                // Create the driver's I²C configuration
                _i2CConfiguration = new I2CDevice.Configuration(0x10, (int)clockRateI2C);

                // Check if it's the first time an I²C device is created
                if (Hardware.I2CBus == null)
                {
                    Hardware.I2CBus = new I2CDevice(_i2CConfiguration);
                }

                _resetPin = new OutputPort(socket.Rst, false);

                PowerUp();

                SetRadioConfiguration(Spacing.UsaAustralia, Band.UsaEurope);

                //Start at the bottom of the radio band and at the lowest output volume.
                Station = MinChannel;
                Volume  = MinVolume;

                new Thread(RdsWorkerThread).Start();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions and send it directly to caller.
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }