public DisplayTftSpiBase(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin,
            uint width, uint height)
        {
            _width = width;
            _height = height;

            spi = (SpiBus)spiBus;

            spiBuffer = new byte[_width * _height * sizeof(ushort)];
            spiReceive = new byte[_width * _height * sizeof(ushort)];

            dataCommandPort = device.CreateDigitalOutputPort(dcPin, false);
            if (resetPin != null) { resetPort = device.CreateDigitalOutputPort(resetPin, true); }
            if (chipSelectPin != null) { chipSelectPort = device.CreateDigitalOutputPort(chipSelectPin, false); }

            spiDisplay = new SpiPeripheral(spiBus, chipSelectPort);
        }
        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();
        }
Example #3
0
 /// <summary>
 /// Creates a FC28 soil moisture sensor object with the especified analog pin, digital pin and IO device.
 /// </summary>
 /// <param name="analogPort"></param>
 /// <param name="digitalPort"></param>
 public Fc28(
     IIODevice device,
     IPin analogPin,
     IPin digitalPin,
     float minimumVoltageCalibration = 0f,
     float maximumVoltageCalibration = 3.3f) :
     this(device.CreateAnalogInputPort(analogPin), device.CreateDigitalOutputPort(digitalPin), minimumVoltageCalibration, maximumVoltageCalibration)
 {
 }
Example #4
0
 /// <summary>
 ///     Create a new ADXL362 object using the specified SPI module.
 /// </summary>
 /// <param name="spiBus">Spi Bus object</param>
 /// <param name="chipSelect">Chip select pin.</param>
 public Adxl362(IIODevice device, ISpiBus spiBus, IPin chipSelect)
 {
     //
     //  ADXL362 works in SPI mode 0 (CPOL = 0, CPHA = 0).
     //
     _adxl362 = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(chipSelect));
     Reset();
     Start();
 }
Example #5
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();
        }
Example #6
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)
         )
 {
 }
        public ArducamMini(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, II2cBus i2cBus, byte address = 0x30)
        {
            i2cDevice = new I2cPeripheral(i2cBus, address);

            chipSelectPort = device.CreateDigitalOutputPort(chipSelectPin);

            spiDevice = new SpiPeripheral(spiBus, chipSelectPort);

            Initialize();
        }
Example #8
0
        /// <param name="i2cBus">I2C bus</param>
        /// <param name="address">VL53L0X address</param>
        /// <param name="units">Unit of measure</param>
        public Vl53l0x(IIODevice device, II2cBus i2cBus, IPin shutdownPin, byte address = DefaultI2cAddress, UnitType units = UnitType.mm)
        {
            i2cPeripheral = new I2cPeripheral(i2cBus, address);

            if (shutdownPin != null)
            {
                device.CreateDigitalOutputPort(shutdownPin, true);
            }
            Units = units;

            Initialize();
        }
Example #9
0
        /// <summary>
        /// Creates an instance of the A4988 Stepper Motor Driver
        /// </summary>
        /// <param name="device">The IIoDevice instance that can create Digital Output Ports</param>
        /// <param name="step">The Meadow pin connected to the STEP pin of the A4988</param>
        /// <param name="direction">The Meadow pin connected to the DIR pin of the A4988</param>
        /// <param name="enable">The (optional) Meadow pin connected to the ENABLE pin of the A4988</param>
        /// <param name="ms1">The (optional) Meadow pin connected to the MS1 pin of the A4988</param>
        /// <param name="ms2">The (optional) Meadow pin connected to the MS2 pin of the A4988</param>
        /// <param name="ms3">The (optional) Meadow pin connected to the MS3 pin of the A4988</param>
        /// <remarks>You must provide either all of the micro-step (MS) lines or none of them</remarks>
        public A4988(IIODevice device, IPin step, IPin direction, IPin enable, IPin ms1, IPin ms2, IPin ms3)
        {
            stepPort      = device.CreateDigitalOutputPort(step);
            directionPort = device.CreateDigitalOutputPort(direction);
            if (enable != null)
            {
                this.enable = device.CreateDigitalOutputPort(enable);
            }

            // micro-step lines (for now) are all-or-nothing
            // TODO: rethink this?
            if (new IPin[] { ms1, ms2, ms3 }.All(p => p != null))
            {
                this.ms1 = device.CreateDigitalOutputPort(ms1);
                this.ms2 = device.CreateDigitalOutputPort(ms2);
                this.ms3 = device.CreateDigitalOutputPort(ms3);
            }
            else if (new IPin[] { ms1, ms2, ms3 }.All(p => p == null))
            {
                // nop
            }
            else
            {
                throw new ArgumentException("All micro-step pins must be either null or valid pins");
            }

            StepAngle            = 1.8f; // common default
            RotationSpeedDivisor = 2;
        }
