Exemplo n.º 1
0
		public KeyPad(int pinCount, IGpioPinMapping[] mappings)
		{
			this.CharacterGridMappings = this.OnGetCharacterMappings();
			this.PinCount = pinCount;

			if (mappings.Length != pinCount)
			{
				throw new ArgumentOutOfRangeException(string.Format("The number of pins required for this keypad is {0}.", pinCount));
			}

			// ***
			// *** Add the mappings to the internal list
			// ***
			this.PinMappings.AddRange(mappings);

			// ***
			// *** Initialize the rows
			// ***
			foreach (var mapping in this.RowMappings)
			{
				mapping.InitializeRow();
			}

			// ***
			// *** Initialize the columns
			// ***
			foreach (var mapping in this.ColumnMappings)
			{
				mapping.InitializeColumn(this.DebounceTimeout);
				mapping.GpioPin.ValueChanged += Pin_ValueChanged;
			}
		}
Exemplo n.º 2
0
		private Task TestKeyPad1()
		{
			IGpioPinMapping[] mappings = new IGpioPinMapping[]
			{
				new GpioPinMappingRow(row: 1, pinNumber: 18),
				new GpioPinMappingColumn(column: 1, pinNumber: 22),
				new GpioPinMappingColumn(column: 2, pinNumber: 23),
				new GpioPinMappingColumn(column: 3, pinNumber: 24),
				new GpioPinMappingColumn(column: 4, pinNumber: 25),
			};

			IKeyPad keypad = new Membrane1x4(mappings);
			keypad.KeyEvent += Keypad_KeyEvent;
			return Task.FromResult(0);
		}
Exemplo n.º 3
0
        private Task TestKeyPad1()
        {
            IGpioPinMapping[] mappings = new IGpioPinMapping[]
            {
                new GpioPinMappingRow(row: 1, pinNumber: 18),
                new GpioPinMappingColumn(column: 1, pinNumber: 22),
                new GpioPinMappingColumn(column: 2, pinNumber: 23),
                new GpioPinMappingColumn(column: 3, pinNumber: 24),
                new GpioPinMappingColumn(column: 4, pinNumber: 25),
            };

            IKeyPad keypad = new Membrane1x4(mappings);

            keypad.KeyEvent += Keypad_KeyEvent;
            return(Task.FromResult(0));
        }
