示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OLEDCClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the OLEDc Click board is inserted on MikroBus.Net</param>
        /// <exception cref="PinInUseException">If some pins are already used by another driver, then the exception is thrown.</exception>
        /// <example>Example usage:
        /// <code language = "C#">
        ///	var _oled = new OLEDCClick(Hardware.SocketFour);
        /// </code>
        /// <code language = "VB">
        ///	Dim _oled as OLEDCClick = New OLEDCClick(Hardware.SocketFour)
        /// </code>
        /// </example>
        public OLEDCClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Cs, socket.Sck, socket.Rst, socket.An, socket.Pwm);

                _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, true, true, 40000, socket.SpiModule);

                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(_spiConfig);
                }

                _resetPin = new OutputPort(socket.Rst, true);
                _dcPin    = new OutputPort(socket.Pwm, true);
                _rwPin    = new OutputPort(socket.An, true);

                _canvas = new MikroBitmap(_canvasWidth, _canvasHeight);

                InitilizeOLED();
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TempHum6Click" /> class.
        /// </summary>
        /// <param name="socket">The socket on which the TempHum6Click module is plugged on MikroBus.Net board</param>
        public TempHum6Click(Hardware.Socket socket)
        {
            _socket = socket;
            _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(0x43, 100000));

            // Reset device
            Reset(ResetModes.Soft);

            // Deactivate Low Power to be able to read the PartID and UID registers.
            PowerMode = PowerModes.On;

            PartID = BitConverter.ToUInt16(ReadRegister(ENS210_REG_PART_ID, 2), 0);

            if (PartID != 0x210)
            {
                throw new DeviceInitialisationException("TempHum6 Click not found on I2C Bus.");
            }
            UniqueID = BitConverter.ToInt64(ReadRegister(ENS210_REG_UID, 8), 0);

            ConfigureSensor(new SensorConfiguration(
                                true,
                                true,
                                MeasurementMode.Continuous,
                                MeasurementMode.Continuous,
                                false));
        }
        /// <summary>Initializes a new instance of the <see cref="Proximity3Click" /> class.</summary>
        /// <param name="socket">The socket on which the ADC3 Click board is plugged on MikroBus.Net</param>
        /// <param name="address">The I2C address of the module</param>
        public Proximity3Click(Hardware.Socket socket, Byte address = 0x51)
        {
            _prox = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000));

            if (ChipRevision.Major == 0x10 & ChipRevision.Minor == 0x58)
            {
                _prox.Write(new Byte[] { ALS_CONF_REG, _alsConf, 0b00000000 });
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Wifi"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Wifi module is plugged on MikroBus.Net board</param>
        public Wifi(Hardware.Socket socket)
        {
            Hardware.CheckPins(socket, socket.Tx, socket.Rx, socket.Rst);

            //CurrentProfile = 0;
            _profilesCount = 0;
            _profiles      = new ConnectionProfile[2];

            //_error = 0;
            //_nStat = 0;
            //Hibernating = false;
            _chipReady    = false;
            _receivedData = new ArrayList();
            _firstTime    = true;
            _commands     = new Queue();
            _sp           = new SerialPort(socket.ComPort, 115200, Parity.None, 8, StopBits.Two);
            _sp.Open();
            _sp.DataReceived += sp_DataReceived;

            _resetPort = new OutputPort(socket.Rst, true);
            Thread.Sleep(10);
            _resetPort.Write(false);
            Thread.Sleep(10);
            _resetPort.Write(true);
        }
示例#5
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(); }
        }
