예제 #1
0
        /// <summary>
        /// Scan for devices on the I2C bus and populate the internal list. By default,
        /// the standard speed (100KHz) and shared bus mode is used
        /// </summary>
        /// <param name="startAddr">The I2C address to start scanning</param>
        /// <param name="endAddr">The I2C address to end scanning</param>
        /// <returns>Total devices found on the bus</returns>
        public int ScanDevicesOnBus(int startAddr, int endAddr)
        {
            if (startAddr < 0 || startAddr > 127 || startAddr > endAddr || endAddr > 127)
            {
                throw new ArgumentException("Invalid I2C address range");
            }

            byte[]            tempBuffer = new byte[8]; //why 8??
            I2cDevice         device     = null;
            I2cTransferStatus xferStatus = I2cTransferStatus.FullTransfer;

            for (int addr = startAddr; addr <= endAddr; addr++)
            {
                device = I2cDevice.FromId(_deviceSelector, new I2cConnectionSettings(addr)
                {
                    BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
                });
                xferStatus = device.ReadPartial(tempBuffer).Status;
                if (xferStatus == I2cTransferStatus.FullTransfer || xferStatus == I2cTransferStatus.PartialTransfer)
                {
                    //we have a device...
                    _i2CDevices.Add(addr, device);
                }
            }
            return(_i2CDevices.Count);
        }
예제 #2
0
 // Constructor for i2c bus
 // Example: EEprom24LC256 eeprom = new EEprom24LC256(EEprom24LC256.DeviceConnectionSting.I2C1, 0x54);
 public EEprom24LC256(string device, byte DeviceAddress)
 {
     EEprom = I2cDevice.FromId(device, new I2cConnectionSettings(DeviceAddress)
     {
         BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
     });
 }
예제 #3
0
        public static ADS1015 CreateDevice(string i2cBus, byte hardwareAddress = BASE_ADDRESS, I2cBusSpeed busSpeed = I2cBusSpeed.StandardMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive)
        {
            // Create the I2c connection settings instance.
            I2cConnectionSettings settings = new I2cConnectionSettings(hardwareAddress)
            {
                BusSpeed = busSpeed, SharingMode = sharingMode
            };

            // Create teh I2c device instance
            var i2cDevice = I2cDevice.FromId(i2cBus, settings);

            if (i2cDevice == null)
            {
                // No device was created
                throw new Exception("Unable to create I2c instance.");
            }

            try
            {
                var instance = new ADS1015(i2cDevice);
                return(instance);
            }
            catch (Exception)
            {
                i2cDevice?.Dispose();
                throw;
            }
        }
예제 #4
0
 // Constructor for i2c bus
 // Example: OLED oled = new OLED(OLED.DeviceConnectionSting.I2C1, 0x3C);
 public OLED(string device, byte DeviceAddress)
 {
     SS1306 = I2cDevice.FromId(device, new I2cConnectionSettings(DeviceAddress)
     {
         BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
     });
 }
예제 #5
0
        public static AT30TS75A CreateDevice(string i2cBus, byte hardwareAddress = BASE_ADDRESS, I2cBusSpeed busSpeed = I2cBusSpeed.StandardMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive)
        {
            // Create the I2c connection settings instance.
            I2cConnectionSettings settings = new I2cConnectionSettings(hardwareAddress)
            {
                BusSpeed = busSpeed, SharingMode = sharingMode
            };

            // Create teh I2c device instance
            var i2cDevice = I2cDevice.FromId(i2cBus, settings);

            if (i2cDevice == null)
            {
                // No device was created
                throw new Exception("Unable to create I2c instance.");
            }


            try
            {
                var instance = new AT30TS75A(i2cDevice);

                // Configure the device (normal operation, 12 bit percision)
                instance._i2cDevice.Write(new byte[] { 0x01, 0b01100010 });

                return(instance);
            }
예제 #6
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="I2CBus">The socket that has SPI bus.</param>
        public TempHumidSI70(string I2CBus)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this);

            //this.i2c = new GTI.SoftwareI2CBus(socket, Socket.Pin.Five, Socket.Pin.Four, TempHumidSI70.I2C_ADDRESS, 400, this);

            var Devices = DeviceInformation.FindAll(I2CBus);

            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_ADDRESS);

            //Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz
            // Or
            Setting.BusSpeed = I2cBusSpeed.FastMode; // 400kHz
            //Debug.WriteLine("jumlah device : "+Devices.Length);
            i2c = I2cDevice.FromId(Devices[0].Id, Setting);

            this.writeBuffer1 = new byte[1] {
                TempHumidSI70.MEASURE_HUMIDITY_HOLD
            };
            this.writeBuffer2 = new byte[1] {
                TempHumidSI70.READ_TEMP_FROM_PREVIOUS
            };
            this.readBuffer1 = new byte[2];
            this.readBuffer2 = new byte[2];
        }