Example #10
0
        public TftSpiBase(IIODevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin,
                          int width, int height, DisplayColorMode mode = DisplayColorMode.Format16bppRgb565)
        {
            this.width  = width;
            this.height = height;

            spi = (SpiBus)spiBus;

            dataCommandPort = device.CreateDigitalOutputPort(dcPin, false);
            if (resetPin != null)
            {
                resetPort = device.CreateDigitalOutputPort(resetPin, true);
            }
            if (chipSelectPin != null)
            {
                chipSelectPort = device.CreateDigitalOutputPort(chipSelectPin, false);
            }

            spiDisplay = new SpiPeripheral(spiBus, chipSelectPort);

            SetColorMode(mode);
        }
Example #11
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();
        }
 /// <summary>
 /// Creates a SevenSegment connected to the especified IPins to a IODevice
 /// </summary>
 /// <param name="device"></param>
 /// <param name="pinA"></param>
 /// <param name="pinB"></param>
 /// <param name="pinC"></param>
 /// <param name="pinD"></param>
 /// <param name="pinE"></param>
 /// <param name="pinF"></param>
 /// <param name="pinG"></param>
 /// <param name="pinDecimal"></param>
 /// <param name="isCommonCathode"></param>
 public SevenSegment(
     IIODevice device,
     IPin pinA, IPin pinB,
     IPin pinC, IPin pinD,
     IPin pinE, IPin pinF,
     IPin pinG, IPin pinDecimal,
     bool isCommonCathode) :
     this(device.CreateDigitalOutputPort(pinA),
          device.CreateDigitalOutputPort(pinB),
          device.CreateDigitalOutputPort(pinC),
          device.CreateDigitalOutputPort(pinD),
          device.CreateDigitalOutputPort(pinE),
          device.CreateDigitalOutputPort(pinF),
          device.CreateDigitalOutputPort(pinG),
          device.CreateDigitalOutputPort(pinDecimal),
          isCommonCathode)
 {
 }
Example #13
0
        /// <summary>
        ///     Constructor a ShiftRegister 74595 object.
        /// </summary>
        /// <param name="pins">Number of pins in the shift register (should be a multiple of 8 pins).</param>
        /// <param name="spiBus">SpiBus object</param>
        public x74595(IIODevice device, ISpiBus spiBus, IPin pinChipSelect, int pins = 8)
        {
            // if ((pins > 0) && ((pins % 8) == 0))
            if (pins == 8)
            {
                _numberOfChips = pins / 8;

                _latchData = new byte[_numberOfChips];

                _spi = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(pinChipSelect));
            }
            else
            {
                throw new ArgumentOutOfRangeException(
                          "x74595: Size must be greater than zero and a multiple of 8 pins, driver is currently limited to one chip (8 pins)");
            }
        }
        public CharacterDisplay(IIODevice device, IPin pinRS, IPin pinE, IPin pinD4, IPin pinD5, IPin pinD6, IPin pinD7,
                                ushort rows = 4, ushort columns = 20)
        {
            DisplayConfig = new TextDisplayConfig {
                Height = rows, Width = columns
            };

            LCD_RS = device.CreateDigitalOutputPort(pinRS);
            LCD_E  = device.CreateDigitalOutputPort(pinE);
            LCD_D4 = device.CreateDigitalOutputPort(pinD4);
            LCD_D5 = device.CreateDigitalOutputPort(pinD5);
            LCD_D6 = device.CreateDigitalOutputPort(pinD6);
            LCD_D7 = device.CreateDigitalOutputPort(pinD7);

            Initialize();
        }
