Ejemplo n.º 1
0
        public static ISensor GetSensor(SensorWeatherType sensorWeatherType, string name, int sensorId, bool rgbDisplay)
        {
            if (webWeather == null)
            {
                webWeather = new WebWeather();
                refresher  = new Refresher();
                refresher.AddSensor(webWeather);
                refresher.Start(600000);
            }

            switch (sensorWeatherType)
            {
            case SensorWeatherType.Temperature:
                return(new WeatherTemperature(webWeather, name, sensorId, rgbDisplay));

            case SensorWeatherType.Humidity:
                return(new WeatherHumidity(webWeather, name, sensorId, rgbDisplay));

            case SensorWeatherType.Pressure:
                return(new WeatherPressure(webWeather, name, sensorId, rgbDisplay));

            case SensorWeatherType.WindSpeed:
                return(new WeatherWindSpeed(webWeather, name, sensorId, rgbDisplay));

            case SensorWeatherType.WindDirection:
                return(new WeatherWindDirection(webWeather, name, sensorId, rgbDisplay));

            default:
                throw new Exception("The type <" + webWeather + "> is not manage by the WeatherSensorBuilder");
            }
        }
Ejemplo n.º 2
0
        public static ISensor CreateSensor(SensorType sensorType, GrovePort port, string name, int sensorId, bool rgbDisplay)
        {
#if DEBUG
            var fakeSensor = new GrovePiFakeSensor(sensorType, name, sensorId);
            refresher.AddSensor(fakeSensor);
            return(fakeSensor);
#endif

            var grovePi = GrovePiDevice.GetGrovePi();

            switch (sensorType)
            {
            case SensorType.AnalogSensor:
                ThrowExceptionIfPortIsUsed(port);
                var analogSensor = new GrovePiAnalogSensor(new AnalogSensor(grovePi, port), name, sensorId, port, rgbDisplay);
                refresher.AddSensor(analogSensor);
                _sensors.Add(analogSensor);
                return(analogSensor);

            case SensorType.DhtTemperatureSensor:
                return(GetDhtSensor(grovePi, port, SensorType.DhtTemperatureSensor, name, sensorId, rgbDisplay));

            case SensorType.DhtHumiditySensor:
                return(GetDhtSensor(grovePi, port, SensorType.DhtHumiditySensor, name, sensorId, rgbDisplay));

            case SensorType.PotentiometerSensor:
                ThrowExceptionIfPortIsUsed(port);
                var potentiometreSensor = new GrovePiAnalogPotentiometer(new PotentiometerSensor(grovePi, port), name, sensorId, port, rgbDisplay);
                refresher.AddSensor(potentiometreSensor);
                _sensors.Add(potentiometreSensor);
                return(potentiometreSensor);

            case SensorType.UltrasonicSensor:
                ThrowExceptionIfPortIsUsed(port);
                var ultrasonicSensor = new GrovePiAnalogUltrasonic(new UltrasonicSensor(grovePi, port), name, sensorId, port, rgbDisplay);
                refresher.AddSensor(ultrasonicSensor);
                _sensors.Add(ultrasonicSensor);

                return(ultrasonicSensor);

            case SensorType.GrooveTemperartureSensor:
                ThrowExceptionIfPortIsUsed(port);
                var temperatureSensor = new GrovePiAnalogTemperature(new GroveTemperatureSensor(grovePi, port), name, sensorId, port, rgbDisplay);
                refresher.AddSensor(temperatureSensor);
                _sensors.Add(temperatureSensor);
                return(temperatureSensor);

            case SensorType.LightSensor:
            case SensorType.SoundSensor:
            default:
                throw new Exception("GrovePiSensor: unsupported sensor type: " + sensorType);
            }
        }