Exemplo n.º 1
0
        private static void GPIOButtonInputProvider_ButtonInput(InputReportArgs arg)
        {
            InputReportArgs      args   = (InputReportArgs)arg;
            RawButtonInputReport report = (RawButtonInputReport)args.Report;
            string info = report.Timestamp.ToLocalTime().ToString("HH:mm:ss.fff") +
                          " Button=" + report.Button.ToString() +
                          " Action=" + report.Actions.ToString();

            Debug.Print(info);
            Display.WriteLine(info);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 public void InitializeForEventSource()
 {
     if (Application._inputManager != null)
     {
         return;
     }
     Application._inputManager      = InputManager.CurrentInputManager;
     this._inputProviderSite        = Application._inputManager.RegisterInputProvider((object)this);
     Application._reportInputMethod = (DispatcherOperationCallback)(o =>
     {
         InputReportArgs inputReportArgs = (InputReportArgs)o;
         return((object)this._inputProviderSite.ReportInput(inputReportArgs.Device, inputReportArgs.Report));
     });
 }
Exemplo n.º 4
0
        public void InitializeForEventSource()
        {
            if (_inputManager == null)
            {
                _inputManager = InputManager.CurrentInputManager;

                _inputProviderSite =
                    _inputManager.RegisterInputProvider(this);

                _reportInputMethod =
                    new DispatcherOperationCallback(delegate(object o)
                {
                    InputReportArgs args = (InputReportArgs)o;
                    return(_inputProviderSite.ReportInput(args.Device, args.Report));
                });
            }
        }
        /// <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();
        }
        public GPIOButtonInputProvider(PresentationSource source)
        {
            _source   = source;
            _site     = InputManager.CurrentInputManager.RegisterInputProvider(this);
            _callback = new DispatcherOperationCallback(delegate(object report)
            {
                InputReportArgs args = (InputReportArgs)report;
                return(_site.ReportInput(args.Device, args.Report));
            });
            Dispatcher = Dispatcher.CurrentDispatcher;

            ButtonPad[] buttons = new ButtonPad[]
            {
                new ButtonPad(this, Button.VK_MENU, Pins.GPIO_PORT_A_3, Port.InterruptMode.InterruptEdgeBoth),
                new ButtonPad(this, Button.VK_SELECT, Pins.GPIO_PORT_A_8, Port.InterruptMode.InterruptEdgeBoth),
                new ButtonPad(this, Button.VK_LEFT, Pins.GPIO_PORT_A_7, Port.InterruptMode.InterruptEdgeBoth),
                new ButtonPad(this, Button.VK_RIGHT, Pins.GPIO_PORT_A_5, Port.InterruptMode.InterruptEdgeBoth),
                new ButtonPad(this, Button.VK_UP, Pins.GPIO_PORT_A_4, Port.InterruptMode.InterruptEdgeBoth),
                new ButtonPad(this, Button.VK_DOWN, Pins.GPIO_PORT_A_6, Port.InterruptMode.InterruptEdgeBoth),
            };

            _buttons = buttons;
        }
        /// <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;
        }
Exemplo n.º 8
0
        private object ReportInputCallback(object report)
        {
            InputReportArgs args = ( InputReportArgs )report;

            return(InputSite.ReportInput(args.Device, args.Report));
        }