Example #15
0
 public CharacterDisplay(
     IIODevice device,
     IPin pinRS,
     IPin pinE,
     IPin pinD4,
     IPin pinD5,
     IPin pinD6,
     IPin pinD7,
     ushort rows = 4, ushort columns = 20) :
     this(
         device.CreateDigitalOutputPort(pinRS),
         device.CreateDigitalOutputPort(pinE),
         device.CreateDigitalOutputPort(pinD4),
         device.CreateDigitalOutputPort(pinD5),
         device.CreateDigitalOutputPort(pinD6),
         device.CreateDigitalOutputPort(pinD7),
         rows, columns)
 {
 }
 public GpioCharacterDisplay(
     IIODevice device,
     IPin pinV0,
     IPin pinRS,
     IPin pinE,
     IPin pinD4,
     IPin pinD5,
     IPin pinD6,
     IPin pinD7,
     byte rows = 4, byte columns = 20) :
     this(
         device.CreatePwmPort(pinV0, 100, 0.5f, true),
         device.CreateDigitalOutputPort(pinRS),
         device.CreateDigitalOutputPort(pinE),
         device.CreateDigitalOutputPort(pinD4),
         device.CreateDigitalOutputPort(pinD5),
         device.CreateDigitalOutputPort(pinD6),
         device.CreateDigitalOutputPort(pinD7),
         rows, columns)
 {
 }
Example #17
0
 /// <summary>
 /// Creates a Max7219 Device given a <see paramref="spiBus" /> to communicate over and the
 /// number of devices that are cascaded.
 /// </summary>
 public Max7219(IIODevice device, ISpiBus spiBus, IPin csPin, int deviceCount = 1, bool characterMode = false)
     : this(spiBus, device.CreateDigitalOutputPort(csPin), deviceCount, characterMode)
 {
 }
Example #18
0
 /// <summary>
 /// Creates a FC28 soil moisture sensor object with the especified analog pin, digital pin and IO device.
 /// </summary>
 /// <param name="analogPort"></param>
 /// <param name="digitalPort"></param>
 public FC28(IIODevice device, IPin analogPin, IPin digitalPin) :
     this(device.CreateAnalogInputPort(analogPin), device.CreateDigitalOutputPort(digitalPin))
 {
 }
Example #19
0
 public Max7219(IIODevice device, ISpiBus spiBus, IPin csPin, int deviceCount = 1, Max7219Type maxMode = Max7219Type.Display)
     : this(spiBus, device.CreateDigitalOutputPort(csPin), deviceCount, 1, maxMode)
 {
 }
Example #20
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))
 {
 }
Example #21
0
 /// <summary>
 /// Creates a LED through a pin directly from the Digital IO of the board
 /// </summary>
 /// <param name="pin"></param>
 public Led(IIODevice device, IPin pin) :
     this(device.CreateDigitalOutputPort(pin, false))
 {
 }
Example #22
0
 public HCSR_04(IIODevice device, IPin echo, IPin trigger, Unit measureUnit) : this(device.CreateDigitalInputPort(echo, InterruptMode.EdgeBoth), device.CreateDigitalOutputPort(trigger, false), measureUnit)
 {
 }
Example #23
0
        /// <summary>
        /// Creates a new DigitalOutputPort using the specified pin and initial state.
        /// </summary>
        /// <param name="pin">The pin number to create the port on.</param>
        /// <param name="initialState">Whether the pin is initially high or low.</param>
        /// <returns></returns>
        public IDigitalOutputPort CreateOutputPort(IIODevice device, IPin pin, bool initialState)
        {
            return(device.CreateDigitalOutputPort(pin, initialState));

            // throw new IndexOutOfRangeException(EM_PIN_RANGE_MESSAGE);
        }