Exemple #1
0
        public static async Task SetDeviceAddress(GpioI2CDevice device)
        {
            // 1. Write an all zero slave address, followed by a LOW R/W bit
            byte[] data = new byte[] { 0x0, 0x0E, };
            device.Write(0, data);

            // 2.
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            var ft232Device = FT232HDetector.Detect();

            if (ft232Device.Ok)
            {
                Console.WriteLine(ft232Device.ToString());
            }
            else
            {
                throw new Exception("Could not find a device");
            }

            var i2cDevice = new GpioI2CDevice(new I2C_CHANNEL_CONFIG
            {
                ClockRate    = I2C_CLOCKRATE.I2C_CLOCK_FAST_MODE,
                LatencyTimer = 1
            }, channelIndex: 0);

            try
            {
                var gpios = i2cDevice.GPIO;
                await Blink(gpios, 4, 5, 250);

                var tempSensor = new Mlx90614(i2cDevice, 0x2A)
                {
                    TempInF = true
                };

                // Trying to figure out sane values for these:
                gsensor.SetGestureThreshold(0x30, 0x20, 0b11);
                gsensor.SetGainAndIrIntensity(0b11 /* Full Gain */, 0b11 /* Full Intensity */);

                do
                {
                    while (!gsensor.GestureAvailable())
                    {
                        //byte status = await gsensor.ReadStatus();
                        //byte gstatus = await gsensor.ReadGestureStatus();
                        //Debug.WriteLine($"Status: {status.ToString("X")}; GStatus: {gstatus.ToString("X")}");
                        await Task.Delay(10);
                    }

                    //Console.WriteLine("Gesture is available!");
                    //byte[] data = await gsensor.ReadAvailableGestureData();
                    //string hexstring = BytesToHexString(data);
                    //WriteLine($"Gesture Data:\n{hexstring}");

                    var result = await gsensor.ReadGesture();

                    WriteLine(result);

                    //await Task.Delay(1000);
                    //Read(i2cDevice).Wait();
                } while (true);
                //try
                //{
                //	await tempSensor.SetAddress(0x2A);
                //}
                //catch { }

                var temperatures = new List <string>();

                for (int i = 0; i < 100; i++)
                {
                    var ambientTemp = await tempSensor.ReadAmbientTemperature();

                    var objectTemp = await tempSensor.ReadObjectTemperature();

                    Console.WriteLine($"Ambient: {ambientTemp}, Object: {objectTemp}");
                    temperatures.Add($"Ambient: {ambientTemp}, Object: {objectTemp}");

                    await Task.Delay(1000);
                }
            }
            catch (Exception e)
            {
                WriteLine(e);
            }
            WriteLine("Press any key to exit...");
            Console.Read();
        }
Exemple #3
0
 public static async Task Read(GpioI2CDevice device)
 {
     byte[] buffer = new byte[10];
     device.Read(0x39, buffer);
 }