/// <summary>
            /// Constructs the ButtonPad object and sets the ButtonPad class to
            /// handle the emulated hardware's button interrupts.
            /// </summary>
            /// <param name="sink"></param>
            /// <param name="button"></param>
            /// <param name="pin"></param>
            public ButtonPad(GPIOButtonInputProvider sink, Button button,
                             Cpu.Pin pin)
            {
                this.sink         = sink;
                this.button       = button;
                this.buttonDevice = InputManager.CurrentInputManager.ButtonDevice;

                // When this GPIO pin is true, call the Interrupt method.
                port = new InterruptPort(pin, true, Port.ResistorMode.PullUp,
                                         Port.InterruptMode.InterruptEdgeBoth);
                port.OnInterrupt += new NativeEventHandler(this.Interrupt);
            }
예제 #2
0
            public ButtonPad(GPIOButtonInputProvider sink, Button button, Cpu.Pin pin)
            {
                m_sink         = sink;
                m_button       = button;
                m_buttonDevice = InputManager.CurrentInputManager.ButtonDevice;

                // Do not set an InterruptPort with GPIO_NONE.
                if (pin != Cpu.Pin.GPIO_NONE)
                {
                    // When this GPIO pin is true, call the Interrupt method.
                    m_port = new InterruptPort(pin,
                                               true,
                                               Port.ResistorMode.PullUp,
                                               Port.InterruptMode.InterruptEdgeBoth);
                    m_port.OnInterrupt += new NativeEventHandler(this.Interrupt);
                }
            }
