Example #1
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);
        }
Example #2
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);
            }
        }
Example #3
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);
        }
Example #4
0
        /// <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.");
            }
        }
Example #5
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);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        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(); }
        }
Example #8
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); }
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelayClick"/> class.
        /// </summary>
        /// <param name="socket">he socket on which the Relay Click board is plugged on MikroBus.Net</param>
        /// <param name="relay0InitialState">Sets the initial state of relay 0 : <c>true</c> = ON, <c>false</c> = OFF.</param>
        /// <param name="relay1InitialState">Sets the initial state of relay 1 : <c>true</c> = ON, <c>false</c> = OFF.</param>
        public RelayClick(Hardware.Socket socket, Boolean relay0InitialState = false, Boolean relay1InitialState = false)
        {
            // Check if needed pins are available
            Hardware.CheckPins(socket, socket.Pwm, socket.Cs);

            // Init the array containing the relays states
            _states = new [] { relay0InitialState, relay1InitialState };
            // Initialize hardware ports with requested initial states
            _relays = new [] { new OutputPort(socket.Pwm, relay0InitialState), new OutputPort(socket.Cs, relay1InitialState) };
        }
Example #10
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)
 {
     try
     {
         Hardware.CheckPins(socket, socket.Tx, socket.Rx);
         _sp = new SerialPort(Hardware.SocketTwo.ComPort, 115200, Parity.None, 8, StopBits.One);
     }
     // Catch only the PinInUse exception, so that program will halt on other exceptions
     // Send it directly to the caller
     catch (PinInUseException) { throw new PinInUseException(); }
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FlashClick"/> class.
 /// </summary>
 /// <param name="socket">The socket on the MBN mainboard.</param>
 public FlashClick(Hardware.Socket socket)
 {
     try
     {
         Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Pwm, socket.Rst);
         _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, false, true, 10000, socket.SpiModule);
         if (Hardware.SPIBus == null)
         {
             Hardware.SPIBus = new SPI(_spiConfig);
         }
     }
     catch (PinInUseException) { throw new PinInUseException(); }
 }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FTDIClick" /> class.
        /// </summary>
        /// <param name="socket">The socket on which the FTDIClick module is plugged on MikroBus.Net board</param>
        /// <param name="baudRate">The baud rate.</param>
        /// <param name="parity">The parity.</param>
        /// <param name="dataBits">The data bits.</param>
        /// <param name="stopBits">The stop bits.</param>
        /// <exception cref="MBN.Exceptions.PinInUseException"></exception>
        public FTDIClick(Hardware.Socket socket, Int32 baudRate = 9600, Parity parity = Parity.None, Int32 dataBits = 8, StopBits stopBits = StopBits.One)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Tx, socket.Rx);

                _sp = new SerialPort(socket.ComPort, baudRate, parity, dataBits, stopBits);
                _sp.Open();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to the caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Example #13
0
        private Byte[] _screen;                             // Internal buffer to hold display

        /// <summary>
        /// Initializes a new instance of the <see cref="Led8X8Click"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Led 8x8 Click board is plugged on MikroBus.Net</param>
        /// <param name="initialState">Initial state of display : enabled (true) or disabled (false). Defaults to Enabled (true).</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public Led8X8Click(Hardware.Socket socket, Boolean initialState = true)
        {
            // Checks if needed SPI pins are available
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck);

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

            Init(initialState);
        }
Example #14
0
        /// <summary>
        /// Main class constructor for Buzzer
        /// <para><b>Pins used :</b> Cs, Pwm</para>
        /// </summary>
        /// <param name="socket">The socket on which the Buzzer Click board is plugged on MikroBus.Net</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public BuzzerClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Cs, socket.Pwm);

                _buzzPwm = new PWM(socket.PwmChannel, 10000, 0, false);
                _buzzPwm.Start();
                _playList = new Melody();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Example #15
