Example #1
0
        public IOHandler()
        {
            RaspberryPi.Initialize();
            this.I2C            = new I2CBusPi();
            this.SPI            = new SPIBusPi(0);
            this.PWMGenHighFreq = new PCA9685(this.I2C, 0x4C, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain);
            this.PWMGenLowFreq  = new PCA9685(this.I2C, 0x74, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain);
            this.PWMGenHighFreq.SetFrequency(333);
            this.PWMGenLowFreq.SetFrequency(50);

            this.RailController = new Rail(this.PWMGenHighFreq.Outputs[0], new DigitalInPi(11), this.SPI, new DigitalOutPi(29), this.I2C, null)
            {
                TraceLogging = true
            };
            this.DrillController  = new Drill(this.PWMGenHighFreq.Outputs[1], this.PWMGenLowFreq.Outputs[0]);
            this.SampleController = new Sample(this.PWMGenLowFreq.Outputs[1]);
            this.LEDController    = new LEDs(this.PWMGenLowFreq.Outputs, this.PWMGenHighFreq.Outputs);
            this.AuxSensors       = new AuxSensors(this.SPI, this.I2C)
            {
                TraceLogging = false
            };
            this.SysSensors = new SysSensors();
            this.Music      = new MusicPlayer();

            this.InitProcedure   = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors, this.Music };
            this.EStopProcedure  = new ISubsystem[] { this.Music, this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors };
            this.UpdateProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController /*, this.AuxSensors, this.SysSensors*/ };
            if (this.EStopProcedure.Length < this.InitProcedure.Length || this.EStopProcedure.Length < this.UpdateProcedure.Length)
            {
                throw new Exception("A system is registered for init or updates, but not for emergency stop. For safety reasons, this is not permitted.");
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Scarlet.Components.Sensors.BNO055"/> class, which will communicate via
 /// the given I2C bus.
 /// </summary>
 /// <param name="I2C"> The I2C bus to communicate over. </param>
 /// <param name="ID"> ID of BNO055. -1 by default. You probably shouldn't change this. </param>
 /// <param name="Address"> The I2C address of the BNO055. Defaults to 0x28. You probably shouldn't change this. </param>
 public BNO055(II2CBus I2C, int ID = -1, byte Address = BNO055_ADDRESS_A)
 {
     this.ID      = ID;
     this.Address = Address;
     this.I2C     = I2C;
     Begin();
 }
Example #3
0
 public VEML6070(II2CBus Bus, byte Address = 0x38)
 {
     this.AddressLSB = Address;
     this.AddressMSB = (byte)(Address + 1);
     this.Bus        = Bus;
     SetRefreshSpeed((RefreshSpeed)this.Speed);
 }
Example #4
0
        public static void Scan(II2CBus bus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }
            int        count        = 0;
            const int  clockRateKhz = 100;
            const int  timeout      = 100;
            const byte startAddress = 0x08;
            const byte endAddress   = 127;

            Debug.Print("Scanning I2C Bus for devices starting at: " + HexString.GetString(startAddress) + " ... ");
            for (byte address = startAddress; address < endAddress; address++)
            {
                var configuration = new I2CDevice.Configuration(address, clockRateKhz);
                var buffer        = new byte[] {
                    0
                };
                bool canRead  = bus.Read(configuration, buffer, timeout);
                bool canWrite = bus.Write(configuration, buffer, timeout);
                if (canRead || canWrite)
                {
                    count++;
                    Debug.Print("Address: 0x" + HexString.GetString(address) + ", Read => " + canRead + ", Write => " + canWrite);
                }
            }
            Debug.Print("Scanning ended at: " + HexString.GetString(endAddress));
            Debug.Print("Scanning found " + count + " devices.");
        }
Example #5
0
        public HSPE16InputOnly(DeviceId id, I2CSlaveAddress address, II2CBus i2cBus)
            : base(id, new MAX7311Driver(address, i2cBus))
        {
            byte[] setupAsInputs = { 0x06, 0xFF, 0xFF };
            i2cBus.Execute(address, b => b.Write(setupAsInputs));

            FetchState();
        }
Example #6
0
        public HSPE16InputOnly(DeviceId id, I2CSlaveAddress address, II2CBus i2cBus, IHttpRequestController httpApi, ILogger logger)
            : base(id, new MAX7311Driver(address, i2cBus), httpApi, logger)
        {
            byte[] setupAsInputs = { 0x06, 0xFF, 0xFF };
            i2cBus.Execute(address, b => b.Write(setupAsInputs));

            FetchState();
        }
Example #7
0
 public HSREL5(DeviceId id, I2CSlaveAddress i2CAddress, II2CBus bus, IHttpRequestController httpApi, ILogger logger)
     : base(id, new PCF8574Driver(i2CAddress, bus), httpApi, logger)
 {
     // Ensure that all relays are off by default. The first 5 ports are hardware inverted! The other ports are not inverted but the
     // connected relays are inverted.
     SetState(new byte[] { 0xFF });
     CommitChanges(true);
 }
