示例#1
0
 public OLED128x32Wing(II2cBus i2cBus, IIODevice device, IPin pinA, IPin pinB, IPin pinC) :
     this(i2cBus,
          device.CreateDigitalInputPort(pinA, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp),
          device.CreateDigitalInputPort(pinB, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp),
          device.CreateDigitalInputPort(pinC, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp))
 {
 }
示例#2
0
        /// <summary>
        ///   Initializes SPI connection and control pins
        /// </summary>
        /// <param name="chipEnablePin">
        ///   Number representing the chip enable pin. This pin will be set to drive output
        /// </param>
        /// <param name="chipSelectLine">
        ///   Number representing the chip select line. For RPi2, this is typically 0
        /// </param>
        /// <param name="interruptPin">
        ///   Number representing the interrupt pin. This should be a Pull-up pin, and will drive Input
        /// </param>
        public void Initialize(IIODevice device, ISpiBus spiBus, IPin chipEnablePin, IPin chipSelectLine, IPin interruptPin)
        {
            _SpiBus = spiBus;

            _cePin = device.CreateDigitalOutputPort(chipEnablePin, false);

            _csPin = device.CreateDigitalOutputPort(chipSelectLine, false);

            _irqPin          = device.CreateDigitalInputPort(interruptPin, InterruptMode.EdgeFalling, resistorMode: ResistorMode.PullUp);
            _irqPin.Changed += InterruptGpioPin_ValueChanged;

            // Module reset time
            Task.Delay(100).GetAwaiter().GetResult();

            IsInitialized = true;

            // Set reasonable default values
            Address           = Encoding.UTF8.GetBytes("NRF1");
            DataRate          = DataRate.DR2Mbps;
            IsDynamicPayload  = true;
            IsAutoAcknowledge = true;

            FlushReceiveBuffer();
            FlushTransferBuffer();
            ClearIrqMasks();
            SetRetries(5, 60);

            // Setup, CRC enabled, Power Up, PRX
            SetReceiveMode();
        }
示例#3
0
        /// <summary>
        /// Creates an instance of the NAU7802 Driver class
        /// </summary>
        /// <param name="bus"></param>
        public Hx711(IIODevice device, IPin sck, IPin dout)
        {
            this.sck     = device.CreateDigitalOutputPort(sck);
            this.dout    = device.CreateDigitalInputPort(dout);
            createdPorts = true; // we need to dispose what we create

            CalculateRegisterValues(sck, dout);
            Start();
        }
示例#4
0
        public IDigitalInputPort CreateInputPort(IIODevice device, IPin pin, bool enablePullUp = false)
        {
            if (pin != null)
            {
                return(device.CreateDigitalInputPort(pin, InterruptMode.None, ResistorMode.PullUp));
            }

            throw new Exception("Pin is out of range");
        }
示例#5
0
        protected Ds323x(I2cPeripheral peripheral, IIODevice device, IPin interruptPin)
        {
            ds323x = peripheral;

            if (interruptPin != null)
            {
                var interruptPort = device.CreateDigitalInputPort(interruptPin, InterruptMode.EdgeFalling, ResistorMode.InternalPullUp, 10, 10);
                _interruptCreatedInternally = true;

                Initialize(interruptPort);
            }
        }
示例#6
0
        /// <summary>
        /// Create a new MAG3110 object using the default parameters for the component.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="interruptPin">Digital pin connected to the alarm interrupt pin on the RTC.</param>
        public Ds3231(IIODevice device, II2cBus i2cBus, IPin interruptPin, byte address = 0x68, ushort speed = 100)
        {
            _ds323x = new I2cPeripheral(i2cBus, address);

            // samples will need to pass null
            if (interruptPin != null)
            {
                _interruptPort = device.CreateDigitalInputPort(interruptPin);

                _interruptPort.Changed += InterruptPort_Changed;
            }
        }
示例#7
0
 public Nrf24l01(
     IIODevice device,
     ISpiBus spiBus,
     IPin chipEnablePin,
     IPin chipSelectLine,
     IPin interruptPin)
     : this(
         spiBus,
         device.CreateDigitalOutputPort(chipEnablePin),
         device.CreateDigitalOutputPort(chipSelectLine),
         device.CreateDigitalInputPort(interruptPin))
 {
 }
