public async Task OnKeyUp(KeyPress keyPress) { lock (this) { var key = keyPress.Key; if (keyPress.Id == _lastKeyPressId) { Debug.WriteLine("Ignoring duplicate keypress"); return; } _lastKeyPressId = keyPress.Id; Debug.WriteLine("OnKeyUp"); byte keyCode = 0x00; if (key.Length == 1) { keyCode = (byte)key[0]; } _eventBuffer.Write( new KeyboardEvent( (byte)(StatusBits.AsciiAvailable | StatusBits.KeyUp | StatusBits.ScanCodeAvailable), keyCode, keyCode)); KeyUp?.Invoke(this, keyCode); RequestInterrupt?.Invoke(this, null); } await Task.Delay(0); }
public void NonFullFifoDoesntReturnIsFull() { var fifo = new FifoBuffer <int>(5); Assert.IsTrue(fifo.Write(1)); Assert.IsTrue(fifo.Write(2)); Assert.IsTrue(fifo.Write(3)); Assert.IsTrue(fifo.Write(4)); Assert.IsFalse(fifo.IsFull()); }
public void FullFifoReturnIsFull() { var fifo = new FifoBuffer <int>(5); Assert.IsTrue(fifo.Write(1)); Assert.IsTrue(fifo.Write(2)); Assert.IsTrue(fifo.Write(3)); Assert.IsTrue(fifo.Write(4)); Assert.IsTrue(fifo.Write(5)); Assert.IsTrue(fifo.IsFull()); }
public void NonEmptyFifoDoesNotReturnIsEmpty() { var fifo = new FifoBuffer <int>(5); fifo.Write(99); Assert.IsFalse(fifo.IsEmpty()); }
public void ReadOneValueEmptiesFifo() { var fifo = new FifoBuffer <int>(5); fifo.Write(99); int result; Assert.IsTrue(fifo.Read(out result)); Assert.IsFalse(fifo.Read(out result)); }
public void PeekNonEmptyFifoReturnsTrue() { var fifo = new FifoBuffer <int>(5); fifo.Write(99); int result; Assert.IsTrue(fifo.Peek(out result)); Assert.AreEqual(99, result); }
private void OnReadComplete(IAsyncResult ar) { if (!_isInitialized || _stream == null) { OnRead(); return; } try { int bytesRead = _stream.EndRead(ar); int totalBytesRead = 0; if (bytesRead == 0) { _isReadFailure = true; OnRead(); return; } while (bytesRead > 0) { totalBytesRead += bytesRead; _fifoToDevice.Write(_buffer, 0, bytesRead); bytesRead = Math.Min(this.AvailableBytes, _buffer.Length); if (bytesRead > 0) { bytesRead = _stream.Read(_buffer, 0, bytesRead); } } if (totalBytesRead > 0) { OnRead(); } _asyncResult = null; StartRead(); } catch { _isReadFailure = true; OnRead(); } }
public void CantOverflowFifo() { var fifo = new FifoBuffer <int>(5); Assert.IsTrue(fifo.Write(1)); Assert.IsTrue(fifo.Write(2)); Assert.IsTrue(fifo.Write(3)); Assert.IsTrue(fifo.Write(4)); Assert.IsTrue(fifo.Write(5)); Assert.IsFalse(fifo.Write(6)); }
public override void Write(byte[] buffer, int offset, int count) { _fifoWrite.Write(buffer, offset, count); }