Example #8
0
 public TinyRTC(II2CBus bus, byte clockI2CAddress = 0x68, byte eepromI2CAddress = 0x50, int clockRateKhz = 100)
 {
     _clock = new DS1307(bus, clockI2CAddress, clockRateKhz);
     //_eeprom = new _eeprom(bus, eepromI2CAddress, clockRateKhz);
     _addressedMemoryMap = new AddressMap();
     // 4k byte of ram on eeprom >> Virtual Address 0..3999
     // 56 byte of ram on clock >> Virtual Address 5000..5055
     _addressedMemoryMap.MapRange(0, 3999, address => address, _eeprom);
 }
Example #9
0
        public void Initialize()
        {
            this.I2C1 = new I2CBusPi();

            this.SystemSensor = new INA226(this.I2C1, 0x48, 10, 0.150);
            this.DrillSensor  = new INA226(this.I2C1, 0x49, 15, 0.010);
            this.RailSensor   = new INA226(this.I2C1, 0x4A, 60, 0.002);

            this.TakeReadings = true;
        }
Example #10
0
        public MAX7311Driver(I2CSlaveAddress address, II2CBus i2CBus)
        {
            if (i2CBus == null)
            {
                throw new ArgumentNullException(nameof(i2CBus));
            }

            _address = address;
            _i2CBus  = i2CBus;
        }
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/>
		/// class with the I2C bus device this instance is connected to and
		/// the bus address of that device.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="busAddress">
		/// The bus address of the device.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null.
		/// </exception>
		/// <exception cref="IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MicrochipPotDeviceController(II2CBus device, Int32 busAddress) {
			if (device == null) {
				throw new ArgumentNullException("device");
			}

			this._busAddr = busAddress;
			this._device = device;
			if (!this._device.IsOpen) {
				this._device.Open();
			}
		}
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Scarlet.Components.Sensors.BNO055"/> class, which will communicate via
        /// the given I2C bus.
        /// </summary>
        /// <param name="I2C"> The I2C bus to communicate over. </param>
        /// <param name="ID"> ID of BNO055. -1 by default. You probably shouldn't change this. </param>
        /// <param name="Address"> The I2C address of the BNO055. Defaults to 0x28. You probably shouldn't change this. </param>
        /// <param name="GPS"> A GPS to use to correct for location-based magnetic declination. </param>
        public BNO055(II2CBus I2C, int ID = -1, byte Address = BNO055_ADDRESS_A, IGPS GPS = null)
        {
            this.ID      = ID;
            this.Address = Address;
            this.I2C     = I2C;
            this.GPS     = GPS;
            bool SetupSuccess = Begin();

            if (!SetupSuccess)
            {
                Log.Output(Log.Severity.WARNING, Log.Source.SENSORS, "BNO055 failed to initialize. Perhaps the sensor is not connected?");
            }
        }
Example #13
0
        public CCToolsBoardController(IController controller, II2CBus i2cBus)
        {
            if (i2cBus == null)
            {
                throw new ArgumentNullException(nameof(i2cBus));
            }
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

            _controller = controller;
            _i2CBus     = i2cBus;
        }
Example #14
0
 /// <summary> Prepares the PCS9535E device for use. </summary>
 /// <param name="Bus"> The I2C bus used to communicate with the device. </param>
 /// <param name="Address"> The I2C address that the device is using. </param>
 public PCA9535E(II2CBus Bus, byte Address)
 {
     this.Bus             = Bus;
     this.Address         = Address;
     this.IsChannelOutput = new bool[16];
     this.Inputs          = new PCA9535Input[16];
     this.Outputs         = new PCA9535Output[16];
     for (byte i = 0; i < this.Inputs.Length; i++)
     {
         this.IsChannelOutput[i] = false;
         this.Inputs[i]          = new PCA9535Input(this, i);
         this.Outputs[i]         = new PCA9535Output(this, i);
     }
 }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/>
        /// class with the I2C bus device this instance is connected to and
        /// the bus address of that device.
        /// </summary>
        /// <param name="device">
        /// The I2C bus device this instance is connected to.
        /// </param>
        /// <param name="busAddress">
        /// The bus address of the device.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="device"/> cannot be null.
        /// </exception>
        /// <exception cref="IOException">
        /// Unable to open the I2C bus.
        /// </exception>
        public MicrochipPotDeviceController(II2CBus device, Int32 busAddress)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            this._busAddr = busAddress;
            this._device  = device;
            if (!this._device.IsOpen)
            {
                this._device.Open();
            }
        }
