コード例 #1
0
ファイル: Mpu6050.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        /// Discover any MPU6050 IMUs (or optionally MPU9250s) attached to the specified bus.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="includeMpu9250">Whether to include MPU-9250 IMUs.</param>
        /// <param name="rate">The rate, in kHz, to use.</param>
        /// <returns>An awaitable task that completes with a list of of discovered sensors</returns>
        public static async Task <IList <Mpu6050> > ProbeAsync(I2C i2c, bool includeMpu9250 = false, int rate = 100)
        {
            var deviceList = new List <Mpu6050>();

            try
            {
                var dev    = new SMBusDevice(0x68, i2c, rate);
                var whoAmI = await dev.ReadByteDataAsync(0x75).ConfigureAwait(false);

                if (whoAmI == 0x68 || (whoAmI == 0x71 & includeMpu9250))
                {
                    deviceList.Add(new Mpu6050(i2c, false));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x69, i2c, rate);
                var whoAmI = await dev.ReadByteDataAsync(0x75).ConfigureAwait(false);

                if (whoAmI == 0x68 || (whoAmI == 0x71 & includeMpu9250))
                {
                    deviceList.Add(new Mpu6050(i2c, true));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
コード例 #2
0
 public ServoMotor(ServoMotorPort port, SMBusDevice controller)
 {
     _controller   = controller;
     Port          = port;
     ZeroPoint     = Angle.Zero;
     _defaultSpeed = RotationalSpeed.FromDegreesPerSecond(50);
 }
コード例 #3
0
ファイル: Tsl2561.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        /// Probes the specified I2C bus to discover any TSL2561 sensors attached.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="rate">The rate to use. Defaults to 100.</param>
        /// <returns>A TSL2561 if found, or null if not found.</returns>
        public static async Task <Tsl2561> ProbeAsync(I2C i2c, int rate = 100)
        {
            var dev    = new SMBusDevice(0x29, i2c, rate);
            var result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Gnd, rate));
            }

            dev    = new SMBusDevice(0x39, i2c, rate);
            result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Float, rate));
            }

            dev    = new SMBusDevice(0x49, i2c, rate);
            result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Vdd, rate));
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Probes the specified I2C bus to discover any BNO055 sensors attached.
        /// </summary>
        /// <param name="i2c">The I2C bus to probe</param>
        /// <param name="rateKhz">The rate, in kHz, to use</param>
        /// <returns>An awaitable task that completes with a list of BNO055 sensors.</returns>
        public static async Task <List <Bno055> > ProbeAsync(I2C i2c, int rateKhz = 100)
        {
            var deviceList = new List <Bno055>();

            try
            {
                var dev    = new SMBusDevice(0x28, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xA0)
                {
                    deviceList.Add(new Bno055(i2c, false, rateKhz));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x29, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xA0)
                {
                    deviceList.Add(new Bno055(i2c, true, rateKhz));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
コード例 #5
0
 /// <summary>
 ///     Construct a new HT16K33 16x8 LED driver
 /// </summary>
 /// <param name="i2c">The I2c port to use with this display.</param>
 /// <param name="address">The 7-bit I2c address to use</param>
 /// <param name="package">Which package is used</param>
 public Ht16k33(I2C i2c, byte address, Package package) : base((int)package, true, false)
 {
     dev = new SMBusDevice(address, i2c);
     dev.WriteByteAsync(0x21);
     Brightness   = 1.0;
     this.package = package;
 }
コード例 #6
0
        public static async Task <IList <Adxl345> > ProbeAsync(I2C i2c, int rate = 100)
        {
            List <Adxl345> deviceList = new List <Adxl345>();

            try
            {
                var dev    = new SMBusDevice(0x53, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xE5)
                {
                    deviceList.Add(new Adxl345(i2c, true, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x1D, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xE5)
                {
                    deviceList.Add(new Adxl345(i2c, false, rate));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
コード例 #7
0
ファイル: Lis3dh.cs プロジェクト: ehailey1/treehopper-sdk
        public static async Task <IList <Lis3dh> > ProbeAsync(I2C i2c, int rate = 100)
        {
            var deviceList = new List <Lis3dh>();

            try
            {
                var dev    = new SMBusDevice(0x18, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0F).ConfigureAwait(false);

                if (whoAmI == 0x33)
                {
                    deviceList.Add(new Lis3dh(i2c, false, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x19, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0F).ConfigureAwait(false);

                if (whoAmI == 0x33)
                {
                    deviceList.Add(new Lis3dh(i2c, true, rate));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
コード例 #8
0
ファイル: Bmp280.cs プロジェクト: ehailey1/treehopper-sdk
        public static async Task <IList <Bmp280> > ProbeAsync(I2C i2c, bool includeBme280 = true)
        {
            var deviceList = new List <Bmp280>();

            try
            {
                var dev    = new SMBusDevice(0x76, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0xD0).ConfigureAwait(false);

                if (whoAmI == 0x58 || (whoAmI == 0x60 & includeBme280))
                {
                    deviceList.Add(new Bmp280(i2c, false));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x77, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0xD0).ConfigureAwait(false);

                if (whoAmI == 0x58 || (whoAmI == 0x60 & includeBme280))
                {
                    deviceList.Add(new Bmp280(i2c, true));
                }
            }
            catch (Exception ex) { }
            return(deviceList);
        }
コード例 #9
0
ファイル: Mpu6050.cs プロジェクト: ehailey1/treehopper-sdk
 /// <summary>
 ///     Construct an MPU9150 9-Dof IMU
 /// </summary>
 /// <param name="i2c">The I2c module this module is connected to.</param>
 /// <param name="addressPin">The address of the module</param>
 /// <param name="ratekHz">The rate, in kHz, to use with this IC</param>
 public Mpu6050(I2C i2c, bool addressPin = false, int ratekHz = 400)
 {
     this.dev        = new SMBusDevice((byte)(addressPin ? 0x69 : 0x68), i2c, ratekHz);
     this._registers = new Mpu6050Registers(new SMBusRegisterManagerAdapter(dev));
     Task.Run(async() =>
     {
         await _registers.powerMgmt1.read().ConfigureAwait(false);
         _registers.powerMgmt1.reset = 1;
         await _registers.powerMgmt1.write().ConfigureAwait(false);
         _registers.powerMgmt1.reset = 0;
         _registers.powerMgmt1.sleep = 0;
         await _registers.powerMgmt1.write().ConfigureAwait(false);
         _registers.powerMgmt1.clockSel = 1;
         await _registers.powerMgmt1.write().ConfigureAwait(false);
         _registers.configuration.dlpf = 3;
         await _registers.configuration.write().ConfigureAwait(false);
         _registers.sampleRateDivider.value = 4;
         await _registers.sampleRateDivider.write().ConfigureAwait(false);
         await _registers.accelConfig2.read().ConfigureAwait(false);
         _registers.accelConfig2.accelFchoice = 0;
         _registers.accelConfig2.dlpfCfg      = 3;
         await _registers.accelConfig2.write().ConfigureAwait(false);
         await _registers.powerMgmt1.read().ConfigureAwait(false);
     }).Wait();
     AccelerometerScale = AccelScales.Fs_2g;
     GyroscopeScale     = GyroScales.Dps_250;
 }
コード例 #10
0
ファイル: Nau7802.cs プロジェクト: ehailey1/treehopper-sdk
        public Nau7802(I2C i2c, DigitalIn drdy = null) : base(null, 24, 0)
        {
            parent = this;

            if (drdy != null)
            {
                this.drdy = drdy;
                drdy.MakeDigitalInAsync();
                drdy.DigitalValueChanged += Drdy_DigitalValueChanged;
            }

            AutoUpdateWhenPropertyRead = true;

            dev       = new SMBusDevice(0x2A, i2c);
            registers = new Nau7802Registers(new SMBusRegisterManagerAdapter(dev));

            registers.puCtrl.registerReset = 1;  // reset all registers
            registers.puCtrl.write().Wait();
            registers.puCtrl.registerReset  = 0; // clear reset
            registers.puCtrl.powerUpDigital = 1; // power up digital
            registers.puCtrl.write().Wait();

            Task.Delay(10).Wait();
            if (registers.puCtrl.read().Result.powerUpReady == 0)
            {
                Utility.Error("Could not power up NAU7802");
                return;
            }


            // useful defaults
            registers.puCtrl.useExternalCrystal = 0;
            registers.puCtrl.useInternalLdo     = 1;
            registers.puCtrl.powerUpDigital     = 1;
            registers.puCtrl.powerUpAnalog      = 1;
            registers.puCtrl.write().Wait();

            registers.ctrl1.setVldo(Vldoes.mV_3000);
            registers.ctrl1.write().Wait();

            UpdateReferenceVoltage(); // set the pins up with the default gains

            registers.pga.pgaBypass      = 0;
            registers.pga.disableChopper = 1;
            registers.pga.write().Wait();

            registers.adc.setRegChpFreq(RegChpFreqs.off);
            registers.adc.regChp = 0;
            registers.adc.write().Wait();

            registers.i2cCtrl.bgpCp = 0;
            registers.i2cCtrl.write().Wait();

            registers.ctrl2.setConversionRate(ConversionRates.Sps_10);
            registers.ctrl2.write().Wait();

            registers.puCtrl.cycleStart = 1;
            registers.puCtrl.write().Wait();
        }
コード例 #11
0
 /// <summary>
 ///     Construct a new MCP23008
 /// </summary>
 /// <param name="i2c">The I2c bus to use</param>
 /// <param name="address">The address to use</param>
 /// <param name="speedKHz">The speed, in KHz, to use</param>
 public Mcp23008(I2C i2c, byte address, int speedKHz = 100)
 {
     dev = new SMBusDevice(address, i2c, speedKHz);
     for (var i = 0; i < 8; i++)
     {
         Pins.Add(new Pin(this, i));
     }
 }
コード例 #12
0
 /// <summary>
 ///     Construct a new PCA9685
 /// </summary>
 /// <param name="i2c">The i2c port this chip is attached to</param>
 /// <param name="address">The 7-bit address to use</param>
 /// <param name="speed">The speed, in kHz, to use with this chip</param>
 public Pca9685(I2C i2c, byte address, int speed = 100)
 {
     dev = new SMBusDevice(address, i2c, speed);
     for (var i = 0; i < 16; i++)
     {
         Pins.Add(new Pin(this, i));
     }
     updateConfig();
 }
コード例 #13
0
ファイル: WiiNunchuk.cs プロジェクト: ehailey1/treehopper-sdk
        public WiiNunchuk(I2C i2c)
        {
            dev = new SMBusDevice(0x52, i2c);
            dev.WriteDataAsync(new byte[] { 0xF0, 0x55 }).Wait();
            dev.WriteDataAsync(new byte[] { 0xFB, 0x00 }).Wait();

            C = new Button(new DigitalInPeripheralPin(this), false);
            Z = new Button(new DigitalInPeripheralPin(this), false);
        }
コード例 #14
0
ファイル: Is31fl3236.cs プロジェクト: ehailey1/treehopper-sdk
 /// <summary>
 ///     Construct a new IS31FL3236
 /// </summary>
 /// <param name="i2c">The I2C peripheral this chip is attached to</param>
 /// <param name="rateKhz">The frequency, in kHz, that should be used to communicate with the chip</param>
 /// <param name="sdb">The (optional) hardware shutdown pin, SDB</param>
 public Is31fl3236(I2C i2c, int rateKhz = 100, bool ad0 = false, DigitalOut sdb = null) : base(36, false, true)
 {
     if (sdb != null)
     {
         sdb.DigitalValue = true;
     }
     dev = new SMBusDevice(0x3C, i2c, rateKhz);
     dev.WriteByteDataAsync((byte)Registers.Shutdown, 0x01).Wait();
 }
コード例 #15
0
 /// <summary>
 /// Construct a new Analog Devices ADXL345.
 /// </summary>
 /// <param name="i2c">The I2C bus to use.</param>
 /// <param name="altAddressPin">The state of the address pin.</param>
 /// <param name="rate">The rate, in kHz, to use.</param>
 public Adxl345(I2C i2c, bool altAddressPin = false, int rate = 100)
 {
     _dev      = new SMBusDevice((byte)(!altAddressPin ? 0x1D : 0x53), i2c, rate);
     registers = new Adxl345Registers(new SMBusRegisterManagerAdapter(_dev));
     registers.powerCtl.sleep     = 0;
     registers.powerCtl.measure   = 1;
     registers.dataFormat.range   = 0x00;
     registers.dataFormat.fullRes = 1;
     Task.Run(() => registers.writeRange(registers.powerCtl, registers.dataFormat)).Wait();
 }
コード例 #16
0
ファイル: Bmp280.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        ///     Construct a BMP280 hooked up to the i2C bus
        /// </summary>
        /// <param name="i2c">the i2C bus to use</param>
        /// <param name="sdoPin">the state of the SDO pin, which sets the address</param>
        public Bmp280(I2C i2c, bool sdoPin = false)
        {
            dev       = new SMBusDevice((byte)(0x76 | (sdoPin ? 1 : 0)), i2c);
            registers = new Bmp280Registers(new SMBusRegisterManagerAdapter(dev));

            registers.ctrlMeasure.setMode(Modes.Normal);
            registers.ctrlMeasure.setOversamplingPressure(OversamplingPressures.Oversampling_x16);
            registers.ctrlMeasure.setOversamplingTemperature(OversamplingTemperatures.Oversampling_x16);
            Task.Run(registers.ctrlMeasure.write).Wait();

            Task.Run(() => registers.readRange(registers.t1, registers.h1)).Wait();
        }
コード例 #17
0
ファイル: Tsl2591.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        /// Probes the specified I2C bus to discover any TSL2591 sensors attached.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="rate">The rate to use.</param>
        /// <returns>A TSL2591 if found, or null if not found.</returns>
        public static async Task <Tsl2591> ProbeAsync(I2C i2c, int rate = 100)
        {
            var dev    = new SMBusDevice(0x29, i2c, rate);
            var result = await dev.ReadByteDataAsync(0xB2);

            if (result == 0x50)
            {
                return(new Tsl2591(i2c, rate));
            }

            return(null);
        }
コード例 #18
0
ファイル: Ads1115.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        ///     Construct a new ADS1115
        /// </summary>
        /// <param name="i2c">The i2C port this ADC is attached to</param>
        /// <param name="channelMode">Whether this ADC is single-ended or differential</param>
        /// <param name="addr">The address pin of this module</param>
        /// <param name="refVoltage">The supply (reference) voltage of this module</param>
        /// <param name="speed">The speed to use when communicating with this module, in kHz</param>
        public Ads1115(I2C i2c, ChannelMode channelMode = ChannelMode.SingleEnded, bool addr = false,
                       double refVoltage = 3.3, int speed = 400)
        {
            dev  = new SMBusDevice((byte)(0x48 | (addr ? 1 : 0)), i2c, speed);
            Mode = channelMode;

            dev.WriteBufferDataAsync(0x01, new byte[] { 0x01, 0x83 }).Wait();

            for (var i = 0; i < (channelMode == ChannelMode.SingleEnded ? 4 : 2); i++)
            {
                Pins.Add(new AdsPin(this));
            }
        }
コード例 #19
0
        /// <summary>
        ///     Construct a new SSD1306 OLED display
        /// </summary>
        /// <param name="I2c">The I2c module to use</param>
        /// <param name="width">The number of pixels wide</param>
        /// <param name="height">The number of pixels tall</param>
        /// <param name="address">The address</param>
        /// <param name="rate">The rate, in kHz, to use</param>
        /// <param name="mode">The VCC mode of the display</param>
        public Ssd1306(I2C I2c, int width = 128, int height = 32, byte address = 0x3C, int rate = 400,
                       VccMode mode       = VccMode.SwitchCap) : base(width, height)
        {
            if (!(Width == 128 && Height == 32 || Width == 128 && Height == 64 || Width == 96 && Height == 16))
            {
                throw new ArgumentException("The only supported display sizes are 128x32, 128x64, and 96x16");
            }

            dev = new SMBusDevice(address, I2c, rate);

            RawBuffer  = new byte[Width * Height / 8 + Width];
            BoolBuffer = new bool[Width, Height];

            this.mode = mode;
            Task.Run(InitAsync).Wait();
        }
コード例 #20
0
ファイル: Lis3dh.cs プロジェクト: ehailey1/treehopper-sdk
        public Lis3dh(I2C i2c, bool sdo = true, int rate = 100)
        {
            dev       = new SMBusDevice((byte)(sdo ? 0x19 : 0x18), i2c, rate);
            registers = new Lis3dhRegisters(new SMBusRegisterManagerAdapter(dev));

            if (Task.Run(registers.whoAmI.read).Result.value != 0x33)
            {
                Utility.Error("Incorrect chip ID found when addressing the LIS3DH");
            }

            registers.ctrl1.xAxisEnable = 1;
            registers.ctrl1.yAxisEnable = 1;
            registers.ctrl1.zAxisEnable = 1;
            registers.ctrl1.setOutputDataRate(OutputDataRates.Hz_1);
            registers.ctrl1.lowPowerEnable = 0;
            Task.Run(registers.ctrl1.write).Wait();
        }
コード例 #21
0
ファイル: Hmc5883l.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        ///     Construct a new HMC5883L connected to the specified <see cref="I2C" /> port.
        /// </summary>
        /// <param name="i2c">The I2C port to use</param>
        /// <param name="rateKHz">The frequency, in kHz, to use.</param>
        public Hmc5883l(I2C i2c, int rateKHz = 100)
        {
            dev = new SMBusDevice(0x1E, i2c, rateKHz);

            var idA = dev.ReadByteDataAsync((byte)Registers.IdA).Result;
            var idB = dev.ReadByteDataAsync((byte)Registers.IdB).Result;
            var idC = dev.ReadByteDataAsync((byte)Registers.IdC).Result;

            if (idA != 0x48 || idB != 0x34 || idC != 0x33)
            {
                Debug.WriteLine("WARNING: this library may not be compatible with the attached chip");
            }

            dev.WriteByteDataAsync((byte)Registers.ConfigA, 0x1C).Wait();
            dev.WriteByteDataAsync((byte)Registers.Mode, 0x00).Wait();  // continuous conversion
            Range = RangeSetting.GAIN_1_3;
        }
コード例 #22
0
        public WiiClassicController(I2C i2c)
        {
            dev = new SMBusDevice(0x52, i2c);
            dev.WriteDataAsync(new byte[] { 0xF0, 0x55 }).Wait();
            dev.WriteDataAsync(new byte[] { 0xFB, 0x00 }).Wait();

            L     = new Button(new DigitalInPeripheralPin(this), false);
            R     = new Button(new DigitalInPeripheralPin(this), false);
            ZL    = new Button(new DigitalInPeripheralPin(this), false);
            ZR    = new Button(new DigitalInPeripheralPin(this), false);
            Home  = new Button(new DigitalInPeripheralPin(this), false);
            Plus  = new Button(new DigitalInPeripheralPin(this), false);
            Minus = new Button(new DigitalInPeripheralPin(this), false);
            A     = new Button(new DigitalInPeripheralPin(this), false);
            B     = new Button(new DigitalInPeripheralPin(this), false);
            X     = new Button(new DigitalInPeripheralPin(this), false);
            Y     = new Button(new DigitalInPeripheralPin(this), false);
        }
コード例 #23
0
        /// <summary>
        /// Construct a PCF-series I/O expander
        /// </summary>
        /// <param name="i2c">the I2c module to use</param>
        /// <param name="numPins">The number of pins of this expander</param>
        /// <param name="Address0">The state of the Address0 pin</param>
        /// <param name="Address1">The state of the Address1 pin</param>
        /// <param name="Address2">The state of the Address2 pin</param>
        /// <param name="baseAddress">The base address of the chip</param>
        public PcfInterface(I2c i2c, int numPins, bool Address0, bool Address1, bool Address2, byte baseAddress) : base(numPins)
        {
            byte address = (byte)(baseAddress | (Address0 ? 1 : 0) | (Address1 ? 1 : 0) << 1 | (Address2 ? 1 : 0) << 2);
            dev = new SMBusDevice(address, i2c);

            numBytes = numPins / 8;

            oldValues = new byte[numBytes];
            newValues = new byte[numBytes];
            
            // make all pins inputs by default
            AutoFlush = false;
            foreach (var pin in Pins)
                pin.Mode = InputOutputPinMode.DigitalInput;
            AutoFlush = true;
            Flush(true).Wait();

        }
コード例 #24
0
ファイル: Pcf8574.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        ///     Construct a PCF-series I/O expander
        /// </summary>
        /// <param name="i2c">the I2c module to use</param>
        /// <param name="Address0">The state of the Address0 pin</param>
        /// <param name="Address1">The state of the Address1 pin</param>
        /// <param name="Address2">The state of the Address2 pin</param>
        /// <param name="baseAddress">The base address of the chip</param>
        /// <param name="numPins">The number of pins of this expander</param>
        public Pcf8574(I2C i2c, bool Address0 = false, bool Address1 = false, bool Address2 = false,
                       byte baseAddress       = 0x20, int numPins    = 8) : base(numPins)
        {
            var address = (byte)(baseAddress | (Address0 ? 1 : 0) | ((Address1 ? 1 : 0) << 1) |
                                 ((Address2 ? 1 : 0) << 2));

            dev = new SMBusDevice(address, i2c);

            numBytes = numPins / 8;

            oldValues = new byte[numBytes];

            // make all pins inputs by default
            AutoFlush = false;
            foreach (var pin in Pins)
            {
                pin.Mode = PortExpanderPinMode.DigitalInput;
            }
            AutoFlush = true;
            Task.Run(() => FlushAsync(true)).Wait();
        }
コード例 #25
0
        public Bno055(I2C i2c, bool addressPin, int rateKhz = 100) : base()
        {
            if (addressPin)
            {
                dev = new SMBusDevice(0x29, i2c, rateKhz);
            }
            else
            {
                dev = new SMBusDevice(0x28, i2c, rateKhz);
            }

            registers = new Bno055Registers(new SMBusRegisterManagerAdapter(dev));

            registers.operatingMode.setOperatingMode(OperatingModes.ConfigMode);
            Task.Run(registers.operatingMode.write);
            registers.sysTrigger.resetSys = 1;
            Task.Run(registers.sysTrigger.write);
            registers.sysTrigger.resetSys = 0;
            int id = 0;

            do
            {
                Task.Run(registers.chipId.read).Wait();
                id = registers.chipId.value;
            }while (id != 0xA0);
            Task.Delay(50);
            registers.powerMode.setPowerMode(PowerModes.Normal);
            Task.Run(registers.powerMode.write);
            Task.Delay(10);
            registers.sysTrigger.selfTest = 0;
            Task.Run(registers.sysTrigger.write);
            Task.Delay(10);
            registers.operatingMode.setOperatingMode(OperatingModes.NineDegreesOfFreedom);
            Task.Run(registers.operatingMode.write);
            Task.Delay(20);
        }
コード例 #26
0
ファイル: Pca9632.cs プロジェクト: ehailey1/treehopper-sdk
        public Pca9632(I2C i2c)
        {
            dev = new SMBusDevice(0x62, i2c);

            mode1.Ai    = RegisterAutoIncrement.AutoIncrementAllRegisters;
            mode1.Sleep = false;
            dev.WriteByteDataAsync((byte)Registers.Mode1, mode1.ToByte()).Wait();

            // clear PWM values
            dev.WriteBufferDataAsync((byte)Registers.Pwm0 | 0x80, new byte[4] {
                0x00, 0x00, 0x00, 0x00
            }).Wait();

            ledOut.Ldr0 = LedOutputState.LedPwm;
            ledOut.Ldr1 = LedOutputState.LedPwm;
            ledOut.Ldr2 = LedOutputState.LedPwm;
            ledOut.Ldr3 = LedOutputState.LedPwm;
            dev.WriteByteDataAsync((byte)Registers.LedOut, ledOut.ToByte()).Wait();

            Pins.Add(new Pin(this, 0));
            Pins.Add(new Pin(this, 1));
            Pins.Add(new Pin(this, 2));
            Pins.Add(new Pin(this, 3));
        }
コード例 #27
0
 public Mpu9150(I2c i2c, bool addressPin = false, int ratekHz = 400) : base(i2c, addressPin, ratekHz)
 {
     dev.WriteByteData((byte)Registers.INT_PIN_CFG, 0x22).Wait();
     mag = new SMBusDevice(0x0C, i2c, ratekHz);
 }
コード例 #28
0
 /// <summary>
 ///     Construct a new MLX90615 attached to the given i2c port
 /// </summary>
 /// <param name="module"></param>
 public Mlx90615(I2C module) : base(module)
 {
     dev     = new SMBusDevice(0x5B, module);
     Object  = new TempRegister(dev, 0x27);
     Ambient = new TempRegister(dev, 0x26);
 }
コード例 #29
0
ファイル: Ak8975.cs プロジェクト: ehailey1/treehopper-sdk
 /// <summary>
 /// Construct a new AKM AK8975 attached to the bus
 /// </summary>
 /// <param name="i2c">The bus to probe.</param>
 /// <param name="rate">The rate, in kHz, to use.</param>
 public Ak8975(I2C i2c, int rate = 100)
 {
     dev        = new SMBusDevice(0x0c, i2c, rate);
     _registers = new Ak8975Registers(new SMBusRegisterManagerAdapter(dev));
 }
コード例 #30
0
ファイル: Mlx90614.cs プロジェクト: ehailey1/treehopper-sdk
 internal TempRegister(SMBusDevice dev, byte register)
 {
     this.register = register;
     this.dev      = dev;
 }
コード例 #31
0
ファイル: Mlx90614.cs プロジェクト: ehailey1/treehopper-sdk
 /// <summary>
 ///     Construct a new MLX90614 attached to the given i2c port
 /// </summary>
 /// <param name="i2c">The i2c module to use</param>
 public Mlx90614(I2C i2c)
 {
     dev     = new SMBusDevice(0x5A, i2c);
     Object  = new TempRegister(dev, 0x07);
     Ambient = new TempRegister(dev, 0x06);
 }
コード例 #32
0
ファイル: L3gd20.cs プロジェクト: ehailey1/treehopper-sdk
        /// <summary>
        /// Discover any L3GD20H, L3GD20, or L3G4200D gyroscopes attached to this system.
        /// </summary>
        /// <param name="i2c">The bus to scan.</param>
        /// <param name="rate">The rate, in kHz, to use.</param>
        /// <returns></returns>
        public static async Task <IList <L3gd20> > ProbeAsync(I2C i2c, int rate = 100)
        {
            var devList = new List <L3gd20>();

            try
            {
                // L3G4200D - SDO low
                var dev    = new SMBusDevice(0x68, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD3)
                {
                    devList.Add(new L3gd20(i2c, 0x68, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3G4200D - SDO high
                var dev    = new SMBusDevice(0x69, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD3)
                {
                    devList.Add(new L3gd20(i2c, 0x69, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20 - SDO low
                var dev    = new SMBusDevice(0x6A, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD4)
                {
                    devList.Add(new L3gd20(i2c, 0x6A, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20 - SDO high
                var dev    = new SMBusDevice(0x6B, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD4)
                {
                    devList.Add(new L3gd20(i2c, 0x6B, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20H - SDO low
                var dev    = new SMBusDevice(0x6A, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD7)
                {
                    devList.Add(new L3gd20(i2c, 0x6A, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20H - SDO high
                var dev    = new SMBusDevice(0x6B, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD7)
                {
                    devList.Add(new L3gd20(i2c, 0x6B, rate));
                }
            }
            catch (Exception ex) { }

            return(devList);
        }
コード例 #33
0
 public Mlx90615(I2c module)
 {
     this.dev = new SMBusDevice(0x5B, module, 30);
     Object =  new TempRegister(dev, 0x27);
     Ambient = new TempRegister(dev, 0x26);
 }
コード例 #34
0
 public TempRegister(SMBusDevice dev, byte register)
 {
     this.register = register;
     this.dev = dev;
 }