예제 #7
0
        /// <summary>
        /// Initialises a new Wii Nunchuk
        /// </summary>
        /// <param name="busId">The identifier of the I²C bus.</param>
        /// <param name="slaveAddress">The I²C address.</param>
        /// <param name="busSpeed">The bus speed, an enumeration that defaults to StandardMode</param>
        /// <param name="sharingMode">The sharing mode, an enumeration that defaults to Shared.</param>
        public WiiNunchuk(string busId, ushort slaveAddress = 0x52, I2cBusSpeed busSpeed = I2cBusSpeed.StandardMode, I2cSharingMode sharingMode = I2cSharingMode.Shared)
        {
            I2cTransferResult result;

            // This initialisation routine seems to work. I got it at http://wiibrew.org/wiki/Wiimote/Extension_Controllers#The_New_Way
            Device = I2cDevice.FromId(busId, new I2cConnectionSettings(slaveAddress)
            {
                BusSpeed    = busSpeed,
                SharingMode = sharingMode,
            });

            result = Device.WritePartial(new byte[] { 0xf0, 0x55 });
            if (result.Status != I2cTransferStatus.FullTransfer)
            {
                throw new ApplicationException("Something went wrong reading the Nunchuk. Did you use proper pull-up resistors?");
            }

            result = Device.WritePartial(new byte[] { 0xfb, 0x00 });
            if (result.Status != I2cTransferStatus.FullTransfer)
            {
                throw new ApplicationException("Something went wrong reading the Nunchuk. Did you use proper pull-up resistors?");
            }

            this.Device.Write(new byte[] { 0xf0, 0x55 });
            this.Device.Write(new byte[] { 0xfb, 0x00 });
        }
