Esempio n. 1
0
        private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            var edge = e.Edge;

            if ((pressedValue == GpioPinValue.High) && (edge == GpioPinEdge.RisingEdge))
            {
                isPressed = true;
            }
            else if ((pressedValue == GpioPinValue.Low) && (edge == GpioPinEdge.FallingEdge))
            {
                isPressed = true;
            }
            else
            {
                isPressed = false;
            }

            // Notify
            if (isPressed)
            {
                pressedEvent.Raise(owner, EmptyEventArgs.Instance);
                if (ClickMode == ButtonClickMode.Press)
                {
                    clickEvent.Raise(owner, EmptyEventArgs.Instance);
                }
            }
            else
            {
                releasedEvent.Raise(owner, EmptyEventArgs.Instance);
                if (ClickMode == ButtonClickMode.Release)
                {
                    clickEvent.Raise(owner, EmptyEventArgs.Instance);
                }
            }
        }
Esempio n. 2
0
        private void Update(AnalogSensorReading reading)
        {
            // Determine starting point and average count based on a value being passed in
            double AverageRatio = (reading != null ? reading.Ratio : 0);
            int    totalReads   = (reading != null ? 6 : 5);

            // Calculate average
            for (int i = 0; i < totalReads; i++)
            {
                AverageRatio += sensor.GetCurrentReading().Ratio;
                Task.Delay(1).Wait();
            }
            var ratio = AverageRatio / totalReads;

            // Multiply by reference
            double milliVolts = ratio * ReferenceMilliVolts;

            // Convert to Celsius
            double celsius = ((milliVolts - ZeroDegreeOffset) / MillivoltsPerDegree) + CalibrationOffset;

            // Update current value
            lock (currentReading)
            {
                currentReading = new TemperatureReading(Temperature.FromDegreesCelsius(celsius));
            }

            // Notify
            readingChangedEvent.Raise(this, currentReading);
        }
Esempio n. 3
0
        private void Update()
        {
            // Read X and Y values
            var x = xChannel.ReadRatio();
            var y = yChannel.ReadRatio();

            // Scale to -1 to 1, and Y needs to be inverted
            x = (x * 2) - 1;
            y = (-y * 2) + 1;

            // Button
            bool pressed = false;

            if (buttonPin != null)
            {
                pressed = (buttonPin.Read() == GpioPinValue.Low);
            }

            // Update current value
            lock (currentReading)
            {
                currentReading = new ThumbstickReading(x, y, pressed);
            }

            // Notify
            readingChangedEvent.Raise(this, new ThumbstickReadingChangedEventArgs(currentReading));
        }
Esempio n. 4
0
 private void ClockPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (args.Edge == GpioPinEdge.RisingEdge)
     {
         var dirValue = directionPin.Read();
         if ((lastDirValue == GpioPinValue.Low) && (dirValue == GpioPinValue.High))
         {
             rotatedEvent.Raise(this, new RotaryEncoderRotatedEventArgs(RotationDirection.Counterclockwise));
         }
         if ((lastDirValue == GpioPinValue.High) && (dirValue == GpioPinValue.Low))
         {
             rotatedEvent.Raise(this, new RotaryEncoderRotatedEventArgs(RotationDirection.Clockwise));
         }
     }
     else
     {
         lastDirValue = directionPin.Read();
     }
 }
Esempio n. 5
0
        private void Update(bool raiseEvent)
        {
            // Read X and Y values
            var val   = adcChannel.ReadValue();
            var ratio = adcChannel.ReadRatio(); // TODO: Support customized value scaling

            // Update current value
            lock (currentReading)
            {
                currentReading = new AnalogSensorReading(val, ratio);
            }

            // Notify?
            if (raiseEvent)
            {
                readingChangedEvent.Raise(this, new AnalogSensorReadingChangedEventArgs(currentReading));
            }
        }