예제 #1
0
파일: Program.cs 프로젝트: JohnXi001/iot-1
        public static void Main(string[] args)
        {
            I2cConnectionSettings settings  = new I2cConnectionSettings(1, Mlx90614.DefaultI2cAddress);
            I2cDevice             i2cDevice = I2cDevice.Create(settings);

            using (Mlx90614 sensor = new Mlx90614(i2cDevice))
            {
                while (true)
                {
                    Console.WriteLine($"Ambient: {sensor.ReadAmbientTemperature().Celsius} ℃");
                    Console.WriteLine($"Object: {sensor.ReadObjectTemperature().Celsius} ℃");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
예제 #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();
        }