예제 #8
0
        public static DS1307 CreateDevice(string i2cBus, int i2cAddress = HARDWARE_BASE_ADDRESS, I2cBusSpeed busSpeed = I2cBusSpeed.StandardMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive)
        {
            try
            {
                // Setup our connection settings to the I2C bus
                I2cConnectionSettings i2cSettings = new I2cConnectionSettings(i2cAddress)
                {
                    BusSpeed = busSpeed, SharingMode = sharingMode
                };

                // Get an instance of the i2CDevice.
                var i2cDevice = I2cDevice.FromId(i2cBus, i2cSettings);

                // Create an instance of our device.
                var instance = new DS1307(i2cDevice);

                // Set the defaults for our device

                // Return the instance to the caller
                return(instance);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #9
0
        public static DS3231M CreateDevice(string i2cBus, byte hardwareAddress = BASE_ADDRESS, I2cBusSpeed busSpeed = I2cBusSpeed.StandardMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive, GpioPin alarmPin = null)
        {
            // Create the I2c connection settings instance.
            I2cConnectionSettings settings = new I2cConnectionSettings(hardwareAddress)
            {
                BusSpeed = busSpeed, SharingMode = sharingMode
            };

            // Create teh I2c device instance
            var i2cDevice = I2cDevice.FromId(i2cBus, settings);

            if (i2cDevice == null)
            {
                // No device was created
                throw new Exception("Unable to create I2c instance.");
            }

            try
            {
                var instance = new DS3231M(i2cDevice, alarmPin);
                instance._i2cDevice.Write(new byte[] { DS3231_CONTROL_ADDR, DS3231_INTCN });

                return(instance);
            }
            catch (Exception)
            {
                i2cDevice?.Dispose();
                throw;
            }
        }
예제 #10
0
        private void SetupCapacitiveTouchController(int portId)
        {
            var Setting = new I2cConnectionSettings(I2C_ADDRESS)
            {    // the slave's address
                BusSpeed = I2cBusSpeed.FastMode
            };

            i2cBus = I2cDevice.FromId(I2CBus, Setting);

            //var Devices = DeviceInformation.FindAll(I2CBus);

            // Device I2C1 Slave address
            //I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_ADDRESS);
            //Setting.BusSpeed = I2cBusSpeed.FastMode; // 400kHz
            //i2cBus = I2cDevice.FromId(Devices[0].Id, Setting);
            resultBuffer  = new byte[1];
            addressBuffer = new byte[1];
            //i2cBus = new I2cDevice(new I2cDevice.Configuration(0x38, 400));

            var controller = GpioController.GetDefault();

            this.touchInterrupt = controller.OpenPin(portId);
            this.touchInterrupt.SetDriveMode(GpioPinDriveMode.Input);
            //touchInterrupt = new InterruptPort(portId, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            touchInterrupt.ValueChanged += TouchInterrupt_ValueChanged;

            //+= (object sender, GpioPinValueChangedEventArgs e) =>

            //touchInterrupt.OnInterrupt += (a, b, c) => this.OnTouchEvent();
        }
예제 #11
0
        static void Main()
        {
            int address = 0;

            byte[] write = { 0, 1, 2 };
            byte[] read  = new byte[3];
            for (address = 0; address < 127; address++)
            {
                var settings = new I2cConnectionSettings((byte)(address));
                settings.SharingMode = I2cSharingMode.Shared;
                settings.BusSpeed    = I2cBusSpeed.FastMode;

                I2cDevice DisplayDevice = I2cDevice.FromId(FEZ.I2cBus.I2c1, settings);
                DisplayDevice.Write(write);
                Thread.Sleep(100);
                DisplayDevice.Read(read);
                if (read[0] != 0 || read[1] != 0 || read[2] != 0)
                {
                    for (var i = 0; i < read.Length; i++)
                    {
                        read[i] = 0;
                    }
                    Debug.WriteLine($"It is device on {address.ToString("X2")} address");
                }

                //Debug.WriteLine(read[0].ToString() + " " + read[1].ToString() + " " + read[2].ToString() + "  " + address.ToString("X2"));
            }
            Debug.WriteLine("Finish");
        }
예제 #12
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Gyro(string I2CBus)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('I', this);

            this.readBuffer1  = new byte[1];
            this.writeBuffer1 = new byte[1];
            this.writeBuffer2 = new byte[2];
            this.readBuffer8  = new byte[8];

            this.offsetX = 0;
            this.offsetY = 0;
            this.offsetZ = 0;
            //this.timer.Tick += (a) => this.TakeMeasurement();
            var Devices = DeviceInformation.FindAll(I2CBus);

            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_ADDRESS);

            Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz
            i2c = I2cDevice.FromId(Devices[0].Id, Setting);

            //this.i2c = I2cDeviceFactory.Create(socket, 0x68, 100, this);

            this.SetFullScaleRange();
            TimerInterval = new TimeSpan(0, 0, 0, 0, 200);
            autoEvent     = new AutoResetEvent(false);
            //StartTimer(); //new GT.Timer(200);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="INA219Controller"/> class.
        /// </summary>
        /// <param name="i2cBus">Designated I2C bus that has only INA219 devices</param>
        public INA219Controller(string i2cBus)
        {
            this.INADevices = new ArrayList();
            int  INAAddress = INAStartAddress;
            bool isRunning  = true;

            while (isRunning)
            {
                I2cDevice currentINA;

                currentINA = I2cDevice.FromId(
                    i2cBus,
                    new I2cConnectionSettings(INAAddress)
                {
                    BusSpeed    = I2cBusSpeed.StandardMode,
                    SharingMode = I2cSharingMode.Exclusive
                });

                byte[] writeBuffer = { 0 };
                byte[] readBuffer  = { 0 };

                currentINA.Write(writeBuffer);
                currentINA.Read(readBuffer);

                if (BitConverter.ToInt16(readBuffer, 0) == 0x399)
                {
                    this.INADevices.Add(currentINA);
                }
                else
                {
                    isRunning = false;
                }

                INAAddress++;
            }

            // Math used in this area for configuring the INA219 can be found in the INA219 manual found on page 12 in section 8.5.1
            foreach (I2cDevice INADevice in this.INADevices)
            {
                double maxCurrent = NominalVoltage / ShuntResistance;
                double currentLSB = Math.Round((MaxExpectedCurrent / 32767) * 1000000);
                currentLSB /= 1000000;

                float calibrationReg = (float)Math.Truncate(0.04096 / (maxCurrent * ShuntResistance));

                ushort configurationReg = 0b001101110111111;

                byte[] writeBuffer = BitConverter.GetBytes((ushort)INA219Registers.Configuration);
                INADevice.Write(writeBuffer);

                writeBuffer = BitConverter.GetBytes(configurationReg);
                INADevice.Write(writeBuffer);

                writeBuffer = BitConverter.GetBytes((ushort)INA219Registers.Calibration);
                INADevice.Write(writeBuffer);

                writeBuffer = BitConverter.GetBytes(calibrationReg);
                INADevice.Write(writeBuffer);
            }
        }
예제 #14
0
        public Bh1750(string i2CControllerName,
                      PinConnection pinConnection     = PinConnection.PIN_LOW,
                      MeasurementMode measurementMode = MeasurementMode.ContinuouslyHighResolutionMode2)
        {
            _pinConnection     = pinConnection;
            _i2CControllerName = i2CControllerName;
            try
            {
                var settings = new I2cConnectionSettings((byte)_pinConnection);
                settings.BusSpeed    = I2cBusSpeed.StandardMode;
                settings.SharingMode = I2cSharingMode.Shared;
                string aqs = I2cDevice.GetDeviceSelector(_i2CControllerName);
                _device = I2cDevice.FromId(_i2CControllerName, settings);
                if (_device == null)
                {
                    Logger.Log("Device not found", Logger.LogLevel.Warning);
                }

                SetMode(measurementMode);
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e.Message + "\n" + e.StackTrace, Logger.LogLevel.Error);
                throw;
            }
        }
