/test/Platform/PortingKits/Training3.0/dot_net_micro_framework_v2_0_rtm/Product/Sample/ButtonLib/GPIOButtonInputProvider.cs
C# | 79 lines | 52 code | 16 blank | 11 comment | 0 complexity | a7991270927e831f7341a47e328fe9b6 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, MIT, MPL-2.0-no-copyleft-exception
- //-----------------------------------------------------------------------------
- // Microsoft SPOT Project
- // Copyright (c) 2001,2002,2004,2005 Microsoft Corporation
- // One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
- // All rights reserved.
- // MICROSOFT CONFIDENTIAL
- //-----------------------------------------------------------------------------
-
- using System;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Input;
- using Microsoft.SPOT.Hardware;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Hardware.FreescaleCSB536MS;
-
- //
- // This class should be defined on a per-OEM basis based on their hardware behavior.
- //
-
-
- namespace Microsoft.SPOT.Sample
- {
- public sealed class GPIOButtonInputProvider
- {
- internal class ButtonPad
- {
- public ButtonPad(GPIOButtonInputProvider sink, Button button, Cpu.Pin pin, Port.InterruptMode mode)
- {
- _sink = sink;
- _button = button;
-
- _port = new InterruptPort(pin, true, ResistorMode.PullUp, mode);
-
- _port.OnInterrupt += new GPIOInterruptEventHandler(this.Interrupt);
- }
-
- void Interrupt(Cpu.Pin port, bool state, TimeSpan time)
- {
- // queue the button press to the input provider site.
- _sink.Dispatcher.BeginInvoke(_sink._callback, new RawButtonInputReport(_sink._source, time, _button, state?RawButtonActions.ButtonUp:RawButtonActions.ButtonDown));
- }
-
- Button _button;
- InterruptPort _port;
- GPIOButtonInputProvider _sink;
- }
-
- public GPIOButtonInputProvider(PresentationSource source)
- {
- _source = source;
- _site = InputManager.CurrentInputManager.RegisterInputProvider(this);
- _callback = new ReportInputCallback(_site.ReportInput);
- Dispatcher = Dispatcher.CurrentDispatcher;
-
- ButtonPad[] buttons = new ButtonPad[]
- {
- new ButtonPad(this, Button.Menu, Pins.GPIO_PORT_A_3, InterruptMode.InterruptEdgeBoth),
- new ButtonPad(this, Button.Select, Pins.GPIO_PORT_A_8, InterruptMode.InterruptEdgeBoth),
- new ButtonPad(this, Button.Left, Pins.GPIO_PORT_A_7, InterruptMode.InterruptEdgeBoth),
- new ButtonPad(this, Button.Right, Pins.GPIO_PORT_A_5, InterruptMode.InterruptEdgeBoth),
- new ButtonPad(this, Button.Up, Pins.GPIO_PORT_A_4, InterruptMode.InterruptEdgeBoth),
- new ButtonPad(this, Button.Down, Pins.GPIO_PORT_A_6, InterruptMode.InterruptEdgeBoth),
- };
-
- _buttons = buttons;
- }
-
- public readonly Dispatcher Dispatcher;
-
- private ButtonPad[] _buttons;
- private ReportInputCallback _callback;
- private InputProviderSite _site;
- private PresentationSource _source;
-
- private delegate bool ReportInputCallback(InputReport inputReport);
- }
- }
-
-