Example #16
0
        /// <summary>
        /// Creates an object of type IGpioExpander.
        /// </summary>
        /// <param name="bus">Object of type II2CBus.</param>
        /// <param name="address">GPIO expander address.</param>
        /// <returns>Returns an object of type IGpioExpander.</returns>
        /// <exception cref="ArgumentNullException">Object of type II2CBus is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Invalid address value.</exception>
        /// <exception cref="KeyNotFoundException">Device not found.</exception>

#if WIRING_PI
        public static GpioExpander GetGpioExpander(this II2CBus bus, int address = GpioExpander.DefaultAddress)
        {
            if (bus is null)
            {
                throw ThrowHelper.ArgumentNullException(nameof(bus));
            }

            if (address is < 0 or > 127)
            {
                throw ThrowHelper.ArgumentOutOfRangeException(nameof(address), address);
            }

            return(new RaspberryPiExpander(bus.AddDevice(address)));
        }
Example #17
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        /// <remarks>Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/>. The <see cref="Dispose"/> method
        /// leaves the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> in an unusable state. After
        /// calling <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> so the garbage collector can reclaim
        /// the memory that the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> was occupying.</remarks>
        public override void Dispose()
        {
            if (base.IsDisposed)
            {
                return;
            }

            if (this._device != null)
            {
                this._device.Dispose();
                this._device = null;
            }

            if (this._aX != null)
            {
                this._aX.Dispose();
                this._aX = null;
            }

            if (this._aY != null)
            {
                this._aY.Dispose();
                this._aY = null;
            }

            if (this._aZ != null)
            {
                this._aZ.Dispose();
                this._aZ = null;
            }

            if (this._x != null)
            {
                this._x.Dispose();
                this._x = null;
            }

            if (this._y != null)
            {
                this._y.Dispose();
                this._y = null;
            }

            if (this._z != null)
            {
                this._z.Dispose();
                this._z = null;
            }
            base.Dispose();
        }
Example #18
0
        public PCA9685(II2CBus Bus, byte I2CAddress = 0x60)
        {
            SetAllPWM(0, 0);
            this.Bus.WriteRegister(this.Address, PCA9685_MODE2, new byte[] { OUTDRV });
            this.Bus.WriteRegister(this.Address, PCA9685_MODE1, new byte[] { ALLCALL });
            Thread.Sleep(5);

            byte mode1 = this.Bus.ReadRegister(this.Address, PCA9685_MODE1, 1)[0];

            this.Bus.WriteRegister(this.Address, PCA9685_MODE1, new byte[] { (byte)(mode1 & ~SLEEP) });
            Thread.Sleep(5);

            SetFrequency(Frequency);
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        /// <remarks>Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/>. The <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> in an unusable state. After calling
        /// <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> so the garbage collector can reclaim the memory that
        /// the <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> was occupying.</remarks>
        public void Dispose()
        {
            if (this._isDisposed)
            {
                return;
            }

            // Try to abort gracefully first.
            lock (_syncLock) {
                this._pollAbort = true;
            }

            Thread.Sleep(100);
            if ((this._pollThread != null) && (this._pollThread.IsAlive))
            {
                try {
                    // Graceful abort did not complete in time. Force terminate.
                    this._pollThread.Abort();
                }
                catch (ThreadAbortException) {
                    Thread.ResetAbort();
                }
                finally {
                    this._pollThread = null;
                }
            }

            // Cleanup everything else.
            if (this._device != null)
            {
                this._device.Dispose();
                this._device = null;
            }

            if (this._pinCache != null)
            {
                this._pinCache.Clear();
                this._pinCache = null;
            }

            if (this._currentStates != null)
            {
                this._currentStates.Clear();
                this._currentStates = null;
            }

            this._isDisposed = true;
            GC.SuppressFinalize(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>
 /// class with the I2C bus device, bus address of PCA9685 device,
 /// target frequency, and frequency correction factor.
 /// </summary>
 /// <param name="bus">
 /// The I2C bus device used to communicate with the PCA9685 chip.
 /// </param>
 /// <param name="address">
 /// The address of the PCA9685 on the I2C bus.
 /// </param>
 /// <param name="targetFreq">
 /// The target PWM frequency to set.
 /// </param>
 /// <param name="freqCorrectionFactor">
 /// The PWM frequency correction factor.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="bus"/> cannot be null.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="targetFreq"/> must be between 40Hz and 1000Hz.
 /// </exception>
 /// <exception cref="ObjectDisposedException">
 /// The specified I2C bus instance has been disposed and can no longer be used.
 /// </exception>
 /// <exception cref="IOException">
 /// An I/O error occurred. The specified address is inacessible or the
 /// I2C transaction failed.
 /// </exception>
 public PCA9685GpioProvider(II2CBus bus, Int32 address, Decimal targetFreq, Decimal freqCorrectionFactor)
 {
     if (bus == null)
     {
         throw new ArgumentNullException("bus");
     }
     this._pinCache  = new List <IPCA9685Pin>();
     this._busAddr   = address;
     this._busDevice = bus;
     if (!this._busDevice.IsOpen)
     {
         this._busDevice.Open();
     }
     this._busDevice.WriteBytes(this._busAddr, new Byte[] { PCA9685_MODE1, (Byte)0x00 });
     this.SetFrequency(targetFreq, freqCorrectionFactor);
 }
Example #21
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        /// <remarks>Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/>. The
        /// <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> in an unusable
        /// state. After calling <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> so the garbage
        /// collector can reclaim the memory that the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> was occupying.</remarks>
        public void Dispose()
        {
            if (this._isDisposed)
            {
                return;
            }

            if (this._device != null)
            {
                this._device.Dispose();
                this._device = null;
            }

            this._isDisposed = true;
            GC.SuppressFinalize(this);
        }
        public I2CHardwareBridge(I2CSlaveAddress address, II2CBus i2cBus, IHomeAutomationTimer timer)
        {
            if (i2cBus == null)
            {
                throw new ArgumentNullException(nameof(i2cBus));
            }
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }

            _address = address;
            _i2CBus  = i2cBus;

            DHT22Accessor = new DHT22Accessor(this, timer);
        }
Example #23
0
        public I2CHardwareBridge(I2CSlaveAddress address, II2CBus i2cBus, ISchedulerService schedulerService)
        {
            if (i2cBus == null)
            {
                throw new ArgumentNullException(nameof(i2cBus));
            }
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }

            _address = address;
            _i2CBus  = i2cBus;

            DHT22Accessor = new DHT22Accessor(this, schedulerService);
        }
Example #24
0
        static void Main(string[] args)
        {
            int DEGREES_OFFSET = -20;

            StateStore.Start("MagTest");
            BeagleBone.Initialize(SystemMode.DEFAULT, true);
            BBBPinManager.AddMappingsI2C(BBBPin.P9_17, BBBPin.P9_26);

            BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE);
            II2CBus I2C = I2CBBB.I2CBus1;

            Console.WriteLine("Status: BBB Pin Mapings Complete");

            if (I2C == null)
            {
                Console.WriteLine("ERROR: I2C not mapped correctly. Fix First");
            }
            else
            {
                Console.WriteLine("Status: I2C Not null");
                BNO055 magObj = new BNO055(I2C);
                Console.WriteLine("Status: BNO055 object created");

                magObj.SetMode(BNO055.OperationMode.OPERATION_MODE_COMPASS);
                magObj.Begin();

                double direction;

                while (true)
                {
                    Tuple <float, float, float> magnets;
                    magnets = magObj.GetVector(BNO055.VectorType.VECTOR_MAGNETOMETER);

                    // Convert magnetic readings to degrees
                    direction = getDegrees(magnets);

                    //Add the offset from specific location
                    direction += DEGREES_OFFSET;

                    // Make sure degrees value is between 0 and 360
                    direction = standarize(direction);

                    Console.WriteLine(direction);
                }
            }
        }