예제 #15
0
파일: STMPE811.cs 프로젝트: LeTsoy/Samples
        /// <summary>
        /// Creates a driver for the STMPE811.
        /// </summary>
        /// <param name="address">The I2C address of the device.</param>
        /// <param name="i2cBus">The I2C bus where the device is connected to.</param>
        public STMPE811(int address, string i2cBus)
        {
            // store I2C address
            _address = address;

            // instantiate I2C controller
            _touchController = I2cDevice.FromId(i2cBus, new I2cConnectionSettings(address));
        }
예제 #16
0
파일: Rtc.cs 프로젝트: nattlip/TinyClrLib
        /// <summary>
        /// Constructor of Rtc component
        /// </summary>
        /// <param name="i2C">String that represent i2c bus</param>
        public Rtc(string i2C)
        {
            var settings = new I2cConnectionSettings(0x68)
            {
                BusSpeed = I2cBusSpeed.FastMode
            };

            _rtcDevice = I2cDevice.FromId(i2C, settings);
        }
예제 #17
0
 public Accelerometer()
 {
     _device = I2cDevice.FromId("GHIElectronics.TinyCLR.NativeApis.STM32F4.I2cProvider\\0", new I2cConnectionSettings(28)
     {
         BusSpeed    = I2cBusSpeed.FastMode,
         SharingMode = I2cSharingMode.Shared
     });
     WriteRegister(42, 1);
 }
예제 #18
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="Pca9685PwmController" /> class at the specified I2C address
 ///   and with the specified output modulation frequency.
 /// </summary>
 /// <param name="i2cAddress">The base I2C address for the device.</param>
 /// <param name="outputModulationFrequencyHz">
 ///   The output modulation frequency of all 16 PWM channels, in Hertz (cycles per second).
 ///   If not specified, then the default value of 1.6 KHz is used. The theoretical range is
 ///   approximately 24 Hz to 1743 Hz, but extremes should be avoided if possible.
 /// </param>
 public Pca9685PwmController(
     ushort i2cAddress = 0x60,
     float outputModulationFrequencyHz = Pca9685Constants.DefaultOutputModulationFrequency)
 {
     _i2cDevice = I2cDevice.FromId("IC21", new I2cConnectionSettings(i2cAddress));
     Reset();
     SetOutputModulationFrequency(outputModulationFrequencyHz);
     // At this point the device is fully configured but all PWM channels are turned off.
 }
        /// <summary>
        /// Creates a driver for the AT24C128C.
        /// </summary>
        /// <param name="address">The I2C address of the device.</param>
        /// <param name="i2cBus">The I2C bus where the device is connected to.</param>
        public AT24C128C(int address, string i2cBus)
        {
            // Store I2C address
            _address = address;

            var settings = new I2cConnectionSettings(address);

            // Instantiate I2C controller
            _memoryController = I2cDevice.FromId(i2cBus, settings);
        }
