PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. //-----------------------------------------------------------------------------
  2. // Microsoft SPOT Project
  3. // Copyright (c) 2001,2002,2004,2005 Microsoft Corporation
  4. // One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
  5. // All rights reserved.
  6. // MICROSOFT CONFIDENTIAL
  7. //-----------------------------------------------------------------------------
  8. using System;
  9. using Microsoft.SPOT;
  10. using Microsoft.SPOT.Input;
  11. using Microsoft.SPOT.Hardware;
  12. using Microsoft.SPOT.Presentation;
  13. using Microsoft.SPOT.Hardware.FreescaleCSB536MS;
  14. //
  15. // This class should be defined on a per-OEM basis based on their hardware behavior.
  16. //
  17. namespace Microsoft.SPOT.Sample
  18. {
  19. public sealed class GPIOButtonInputProvider
  20. {
  21. internal class ButtonPad
  22. {
  23. public ButtonPad(GPIOButtonInputProvider sink, Button button, Cpu.Pin pin, Port.InterruptMode mode)
  24. {
  25. _sink = sink;
  26. _button = button;
  27. _port = new InterruptPort(pin, true, ResistorMode.PullUp, mode);
  28. _port.OnInterrupt += new GPIOInterruptEventHandler(this.Interrupt);
  29. }
  30. void Interrupt(Cpu.Pin port, bool state, TimeSpan time)
  31. {
  32. // queue the button press to the input provider site.
  33. _sink.Dispatcher.BeginInvoke(_sink._callback, new RawButtonInputReport(_sink._source, time, _button, state?RawButtonActions.ButtonUp:RawButtonActions.ButtonDown));
  34. }
  35. Button _button;
  36. InterruptPort _port;
  37. GPIOButtonInputProvider _sink;
  38. }
  39. public GPIOButtonInputProvider(PresentationSource source)
  40. {
  41. _source = source;
  42. _site = InputManager.CurrentInputManager.RegisterInputProvider(this);
  43. _callback = new ReportInputCallback(_site.ReportInput);
  44. Dispatcher = Dispatcher.CurrentDispatcher;
  45. ButtonPad[] buttons = new ButtonPad[]
  46. {
  47. new ButtonPad(this, Button.Menu, Pins.GPIO_PORT_A_3, InterruptMode.InterruptEdgeBoth),
  48. new ButtonPad(this, Button.Select, Pins.GPIO_PORT_A_8, InterruptMode.InterruptEdgeBoth),
  49. new ButtonPad(this, Button.Left, Pins.GPIO_PORT_A_7, InterruptMode.InterruptEdgeBoth),
  50. new ButtonPad(this, Button.Right, Pins.GPIO_PORT_A_5, InterruptMode.InterruptEdgeBoth),
  51. new ButtonPad(this, Button.Up, Pins.GPIO_PORT_A_4, InterruptMode.InterruptEdgeBoth),
  52. new ButtonPad(this, Button.Down, Pins.GPIO_PORT_A_6, InterruptMode.InterruptEdgeBoth),
  53. };
  54. _buttons = buttons;
  55. }
  56. public readonly Dispatcher Dispatcher;
  57. private ButtonPad[] _buttons;
  58. private ReportInputCallback _callback;
  59. private InputProviderSite _site;
  60. private PresentationSource _source;
  61. private delegate bool ReportInputCallback(InputReport inputReport);
  62. }
  63. }