// This class maps GPIOs to Buttons processable by Microsoft.SPOT.Presentation
        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 ReportInputCallback(site.ReportInput);
            Dispatcher = Dispatcher.CurrentDispatcher;

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

            // Create the pins we will need 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 then assume none of them are
            // 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.º 2
0
        public GPIOButtonInputProvider(GPIOButtonInputHandler buttonInputHandler)
        {
            if (buttonInputHandler == null)
            {
                throw new ArgumentNullException("buttonInputHandler");
            }
            m_buttonInputHandler = buttonInputHandler;
            m_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.
            m_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),
            };
        }
        /// <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.º 4
0
        public static void Main(string[] args)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            Debug.Print("Test GPIO Hardware provider functions ");

            while (true)
            {
                // GPIO
                int            GpioCnt = hwProvider.GetPinsCount();
                Cpu.PinUsage[] PinMap;
                int            size;
                hwProvider.GetPinsMap(out PinMap, out size);
                Debug.Print("------------------------------");

                Debug.Print("-------Pin Map ----------");
                for (int i = 0; i < GpioCnt; i++)
                {
                    Debug.Print("Pin Map - usage" + i + " : " + PinMap[i]);
                }
                Debug.Print("Pin count size " + size);

                Debug.Print("------------------------------");
                Debug.Print("---Pin Usage -------");

                Cpu.PinUsage OnePinUsage;
                for (int i = 0; i < GpioCnt; i++)
                {
                    OnePinUsage = hwProvider.GetPinsUsage((Cpu.Pin)i);
                    if (OnePinUsage != PinMap[i])
                    {
                        Debug.Print("ERRORR       **** ");
                    }
                    Debug.Print("cnt " + i + "usage" + OnePinUsage);
                }
                Debug.Print("------------------------------");

                Cpu.PinValidResistorMode OnePinResistorMode = hwProvider.GetSupportedResistorModes((Cpu.Pin) 0);
                Debug.Print("Reistor Mode " + OnePinResistorMode);

                Debug.Print("------------------------------");

                Cpu.PinValidInterruptMode OnePinIntMode = hwProvider.GetSupportedInterruptModes((Cpu.Pin) 0);
                Debug.Print("Interrupt Mode " + OnePinIntMode);
                Debug.Print("------------------------------");



                // serial
                Cpu.Pin rxPin;
                Cpu.Pin txPin;
                Cpu.Pin ctsPin;
                Cpu.Pin rtsPin;

                hwProvider.GetSerialPins("COM1", out rxPin, out txPin, out ctsPin, out rtsPin);
                Debug.Print("Serial Port : ");
                Debug.Print("Rx- " + rxPin);
                Debug.Print("Tx- " + txPin);
                Debug.Print("cts- " + ctsPin);
                Debug.Print("Rts- " + rtsPin);

                int SerialNo = hwProvider.GetSerialPortsCount();
                Debug.Print("Total Serial Port : " + SerialNo);

                System.IO.Ports.BaudRate[] StandardBR;
                hwProvider.GetSupportBaudRates(0, out StandardBR, out size);
                Debug.Print("#Standard Baudrate size" + size);
                for (int i = 0; i < size; i++)
                {
                    Debug.Print("Baudrate " + StandardBR[i]);
                }
                Debug.Print("------------------------------");



                bool SupportNonStandardBR = hwProvider.SupportsNonStandardBaudRate(0);
                Debug.Print("Support NonStandard Baudrate " + SupportNonStandardBR);

                uint br = 115200;
                Debug.Print(" support " + br);

                bool result;
                result = hwProvider.IsSupportedBaudRate(0, ref br);
                Debug.Print(" result " + result + "(" + br + ")");

                uint maxbr, minbr;
                hwProvider.GetBaudRateBoundary(0, out maxbr, out minbr);
                Debug.Print("Com 0 max br" + maxbr + " minBr: " + minbr);

                br     = maxbr + 1000;
                result = hwProvider.IsSupportedBaudRate(0, ref br);
                Debug.Print(" over max+100 result " + result + "(" + br + ")");

                // SPI
                Cpu.Pin msk;
                Cpu.Pin miso;
                Cpu.Pin mosi;

                hwProvider.GetSpiPins(SPI.SPI_module.SPI1, out msk, out miso, out mosi);
                Debug.Print("SPI Port : ");
                Debug.Print("msk- " + msk);
                Debug.Print("miso- " + miso);
                Debug.Print("mosi- " + mosi);


                int SpiNo = hwProvider.GetSpiPortsCount();
                Debug.Print("Total Spi Port : " + SpiNo);

                // I2C
                Cpu.Pin scl;
                Cpu.Pin sda;

                hwProvider.GetI2CPins(out scl, out sda);
                Debug.Print("I2C Port : ");
                Debug.Print("scl- " + scl);
                Debug.Print("sda- " + sda);


                // LCD
                int width, height, orientation, bpp;
                hwProvider.GetLCDMetrics(out width, out height, out bpp, out orientation);
                Debug.Print("width : " + height);
                Debug.Print("Length : " + height);
                Debug.Print("Bit Per Pixel : " + bpp);
                Debug.Print("orientatoin " + orientation);


                //get button -
                Debug.Print("Button Menu pin no " + hwProvider.GetButtonPins(Button.VK_MENU));
                Debug.Print("Button Select pin no " + hwProvider.GetButtonPins(Button.VK_SELECT));
                Debug.Print("Button Back pin no " + hwProvider.GetButtonPins(Button.VK_BACK));
                Debug.Print("Button Up pin no " + hwProvider.GetButtonPins(Button.VK_UP));
                Debug.Print("Button down pin no " + hwProvider.GetButtonPins(Button.VK_DOWN));
                Debug.Print("Button Left pin no " + hwProvider.GetButtonPins(Button.VK_LEFT));

                Debug.Print("Button right pin no " + hwProvider.GetButtonPins(Button.VK_RIGHT));
                Debug.Print("Button home pin no " + hwProvider.GetButtonPins(Button.VK_HOME));
                Debug.Print("Button appdef pin no " + hwProvider.GetButtonPins(Button.AppDefined1));
                Debug.Print("Button VK convert pin no " + hwProvider.GetButtonPins(Button.VK_CONVERT));



                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Execution entry point.
        /// </summary>
        public static void Main()
        {
            // Gain access to all USB controllers.
            UsbController[] controllers = UsbController.GetControllers();

            HardwareProvider hwProvider = new HardwareProvider();

            // Set up all buttons to be monitored.
            buttons.Up = new InputPort(hwProvider.GetButtonPins(Button.VK_UP),
                                       true, Port.ResistorMode.Disabled);
            buttons.Down = new InputPort(hwProvider.GetButtonPins(Button.VK_DOWN),
                                         true, Port.ResistorMode.Disabled);
            buttons.Left = new InputPort(hwProvider.GetButtonPins(Button.VK_LEFT),
                                         true, Port.ResistorMode.Disabled);
            buttons.Right = new InputPort(hwProvider.GetButtonPins(Button.VK_RIGHT),
                                          true, Port.ResistorMode.Disabled);
            buttons.LeftMouseButton = new InputPort(hwProvider.GetButtonPins(Button.VK_BACK),
                                                    true, Port.ResistorMode.Disabled);
            buttons.RightMouseButton = new InputPort(hwProvider.GetButtonPins(Button.VK_HOME),
                                                     true, Port.ResistorMode.Disabled);
            buttons.Toggle = new InputPort(hwProvider.GetButtonPins(Button.VK_SELECT),
                                           true, Port.ResistorMode.Disabled);
            buttons.Done = new InputPort(hwProvider.GetButtonPins(Button.VK_MENU),
                                         true, Port.ResistorMode.Disabled);

            // Use the first available USB controller, if it exists.
            if (controllers.Length < 1)
            {
                Debug.Print("No USB controllers exist for this device - we're done.");
                return;
            }
            UsbController UsbPort     = controllers[0];
            UsbStream     mouseStream = null;

            if (UsbPort.Status == UsbController.PortState.Running)
            {
                Debug.Print(
                    "USB controller 0 is up and running - are you debugging with USB?");

                Debug.Print(
                    "Make sure your platform supports overriding the debug transport.");

                Thread.Sleep(500);
            }

            try
            {
                ConfigureUsbPort(UsbPort, true);

                mouseStream = UsbPort.CreateUsbStream(3, UsbStream.NullEndpoint);
            }
            catch (Exception e)
            {
                Debug.Print(
                    "Mouse stream could not be created due to exception " +
                    e.Message);
                Debug.Print(
                    "Perhaps your native configuration does not contain endpoint 3?");
                return;
            }

            // Be a mouse until the Done button is pressed.
            MouseLoop(UsbPort, mouseStream);

            mouseStream.Close();
        }