Example #25
0
 protected override void DisposeManagedResources()
 {
     if (_i2CBus != null)
     {
         _i2CBus.Dispose();
         _i2CBus = null;
     }
     if (_spiBus != null)
     {
         _spiBus.Dispose();
         _spiBus = null;
     }
     if (_onboardLed != null)
     {
         _onboardLed.Dispose();
         _onboardLed = null;
     }
 }
Example #26
0
        public AdafruitMotorPWM(Motors Motor, II2CBus Bus, byte Address = 0x60)
        {
            this.Bus     = Bus;
            this.Address = Address;
            this.Motor   = Motor;

            SetAllPWM(0, 0);
            this.Bus.WriteRegister(this.Address, PCA9685_MODE2, new byte[] { OUTDRV });
            this.Bus.WriteRegister(this.Address, PCA9685_MODE1, new byte[] { ALLCALL });
            Thread.Sleep(5);

            byte mode1 = this.Bus.ReadRegister(this.Address, PCA9685_MODE1, 1)[0];

            this.Bus.WriteRegister(this.Address, PCA9685_MODE1, new byte[] { (byte)(mode1 & ~SLEEP) });
            Thread.Sleep(5);

            SetFrequency(Frequency);
        }
Example #27
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/>
		/// class with the I2C device that represents the physical connection
		/// to the gyro.
		/// </summary>
		/// <param name="device">
		/// The I2C device that represents the physical connection to the gyro.
		/// If null, then it is assumed that the host is a revision 2 or higher
		/// board and a default <see cref="CyrusBuilt.MonoPi.IO.I2C.I2CBus"/>
		/// using the rev 2 I2C bus path will be used instead.
		/// </param>
		/// <exception cref="IOException">
		/// Unable to open the specified I2C bus device.
		/// </exception>
		/// <exception cref="ObjectDisposedException">
		/// The specified device instance has been disposed.
		/// </exception>
		public ADXL345(II2CBus device)
			: base() {
			if (device == null) {
				device = new I2CBus(BoardRevision.Rev2);
			}

			this._device = device;
			if (!this._device.IsOpen) {
				this._device.Open();
			}

			this._x = new AxisGyroscope(this, 20f);
			this._y = new AxisGyroscope(this, 20f);
			this._z = new AxisGyroscope(this, 20f);

			this._aX = (AxisGyroscope)this._x;
			this._aY = (AxisGyroscope)this._y;
			this._aZ = (AxisGyroscope)this._z;
		}