Exemplo n.º 4
0
        private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            lock (_lock)
            {
                if (!_evaluatingRows)
                {
                    IGpioPinMapping mapping = this.PinMappings.Where(t => t.PinNumber == sender.PinNumber).SingleOrDefault();

                    if (mapping != null)
                    {
                        PinChangedStatus status = mapping.GetChangedStatus(args.Edge);
                        if (status != PinChangedStatus.None)
                        {
                            this.OnPinValueChanged(mapping, status);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private Task InitializeKeyPad(bool enableKeyupEvent)
        {
            IGpioPinMapping[] mappings = new IGpioPinMapping[]
            {
                new GpioPinMappingColumn(column: 3, pinNumber: 13),
                new GpioPinMappingColumn(column: 2, pinNumber: 16),
                new GpioPinMappingColumn(column: 1, pinNumber: 18),
                new GpioPinMappingRow(row: 4, pinNumber: 22),
                new GpioPinMappingRow(row: 3, pinNumber: 23),
                new GpioPinMappingRow(row: 2, pinNumber: 24),
                new GpioPinMappingRow(row: 1, pinNumber: 25),
            };

            // ***
            // *** Use the physical 3x4 keypad/comment
            // *** to use the emulator.
            // ***
            //_keypad = new Membrane3x4(mappings)
            //{
            //	EnableButtonUpEvent = enableKeyupEvent
            //};

            // ***
            // *** Uncomment to use the emulator/comment
            // *** to use the physical keypad.
            // ***
            _keypad = new Membrane3x4Emulator()
            {
                EnableButtonUpEvent = enableKeyupEvent
            };

            // ***
            // *** Return a task...
            // ***
            return(Task.FromResult(0));
        }
Exemplo n.º 6
0
        protected virtual void OnPinValueChanged(IGpioPinMapping mapping, PinChangedStatus status)
        {
            try
            {
                // ***
                // *** Need to ignore other keypad changes until this is complete
                // ***
                _evaluatingRows = true;

                if (status == PinChangedStatus.WentHigh)
                {
                    // ***
                    // *** Once the column and row is known we can determine the key
                    // ***
                    ICharacterGridMapping characterGridMapping = null;

                    // ***
                    // *** Need to change each row to LOW until the pin we have changes again. This helps determine which
                    // *** row is selected.
                    // ***
                    foreach (var rowMapping in this.RowMappings)
                    {
                        try
                        {
                            rowMapping.GpioPin.Write(GpioPinValue.Low);
                            GpioPinValue newValue = mapping.GpioPin.Read();

                            if (newValue == GpioPinValue.Low)
                            {
                                // ***
                                // *** Select the character mapping
                                // ***
                                characterGridMapping = this.CharacterGridMappings.Where(t => t.Row == rowMapping.MatrixValue && t.Column == mapping.MatrixValue).SingleOrDefault();

                                if (characterGridMapping != null)
                                {
                                    if (this.EnableButtonUpEvent)
                                    {
                                        _lastCharacterDown = characterGridMapping;
                                    }
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            // ***
                            // *** Need the pin to be on high in it's default state
                            // ***
                            rowMapping.GpioPin.Write(GpioPinValue.High);
                        }
                    }

                    if (characterGridMapping != null)
                    {
                        this.OnKeyEvent(new KeyPadEventArgs(characterGridMapping.Value, KeyDownEventType.ButtonDown));
                    }
                }
                else
                {
                    if (_lastCharacterDown != null)
                    {
                        char key = _lastCharacterDown.Value;
                        _lastCharacterDown = null;
                        this.OnKeyEvent(new KeyPadEventArgs(key, KeyDownEventType.ButtonUp));
                    }
                }
            }
            finally
            {
                _evaluatingRows = false;
            }
        }
Exemplo n.º 7
0
		protected virtual void OnPinValueChanged(IGpioPinMapping mapping, PinChangedStatus status)
		{
			try
			{
				// ***
				// *** Need to ignore other keypad changes until this is complete
				// ***
				_evaluatingRows = true;

				if (status == PinChangedStatus.WentHigh)
				{
					// ***
					// *** Once the column and row is known we can determine the key
					// ***
					ICharacterGridMapping characterGridMapping = null;

					// ***
					// *** Need to change each row to LOW until the pin we have changes again. This helps determine which
					// *** row is selected.
					// ***
					foreach (var rowMapping in this.RowMappings)
					{
						try
						{
							rowMapping.GpioPin.Write(GpioPinValue.Low);
							GpioPinValue newValue = mapping.GpioPin.Read();

							if (newValue == GpioPinValue.Low)
							{
								// ***
								// *** Select the character mapping
								// ***
								characterGridMapping = this.CharacterGridMappings.Where(t => t.Row == rowMapping.MatrixValue && t.Column == mapping.MatrixValue).SingleOrDefault();

								if (characterGridMapping != null)
								{
									if (this.EnableButtonUpEvent) { _lastCharacterDown = characterGridMapping; }
									break;
								}
							}
						}
						finally
						{
							// ***
							// *** Need the pin to be on high in it's default state
							// ***
							rowMapping.GpioPin.Write(GpioPinValue.High);
						}
					}

					if (characterGridMapping != null)
					{
						this.OnKeyEvent(new KeyPadEventArgs(characterGridMapping.Value, KeyDownEventType.ButtonDown));
					}
				}
				else
				{
					if (_lastCharacterDown != null)
					{
						char key = _lastCharacterDown.Value;
						_lastCharacterDown = null;
						this.OnKeyEvent(new KeyPadEventArgs(key, KeyDownEventType.ButtonUp));
					}
				}
			}
			finally
			{
				_evaluatingRows = false;
			}
		}