コード例 #1
0
ファイル: ADConverter.cs プロジェクト: knaufinator/PiDro
        public Double GetADVoltage(int sensorId)
        {
            double measuredVoltage = 5.0;
            double adSteps         = 255;
            double result          = 0.0;
            byte   buffer;

            try
            {
                myDevice.Write((byte)(0x40 | (sensorId & 3)));

                //this has the goods onthe second read, without this, you get bleedover to other sensor reads.
                myDevice.Read();
                buffer = (byte)myDevice.Read();

                short unsignedValue = (short)((short)0x00FF & buffer);
                result = unsignedValue * measuredVoltage / adSteps;
            }
            catch (Exception e)
            {
                Console.WriteLine("AD read error: " + e.Message);
            }

            return(result);
        }
コード例 #2
0
        public int Begin(int address)
        {
            if (_i2cDevice == null)
            {
                var adci2cConfig = new FtChannelConfig
                {
                    ClockRate    = ConnectionSpeed,
                    LatencyTimer = LatencyTimer
                };

                if (_i2cDevice == null)
                {
                    _i2cDevice = new I2CDevice(adci2cConfig, address);

                    var b = _i2cDevice.Read(1);

                    if (b == null)
                    {
                        Debugger.Break();
                    }

                    _shadow      = Convert.ToInt32(b[0]);
                    _initialised = true;
                }
            }

            return(1);
        }
コード例 #3
0
ファイル: I2CIO.cs プロジェクト: jakkaj/libMPSSE-.Net-Wrapper
        public int Begin(int address)
        {
            if (_i2cDevice == null)
            {
                var adci2cConfig = new FtChannelConfig
                {
                    ClockRate = ConnectionSpeed,
                    LatencyTimer = LatencyTimer
                };

                if (_i2cDevice == null)
                {
                    _i2cDevice = new I2CDevice(adci2cConfig, address);

                    var b = _i2cDevice.Read(1);

                    if (b == null)
                    {
                        Debugger.Break();
                    }

                    _shadow = Convert.ToInt32(b[0]);
                    _initialised = true;
                }
            }

            return 1;
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Test of SHT31-D and armbianI2Clib");

            try
            {
                using (var device = new I2CDevice("/dev/i2c-0", 0x44))
                {
                    Console.WriteLine("init complete");

                    device.Write(new byte[] { 0x24, 0x00 }, 2);
                    Thread.Sleep(100);
                    Console.WriteLine("write complete");

                    var readBuff = device.Read(3);

                    Console.WriteLine($"Read count: {readBuff.Length}");
                    Console.WriteLine($"Read 1:{readBuff[0]}, 2:{readBuff[1]}, 3:{readBuff[2]}");
                    Console.WriteLine($"Temp: {CalcTemp(readBuff[0], readBuff[1])}C");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
            }
            Console.WriteLine("END");
        }
コード例 #5
0
        public int GetNumSensors(I2CDevice device)
        {
            device.Write(0x01);
            int numSensors = device.Read();

            return(numSensors);
        }
コード例 #6
0
ファイル: SodarDriver.cs プロジェクト: nojan1/MiniRover
        public IDictionary <int, int> GetRanges()
        {
            var ranges = new Dictionary <int, int>();

            var numSamples = _device.ReadAddressByte(RANGE_REGISTER);
            var sampleData = _device.Read(numSamples * 2);

            for (int i = 0; i < sampleData.Length; i += 2)
            {
                ranges[sampleData[i]] = sampleData[i + 1];
            }

            return(ranges);
        }
コード例 #7
0
ファイル: IMUDriver.cs プロジェクト: nojan1/MiniRover
        private Vector ReadRawGyro()
        {
            _device.Write(MPU6050_REG_GYRO_XOUT_H);
            var data = _device.Read(6);

            int xha = data[0];
            int xla = data[1];
            int yha = data[2];
            int yla = data[3];
            int zha = data[4];
            int zla = data[5];

            return(new Vector
            {
                XAxis = xha << 8 | xla,
                    YAxis = yha << 8 | yla,
                    ZAxis = zha << 8 | zla
            });
        }