Ejemplo n.º 1
0
        /// <summary>
        /// Maps GPIOs to Buttons that can be processed by
        /// Microsoft.SPOT.Presentation.
        /// </summary>
        /// <param name="source"></param>
        public GPIOButtonInputProvider(PresentationSource source)
        {
            // Set the input source.
            this.source = source;

            // Register our object as an input source with the input manager and
            // get back an InputProviderSite object which forwards the input
            // report to the input manager, which then places the input in the
            // staging area.
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);

            // Create a delegate that refers to the InputProviderSite object's
            // ReportInput method.
            callback = new DispatcherOperationCallback(delegate(object report)
            {
                InputReportArgs args = (InputReportArgs)report;
                return(site.ReportInput(args.Device, args.Report));
            });
            Dispatcher = Dispatcher.CurrentDispatcher;

            //--------------
            // Create a hardware provider.
            // HardwareProvider hwProvider = new HardwareProvider();


            //--------------

            // Create the pins that are needed for the buttons.  Default their
            // values for the emulator.
            GpioPin pinLeft   = Gpio.OpenPin(1);
            GpioPin pinRight  = Gpio.OpenPin(2);
            GpioPin pinUp     = Gpio.OpenPin(3);
            GpioPin pinSelect = Gpio.OpenPin(4);
            GpioPin pinDown   = Gpio.OpenPin(5);


            // Allocate button pads and assign the (emulated) hardware pins as
            // input from specific buttons.
            ButtonPad[] buttons = new ButtonPad[]
            {
                // Associate the buttons to the pins as discovered or set above
                new ButtonPad(this, Button.VK_LEFT, pinLeft),
                new ButtonPad(this, Button.VK_RIGHT, pinRight),
                new ButtonPad(this, Button.VK_UP, pinUp),
                new ButtonPad(this, Button.VK_SELECT, pinSelect),
                new ButtonPad(this, Button.VK_DOWN, pinDown),
            };

            this.buttons = buttons;
        }
 private void HandleTouch(RawButtonActions action, TouchScreenEventArgs eventArgs)
 {
     dispatcher.Invoke(
         new TimeSpan(0, 0, 3),
         delegate(object arg)
     {
         Button button = (Button)eventArgs.Target;
         RawButtonInputReport report = new RawButtonInputReport(this.presentationSource, eventArgs.TimeStamp, button, action);
         bool handled = site.ReportInput(this.buttonDevice, report);
         if (!handled)
         {
             ButtonEventArgs buttonEventArgs = new ButtonEventArgs(this.buttonDevice, this.presentationSource, eventArgs.TimeStamp, button);
             this.OnButtonUp(buttonEventArgs);
         }
         return(null);
     },
         null);
 }
        /// <summary>
        /// Maps GPIOs to Buttons that can be processed by
        /// nanoFramework.Presentation.
        /// </summary>
        /// <param name="source"></param>
        public GPIOButtonInputProvider(PresentationSource source)
        {
            // Set the input source.
            this.source = source;

            // Register our object as an input source with the input manager and
            // get back an InputProviderSite object which forwards the input
            // report to the input manager, which then places the input in the
            // staging area.
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);

            // Create a delegate that refers to the InputProviderSite object's
            // ReportInput method.
            callback = new DispatcherOperationCallback(delegate(object report)
            {
                InputReportArgs args = (InputReportArgs)report;
                return(site.ReportInput(args.Device, args.Report));
            });

            Dispatcher = Dispatcher.CurrentDispatcher;

            this.buttons = new ArrayList();
        }
        /// <summary>
        /// Maps GPIOs to Buttons that can be processed by
        /// Microsoft.SPOT.Presentation.
        /// </summary>
        /// <param name="source"></param>
        public GPIOButtonInputProvider(PresentationSource source)
        {
            // Set the input source.
            this.source = source;

            // Register our object as an input source with the input manager and
            // get back an InputProviderSite object which forwards the input
            // report to the input manager, which then places the input in the
            // staging area.
            site = InputManager.CurrentInputManager.RegisterInputProvider(this);

            // Create a delegate that refers to the InputProviderSite object's
            // ReportInput method.
            callback = new DispatcherOperationCallback(delegate(object report)
            {
#if MF_FRAMEWORK_VERSION_V3_0
                return(site.ReportInput((InputReport)report));
#else
                InputReportArgs args = (InputReportArgs)report;
                return(site.ReportInput(args.Device, args.Report));
#endif
            });
            Dispatcher = Dispatcher.CurrentDispatcher;

            // Create a hardware provider.
            HardwareProvider hwProvider = new HardwareProvider();

            // Create the pins that are needed for the buttons.  Default their
            // values for the emulator.
            Cpu.Pin pinLeft   = Cpu.Pin.GPIO_Pin0;
            Cpu.Pin pinRight  = Cpu.Pin.GPIO_Pin1;
            Cpu.Pin pinUp     = Cpu.Pin.GPIO_Pin2;
            Cpu.Pin pinSelect = Cpu.Pin.GPIO_Pin3;
            Cpu.Pin pinDown   = Cpu.Pin.GPIO_Pin4;

            // Use the hardware provider to get the pins.  If the left pin is
            // not set, assume none of the pins are set, and set the left pin
            // back to the default emulator value.
            if ((pinLeft = hwProvider.GetButtonPins(Button.VK_LEFT)) ==
                Cpu.Pin.GPIO_NONE)
            {
                pinLeft = Cpu.Pin.GPIO_Pin0;
            }
            else
            {
                pinRight  = hwProvider.GetButtonPins(Button.VK_RIGHT);
                pinUp     = hwProvider.GetButtonPins(Button.VK_UP);
                pinSelect = hwProvider.GetButtonPins(Button.VK_SELECT);
                pinDown   = hwProvider.GetButtonPins(Button.VK_DOWN);
            }

            // Allocate button pads and assign the (emulated) hardware pins as
            // input from specific buttons.
            ButtonPad[] buttons = new ButtonPad[]
            {
                // Associate the buttons to the pins as discovered or set above
                new ButtonPad(this, Button.VK_LEFT, pinLeft),
                new ButtonPad(this, Button.VK_RIGHT, pinRight),
                new ButtonPad(this, Button.VK_UP, pinUp),
                new ButtonPad(this, Button.VK_SELECT, pinSelect),
                new ButtonPad(this, Button.VK_DOWN, pinDown),
            };

            this.buttons = buttons;
        }