예제 #3
0
 public MainTextView(Mfrc522Device rfidTransceiver, Ky040Device rotaryEncoder, ButtonDevice menuButton, ButtonDevice playButton, ButtonDevice nextButton, ButtonDevice prevButton)
 {
     this.rfidTransceiver              = rfidTransceiver;
     this.rotaryEncoder                = rotaryEncoder;
     this.menuButton                   = menuButton;
     this.playButton                   = playButton;
     this.nextButton                   = nextButton;
     this.prevButton                   = prevButton;
     this.menuButton.Pressed          += (_, e) => this.Pressed('M');
     this.playButton.Pressed          += (_, e) => this.Pressed('P');
     this.nextButton.Pressed          += (_, e) => this.Pressed('N');
     this.prevButton.Pressed          += (_, e) => this.Pressed('B');
     this.rotaryEncoder.Pressed       += (_, e) => this.Pressed('R');
     this.rotaryEncoder.Rotated       += this.OnRotaryEncoderRotated;
     this.rfidTransceiver.TagDetected += this.OnRfidTransceiverTagDetected;
     this.thread = new CurrentThread();
 }
            /// <summary>
            /// Constructs a ButtonPad that handles the emulated hardware's
            /// button interrupts.
            /// </summary>
            /// <param name="sink"></param>
            /// <param name="button"></param>
            /// <param name="pin"></param>
            public ButtonPad(GPIOButtonInputProvider sink, Button button,
                             Cpu.Pin pin)
            {
                this.sink   = sink;
                this.button = button;
#if !MF_FRAMEWORK_VERSION_V3_0
                this.buttonDevice = InputManager.CurrentInputManager.ButtonDevice;
#endif

                if (pin != Cpu.Pin.GPIO_NONE)
                {
                    // When this GPIO pin is true, call the Interrupt method.
                    port = new InterruptPort(pin, true,
                                             Port.ResistorMode.PullUp,
                                             Port.InterruptMode.InterruptEdgeBoth);
                    port.OnInterrupt += new NativeEventHandler(this.Interrupt);
                }
            }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Ky040Device" /> class.
 /// </summary>
 /// <param name="gpioController">The gpio controller.</param>
 /// <param name="clockPin">The clock connector pin.</param>
 /// <param name="dataPin">The data connector pin.</param>
 /// <param name="buttonPin">The button connector pin.</param>
 /// <param name="activate">if set to <c>true</c> [activate].</param>
 /// <param name="debounce">The debounce.</param>
 /// <param name="rotaryEncoderReporter">The rotary encoder reporter.</param>
 public Ky040Device(
     GpioController gpioController,
     int clockPin,
     int dataPin,
     int buttonPin,
     bool activate,
     TimeSpan?debounce = null,
     IRotaryEncoderReporter?rotaryEncoderReporter = null)
 {
     this.gpioController        = gpioController;
     this.clockPin              = clockPin;
     this.dataPin               = dataPin;
     this.debounce              = debounce ?? TimeSpan.FromMilliseconds(1);
     this.buttonDevice          = new ButtonDevice(this.gpioController, buttonPin, PinEventTypes.Rising, PullMode.Up, this.debounce, false);
     this.buttonDevice.Pressed += this.OnButtonPressed;
     this.rotaryEncoderReporter = rotaryEncoderReporter;
     this.activation            = new Activation(
         () => this.buttonDevice.IsActivated,
         () =>
     {
         this.buttonDevice.SetActivation(true);
         this.gpioController.OpenPin(this.clockPin, PinMode.InputPullUp);
         this.gpioController.RegisterCallbackForPinValueChangedEvent(this.clockPin, PinEventTypes.Falling | PinEventTypes.Rising, this.OnEncoderChanged);
         this.gpioController.OpenPin(this.dataPin, PinMode.InputPullUp);
         this.gpioController.RegisterCallbackForPinValueChangedEvent(this.dataPin, PinEventTypes.Falling | PinEventTypes.Rising, this.OnEncoderChanged2);
         this.debouncer.Start();
         this.debouncer2.Start();
         this.lastSwitchesState = this.GetSwitchesState();
         Console.WriteLine(Convert.ToString(this.lastSwitchesState, 2).PadLeft(4, '0'));
     },
         () =>
     {
         this.debouncer.Stop();
         this.debouncer2.Stop();
         this.gpioController.UnregisterCallbackForPinValueChangedEvent(this.clockPin, this.OnEncoderChanged);
         this.gpioController.ClosePin(this.clockPin);
         this.gpioController.UnregisterCallbackForPinValueChangedEvent(this.dataPin, this.OnEncoderChanged);
         this.gpioController.ClosePin(this.dataPin);
         this.buttonDevice.SetActivation(false);
     },
         activate);
     this.rotaryEncoderReporter?.SetSource(typeof(IRotaryEncoderReporter), this);
 }
        public TouchSimulatedButtonInputProvider(PresentationSource presentationSource)
        {
            this.presentationSource = presentationSource;
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);

            this.dispatcher   = Dispatcher.CurrentDispatcher;
            this.buttonDevice = InputManager.CurrentInputManager.ButtonDevice;

            TouchScreen touchScreen = new TouchScreen(new TouchScreen.ActiveRectangle[] {
                new TouchScreen.ActiveRectangle(0, SystemMetrics.ScreenHeight / 3, (2 * SystemMetrics.ScreenWidth) / 3, SystemMetrics.ScreenHeight / 3, Button.VK_SELECT),
                new TouchScreen.ActiveRectangle((2 * SystemMetrics.ScreenWidth) / 3, SystemMetrics.ScreenHeight / 3, SystemMetrics.ScreenWidth / 3, SystemMetrics.ScreenHeight / 3, Button.VK_RIGHT),
                new TouchScreen.ActiveRectangle(0, 0, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight / 3, Button.VK_UP),
                new TouchScreen.ActiveRectangle(0, (2 * SystemMetrics.ScreenHeight) / 3, SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight / 3, Button.VK_DOWN),
            });

            Touch.Initialize(touchScreen);
            TouchCollectorConfiguration.CollectionMethod = CollectionMethod.Native;
            TouchCollectorConfiguration.CollectionMode   = CollectionMode.InkAndGesture;
            //TouchCollectorConfiguration.SamplingFrequency = 20000;
            //TouchCollectorConfiguration.TouchMoveFrequency = 5;
            touchScreen.OnTouchUp   += new TouchScreenEventHandler(this.TouchScreen_OnTouchUp);
            touchScreen.OnTouchDown += new TouchScreenEventHandler(this.TouchScreen_OnTouchDown);
        }