示例#8
0
        /// <summary>
        ///     Create a new instance of the APDS9960 communicating over the I2C interface.
        /// </summary>
        /// <param name="address">Address of the I2C sensor</param>
        /// <param name="i2cBus">SI2C bus object</param>
        public Apds9960(IIODevice device, II2cBus i2cBus, IPin interruptPin, byte address = 0x39)
        {
            apds9960 = new I2cPeripheral(i2cBus, address);

            if (interruptPin != null)
            {
                interruptPort = device.CreateDigitalInputPort(interruptPin, InterruptMode.EdgeRising, ResistorMode.Disabled);

                interruptPort.Changed += InterruptPort_Changed;
            }

            Apds9960Init();
        }
示例#9
0
 public JoyWing(IIODevice device, IPin pinX, IPin pinY, IPin pinA, IPin pinB, IPin pinSelect,
                IPin pinJoyHorizontal, IPin pinJoyVertical) :
     this(device.CreateDigitalInputPort(pinX, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinY, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinA, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinB, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinSelect, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinJoyHorizontal, InterruptMode.EdgeRising),
          device.CreateDigitalInputPort(pinJoyVertical, InterruptMode.EdgeRising))
 {
 }
示例#10
0
        /// <summary>
        ///     Configure the interrupts for the ADXL362.
        /// </summary>
        /// <remark>
        ///     Set the interrupt mask for interrupt pins 1 and 2
        ///     pins to the interrupt pins on the ADXL362 if requested.
        ///
        ///     Interrupts can be disabled by passing 0 for the interrupt maps.  It is also
        ///     possible to disconnect and ADXL362 by setting the interrupt pin
        ///     to GPIO_NONE.
        /// </remark>
        /// <param name="interruptMap1">Bit mask for interrupt pin 1</param>
        /// <param name="interruptPin1">Pin connected to interrupt pin 1 on the ADXL362.</param>
        /// <param name="interruptMap2">Bit mask for interrupt pin 2</param>
        /// <param name="interruptPin2">Pin connected to interrupt pin 2 on the ADXL362.</param>
        private void ConfigureInterrupts(IIODevice device, byte interruptMap1, IPin interruptPin1, byte interruptMap2 = 0, IPin interruptPin2 = null) // TODO: interrupPin2 = IDigitalPin.GPIO_NONE
        {
            _adxl362.WriteBytes(new byte[] { Command.WriteRegister, interruptMap1, interruptMap2 });

            if (interruptPin1 != null)
            {
                _digitalInputPort1          = device.CreateDigitalInputPort(interruptPin1, InterruptMode.EdgeRising, MapResistorMode((interruptMap1 & 0xf0) > 0));
                _digitalInputPort1.Changed += InterruptChanged;
            }
            else
            {
                _digitalInputPort1 = null;
            }

            if (interruptPin2 != null)
            {
                _digitalInputPort2          = device.CreateDigitalInputPort(interruptPin2, InterruptMode.EdgeRising, MapResistorMode((interruptMap2 & 0xf0) > 0));
                _digitalInputPort2.Changed += InterruptChanged;
            }
            else
            {
                _digitalInputPort2 = null;
            }
        }
示例#11
0
        public EPDBase(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, IPin busyPin)
        {
            dataCommandPort = device.CreateDigitalOutputPort(dcPin, false);
            resetPort       = device.CreateDigitalOutputPort(resetPin, true);
            busyPort        = device.CreateDigitalInputPort(busyPin);

            spi = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(chipSelectPin));

            imageBuffer = new byte[Width * Height / 8];

            for (int i = 0; i < Width * Height / 8; i++)
            {
                imageBuffer[i] = 0xff;
            }

            Initialize();
        }