Example #28
0
        public CCToolsBoardController(IController controller, II2CBus i2cBus, IHttpRequestController httpApi, ILogger log)
        {
            if (i2cBus == null)
            {
                throw new ArgumentNullException(nameof(i2cBus));
            }
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }
            if (httpApi == null)
            {
                throw new ArgumentNullException(nameof(httpApi));
            }

            _controller = controller;
            _i2CBus     = i2cBus;

            _httpApi = httpApi;
            _log     = log;
        }
Example #29
0
        // TODO: Implement the following:
        // - Subaddress set (and use)
        // - All call set (and use)
        // - Software reset

        /// <summary> Prepares the PCA9685 device for use. </summary>
        /// <remarks> During setup, there will be quite a bit of communication with the device (70+ bytes). </remarks>
        /// <param name="Bus"> The I2C bus that the device will communicate over. </param>
        /// <param name="Address"> The I2C address set via the device's physical address pins. </param>
        /// <param name="ExtOscFreq"> If there is an external oscillator, set the frequency here. If there isn't, set to -1. </param>
        /// <param name="InvertMode"> Sets device-wide output invert mode. </param>
        /// <param name="DriverMode"> Sets device-wide output driver configuration. </param>
        /// <param name="DisableMode"> Sets device-wide output disable behaviour. </param>
        /// <exception cref="ArgumentException"> If invalid oscillator frequency is provided. </exception>
        public PCA9685(II2CBus Bus, byte Address, int ExtOscFreq = -1, OutputInvert InvertMode = OutputInvert.Regular, OutputDriverMode DriverMode = OutputDriverMode.TotemPole, OutputDisableBehaviour DisableMode = OutputDisableBehaviour.Low)
        {
            this.Bus         = Bus;
            this.PartAddress = Address;
            this.ExtOscFreq  = ExtOscFreq;
            if (ExtOscFreq < -1 || ExtOscFreq > 50000000)
            {
                throw new ArgumentException("Invalid oscillator frequency supplied. Must be between 0 and 50 MHz, or -1 for internal oscillator.");
            }
            this.Outputs = new PWMOutputPCA9685[16];
            for (byte i = 0; i < this.Outputs.Length; i++)
            {
                this.Outputs[i] = new PWMOutputPCA9685(i, this);
            }
            this.AllOutputs  = new PWMOutputPCA9685(255, this);
            this.InvertMode  = InvertMode;
            this.DriverMode  = DriverMode;
            this.DisableMode = DisableMode;
            SetupDevice();
            ReadAllStates();
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        /// <remarks>Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>. The <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> in an unusable state. After calling
        /// <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> so the garbage collector can reclaim the memory that
        /// the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> was occupying.</remarks>
        public void Dispose()
        {
            if (this._isDisposed)
            {
                return;
            }

            if (this._busDevice != null)
            {
                this._busDevice.Dispose();
                this._busDevice = null;
            }

            if (this._pinCache != null)
            {
                this._pinCache.Clear();
                this._pinCache = null;
            }

            this._isDisposed = true;
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/>
        /// class with the I2C device connection, pin A0,A1, and A2 states,
        /// the potentiometer (channel) provided by the device, how to do
        /// non-volatile I/O and the initial value for devices which are not
        /// capable of non-volatile wipers.
        /// </summary>
        /// <param name="device">
        /// The I2C bus device this instance is connected to.
        /// </param>
        /// <param name="pinA0">
        /// Whether the device's address pin A0 is high (true) or low (false).
        /// </param>
        /// <param name="pinA1">
        /// Whether the device's address pin A1 is high (true) or low (false).
        /// </param>
        /// <param name="pinA2">
        /// Whether the device's address pin A2 is high (true) or low (false).
        /// </param>
        /// <param name="channel">
        /// Which of the potentiometers provided by the device to control.
        /// </param>
        /// <param name="nonVolatileMode">
        /// The way non-volatile reads or writes are done.
        /// </param>
        /// <param name="initialNonVolWiperValue">
        /// The value for devices which are not capable of non-volatile wipers.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
        /// cannot be null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="channel"/> is not supported by this device.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// Unable to open the I2C bus.
        /// </exception>
        protected MicrochipPotentiometerBase(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
                                             MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode, Int32 initialNonVolWiperValue)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (!this.IsChannelSupported(channel))
            {
                throw new ArgumentException("Specified channel not supported by device.", "channel");
            }

            this._channel    = channel;
            this._nonVolMode = nonVolatileMode;
            Int32 deviceAddr = BuildI2CAddress(pinA0, pinA1, pinA2);

            this._controller       = new MicrochipPotDeviceController(device, deviceAddr);
            this.WiperActionEvent += this.MicrochipPotentiometerBase_WiperActionEvent;
            this.Initialize(initialNonVolWiperValue);
        }
Example #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/>
        /// class with the I2C device that represents the physical connection
        /// to the gyro.
        /// </summary>
        /// <param name="device">
        /// The I2C device that represents the physical connection to the gyro.
        /// If null, then it is assumed that the host is a revision 2 or higher
        /// board and a default <see cref="CyrusBuilt.MonoPi.IO.I2C.I2CBus"/>
        /// using the rev 2 I2C bus path will be used instead.
        /// </param>
        /// <exception cref="IOException">
        /// Unable to open the specified I2C bus device.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The specified device instance has been disposed.
        /// </exception>
        public ADXL345(II2CBus device)
            : base()
        {
            if (device == null)
            {
                device = new I2CBus(BoardRevision.Rev2);
            }

            this._device = device;
            if (!this._device.IsOpen)
            {
                this._device.Open();
            }

            this._x = new AxisGyroscope(this, 20f);
            this._y = new AxisGyroscope(this, 20f);
            this._z = new AxisGyroscope(this, 20f);

            this._aX = (AxisGyroscope)this._x;
            this._aY = (AxisGyroscope)this._y;
            this._aZ = (AxisGyroscope)this._z;
        }
Example #33
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4552"/>
		/// class with the I2C device that is the connection to MCP4552,
		/// whether the address pin A0 is high or not, Whether the device's
		/// address pin A1 is high, and the initial value of the wiper.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="initialValue">
		/// The initial value to set.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4552(II2CBus device, Boolean pinA0, Boolean pinA1, Int32 initialValue)
			: base(device, pinA0, pinA1, PIN_NOT_AVAILABLE, MicrochipPotChannel.A,
				MicrochipPotNonVolatileMode.VolatileOnly, initialValue) {
		}
Example #34
0
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4631"/>
		/// class with the I2C device connection, pin A0, A1, and A2 states,
		/// the potentiometer (channel) provided by the device, and the
		/// initial value for devices which are not capable of non-volatile wipers.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="pinA2">
		/// Whether the device's address pin A2 is high (true) or low (false).
		/// </param>
		/// <param name="channel">
		/// Which of the potentiometers provided by the device to control.
		/// </param>
		/// <param name="initialValue">
		/// The value for devices which are not capable of non-volatile wipers.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
		/// cannot be null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="channel"/> is not supported by this device.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4631(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
						MicrochipPotChannel channel, Int32 initialValue)
			: base(device, pinA0, pinA1, pinA2, channel, MicrochipPotNonVolatileMode.VolatileOnly, initialValue) {
		}
