예제 #1
0
        public void UpdateMoistureImage(FloatChangeResult moistureReadings)
        {
            float moisture = moistureReadings.New;

            if (moisture > 1)
            {
                moisture = 1f;
            }
            else if (moisture < 0)
            {
                moisture = 0f;
            }

            if (moisture > 0 && moisture <= 0.25)
            {
                UpdateImage(0, 42, 10);
            }
            else if (moisture > 0.25 && moisture <= 0.50)
            {
                UpdateImage(1, 28, 4);
            }
            else if (moisture > 0.50 && moisture <= 0.75)
            {
                UpdateImage(2, 31, 5);
            }
            else if (moisture > 0.75 && moisture <= 1.0)
            {
                UpdateImage(3, 35, 5);
            }

            graphics.Show();
        }
예제 #2
0
        /// <summary>
        /// Takes the analog reading and converts to the wind azimuth, then
        /// raises the event/updates subscribers.
        /// </summary>
        protected void HandleAnalogUpdate(FloatChangeResult result)
        {
            var windAzimuth = LookupWindDirection(result.New);
            WindVaneChangeResult windChangeResult = new WindVaneChangeResult()
            {
                Old = this.LastRecordedWindAzimuth,
                New = windAzimuth
            };

            RaiseUpdated(windChangeResult);
            this.LastRecordedWindAzimuth = windAzimuth;
        }
예제 #3
0
        /// <summary>
        /// Starts continuously sampling the sensor.
        ///
        /// This method also starts raising `Updated` events and IObservable
        /// subscribers getting notified. Use the `standbyDuration` parameter
        /// to specify how often events and notifications are raised/sent.
        /// </summary>
        /// <param name="sampleCount">How many samples to take during a given
        /// reading. These are automatically averaged to reduce noise.</param>
        /// <param name="sampleIntervalDuration">The time, in milliseconds,
        /// to wait in between samples during a reading.</param>
        /// <param name="standbyDuration">The time, in milliseconds, to wait
        /// between sets of sample readings. This value determines how often
        /// `Updated` events are raised and `IObservable` consumers are notified.</param>
        public void StartUpdating(
            int sampleCount            = 10,
            int sampleIntervalDuration = 40,
            int standbyDuration        = 1000)
        {
            // thread safety
            lock (_lock) {
                if (IsSampling)
                {
                    return;
                }
                IsSampling = true;

                //SamplingTokenSource = new CancellationTokenSource();
                //CancellationToken ct = SamplingTokenSource.Token;

                float             oldConditions;
                FloatChangeResult result;
                var task = new Thread(new ThreadStart(() => {
                    while (true)
                    {
                        // TODO: someone please review; is this the correct
                        // place to do this?
                        // check for cancel (doing this here instead of
                        // while(!ct.IsCancellationRequested), so we can perform
                        // cleanup
                        if (!IsSampling)
                        {
                            // do task clean up here
                            //_observers.ForEach(x => x.OnCompleted());
                            break;
                        }
                        // capture history
                        oldConditions = Moisture;

                        // read
                        Moisture = Read(sampleCount, sampleIntervalDuration);

                        // build a new result with the old and new conditions
                        result = new FloatChangeResult(oldConditions, Moisture);

                        // let everyone know
                        RaiseChangedAndNotify(result);

                        // sleep for the appropriate interval
                        Thread.Sleep(standbyDuration);
                    }
                }));
                task.Start();
            }
        }
예제 #4
0
        async Task TestCapacitiveRead()
        {
            Console.WriteLine("TestCapacitiveSensor...");

            while (true)
            {
                FloatChangeResult moisture = await capacitive.Read();

                Console.WriteLine($"Moisture New Value { moisture.New}");
                Console.WriteLine($"Moisture Old Value { moisture.Old}");
                Console.WriteLine($"Moisture Delta Value { moisture.Delta}");
                Thread.Sleep(1000);
            }
        }
예제 #5
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            onboardLed.SetColor(Color.Orange);

            var newMoisture = await capacitive.Read();

            var newTemperature = await analogTemperature.Read();

            displayController.UpdateMoisturePercentage(newMoisture.New, moisture.New);
            moisture = newMoisture;

            displayController.UpdateTemperatureValue(newTemperature.Temperature.Value, temperature.Temperature.Value);
            temperature = newTemperature;

            onboardLed.SetColor(Color.Green);
        }
예제 #6
0
 void HallSensorRPMsChanged(object sender, FloatChangeResult e)
 {
     Console.WriteLine($"RPM: {e.New}");
 }
예제 #7
0
 private void AnalogInputPort_Changed(object sender, FloatChangeResult e)
 {
     CurrentDistance = 26 / e.New;
     DistanceDetected?.Invoke(this, new DistanceEventArgs(CurrentDistance));
 }
 private void _photoResistor_Changed(object sender, FloatChangeResult e)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 protected void RaiseChangedAndNotify(FloatChangeResult changeResult)
 {
     Updated?.Invoke(this, changeResult);
     //base.NotifyObservers(changeResult);
 }