示例#6
0
        public NRFC(Hardware.Socket socket)
        {
            _socket = socket;
            // Initialize SPI
            _nrf = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Initialize IRQ Port
            _irqPin = GpioController.GetDefault().OpenPin(socket.Int);
            _irqPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            _irqPin.ValueChanged += IrqPin_ValueChanged;
            //_irqPin = new InterruptPort(socket.Int, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            // Initialize Chip Enable Port
            _cePin = GpioController.GetDefault().OpenPin(socket.Rst);
            _cePin.SetDriveMode(GpioPinDriveMode.Output);
            _cePin.Write(GpioPinValue.Low);

            // Module reset time
            Thread.Sleep(100);

            _initialized = true;

            _transmitSuccessFlag = new ManualResetEvent(false);
            _transmitFailedFlag  = new ManualResetEvent(false);
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RotaryClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the module is plugged.</param>
        public RotaryClick(Hardware.Socket socket)
        {
            _rot = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Initialize the display and the internal counter
            Write(0);
            InternalCounter = 0;

            // First encoder
            _encA = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _encA.SetDriveMode(GpioPinDriveMode.Input);
            _aLastState         = _encA.Read();
            _encA.ValueChanged += EncA_ValueChanged;

            // Second encoder
            _encB = GpioController.GetDefault().OpenPin(socket.AnPin);
            _encB.SetDriveMode(GpioPinDriveMode.Input);

            // Button switch
            _sw = GpioController.GetDefault().OpenPin(socket.Int);
            _sw.SetDriveMode(GpioPinDriveMode.InputPullDown);
            _sw.ValueChanged += Sw_ValueChanged;
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OLEDCClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the OLEDc Click board is inserted on MikroBus.Net</param>
        /// <example>Example usage:
        /// <code language = "C#">
        ///	var _oled = new OLEDCClick(Hardware.SocketFour);
        /// </code>
        /// </example>
        public OLEDCClick(Hardware.Socket socket)
        {
            _socket = socket;
            SpiConnectionSettings settings = new SpiConnectionSettings
            {
                ChipSelectType        = SpiChipSelectType.Gpio,
                ChipSelectLine        = GpioController.GetDefault().OpenPin(socket.Cs),
                ChipSelectActiveState = false,
                Mode           = SpiMode.Mode3,
                ClockFrequency = 40 * 1000 * 1000
            };

            _oled = SpiController.FromName(socket.SpiBus).GetDevice(settings);

            _resetPin = GpioController.GetDefault().OpenPin(socket.Rst);
            _resetPin.SetDriveMode(GpioPinDriveMode.Output);
            _resetPin.Write(GpioPinValue.High);

            _dataCommandPin = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _dataCommandPin.SetDriveMode(GpioPinDriveMode.Output);
            _dataCommandPin.Write(GpioPinValue.High);

            _readWritePin = GpioController.GetDefault().OpenPin(socket.AnPin);
            _readWritePin.SetDriveMode(GpioPinDriveMode.Output);
            _readWritePin.Write(GpioPinValue.High);

            Canvas = new MikroBitmap(_canvasWidth, _canvasHeight);

            InitilizeOLED();
        }
示例#9
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);
            }
        }
示例#10
0
        /// <summary>
        ///     Default constructor for the Current Click board.
        /// </summary>
        /// <param name="socket">The MBN Socket that the Current click is inserted into.</param>
        /// <param name="shuntResistorResistorValue">The value in Ohms of the resistor in the ShuntResistor Terminal Block</param>
        /// <param name="userDefinedShuntResistor">
        ///     Optional User Defined value of the ShuntResistor Resistor.
        ///     To use a User Defined ShuntResistor Resistor, set the value of the <see cref="ShuntResistor"/> to SR_CUSTOM
        /// </param>
        public CurrentClick(Hardware.Socket socket, ShuntResistor shuntResistorResistorValue, float userDefinedShuntResistor = 1f)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck);

                _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, true, true, 1000, socket.SpiModule);

                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(_spiConfig);
                }

                if (shuntResistorResistorValue == ShuntResistor.SR_CUSTOM)
                {
                    _userdefinedShuntResistorValue = userDefinedShuntResistor;
                }
                else
                {
                    _shuntResistorResistorValue = shuntResistorResistorValue;
                }
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FlashMemory"/> class.
        /// </summary>
        /// <param name="socket">The socket on the MBN mainboard.</param>
        public FlashMemory(Hardware.Socket socket, Boolean detectParameters = true, Int32 hold = -1, Int32 wp = -1)
        {
            _socket = socket;
            _flash  = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 10000000
            });

            if (wp != -1)
            {
                GpioPin _wp = GpioController.GetDefault().OpenPin(wp);
                _wp.SetDriveMode(GpioPinDriveMode.Output);
                _wp.Write(GpioPinValue.High);
            }

            if (hold != -1)
            {
                GpioPin _hold = GpioController.GetDefault().OpenPin(hold);
                _hold.SetDriveMode(GpioPinDriveMode.Output);
                _hold.Write(GpioPinValue.High);
            }
            if (detectParameters)
            {
                DetectParameters();
            }
        }
