Example #1
0
        public List <ObjectBlock> GetBlocks(uint maxBlocks)
        {
            uint checksum, w;
            List <ObjectBlock> objectBlocks = new List <ObjectBlock>();

            if (!skipStart)
            {
                if (GetStart() == 0)
                {
                    return(null);
                }
            }
            else
            {
                skipStart = false;
            }

            for (int i = 0; i < maxBlocks;)
            {
                // After the sync sequence, the rest of the block is read in this order
                checksum = getWord();

                if (checksum == PIXY_START_WORD || checksum == PIXY_START_WORD_CC)
                {
                    skipStart = true;
                    return(objectBlocks);
                }
                else if (checksum == 0)
                {
                    return(objectBlocks);
                }

                ObjectBlock block = getBlock();

                // The checksum should be the sum of all the other values
                uint calculatedSum = block.Signature + block.X + block.Y + block.Width + block.Height;

                // Make sure that the checksum that came with the block and our sum match
                if (calculatedSum == checksum)
                {
                    var args = new PixyCamEventArgs();
                    args.Block = block;
                    objectBlocks.Add(block);
                    lastBlockTime = Global.Stopwatch.ElapsedMilliseconds;
                    i++;
                }

                w = getWord();
                if (w == PIXY_START_WORD || w == PIXY_START_WORD_CC)
                {
                }
                else
                {
                    return(objectBlocks);
                }
            }

            return(objectBlocks);
        }
Example #2
0
        private ObjectBlock getBlock()
        {
            byte[] readData = getBytes(10);
            if (readData != null)
            {
                ObjectBlock block = new ObjectBlock();
                block.Signature = BitConverter.ToUInt16(readData, 0);
                block.X         = BitConverter.ToUInt16(readData, 2);
                block.Y         = BitConverter.ToUInt16(readData, 4);
                block.Width     = BitConverter.ToUInt16(readData, 6);
                block.Height    = BitConverter.ToUInt16(readData, 8);

                return(block);
            }

            return(null);
        }
Example #3
0
        private ObjectBlock getBlock()
        {
            byte[] readData = getBytes(10);
            if (readData != null)
            {
                ObjectBlock block = new ObjectBlock();
                block.Signature = BitConverter.ToUInt16(readData, 0);
                block.X = BitConverter.ToUInt16(readData, 2);
                block.Y = BitConverter.ToUInt16(readData, 4);
                block.Width = BitConverter.ToUInt16(readData, 6);
                block.Height = BitConverter.ToUInt16(readData, 8);

                return block;
            }

            return null;
        }
Example #4
0
        private Point getPuckPosition(ObjectBlock block)
        {
            if (block != null)
            {
                if (block.Signature == 1 && block.Width >= 5 && block.Height >= 5)
                {
                    return CoordinateHelper.TranslatePoint(block.X, block.Y);
                }
            }

            return CoordinateHelper.INVALID_POINT;
        }