コード例 #1
0
ファイル: SS944.cs プロジェクト: msherburne/iot-devices
        private void EnsureInitialized()
        {
            if (isInitialized) { return; }

            // Validate
            if (xChannel == null) { throw new MissingIoException(nameof(XChannel)); }
            if (yChannel == null) { throw new MissingIoException(nameof(YChannel)); }

            // Start with fake reading
            currentReading = new ThumbstickReading(0, 0, false);

            // Initialize button?
            if (buttonPin != null)
            {
                if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                {
                    buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                }
                else
                {
                    buttonPin.SetDriveMode(GpioPinDriveMode.Input);
                }
                buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            }

            isInitialized = true;
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new <see cref="ThumbstickReadingChangedEventArgs"/>
 /// </summary>
 /// <param name="reading"></param>
 public ThumbstickReadingChangedEventArgs(ThumbstickReading reading)
 {
     if (reading == null)
     {
         throw new ArgumentNullException("reading");
     }
     this.Reading = reading;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new <see cref="ThumbstickReadingChangedEventArgs"/>
 /// </summary>
 /// <param name="reading"></param>
 public ThumbstickReadingChangedEventArgs(ThumbstickReading reading)
 {
     if (reading == null) throw new ArgumentNullException("reading");
     this.Reading = reading;
 }
コード例 #4
0
ファイル: SS944.cs プロジェクト: jessejjohnson/iot-devices
        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));
        }