private async void TimerCallback(object state) { try { int i = _rnd.Next(0, 11); ICharacterGridMapping mapping = this.CharacterGridMappings[i]; this.OnKeyEvent(new KeyPadEventArgs(mapping.Value, KeyDownEventType.ButtonDown)); if (this.EnableButtonUpEvent) { await Task.Delay(250); this.OnKeyEvent(new KeyPadEventArgs(mapping.Value, KeyDownEventType.ButtonUp)); } } finally { _timer.Change(1000, Timeout.Infinite); } }
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; } }
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; } }