示例#12
0
        /// <summary>Initializes a new instance of the <see cref="GPS2Click" /> class.</summary>
        /// <param name="socket">The socket on which the module is plugged</param>
        public GPS2Click(Hardware.Socket socket)
        {
            _sl = new SerialListener('$', '\n');
            _sl.MessageAvailable += Sl_MessageAvailable;

            _wakeUp = GpioController.GetDefault().OpenPin(socket.AnPin);
            _wakeUp.SetDriveMode(GpioPinDriveMode.Input);

            _onOff = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _onOff.SetDriveMode(GpioPinDriveMode.Output);
            // Force full mode
            _onOff.Write(GpioPinValue.Low);
            Thread.Sleep(100);
            _onOff.Write(GpioPinValue.High);
            Thread.Sleep(100);
            _onOff.Write(GpioPinValue.Low);
            Thread.Sleep(1);
            _onOff.Write(GpioPinValue.High);
            Thread.Sleep(100);

            _gps2 = UartController.FromName(socket.ComPort); // Socket #1
            _gps2.SetActiveSettings(new UartSetting()
            {
                BaudRate = 4800, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None
            });
            _gps2.DataReceived += Gps2_DataReceived;
            _gps2.Enable();
        }
示例#13
0
        /// <summary>
        ///     Default constructor
        /// </summary>
        /// <param name="socket">The socket in which the USB UART click board is inserted into.</param>
        /// <param name="baudRate">Baud Rate enumeration of usable baud rates (ones that actually work), see <see cref="System.IO.Ports.SerialPort.BaudRate"/></param>
        /// <param name="handshake">Optional - Handshake, defaults to None, see <see cref="System.IO.Ports.Handshake"/>. <see cref="System.IO.Ports.Handshake.RequestToSend "/> is not functional and will be set to <see cref="Handshake.None"/>.</param>
        /// <exception cref="PinInUseException">A <see cref="PinInUseException"/> will be thrown if the Tx, Rx, Rst, Int, Cs, Pwm are used in a stacked module arrangement.</exception>
        public USBUARTClick(Hardware.Socket socket, BaudRate baudRate, Handshake handshake)
        {
            try
            {
                // Rst Pin is connected to FT232RL CTS Pin, Int Pin is connected to FT232RL RTS Pin, Pwm Pin is connected to FT232RL CBUS3 Pin (USB Power), Cs Pin is connected to FT232RL CBUS4 Pin (USB Sleep/Suspend)
                Hardware.CheckPins(socket, socket.Tx, socket.Rx, socket.Rst, socket.Int, socket.Cs, socket.Pwm);
                _serial = new SimpleSerial(socket.ComPort, (int)baudRate)
                {
                    Handshake = handshake == Handshake.RequestToSend ? Handshake.None : handshake
                };

                _serial.DataReceived  += _serial_DataReceived;
                _serial.ErrorReceived += _serial_ErrorReceived;
                _serial.Open();

                _powerPin = new InterruptPort(socket.Pwm, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                _sleepPin = new InterruptPort(socket.Cs, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

                _powerPin.OnInterrupt += powerPin_OnInterrupt;
                _sleepPin.OnInterrupt += sleepPin_OnInterrupt;

                _powerPin.EnableInterrupt();
                _sleepPin.EnableInterrupt();
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CanSpiClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the CANSPIclick module is plugged</param>
        public CanSpiClick(Hardware.Socket socket)
        {
            _socket = socket;
            // Initialize SPI
            _canSpi = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode3,
                ClockFrequency = 2000000
            });

            _rst = GpioController.GetDefault().OpenPin(socket.Rst);
            _rst.SetDriveMode(GpioPinDriveMode.Output);
            _rst.Write(GpioPinValue.High);

            _int = GpioController.GetDefault().OpenPin(socket.Int);
            _int.SetDriveMode(GpioPinDriveMode.Input);
            _int.ValueChangedEdge = GpioPinEdge.FallingEdge;
            _int.ValueChanged    += INT_ValueChanged;

            if (!Reset(ResetModes.Hard))
            {
                throw new NotImplementedException("MCP2515 initialisation failed!");
            }
        }
示例#15
0
文件: DigiPot.cs 项目: valoni/NETMF44
        private byte _currentResistance;                     // Resistance

        /// <summary>
        /// Main class for the MikroE Digipot Click board driver
        /// </summary>
        /// <param name="socket">The socket on which the Digipot Click board is plugged on MikroBus.Net</param>
        /// <param name="initialResistance">The initial resistance the Digipot should be initialized with.</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public DigiPotClick(Hardware.Socket socket, byte initialResistance)
        {
            try
            {
                // Checks if needed SPI pins are available
                Hardware.CheckPins(socket, socket.Cs, socket.Sck, socket.Mosi, socket.Miso);

                // Initialize SPI
                _spiConfig = new SPI.Configuration(
                    socket.Cs,                              //   Cpu.Pin ChipSelect_Port,
                    false,                                  //   bool ChipSelect_ActiveState,
                    10,                                     //   uint ChipSelect_SetupTime,
                    20,                                     //   uint ChipSelect_HoldTime,
                    true,                                   //   bool Clock_IdleState,
                    false,                                  //   bool Clock_Edge,
                    10000,                                  //   uint Clock_RateKHz,
                    socket.SpiModule);
                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(_spiConfig);
                }

                _currentResistance = initialResistance;
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
示例#16
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>
        public JoystickClick(Hardware.Socket socket, Byte address = 0x40)
        {
            // Create the driver's I²C configuration
            _joystick = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000));

            WriteRegister(Registers.CONTROL1, 0b11110000);

            _reset = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _reset.SetDriveMode(GpioPinDriveMode.Output);
            Reset(ResetModes.Hard);

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

            Button = GpioController.GetDefault().OpenPin(socket.Cs);
            Button.SetDriveMode(GpioPinDriveMode.Input);

            PowerMode = PowerModes.On;      // Interrupt mode

            InterruptLine = GpioController.GetDefault().OpenPin(socket.Int);
            InterruptLine.SetDriveMode(GpioPinDriveMode.InputPullUp);

            TimeBase = 3;
            ReadRegister(0x11);     // Don't care about the first data available
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThunderClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Thunder Click board is plugged on MikroBus.Net board</param>
        public ThunderClick(Hardware.Socket socket)
        {
            _socket = socket;
            IRQ     = GpioController.GetDefault().OpenPin(socket.Int);
            IRQ.SetDriveMode(GpioPinDriveMode.Input);
            IRQ.ValueChanged += IRQ_ValueChanged;

            // Initialize SPI
            _thunder = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Direct commands
            lock (_socket.LockSpi)
            {
                _thunder.Write(new Byte[] { PRESET_DEFAULT, 0x96 });                     // Set all registers in default mode
                _thunder.Write(new Byte[] { CALIB_RCO, 0x96 });                          // Calibrate internal oscillators
            }
            _nfl                = 2;                                                     // Noise floor level
            _mode               = AFE.Indoor;                                            // Default mode is Indoor
            _spikeRejection     = 2;                                                     // Default value for spike rejection
            _minNumberLightning = 0;                                                     // Minimum number of detected lightnings
            INL_Indoor          = new[] { 28, 45, 62, 78, 95, 112, 130, 146 };           // Indoor continuous input noise level values (µV rms)
            INL_Outdoor         = new[] { 390, 630, 860, 1100, 1140, 1570, 1800, 2000 }; // Outdoor continuous input noise level values (µV rms)
            _powerMode          = PowerModes.On;
        }
示例#18
0
文件: RHT03.cs 项目: valoni/NETMF44
        /// <summary>
        /// Initializes a new instance of the <see cref="RHT03"/> class.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the RHT03 Sensor is connected to.</param>
        public RHT03(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Rst, socket.Int);

                _portIn              = new InterruptPort(socket.Rst, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
                _portIn.OnInterrupt += portIn_OnInterrupt;
                _portIn.DisableInterrupt(); // Enabled automatically in the previous call

                _portOut = new TristatePort(socket.Int, false, false, Port.ResistorMode.PullUp);
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }

            _pollingTimer = new Timer(UpdateReadings, null, Timeout.Infinite, Timeout.Infinite);

            InitSensor();

            if (SensorError != null)
            {
                SensorError(this, "RHT03 Sensor Initialization is complete.");
            }
        }
示例#19
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>
 public CapSenseClick(Hardware.Socket socket, Byte address = 0x00)
 {
     _socket = socket;
     // Create the driver's I²C configuration
     _cap = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000));
     Init();
 }
