Beispiel #1
0
 protected virtual void OnPinTouched(PinTouchedEventArgs touchedEventArgs)
 {
     if (PinTouched != null)
     {
         PinTouched(this, touchedEventArgs);
     }
 }
Beispiel #2
0
        private void Mpr122IRQpin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (args.Edge == GpioPinEdge.FallingEdge)
            {
                //read the touch status register and convert it in to CapsenseElectrode Enum
                int rawTouchRegisterData = readTouchStatusRegister();
                currentReading = (PinId)rawTouchRegisterData;

                List <PinId> allTouchedPins  = new List <PinId>();
                List <PinId> allReleasedPins = new List <PinId>();

                foreach (PinId val in Enum.GetValues(typeof(PinId))) //loop through all CapSense Pins
                {
                    if (val != PinId.None)
                    {
                        if (currentReading.HasFlag(val) && !lastReading.HasFlag(val))
                        {
                            allTouchedPins.Add(val);
                            this.__pins.Find(p => p.PinId == val).SetTouched(true);
                        }

                        if (!currentReading.HasFlag(val) && lastReading.HasFlag(val))
                        {
                            allReleasedPins.Add(val);
                            this.__pins.Find(p => p.PinId == val).SetTouched(false);
                        }
                    }
                }

                allTouchedPins.TrimExcess();
                allReleasedPins.TrimExcess();
                if (allTouchedPins.Count > 0)
                {
                    PinTouchedEventArgs touchedData = new PinTouchedEventArgs(allTouchedPins);
                    OnPinTouched(touchedData);
                }

                if (allReleasedPins.Count > 0)
                {
                    PinReleasedEventArgs releasedData = new PinReleasedEventArgs(allReleasedPins);
                    OnPinReleased(releasedData);
                }

                lastReading = currentReading;
            }
        }