Example #35
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>
		/// class with the I2C bus device, bus address of PCA9685 device,
		/// target frequency, and frequency correction factor.
		/// </summary>
		/// <param name="bus">
		/// The I2C bus device used to communicate with the PCA9685 chip.
		/// </param>
		/// <param name="address">
		/// The address of the PCA9685 on the I2C bus.
		/// </param>
		/// <param name="targetFreq">
		/// The target PWM frequency to set. 
		/// </param>
		/// <param name="freqCorrectionFactor">
		/// The PWM frequency correction factor.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="bus"/> cannot be null.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <paramref name="targetFreq"/> must be between 40Hz and 1000Hz.
		/// </exception>
		/// <exception cref="ObjectDisposedException">
		/// The specified I2C bus instance has been disposed and can no longer be used.
		/// </exception>
		/// <exception cref="IOException">
		/// An I/O error occurred. The specified address is inacessible or the
		/// I2C transaction failed.
		/// </exception>
		public PCA9685GpioProvider(II2CBus bus, Int32 address, Decimal targetFreq, Decimal freqCorrectionFactor) {
			if (bus == null) {
				throw new ArgumentNullException("bus");
			}
			this._pinCache = new List<IPCA9685Pin>();
			this._busAddr = address;
			this._busDevice = bus;
			if (!this._busDevice.IsOpen) {
				this._busDevice.Open();
			}
			this._busDevice.WriteBytes(this._busAddr, new Byte[] { PCA9685_MODE1, (Byte)0x00 });
			this.SetFrequency(targetFreq, freqCorrectionFactor);
		}