0
        private Int32 _result;                              // Result send back to caller

        /// <summary>
        /// Initializes a new instance of the <see cref="AdcClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the ADC Click board is plugged on MikroBus.Net</param>
        /// <exception cref="System.InvalidOperationException">If some pins are already used by another driver, then the exception is thrown.</exception>
        public AdcClick(Hardware.Socket socket)
        {
            // Checks if needed SPI pins are available
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck);

            // Initialize SPI
            _spiConfig = new SPI.Configuration(socket.Cs, false, 50, 50, true, true, 1000, socket.SpiModule);
            if (Hardware.SPIBus == null)
            {
                Hardware.SPIBus = new SPI(_spiConfig);
            }

            _lastValues = new Int32[4]; // Empty array for last read values
            SetScale();                 // No scaling by default
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SevenSegClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the 7Seg Click board is plugged on the MBN board</param>
        /// <param name="initialBrightness">Initial brightness in the range 0.0 (no display) to 1.0 (full brightness)</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public SevenSegClick(Hardware.Socket socket, Double initialBrightness = 1.0)
        {
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Pwm);

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

            // Sets initial brightness
            _pwm = new PWM(socket.PwmChannel, 10000, initialBrightness, false);
            _pwm.Start();
            _pwmLevel = initialBrightness;
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MotionClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the MotionClick module is plugged on MikroBus.Net board</param>
        public MotionClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Rst, socket.Int);

                resetPin = new OutputPort(socket.Rst, true);                 // Non Re-trigger mode.
                var interruptPin = new InterruptPort(socket.Int, true, Port.ResistorMode.PullUp,
                                                     Port.InterruptMode.InterruptEdgeBoth);
                interruptPin.OnInterrupt += interruptPin_OnInterrupt;
            }
            catch (PinInUseException)
            {
                throw new PinInUseException();
            }
        }
Example #18
0
 /// <summary>
 ///     Default constructor. Creates a new instance of the LCD driver.
 /// </summary>
 /// <param name="socket">"The MBN Board Socket that the Serial LCD is plugged into. </param>
 /// <param name="baudRate">The Baud Rate that the Serial LCD is set to mommunicate at.</param>
 /// <param name="parity">Parity, typically N or None.</param>
 /// <param name="dataBits">DataBits, typically 8.</param>
 /// <param name="stopBits">StopBits, typically 1.</param>
 /// <param name="size">Display size, either 2x16 or 4x20.</param>
 public SerialLCD(Hardware.Socket socket, Baud baudRate, Parity parity, int dataBits, StopBits stopBits, DisplaySize size)
 {
     try
     {
         Hardware.CheckPins(socket, socket.Tx);
         _serialLcd   = new SerialPort(socket.ComPort, (int)baudRate, parity, dataBits, stopBits);
         _displaySize = size;
         _serialLcd.Open();
         InitializeDisplay();
     }
     // Catch only the PinInUse exception, so that program will halt on other exceptions
     // Send it directly to caller
     catch (PinInUseException exception)
     {
         throw new PinInUseException(exception.Message);
     }
 }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DevantechLcd03"/> class using serial communication (UART)
        /// </summary>
        /// <param name="socket">The socket on MBN board where the Lcd is connected</param>
        public DevantechLcd03(Hardware.Socket socket)       // UART mode
        {
            try
            {
                // Checks if needed UART pins are available
                Hardware.CheckPins(socket, socket.Tx, socket.Rx);

                _uart = new SerialPort(socket.ComPort, 9600, Parity.None, 8, StopBits.Two);
                _uart.Open();

                _isUart = true;
                Init();
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Example #20
0
        private readonly PWM _pwm;                           // Brightness control

        /// <summary>
        /// Initializes a new instance of the <see cref="BarGraphClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the BarGraph Click board is plugged on MikroBus.Net</param>
        /// <param name="initialBrightness">Initial brightness in the range 0.0 (no display) to 1.0 (full brightness)</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public BarGraphClick(Hardware.Socket socket, Double initialBrightness = 1.0)
        {
            // Checks if needed SPI pins are available
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Pwm, socket.Rst);

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

            // Sets initial brightness
            _pwm = new PWM(socket.PwmChannel, 10000, initialBrightness, false);
            _pwm.Start();
            _pwmLevel = initialBrightness;
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IRClick" /> class.
        /// </summary>
        /// <param name="socket">The socket that this module is plugged in to.</param>
        /// <exception cref="PinInUseException">A PinInUseException will be thrown if the Pwm, An, Tx, Rx pins are being used by another driver in a stacked module configuration of the same socket.</exception>
        public IRClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Pwm, socket.An, socket.Tx, socket.Rx);

                CreateDevicesHashTable();

                _receiverPin = socket.An;

                IRProtocol = Protocol.NEC;
            }
            // 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);
            }
        }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BiHallClick"/> class.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the AltitudeClick is inserted into.</param>
        /// <exception cref="PinInUseException">A PinInUseException will be thrown if the Int pin is being used by another driver on the same socket.</exception>
        public BiHallClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Int);

                _interrupt              = new InterruptPort(socket.Int, true, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeBoth);
                _interrupt.OnInterrupt += _interrupt_OnInterrupt;

                _interrupt.EnableInterrupt();
            }
            // 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);
            }
        }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThermoClick"/> class.
        /// </summary>
        /// <param name="socket">The socket of the MBN board that the THERMO is connected to.</param>
        public ThermoClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck);
                spiConfiguration = new SPI.Configuration(socket.Cs, false, 1, 1, false, true, ClockRateKHz, socket.SpiModule);

                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(spiConfiguration);
                }
            }
            // 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);
            }
        }