示例#12
0
 public Tb67h420ftg(IIODevice device,
                    IPin inA1, IPin inA2, IPin pwmA,
                    IPin?inB1, IPin?inB2, IPin?pwmB,
                    IPin?fault1, IPin?fault2,
                    IPin?hbMode = null, IPin?tblkab = null) : this(
         inA1 : device.CreatePwmPort(inA1), inA2 : device.CreatePwmPort(inA2),
         pwmA : device.CreateDigitalOutputPort(pwmA),
         inB1 : inB1 is null ? null : device.CreatePwmPort(inB1),
         inB2 : inB2 is null ? null : device.CreatePwmPort(inB2),
         pwmB : pwmB is null ? null : device.CreateDigitalOutputPort(pwmB),
         //fault1: null,
         fault1 is null ? null : device.CreateDigitalInputPort(fault1),
         fault2 : null,
         //fault2 is null ? null : device.CreateDigitalInputPort(fault2),
         hbMode : hbMode == null ? null : device.CreateDigitalOutputPort(hbMode),
         tblkab : tblkab == null ? null : device.CreateDigitalOutputPort(tblkab)
         )
 {
 }
示例#13
0
        /// <summary>
        ///     Turn interrupts on or off and set the conversion trigger count.
        /// </summary>
        /// <remarks>
        ///     The conversion count is the number of conversions that must be outside
        ///     of the upper and lower limits before and interrupt is generated.
        ///     See Interrupt Control Register on page 15 and 16 of the datasheet.
        /// </remarks>
        /// <param name="mode"></param>
        /// <param name="conversionCount">
        ///     Number of conversions that must be outside of the threshold before an interrupt is
        ///     generated.
        /// </param>
        /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin.  Set to null to use the previously supplied pin.</param>
        public void SetInterruptMode(IIODevice device, InterruptMode mode, byte conversionCount, IPin pin = null)
        {
            if (conversionCount > 15)
            {
                throw new ArgumentOutOfRangeException(nameof(conversionCount), "Conversion count must be in the range 0-15 inclusive.");
            }
            //
            //  Attach the interrupt event before we turn on interrupts.
            //
            if (pin != null)
            {
                if (_interruptPin != null)
                {
                    //Port: TODO check  _interruptPin.Dispose();
                }
                _interruptPin          = device.CreateDigitalInputPort(pin, Hardware.InterruptMode.EdgeRising, ResistorMode.InternalPullUp);
                _interruptPin.Changed += InterruptPin_Changed;
            }
            else
            {
                if (_interruptPin == null)
                {
                    throw new ArgumentException("Interrupt pin must be supplied");
                }
            }
            //
            // Put interrupt control in bits 4 & 5 of the Interrupt Control Register.
            // Using the enum above makes sure that mode is in the range 0-3 inclusive.
            //
            var registerValue = (byte)mode;

            registerValue <<= 4;
            //
            // conversionCount is known to be 0-15, put this in the lower four bits of
            // the Interrupt Control Register.
            //
            registerValue |= conversionCount;
            //
            //  Clear the interrupt bit before we turn them on.
            //
            ClearInterrupt();
            tsl2561.WriteRegister(Registers.InterruptControl, registerValue);
        }
示例#14
0
        public EpdColorBase(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, IPin busyPin,
                            int width, int height)
        {
            this.width  = width;
            this.height = height;

            dataCommandPort = device.CreateDigitalOutputPort(dcPin, false);
            resetPort       = device.CreateDigitalOutputPort(resetPin, true);
            busyPort        = device.CreateDigitalInputPort(busyPin);

            spi = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(chipSelectPin));

            blackImageBuffer = new byte[Width * Height / 8];
            colorImageBuffer = new byte[Width * Height / 8];

            for (int i = 0; i < blackImageBuffer.Length; i++)
            {
                blackImageBuffer[i] = 0xFF;
                colorImageBuffer[i] = 0xFF;
            }

            Initialize();
        }
示例#15
0
 /// <summary>
 /// Create a new HYSRF05 object with a IO Device
 /// HSSRF05 must be running the default 4/5 pin mode
 /// 3 pin mode is not supported on Meadow
 /// </summary>
 /// <param name="triggerPin"></param>
 /// <param name="echoPin"></param>
 public Hysrf05(IIODevice device, IPin triggerPin, IPin echoPin) :
     this(device.CreateDigitalOutputPort(triggerPin, false),
          device.CreateDigitalInputPort(echoPin, InterruptMode.EdgeBoth))
 {
 }