示例#20
0
        public NRFC(Hardware.Socket socket)
        {
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Rst, socket.Int);

            _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, false, true, 2000, socket.SpiModule);
            if (Hardware.SPIBus == null)
            {
                Hardware.SPIBus = new SPI(_spiConfig);
            }

            // Initialize IRQ Port
            _irqPin              = new InterruptPort(socket.Int, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            _irqPin.OnInterrupt += HandleInterrupt;

            // Initialize Chip Enable Port
            _cePin = new OutputPort(socket.Rst, false);

            // Module reset time
            Thread.Sleep(100);

            _initialized = true;

            _transmitSuccessFlag = new ManualResetEvent(false);
            _transmitFailedFlag  = new ManualResetEvent(false);
        }
示例#21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DCMotorClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the DCMotor Click board is plugged on MikroBus.Net</param>
        /// <param name="frequency">The frequency of the PWM output. Default value is 1000 Hz</param>
        /// <param name="dutyCycle">The initial duty cycle of PWM. Default to 0.0 %, that is : motor stopped</param>
        public DCMotorClick(Hardware.Socket socket, Double frequency = 1000.0, Double dutyCycle = 0.0)
        {
            // Select1/2 : selection of decay modes. Only Fast decay implemented here.
            _select1 = GpioController.GetDefault().OpenPin(socket.Rst);
            _select1.SetDriveMode(GpioPinDriveMode.Output);
            _select1.Write(GpioPinValue.Low);

            _select2 = GpioController.GetDefault().OpenPin(socket.Cs);
            _select2.SetDriveMode(GpioPinDriveMode.Output);
            _select2.Write(GpioPinValue.Low);

            _sleep = GpioController.GetDefault().OpenPin(socket.AnPin);
            _sleep.SetDriveMode(GpioPinDriveMode.Output);
            _sleep.Write(GpioPinValue.High);

            var PWM = PwmController.FromName(socket.PwmController);

            PWM.SetDesiredFrequency(frequency);
            _pwmOut = PWM.OpenChannel(socket.PwmChannel);
            _pwmOut.SetActiveDutyCyclePercentage(dutyCycle);

            _fault = GpioController.GetDefault().OpenPin(socket.Int);
            _fault.SetDriveMode(GpioPinDriveMode.Input);
            _fault.ValueChanged += Fault_ValueChanged;

            IsMoving   = false;                                                    // Motor not running
            _powerMode = PowerModes.On;
        }
