Example #1
0
        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);
        }
Example #2
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());
        }
Example #3
0
        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());
        }
Example #4
0
        public void NonEmptyFifoDoesNotReturnIsEmpty()
        {
            var fifo = new FifoBuffer <int>(5);

            fifo.Write(99);
            Assert.IsFalse(fifo.IsEmpty());
        }
Example #5
0
        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));
        }
Example #6
0
        public void PeekNonEmptyFifoReturnsTrue()
        {
            var fifo = new FifoBuffer <int>(5);

            fifo.Write(99);
            int result;

            Assert.IsTrue(fifo.Peek(out result));
            Assert.AreEqual(99, result);
        }
Example #7
0
        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();
            }
        }
Example #8
0
        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));
        }
Example #9
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     _fifoWrite.Write(buffer, offset, count);
 }