Esempio n. 1
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;
        }
Esempio n. 2
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;
        }