コード例 #1
0
 protected virtual void OnDataReceived(SensorDataEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(this, e);
     }
 }
コード例 #2
0
        private void SensorProvider_DataReceived(object sender, SensorDataEventArgs e)
        {
            String format    = FormatOfSensorValue(e.SensorValue);
            String nextValue = e.SensorValue + "," + DateTime.Now + Environment.NewLine;

            switch (e.SensorName)
            {
            case "O2":
            {
                O2_VAL = e.SensorValue;
            };
                break;

            case "CO2":
            {
                CO2_VAL = e.SensorValue;
            };
                break;
            }
        }
コード例 #3
0
        /**
         * This method records on a SampleTimer the data measured by the temperature, brightness, and soil moisture sensor,
         * then organizes all of the information collected.
         * */
        private async void TimerCallback(object state)                //ASYNCH with BME I2C sensor
        {
            //ensures that the temperature sensor is initialized before it is measured from
            if (BME280 == null)
            {
                Debug.WriteLine("BME280 is null");
            }
            else
            {
                //receives the value from the temperature sensor and saves
                //the data in the SensorDataEventArgs class, which holds
                //the sensor name, the data point, and the time the value was measured.
                //this data is then sent back to the main page and the UI is adjusted based
                //off of the measurement.
                //float currentTemperature = (float) rand.NextDouble() * 10;
                float currentTemperature = await BME280.ReadTemperature();

                var tempArgs = new SensorDataEventArgs()
                {
                    SensorName  = "Temperature",
                    SensorValue = currentTemperature * (9 / 5) + 32,
                    Timestamp   = DateTime.Now
                };
                OnDataReceived(tempArgs);

                float currentPressure = await BME280.ReadPressure();

                var pressureArgs = new SensorDataEventArgs()
                {
                    SensorName  = "Pressure",
                    SensorValue = currentPressure / 1000, //into kPa (1hPa --> 0.1kPa)  ???
                    Timestamp   = DateTime.Now
                };
                OnDataReceived(pressureArgs);

                float currentHumidity = await BME280.ReadHumidity();

                var humidityArgs = new SensorDataEventArgs()
                {
                    SensorName  = "Humidity",
                    SensorValue = currentHumidity,
                    Timestamp   = DateTime.Now
                };
                OnDataReceived(humidityArgs);

                //float currentAltitude = await BME280.ReadAltitude(seaLevel);
                //var altitudeArgs = new SensorDataEventArgs()
                //{
                //    SensorName = "Altitude",
                //    SensorValue = currentAltitude,
                //    Timestamp = DateTime.Now
                //};
                //OnDataReceived(altitudeArgs);
            }

            //MCP3008 is an ADC and checks to see if this is initialized.
            //the soil moisture sensor and the photocell are on different channels of the ADC
            if (mcp3008 == null)
            {
                Debug.WriteLine("mcp3008 is null");
                return;
            }
            else
            {
                ////Debug.WriteLine("O2Call");

                currentO2 = mcp3008.ReadADC(O2ADCChannel);

                currentO2 = (currentO2 * (3300.0F / 1024.0F)) / 132F;    // Change characteristic EQ based on Sensor
                //  3300mV/132 = 25(%) for a full high signal
                ////Debug.WriteLine(currentO2);
                var O2Args = new SensorDataEventArgs()
                {
                    SensorName  = "O2",
                    SensorValue = currentO2,
                    Timestamp   = DateTime.Now
                };
                OnDataReceived(O2Args);
            }

            if (MHZ16 == null)
            {
                Debug.WriteLine("MHZ16 is null");
                return;
            }
            else
            {
                currentCO2 = (float)(MHZ16.ReadCO2());
                //if (currentCO2 == 999999f)
                //{
                //    //Add Some Method for restarting disconnected/reconnected i2c device
                //}
                var CO2Args = new SensorDataEventArgs()
                {
                    SensorName  = "CO2",
                    SensorValue = currentCO2,
                    Timestamp   = DateTime.Now
                };
                OnDataReceived(CO2Args);
            }
        }
コード例 #4
0
        /**
         * updates the UI when the sensors make a new reading
         * */

        //class DataHandlerClass
        //{
        //    public DataHandlerClass(SensorControl SensorUpdate)
        //    {
        //        SensorUpdate.DataReceived += new HypoxiaChamber.DataReceivedEventHandler(UpdateUI);
        //    }
        //}
        private async void SensorProvider_DataReceived(object sender, SensorDataEventArgs e)
        {
            String format    = FormatOfSensorValue(e.SensorValue);
            String nextValue = e.SensorValue + "," + DateTime.Now + Environment.NewLine;

            switch (e.SensorName)
            {
            case "O2":
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    currentO2     = e.SensorValue;
                    O2Gauge.Value = currentO2;
                    App.O2List.Add(nextValue);
                });

                break;

            case "CO2":
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    currentCO2     = e.SensorValue;
                    CO2Gauge.Value = currentCO2;
                    //App.CO2List.Add(nextValue);
                });

                break;

            //case "Brightness":
            //    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            //    {
            //        currentBrightness = e.SensorValue;
            //        App.BrightnessList.Add(nextValue);
            //    });
            //    break;
            case "Temperature":
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    currentTemperature = e.SensorValue;
                    Temp_Gauge.Value   = currentTemperature;
                    //Temp_Txt.Text = string.Format("{0:0,0.00}", currentTemperature);
                    App.TemperatureList.Add(nextValue);
                });

                break;

            case "Pressure":
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    currentPressure  = e.SensorValue;
                    Pres_Gauge.Value = currentPressure;
                    //App.PressureList.Add(nextValue);
                });

                break;

            case "Humidity":
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    currentHumidity   = e.SensorValue;
                    Humid_Gauge.Value = currentHumidity;
                    //App.HumidityList.Add(nextValue);
                });

                break;
                //case "Altitude":
                //    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                //    {
                //        currentAltitude = e.SensorValue;
                //        App.AltitudeList.Add(nextValue);
                //    });
                //    break;
            }
        }