Example #36
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>
		/// class with the I2C bus device, bus address of PCA9685 device,
		/// and target frequency.
		/// </summary>
		/// <param name="bus">
		/// The I2C bus device used to communicate with the PCA9685 chip.
		/// </param>
		/// <param name="address">
		/// The address of the PCA9685 on the I2C bus.
		/// </param>
		/// <param name="targetFreq">
		/// The target PWM frequency to set. 
		/// </param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <paramref name="targetFreq"/> must be between 40Hz and 1000Hz.
		/// </exception>
		/// <exception cref="ObjectDisposedException">
		/// The specified I2C bus instance has been disposed and can no longer be used.
		/// </exception>
		/// <exception cref="IOException">
		/// An I/O error occurred. The specified address is inacessible or the
		/// I2C transaction failed.
		/// </exception>
		public PCA9685GpioProvider(II2CBus bus, Int32 address, Decimal targetFreq)
			: this(bus, address, targetFreq, Decimal.One) {
		}
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/>. The
		/// <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> in an unusable
		/// state. After calling <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> so the garbage
		/// collector can reclaim the memory that the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotDeviceController"/> was occupying.</remarks>
		public void Dispose() {
			if (this._isDisposed) {
				return;
			}

			if (this._device != null) {
				this._device.Dispose();
				this._device = null;
			}

			this._isDisposed = true;
			GC.SuppressFinalize(this);
		}
Example #38
0
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>. The <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> in an unusable state. After calling
		/// <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> so the garbage collector can reclaim the memory that
		/// the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/> was occupying.</remarks>
		public void Dispose() {
			if (this._isDisposed) {
				return;
			}

			if (this._busDevice != null) {
				this._busDevice.Dispose();
				this._busDevice = null;
			}

			if (this._pinCache != null) {
				this._pinCache.Clear();
				this._pinCache = null;
			}

			this._isDisposed = true;
			GC.SuppressFinalize(this);
		}
Example #39
0
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/>. The <see cref="Dispose"/> method
		/// leaves the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> in an unusable state. After
		/// calling <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> so the garbage collector can reclaim
		/// the memory that the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/> was occupying.</remarks>
		public override void Dispose() {
			if (base.IsDisposed) {
				return;
			}

			if (this._device != null) {
				this._device.Dispose();
				this._device = null;
			}

			if (this._aX != null) {
				this._aX.Dispose();
				this._aX = null;
			}

			if (this._aY != null) {
				this._aY.Dispose();
				this._aY = null;
			}

			if (this._aZ != null) {
				this._aZ.Dispose();
				this._aZ = null;
			}

			if (this._x != null) {
				this._x.Dispose();
				this._x = null;
			}

			if (this._y != null) {
				this._y.Dispose();
				this._y = null;
			}

			if (this._z != null) {
				this._z.Dispose();
				this._z = null;
			}
			base.Dispose();
		}
Example #40
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/>
		/// class with the I2C bus device that is the connection to the PCF8574,
		/// and the bus address of the device.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device that is the connection to the PCF8574.
		/// </param>
		/// <param name="address">
		/// The bus address of the device.
		/// </param>
		public PCF8574GpioProvider(II2CBus device, Int32 address) {
			if (device == null) {
				throw new ArgumentNullException("device");
			}

			this._device = device;
			if (!this._device.IsOpen) {
				this._device.Open();
			}

			this._busAddress = address;
			this._pinCache = new List<IPCF8574Pin>();
			this._currentStates = new BitSet(MAX_IO_PINS);

			foreach (IPCF8574Pin pin in PCF8574Pin.ALL) {
				this._pinCache.Add(pin);
				this._pinCache[this._pinCache.IndexOf(pin)].SetState(PinState.High);
				this._currentStates.Set(pin.Address, true);
			}
		}
Example #41
0
 public Mpu6050Api(II2CBus bus, byte chipAddress = 0x68)
 {
     _i2CDeviceSocket = new I2CDeviceSocket(bus, chipAddress);
 }
Example #42
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.Honeywell.HMC5883L"/>
		/// class with the I2C device that represents the physical connection
		/// to the gyro and the bus address of the device.
		/// </summary>
		/// <param name="device">
		/// The I2C device that represents the physical connection to the gyro.
		/// If null, then it is assumed that the host is a revision 2 or higher
		/// board and a default <see cref="CyrusBuilt.MonoPi.IO.I2C.I2CBus"/>
		/// using the rev 2 I2C bus path will be used instead.
		/// </param>
		/// <param name="address">
		/// The bus address of the device.
		/// </param>
		/// <exception cref="IOException">
		/// Unable to open the specified I2C bus device.
		/// </exception>
		/// <exception cref="ObjectDisposedException">
		/// The specified device instance has been disposed.
		/// </exception>
		public HMC5883L(II2CBus device, Int32 address)
			: this(device) {
			this._address = address;
		}
Example #43
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Gyroscope.AnalogDevices.ADXL345"/>
		/// class with the I2C device that represents the physical connection
		/// to the gyro and the bus address of the device.
		/// </summary>
		/// <param name="device">
		/// The I2C device that represents the physical connection to the gyro.
		/// If null, then it is assumed that the host is a revision 2 or higher
		/// board and a default <see cref="CyrusBuilt.MonoPi.IO.I2C.I2CBus"/>
		/// using the rev 2 I2C bus path will be used instead.
		/// </param>
		/// <param name="busAddress">
		/// The bus address of the device.
		/// </param>
		/// <exception cref="IOException">
		/// Unable to open the specified I2C bus device.
		/// </exception>
		/// <exception cref="ObjectDisposedException">
		/// The specified device instance has been disposed.
		/// </exception>
		public ADXL345(II2CBus device, Int32 busAddress)
			: this(device) {
			this._address = busAddress;
		}