Example #24
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)
        {
            try
            {
                Hardware.CheckPins(socket, socket.An, socket.Rst, socket.Cs, socket.Pwm, socket.Int);

                // Select1/2 : selection of decay modes. Only Fast decay implemented here.
                _select1            = new OutputPort(socket.Rst, false);
                _select2            = new OutputPort(socket.Cs, false);
                _sleep              = new OutputPort(socket.An, true);                                                                           // Sleep mode : OFF by default
                _pwmOut             = new PWM(socket.PwmChannel, frequency, dutyCycle, false);                                                   // PWM Output
                _fault              = new InterruptPort(socket.Int, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelLow); // Fault interrupt line
                _fault.OnInterrupt += Fault_OnInterrupt;                                                                                         // Subscribe to event in order to detect a fault
                _fault.EnableInterrupt();                                                                                                        // Enable interrupts
                IsMoving   = false;                                                                                                              // Motor not running
                _powerMode = PowerModes.On;
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Example #25
0
        private int _scaleLow;                           // Upper bound of scale

        #endregion

        #region CTOR

        /// <summary>
        /// Initializes a new instance of the <see cref="LightClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Light Click board is inserted on MikroBus.Net</param>
        /// <exception cref="System.InvalidOperationException">If some pins are already used by another driver, then the exception is thrown.</exception>
        public LightClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Cs, socket.Sck); //socket.Mosi is not used by MCP3201 ADC

                // Change the SPI.Configuration parameters according to the chip datasheet
                _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, true, true, 1000, socket.SpiModule);

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

                SetScale(); // No scaling by default
            }
            // 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);
            }
        }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UVClick"/> class.
        /// </summary>
        /// <param name="socket">The socket in which the UV Click board is inserted into.</param>
        /// <exception cref="PinInUseException">A <see cref="PinInUseException"/> will be thrown if the  Miso, Mosi, Sck, Cs, Rst pins are already in use in a stacked module arrangement.</exception>
        public UVClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Rst);

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

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

                _enablePin = new OutputPort(socket.Rst, true);
            }
            // 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);
            }
        }