示例#22
0
        /// <summary>
        ///     Default Constructor.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the SHT11 Click is inserted in.</param>
        public SHT11Click(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Sda, socket.Scl);

                _dataPort = new TristatePort(socket.Sda, false, true, Port.ResistorMode.PullDown)
                {
                    Active = true
                };
                _clkPort = new OutputPort(socket.Scl, false);

                // Reset the SHT11 click and throw DeviceInitialisationException on failure. This will also reset the SHT11 Click to Factory Default Settings in the StatusRegister.
                if (!Reset(ResetModes.Soft))
                {
                    throw new DeviceInitialisationException("Failed to initialize the SHT11 Click.");
                }

                _timer = new Timer(HeaterControlDelegate, null, -1, -1);

                AlarmThresholds = new AlarmThresholds(-40F, 123.8F, 0F, 100F);
            }
            // 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); }
        }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StepperClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Stepper Click board is plugged on MikroBus.Net</param>
        public StepperClick(Hardware.Socket socket)
        {
            _ms1    = GpioController.GetDefault().OpenPin(socket.AnPin);
            _ms2    = GpioController.GetDefault().OpenPin(socket.Rst);
            _dir    = GpioController.GetDefault().OpenPin(socket.Cs);
            _enable = GpioController.GetDefault().OpenPin(socket.Int);
            _step   = GpioController.GetDefault().OpenPin(socket.PwmPin);

            _ms1.SetDriveMode(GpioPinDriveMode.Output);
            _ms2.SetDriveMode(GpioPinDriveMode.Output);
            _dir.SetDriveMode(GpioPinDriveMode.Output);
            _enable.SetDriveMode(GpioPinDriveMode.Output);
            _step.SetDriveMode(GpioPinDriveMode.Output);

            // Default step size to full step
            _ms1.Write(GpioPinValue.Low);
            _ms2.Write(GpioPinValue.Low);

            //Enable outputs
            _enable.Write(GpioPinValue.Low);

            // Default direction is Clockwise
            _dir.Write(GpioPinValue.Low);

            // Ensure no step at startup
            _step.Write(GpioPinValue.Low);
        }
