コード例 #1
0
ファイル: Program.cs プロジェクト: SKKbySSK/winofy
        private static void TestD7S()
        {
            Console.Write("D7S I2C address : ");
            var address = int.Parse(Console.ReadLine());

            var d7s = new D7s(address);

            d7s.Reset();
            Console.WriteLine("Reset");

            while (true)
            {
                var st = d7s.GetState();
                if (st == D7sState.Normal)
                {
                    var si = d7s.ReadSI();
                    Console.WriteLine("State : " + st + ", SI : " + si);
                }
                else
                {
                    Console.WriteLine("State : " + st);
                }

                Thread.Sleep(2000);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SKKbySSK/winofy
        static async Task Main(string[] args)
        {
            if (args.Contains("-dht"))
            {
                TestDHT();
                return;
            }

            if (args.Contains("-d7s"))
            {
                TestD7S();
                return;
            }

            HomeConfig config = GetConfig();
            var        client = await PrepareClientAsync(config);

            await client.RecordAsync(config.Device.Id, 40, Axes.XY, 30, 0.99f, WindowState.Opened);

            Pi.Init <BootstrapWiringPi>();

            using (var dht = DhtSensor.Create(config.DhtType, Pi.Gpio[config.DhtSensorPin]))
            {
                dht.Start();
                dht.OnDataAvailable += Dht_OnDataAvailable;

                Console.WriteLine("Preparing vibration sensor...");
                var d7s = new D7s(config.D7sAddress);
                d7s.Reset();

                while (d7s.GetState() != D7sState.Normal)
                {
                    Thread.Yield();
                }

                Console.WriteLine("Preparing DHT sensor...");
                while (!humidity.HasValue || !temperature.HasValue)
                {
                    Thread.Yield();
                }

                Console.WriteLine("Devices preparation finished");
                Console.WriteLine("Recording vibration, temperature, humidty will be started");

                var devId = config.Device?.Id;
                while (true)
                {
                    Thread.Sleep(config.RecordingIntervalMs);

                    try
                    {
                        var ax   = d7s.GetAxis();
                        var si   = d7s.ReadSI();
                        var h    = (float)humidity.Value;
                        var temp = (float)temperature.Value;
                        Console.WriteLine($"温度:{temp}℃, 湿度:{h}%, 軸:{ax}, SI値:{si}");

                        if (!string.IsNullOrEmpty(devId))
                        {
                            var window = HandleTempAndSI(config, temp, si);

                            switch (window)
                            {
                            case WindowState.Opened:
                                Console.WriteLine("Window will be opened");
                                break;

                            case WindowState.Closed:
                                Console.WriteLine("Window will be closed");
                                break;
                            }

                            await client.RecordAsync(devId, si, (Axes)ax, temp, h, window);
                        }
                    }
                    catch (HardwareException hw)
                    {
                        Console.WriteLine("Failed to read SI value");
                    }
                }
            }
        }