예제 #20
0
        private static void CheckWithDeviceSystemI2cInline()
        {
            _device = I2cDevice.FromId("I2C1", new I2cConnectionSettings(0x77)
            {
                BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
            });
            WriteByte(0xD0);
            var ret = ReadByte();

            Debug.WriteLine($"{ret}");
        }
예제 #21
0
        public Bme280 Initialize()
        {
            Logger.Log("BME280::Initialize");
            try
            {
                var settings = new I2cConnectionSettings(Bme280Address);
                settings.BusSpeed    = I2cBusSpeed.StandardMode;
                settings.SharingMode = I2cSharingMode.Shared;
                string aqs = I2cDevice.GetDeviceSelector(_i2CControllerName);
                _bme280 = I2cDevice.FromId(_i2CControllerName, settings);

                if (_bme280 == null)
                {
                    Logger.Log("BME280 device not found", Logger.LogLevel.Warning);
                }
            }
            catch (Exception e)
            {
                Logger.Log("BME 280 exception: " + e.Message + "\n" + e.StackTrace, Logger.LogLevel.Error);
                throw;
            }

            byte[] readChipId = new byte[] { (byte)ERegisters.BME280_REGISTER_CHIPID };
            byte[] readBuffer = new byte[] { 0xFF };

            //Read the device signature
            _bme280.WriteReadPartial(readChipId, readBuffer);
            Logger.Log("BME280 Signature: " + readBuffer[0], Logger.LogLevel.Info);

            //Verify the device signature
            if (readBuffer[0] != Bme280Signature)
            {
                Logger.Log("BME280::Begin Signature Mismatch.", Logger.LogLevel.Warning);
                return(this);
            }

            //Set configuration registers
            WriteConfigRegister();
            WriteControlMeasurementRegister();
            WriteControlRegisterHumidity();

            //Set configuration registers again to ensure configuration of humidity
            WriteConfigRegister();
            WriteControlMeasurementRegister();
            WriteControlRegisterHumidity();

            //Read the coefficients table
            _calibrationData = ReadCoefficeints();

            //Dummy read temp to setup t_fine
            ReadTemperature();

            return(this);
        }
예제 #22
0
        /// <summary>
        /// Constructor of I2CColorSensor
        /// </summary>
        /// <param name="i2CId">string of I2C identifier</param>
        public I2CColorSensor(string i2CId)
        {
            I2cConnectionSettings ics = new I2cConnectionSettings(DeviceAddress)
            {
                BusSpeed = I2cBusSpeed.FastMode, SharingMode = I2cSharingMode.Shared
            };

            _i2C = I2cDevice.FromId(i2CId, ics);
            Init();
            // WriteReg(Register.Control, 0x03);
        }
예제 #23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="busSelector">Which I2C bus to use</param>
 /// <param name="deviceAddr">The I2C device address (default is 0x40, the 7-bit, shifted address)</param>
 /// <param name="speed">The I2C bus speed (by default, 100KHz)</param>
 /// <param name="scale">How many decimal places to look for in the temperature and humidity values</param>
 public HTU21D(string busSelector = "I2C1", int deviceAddr = 0x40, I2cBusSpeed speed = I2cBusSpeed.StandardMode,
               uint scale         = 2)
 {
     _i2CDevice = I2cDevice.FromId(busSelector, new I2cConnectionSettings(deviceAddr)
     {
         BusSpeed = speed, SharingMode = I2cSharingMode.Shared
     });
     RelativeHumidity     = ERROR_HUMIDITY;
     TemperatureInCelcius = ERROR_TEMPERATURE;
     Resolution           = 0x81;
     _scale = scale;
 }
