Пример #1
0
 protected virtual void OnPinTouched(PinTouchedEventArgs touchedEventArgs)
 {
     if (PinTouched != null)
     {
         PinTouched(this, touchedEventArgs);
     }
 }
        private void __mpr121_PinTouched(object sender, PinTouchedEventArgs e)
        {
            
            var task=Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                this.txtStatus.Text = e.Touched[0].ToString() + " Touched"; //just the first touched pin

                __updatePinStatusUI(e.Touched, true);
            });
            
        }
Пример #3
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;
            }
        }
Пример #4
0
        private void __mpr121_PinTouched(object sender, PinTouchedEventArgs e)
        {

            switch (e.Touched[0]) //using only the first pin in the list of touched pins
            {
                case PinId.PIN_0:
                    currentSanta = 0;
                    break;
                case PinId.PIN_2:
                    currentSanta = 1;
                    break;
                case PinId.PIN_4:
                    currentSanta = 2;
                    break;
                case PinId.PIN_6:
                    currentSanta = 3;
                    break;
                case PinId.PIN_8:
                    currentSanta = 4;
                    break;
                case PinId.PIN_10:
                    currentSanta = 5;
                    break;
                case PinId.PIN_11:
                    currentSanta = 0;   //just using six images
                    break;
            }

            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {

                mediaElement.Play();

                santas[currentSanta].Visibility = Visibility.Visible;
            });
        }
 protected virtual void OnPinTouched(PinTouchedEventArgs touchedEventArgs)
 {
     if (PinTouched != null) { PinTouched(this, touchedEventArgs); }
 }
        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;
            }
        }