Esempio n. 1
0
        private static ISensor GetDhtSensor(Iot.Device.GrovePiDevice.GrovePi grovePi, GrovePort port, SensorType sensorType, string name, int sensorId, bool rgbDisplay)
        {
            var sensorPort = _sensors.Where(sen => sen.Port == port).ToList();

            if (sensorPort.Count > 1)
            {
                throw new Exception("The port '" + port + "' is already used.");
            }

            if (sensorType == SensorType.DhtHumiditySensor)
            {
                if (sensorPort.Count == 1)
                {
                    if (sensorPort[0].SensorType == SensorType.DhtTemperatureSensor)
                    {
                        var humiditySensor = new GrovePiDthHumiditySensor((sensorPort[0] as GrovePiDthTemperatureSensor).DhtSensor, name, sensorId, port, rgbDisplay);
                        _sensors.Add(humiditySensor);
                        return(humiditySensor);
                    }
                    else
                    {
                        throw new Exception("The port '" + port + "' is already used.");
                    }
                }

                var dhtHumiditySensor = new GrovePiDthHumiditySensor(new DhtSensor(grovePi, port, DhtType.Dht22), name, sensorId, port, rgbDisplay);
                dhtHumiditySensor.Refresh();
                refresher.AddSensor(dhtHumiditySensor);
                _sensors.Add(dhtHumiditySensor);
                return(dhtHumiditySensor);
            }

            else if (sensorType == SensorType.DhtTemperatureSensor)
            {
                if (sensorPort.Count == 1)
                {
                    if (sensorPort[0].SensorType == SensorType.DhtHumiditySensor)
                    {
                        var temperatureSensor = new GrovePiDthTemperatureSensor((sensorPort[0] as GrovePiDthHumiditySensor).DhtSensor, name, sensorId, port, rgbDisplay);
                        _sensors.Add(temperatureSensor);
                        return(temperatureSensor);
                    }
                    else
                    {
                        throw new Exception("The port '" + port + "' is already used.");
                    }
                }

                var dhtTemperatureSensor = new GrovePiDthTemperatureSensor(new DhtSensor(grovePi, port, DhtType.Dht22), name, sensorId, port, rgbDisplay);
                dhtTemperatureSensor.Refresh();
                refresher.AddSensor(dhtTemperatureSensor);
                _sensors.Add(dhtTemperatureSensor);

                return(dhtTemperatureSensor);
            }

            throw new Exception("Type " + sensorType + " is not compatible for DhtSensor");
        }
Esempio n. 2
0
        public static Iot.Device.GrovePiDevice.GrovePi GetGrovePi()
        {
            if (_grovePi == null)
            {
                _grovePi = new Iot.Device.GrovePiDevice.GrovePi(GetI2Device());
            }

            return(_grovePi);
        }