예제 #24
0
        /// <summary>
        /// Initializes the MCP23017. Has to be called when creating a new instance.
        /// </summary>
        /// <param name="bus">I2C bus controller identifier</param>
        /// <param name="speed">I2C bus speed</param>
        /// <param name="address">MCP23017 hardware address (0 - 7)</param>
        public void init(string bus, I2cBusSpeed speed, byte address)
        {
            if (address > 7)
            {
                throw new ArgumentOutOfRangeException("Address has to be between 0 and 7");
            }

            // Create I2C device instance
            _i2c = I2cDevice.FromId(bus, new I2cConnectionSettings(address | 0b0100000)
            {
                BusSpeed = speed
            });
예제 #25
0
 /// <summary>
 /// Default constructor. Uses standard speed mode for widest compatibility
 /// </summary>
 /// <param name="busSelector">The I2C bus selector</param>
 /// <param name="addr">The EEPROM chip address (default for AT24LCXXX series is 0x50, with A0,A1 and A2 lines tied low)</param>
 /// <param name="pageSizeBytes">What is the size of a page in this EEPROM (in bytes)</param>
 /// <param name="memSizeBytes">What is the size of the EEPROM (in bytes)</param>
 /// <param name="addrSizeInBytes">How many bytes are required to generate the address</param>
 /// <param name="addrModeLE">
 /// Is addressing mode little-endian (when address is broken into bytes, do
 /// we first send MSB or LSB
 /// </param>
 public EEPROM_24LCXXX(string busSelector  = "I2C1", byte addr  = 0x50, uint pageSizeBytes = 64, uint memSizeBytes = 32768,
                       int addrSizeInBytes = 2, bool addrModeLE = false)
 {
     _i2cDevice = I2cDevice.FromId(busSelector, new I2cConnectionSettings(addr)
     {
         BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
     });
     PageSizeInBytes   = pageSizeBytes;
     MemorySizeInBytes = memSizeBytes;
     _addrSizeInBytes  = addrSizeInBytes;
     _addrModeLE       = addrModeLE;
 }
예제 #26
0
        /// <summary>
        /// Creates a driver for the IES-SHIELD-GPS.
        /// </summary>
        /// <param name="i2cBus">The I2C bus where the device is connected to.</param>
        /// <param name="address">The I2C address of the device.</param>
        public IesShieldGps(string i2cBus, int address = GPAM_DEFAULT_ADDDRESS)
        {
            // store I2C address
            _address = address;

            // instantiate I2C controller
            _gpsController = I2cDevice.FromId(i2cBus, new I2cConnectionSettings(address)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Shared
            });
        }
예제 #27
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="busSelector">The I2C bus selector</param>
 /// <param name="addr">The I2C device address</param>
 /// <param name="width">Width of OLED display (in pixel)</param>
 /// <param name="height">Height of OLED display (in pixel)</param>
 public OLEDSSD1306_I2C(string busSelector = "I2C1", int addr = 0x3C, int width = 128, int height = 32)
 {
     this._i2cDevice = I2cDevice.FromId(busSelector, new I2cConnectionSettings(addr)
     {
         BusSpeed = I2cBusSpeed.StandardMode, SharingMode = I2cSharingMode.Shared
     });;
     this._width  = width;
     this._height = height;
     this._pages  = _height / 8;
     _buffer      = new byte[width * _pages];
     _font        = new PixelFont7X9();//default font
 }