Example #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThumbstickClick"/> class.
        /// </summary>
        /// <param name="socket">The socket in which the Thumbstick Click board is inserted into.</param>
        /// <exception cref="PinInUseException">A <see cref="PinInUseException"/> will be thrown if the  Miso, Mosi, Sck, Cs, Int pins are already in use in a stacked module arrangement.</exception>
        public ThumbstickClick(Hardware.Socket socket)
        {
            try
            {
                // Checks if needed SPI pins are available
                Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Int);

                // Initialize SPI
                _spiConfig = new SPI.Configuration(socket.Cs, false, 50, 50, true, true, 1000, socket.SpiModule);
                if (Hardware.SPIBus == null) { Hardware.SPIBus = new SPI(_spiConfig); }

                _button = new InterruptPort(socket.Int, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                _button.OnInterrupt += _button_OnInterrupt;

                Calibrate();

                ThumbstickOrientation = Orientation.RotateZeroDegrees;

            }
            // 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); }
        }
Example #28
0
// ReSharper restore InconsistentNaming

        /// <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>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public ThunderClick(Hardware.Socket socket)
        {
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Int);

            IRQ              = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            IRQ.OnInterrupt += IRQ_OnInterrupt;

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

            // Direct commands
            Hardware.SPIBus.Write(_spiConfig, new Byte[] { PRESET_DEFAULT, 0x96 });      // Set all registers in default mode
            Hardware.SPIBus.Write(_spiConfig, 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;
        }
Example #29
0
        private Gains _gain;                           // Gain mode

        /// <summary>
        /// Initializes a new instance of the <see cref="DacClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the BarGraph Click board is plugged on MikroBus.Net</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        public DacClick(Hardware.Socket socket)
        {
            try
            {
                // Checks if needed SPI pins are available
                Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Rst);

                // Initialize SPI
                _spiConfig = new SPI.Configuration(socket.Cs, false, 15, 10, false, true, 20000, socket.SpiModule);
                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(_spiConfig);
                }

                _controlBits = 0x30;          // Unbuffered, Gain 1x, active mode
                Output       = 0;             // Clean output value
                _powerMode   = PowerModes.On; // Active
                _isBuffered  = false;         // Unbuffered
                _gain        = Gains.X1;      // Gain 1x
            }
            // Catch only the PinInUse exception, so that program will halt on other exceptions
            // Send it directly to caller
            catch (PinInUseException) { throw new PinInUseException(); }
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RFIDClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the RFID Click board is plugged on MikroBus.Net board</param>
        /// <exception cref="System.InvalidOperationException">Thrown if some pins are already in use by another board on the same socket</exception>
        /// <exception cref="MBN.Exceptions.DeviceInitialisationException">RFID module not detected</exception>
        public RFIDClick(Hardware.Socket socket)
        {
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.An, socket.Rst, socket.Int);

            _rBuffer = new Byte[260];

            // Set SPI mode on the chip
            new OutputPort(socket.Rst, true);
            new OutputPort(socket.An, false);
            IRQ_IN = new OutputPort(socket.Pwm, true);
            Thread.Sleep(1);
            ToggleIRQ_IN();

            // Now that the chip is in SPI mode, we can create the NETMF configuration and talk to the module
            _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, false, true, 2000, socket.SpiModule);
            if (Hardware.SPIBus == null)
            {
                Hardware.SPIBus = new SPI(_spiConfig);
            }

            _dataReady              = new InterruptPort(socket.Int, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            _dataReady.OnInterrupt += DataReady_OnInterrupt;
            _dataReady.EnableInterrupt();

            if (Echo() != 0x55)
            {
                throw new DeviceInitialisationException("RFID device not found");
            }

            IndexMod_Gain();
            AutoFDet();
            _protocol        = RFIDProtocol.NONE; // Protocol can't be set before calibration has been done
            _calibrationDone = false;
            _powerMode       = PowerModes.On;
            _lastTag         = "";
        }