示例#24
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);
        }
示例#25
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>
        public HTU21DClick(Hardware.Socket socket)
        {
            _socket = socket;
            _htu    = I2cController.FromName(socket.I2cBus)
                      .GetDevice(new I2cConnectionSettings(HTDU21D_WRITE_ADDRESS, 400000));

            Reset(ResetModes.Soft);
        }
示例#26
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Pressure4Click" /> class using the I2C interface.
        /// </summary>
        /// <param name="socket">The virtual socket on which the Pressure4Click module is connected to on the MikroBus.Net board</param>
        /// <param name="slaveAddress">The I2C Slave Address <see cref="I2CAddress"/> to use.</param>
        public Pressure4Click(Hardware.Socket socket, I2CAddress slaveAddress)
        {
            _interface = Interface.I2C;

            _sensorI2C = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 400000));

            Initialize();
        }
示例#27
0
        private static void TestGnss4(Hardware.Socket socket)
        {
            _gnss4 = new Gnss4Click(socket);

            GPSUtilities.GSAFrameReceived += GPSUtilities_GSAFrameReceived;
            GPSUtilities.GGAFrameReceived += GPSUtilities_GGAFrameReceived;
            GPSUtilities.RMCFrameReceived += GPSUtilities_RMCFrameReceived;
            GPSUtilities.GSVFrameReceived += GPSUtilities_GSVFrameReceived;
        }
示例#28
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="memorySize">Optionnal size of the memory chip, in KB. Default to 8KB, as sold by MikroElektronika.</param>
 public EEpromClick(Hardware.Socket socket, Byte address, Int32 memorySize = 8)
 {
     // Create the driver's I²C configuration
     _eeprom     = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000));
     _memorysize = memorySize * 1024;
     gpio.GpioPin _wp = gpio.GpioController.GetDefault().OpenPin(socket.PwmPin);
     _wp.SetDriveMode(gpio.GpioPinDriveMode.Output);
     _wp.Write(gpio.GpioPinValue.Low);
 }
示例#29
0
        /// <summary>
        /// Initializes a new instance of the TempHum 7 Click class
        /// </summary>
        /// <param name="socket">
        ///     The socket that TempHum 7 Click is plugged into.
        /// </param>
        public TempHum7Click(Hardware.Socket socket)
        {
            _socket = socket;
            _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(0x40, 400000));

            Thread.Sleep(50); // Time from VDD >= 1.64V until ready for a full conversion.

            HumidityMeasurementMode = MeasurementMode.NoHold;
        }
示例#30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpeakUpClick"/> class.
 /// </summary>
 /// <param name="socket">The socket on which the SpeakUpClick module is plugged on MikroBus.Net board</param>
 public SpeakUpClick(Hardware.Socket socket)
 {
     _sp = UartController.FromName(socket.ComPort);
     _sp.SetActiveSettings(new UartSetting()
     {
         BaudRate = 115200, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None
     });
     _sp.Enable();
 }