예제 #28
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="rSocketNumber">The mainboard socket that has the display's R socket connected to it.</param>
        /// <param name="gSocketNumber">The mainboard socket that has the display's G socket connected to it.</param>
        /// <param name="bSocketNumber">The mainboard socket that has the display's B socket connected to it.</param>
        /// <param name="i2cSocketNumber">The mainboard socket that has the display's I socket connected to it.</param>
        public VideoOut(string I2CBus)
        {
            var Devices = DeviceInformation.FindAll(I2CBus);

            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_ADDRESS);

            Setting.SharingMode = I2cSharingMode.Shared;
            Setting.BusSpeed    = I2cBusSpeed.StandardMode; // 100kHz
            i2c = I2cDevice.FromId(Devices[0].Id, Setting);
            this.currentHeight = 320;
            this.currentHeight = 240;

            /*
             *          var i2cSocket = Socket.GetSocket(i2cSocketNumber, true, this, null);
             *          i2cSocket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this);
             *
             *          this.i2c = new GTI.SoftwareI2CBus(i2cSocket, Socket.Pin.Five, Socket.Pin.Four, 0x76, 100, this);
             *
             *          var rSocket = Socket.GetSocket(rSocketNumber, true, this, null);
             *          var gSocket = Socket.GetSocket(gSocketNumber, true, this, null);
             *          var bSocket = Socket.GetSocket(bSocketNumber, true, this, null);
             *
             *          rSocket.EnsureTypeIsSupported('R', this);
             *          gSocket.EnsureTypeIsSupported('G', this);
             *          bSocket.EnsureTypeIsSupported('B', this);
             *
             *          rSocket.ReservePin(Socket.Pin.Three, this);
             *          rSocket.ReservePin(Socket.Pin.Four, this);
             *          rSocket.ReservePin(Socket.Pin.Five, this);
             *          rSocket.ReservePin(Socket.Pin.Six, this);
             *          rSocket.ReservePin(Socket.Pin.Seven, this);
             *          rSocket.ReservePin(Socket.Pin.Eight, this);
             *          rSocket.ReservePin(Socket.Pin.Nine, this);
             *
             *          gSocket.ReservePin(Socket.Pin.Three, this);
             *          gSocket.ReservePin(Socket.Pin.Four, this);
             *          gSocket.ReservePin(Socket.Pin.Five, this);
             *          gSocket.ReservePin(Socket.Pin.Six, this);
             *          gSocket.ReservePin(Socket.Pin.Seven, this);
             *          gSocket.ReservePin(Socket.Pin.Eight, this);
             *          gSocket.ReservePin(Socket.Pin.Nine, this);
             *
             *          bSocket.ReservePin(Socket.Pin.Three, this);
             *          bSocket.ReservePin(Socket.Pin.Four, this);
             *          bSocket.ReservePin(Socket.Pin.Five, this);
             *          bSocket.ReservePin(Socket.Pin.Six, this);
             *          bSocket.ReservePin(Socket.Pin.Seven, this);
             *          bSocket.ReservePin(Socket.Pin.Eight, this);
             *          bSocket.ReservePin(Socket.Pin.Nine, this);
             */
        }
예제 #29
0
        /// <summary>Constructs a new TouchC8 sensor.</summary>
        /// <param name="socketNumber">The socket number the sensor is plugged into.</param>
        public TouchC8(string I2CBus, int DigitalPin3, int DigitalPin6)
        {
            this.readBuffer    = new byte[1];
            this.writeBuffer   = new byte[2];
            this.addressBuffer = new byte[1];

            //this.socket = GT.Socket.GetSocket(socketNumber, false, this, "I");
            //this.reset = GpioPinFactory.Create(this.socket, GT.Socket.Pin.Six, true, this);
            var controller = GpioController.GetDefault();

            this.reset = controller.OpenPin(DigitalPin6);
            this.reset.SetDriveMode(GpioPinDriveMode.Output);


            this.Reset();
            var Devices = DeviceInformation.FindAll(I2CBus);
            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(TouchC8.I2C_ADDRESS);

            Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz
            this.device      = I2cDevice.FromId(Devices[0].Id, Setting);
            //this.device = I2cDeviceFactory.Create(this.socket, TouchC8.I2C_ADDRESS, TouchC8.I2C_CLOCK_RATE, this);

            //this.interrupt = GpioPinFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            //this.interrupt.Interrupt += this.OnInterrupt;

            this.interrupt = controller.OpenPin(DigitalPin3);//GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            if (interrupt.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                interrupt.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                interrupt.SetDriveMode(GpioPinDriveMode.Input);
            }

            //this.input.Interrupt += this.OnInterrupt;
            interrupt.ValueChanged += Interrupt_ValueChanged;


            this.previousWheelDirection = (Direction)(-1);
            this.previousWheelPosition  = 0;
            this.previousWheelTouched   = false;
            this.previousButton1Touched = false;
            this.previousButton2Touched = false;
            this.previousButton3Touched = false;

            Thread.Sleep(250);

            this.ConfigureSPM();
        }
예제 #30
0
        public AT24Cxx(string device, byte DeviceAddress, ushort pagesize, ushort bytesperpageblock)
        {
            _pageSize   = pagesize;
            _memorySize = pagesize * bytesperpageblock;

            EEprom = I2cDevice.FromId(
                device,
                new I2cConnectionSettings(DeviceAddress)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Exclusive
            }
                );
        }