Ejemplo n.º 1
0
        void StartSampling()
        {
            int sampleCount            = samplingSetting.sampleCount;
            int sampleIntervalDuration = samplingSetting.sampleIntervalDuration;
            int standbyDuration        = samplingSetting.standbyDuration;
            var counter = 0;
            var total   = 0f;
            var average = 0f;

            for (int i = 0; i < sampleCount; i++)
            {
                // read the voltage
                float voltage = AnalogInputPort.ReadValue();
                // (sampleCount, sampleIntervalDuration);
                // convert and save to our temp property for later retreival
                var temp = VoltageToTemperature(voltage);
                total += temp;
                counter++;
                average = total / counter;
                if (!IsSampling)
                {
                    break;
                }
                Thread.Sleep(sampleIntervalDuration);
            }
            IsSampling = false;
            RaiseEventsAndNotify
            (
                new AtmosphericConditionChangeResult(new AtmosphericConditions(average, 0, 0), null)
            );
        }
Ejemplo n.º 2
0
        void StartSampling()
        {
            int sampleCount            = samplingSetting.sampleCount;
            int sampleIntervalDuration = samplingSetting.sampleIntervalDuration;
            int standbyDuration        = samplingSetting.standbyDuration;
            var counter = 0;
            var total   = 0f;
            var average = 0f;

            for (int i = 0; i < sampleCount; i++)
            {
                // read the voltage
                float temp = AnalogInputPort.ReadValue();

                total += temp;
                counter++;
                average = total / counter;
                if (!IsSampling)
                {
                    break;
                }
                Thread.Sleep(sampleIntervalDuration);
            }
            IsSampling = false;
            RaiseChangedAndNotify(new FloatChangeResult(average, 0));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Convenience method to get the current temperature. For frequent reads, use
        /// StartSampling() and StopSampling() in conjunction with the SampleBuffer.
        /// </summary>
        /// <param name="sampleCount">The number of sample readings to take.
        /// Must be greater than 0. These samples are automatically averaged.</param>
        /// <param name="sampleIntervalDuration">The time, in milliseconds,
        /// to wait in between samples during a reading.</param>
        /// <returns>A float value that's ann average value of all the samples taken.</returns>
        public AtmosphericConditions Read(int sampleCount = 10, int sampleIntervalDuration = 40)
        {
            // read the voltage
            float voltage = AnalogInputPort.ReadValue();// (sampleCount, sampleIntervalDuration);

            // convert and save to our temp property for later retreival
            Temperature = VoltageToTemperature(voltage);
            // return
            return(new AtmosphericConditions(Temperature, 0, 0));
            //return Temperature;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convenience method to get the current soil moisture. For frequent reads, use
        /// StartUpdating() and StopUpdating().
        /// </summary>
        /// <param name="sampleCount">The number of sample readings to take.
        /// Must be greater than 0.</param>
        /// <param name="sampleInterval">The interval, in milliseconds, between
        /// sample readings.</param>
        /// <returns></returns>
        public float Read(int sampleCount = 10, int sampleInterval = 40)
        {
            float voltage = 0;

            // read the voltage
            for (int i = 0; i < sampleCount; i++)
            {
                var tmp = AnalogInputPort.ReadValue();
                voltage += tmp;
                Thread.Sleep(sampleInterval);
            }
            voltage /= sampleCount;
            // convert and save to our temp property for later retrieval
            Moisture = VoltageToMoisture(voltage);
            // return
            return(Moisture);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convenience method to get the current soil moisture. For frequent reads, use
        /// StartUpdating() and StopUpdating().
        /// </summary>
        /// <param name="sampleCount">The number of sample readings to take.
        /// Must be greater than 0.</param>
        /// <param name="sampleInterval">The interval, in milliseconds, between
        /// sample readings.</param>
        /// <returns></returns>
        public float Read(int sampleCount = 10, int sampleInterval = 40)
        {
            DigitalPort.Write(GpioPinValue.High);
            //float voltage = await AnalogInputPort.Read(sampleCount, sampleInterval);
            float voltage = 0;

            // read the voltage
            for (int i = 0; i < sampleCount; i++)
            {
                var tmp = AnalogInputPort.ReadValue();
                voltage += tmp;
                Thread.Sleep(sampleInterval);
            }
            voltage /= sampleCount;
            DigitalPort.Write(GpioPinValue.Low);

            // convert and save to our temp property for later retrieval
            Moisture = VoltageToMoisture(voltage);
            return(Moisture);
        }