示例#16
0
 public HCSR_04(IIODevice device, IPin echo, IPin trigger, Unit measureUnit) : this(device.CreateDigitalInputPort(echo, InterruptMode.EdgeBoth), device.CreateDigitalOutputPort(trigger, false), measureUnit)
 {
 }
示例#17
0
 /// <summary>
 /// Create a new MAG3110 object using the default parameters for the component.
 /// </summary>
 /// <param name="device">IO Device.</param>
 /// <param name="interruptPin">Interrupt pin used to detect end of conversions.</param>
 /// <param name="address">Address of the MAG3110 (default = 0x0e).</param>
 /// <param name="speed">Speed of the I2C bus (default = 400 KHz).</param>
 public MAG3110(IIODevice device, IPin interruptPin = null, byte address = 0x0e, ushort speed = 400) :
     this(device.CreateDigitalInputPort(interruptPin, true, false, ResistorMode.Disabled), address, speed)
 {
 }
示例#18
0
 /// <summary>
 /// Create a new MAG3110 object using the default parameters for the component.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="interruptPin">Digital pin connected to the alarm interrupt pin on the RTC.</param>
 public DS3231(IIODevice device, II2cBus i2cBus, IPin interruptPin) :
     this(i2cBus, device.CreateDigitalInputPort(interruptPin))
 {
 }
示例#19
0
 /// <summary>
 /// Create a new MAG3110 object using the default parameters for the component.
 /// </summary>
 /// <param name="device">IO Device.</param>
 /// <param name="interruptPin">Interrupt pin used to detect end of conversions.</param>
 /// <param name="address">Address of the MAG3110 (default = 0x0e).</param>
 /// <param name="speed">Speed of the I2C bus (default = 400 KHz).</param>
 public Mag3110(IIODevice device, II2cBus i2cBus, IPin interruptPin = null, byte address = 0x0e, ushort speed = 400) :
     this(i2cBus, device.CreateDigitalInputPort(interruptPin, InterruptMode.EdgeRising, ResistorMode.Disabled), address)
 {
 }
示例#20
0
 /// <summary>
 /// Create a new Parallax PIR object connected to an input pin and IO Device.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="inputPin"></param>
 public ParallaxPir(IIODevice device, IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, int debounceDuration = 20, int glitchFilterCycleCount = 0) :
     this(device.CreateDigitalInputPort(pin, interruptMode, resistorMode, debounceDuration, glitchFilterCycleCount))
 {
 }
示例#21
0
 /// <summary>
 /// Create a new Parallax PIR object connected to an input pin and IO Device.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="inputPin"></param>
 public Hcsens0040(IIODevice device, IPin pin) :
     this(device.CreateDigitalInputPort(pin, InterruptMode.EdgeRising, ResistorMode.PullDown))
 {
 }
示例#22
0
 /// <summary>
 /// Instantiate a new RotaryEncoder on the specified pins.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="aPhasePin"></param>
 /// <param name="bPhasePin"></param>
 public RotaryEncoder(IIODevice device, IPin aPhasePin, IPin bPhasePin) :
     this(device.CreateDigitalInputPort(aPhasePin, InterruptMode.EdgeBoth, ResistorMode.PullUp, 0, .5),
          device.CreateDigitalInputPort(bPhasePin, InterruptMode.EdgeBoth, ResistorMode.PullUp, 0, .5))
 {
 }
        protected ushort _numberOfReads         = 0; //

        /// <summary>
        /// LinearHallEffectTachometer driver
        /// </summary>
        /// <param name="inputPin"></param>
        /// <param name="type"></param>
        /// <param name="numberOfMagnets"></param>
        /// <param name="rpmChangeNotificationThreshold"></param>
        public LinearHallEffectTachometer(IIODevice device, IPin inputPin, CircuitTerminationType type = CircuitTerminationType.CommonGround,
                                          ushort numberOfMagnets = 2, float rpmChangeNotificationThreshold = 1.0F) :
            this(device.CreateDigitalInputPort(inputPin), type, numberOfMagnets, rpmChangeNotificationThreshold)
        {
        }
示例#24
0
 public Ky038(IIODevice device, IPin A0, IPin D0) :
     this(device.CreateAnalogInputPort(A0), device.CreateDigitalInputPort(D0))
 {
 }