Example #44
0
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/>. The <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> in an unusable state. After calling
		/// <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> so the garbage collector can reclaim the memory that
		/// the <see cref="CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider"/> was occupying.</remarks>
		public void Dispose() {
			if (this._isDisposed) {
				return;
			}

			// Try to abort gracefully first.
			lock (_syncLock) {
				this._pollAbort = true;
			}

			Thread.Sleep(100);
			if ((this._pollThread != null) && (this._pollThread.IsAlive)) {
				try {
					// Graceful abort did not complete in time. Force terminate.
					this._pollThread.Abort();
				}
				catch (ThreadAbortException) {
					Thread.ResetAbort();
				}
				finally {
					this._pollThread = null;
				}
			}

			// Cleanup everything else.
			if (this._device != null) {
				this._device.Dispose();
				this._device = null;
			}

			if (this._pinCache != null) {
				this._pinCache.Clear();
				this._pinCache = null;
			}

			if (this._currentStates != null) {
				this._currentStates.Clear();
				this._currentStates = null;
			}

			this._isDisposed = true;
			GC.SuppressFinalize(this);
		}
Example #45
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4541"/>
		/// class with the I2C device that is the connection to MCP4541,
		/// whether the address pin A0 is high or not, and the way to
		/// handle non-volatile I/O.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4541(II2CBus device, Boolean pinA0, MicrochipPotNonVolatileMode nonVolatileMode)
			: base(device, pinA0, PIN_NOT_AVAILABLE, PIN_NOT_AVAILABLE,
				MicrochipPotChannel.A, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM) {
		}
Example #46
0
 public I2CDeviceSocket(II2CBus bus, byte chipAddress)
 {
     _bus = bus;
     _chipAddress = chipAddress;
 }
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/>
		/// class with the I2C device connection, pin A0,A1, and A2 states,
		/// the potentiometer (channel) provided by the device, how to do
		/// non-volatile I/O and the initial value for devices which are not
		/// capable of non-volatile wipers.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="pinA2">
		/// Whether the device's address pin A2 is high (true) or low (false).
		/// </param>
		/// <param name="channel">
		/// Which of the potentiometers provided by the device to control.
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <param name="initialNonVolWiperValue">
		/// The value for devices which are not capable of non-volatile wipers.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
		/// cannot be null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="channel"/> is not supported by this device.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		protected MicrochipPotentiometerBase(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
			MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode, Int32 initialNonVolWiperValue)
			: base() {
			if (device == null) {
				throw new ArgumentNullException("device");
			}
				
			if (!this.IsChannelSupported(channel)) {
				throw new ArgumentException("Specified channel not supported by device.", "channel");
			}
				
			this._channel = channel;
			this._nonVolMode = nonVolatileMode;
			Int32 deviceAddr = BuildI2CAddress(pinA0, pinA1, pinA2);
			this._controller = new MicrochipPotDeviceController(device, deviceAddr);
			this.WiperActionEvent += this.MicrochipPotentiometerBase_WiperActionEvent;
			this.Initialize(initialNonVolWiperValue);
		}
Example #48
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.PCA.PCA9685GpioProvider"/>
		/// class with the I2C bus device and bus address of PCA9685 device.
		/// This overload uses the default target frequency value.
		/// </summary>
		/// <param name="bus">
		/// The I2C bus device used to communicate with the PCA9685 chip.
		/// </param>
		/// <param name="address">
		/// The address of the PCA9685 on the I2C bus.
		/// </param>
		/// <exception cref="ObjectDisposedException">
		/// The specified I2C bus instance has been disposed and can no longer be used.
		/// </exception>
		/// <exception cref="IOException">
		/// An I/O error occurred. The specified address is inacessible or the
		/// I2C transaction failed.
		/// </exception>
		public PCA9685GpioProvider(II2CBus bus, Int32 address)
			: this(bus, address, DEFAULT_FREQUENCY) {
		}
Example #49
0
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4661"/>
		/// class with the I2C device connection, pin A0, A1, and A2 states,
		/// the potentiometer (channel) provided by the device, and how to
		/// do non-volatile I/O.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="pinA2">
		/// Whether the device's address pin A2 is high (true) or low (false).
		/// </param>
		/// <param name="channel">
		/// Which of the potentiometers provided by the device to control.
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
		/// cannot be null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="channel"/> is not supported by this device.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4661(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
						MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode)
			: base(device, pinA0, pinA1, pinA2, channel, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM) {
		}