private HidContactInfo CreateContact(HidContactState state, int id, int x, int y, int width, int height)
        {
            long timestamp = Stopwatch.GetTimestamp();

            ContactData data = new ContactData();

            data.Id        = id;
            data.Position  = new Point(x, y);
            data.MajorAxis = width;
            data.MinorAxis = height;
            data.Area      = width * height;
            Contact        contact        = new Contact(data, IntPtr.Zero, timestamp);
            HidContactInfo hidContactInfo = new HidContactInfo(state, contact);

            return(hidContactInfo);
        }
示例#2
0
		void contactHandler_Frame(object sender, FrameEventArgs e)
		{
			foreach (Contact contact in e.Contacts)
			{
				HidContactInfo contactInfo;
				switch (contact.State)
				{
					case ContactState.New:
						contactInfo = new HidContactInfo(HidContactState.Adding, contact);
						break;
					case ContactState.Moved:
						contactInfo = new HidContactInfo(HidContactState.Updated, contact);
						break;
					case ContactState.Removed:
						contactInfo = new HidContactInfo(HidContactState.Removing, contact);
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
				communicator.Enqueue(contactInfo);
			}
		}
        public void TwoContactsToBytes()
        {
            MultiTouchReport report = new MultiTouchReport(2, true);

            Point point = HidContactInfo.GetPoint(new Point(2, 3));

            report.Contacts.Add(CreateContact(HidContactState.Updated, 1, 2, 3, 4, 5));
            report.Contacts.Add(CreateContact(HidContactState.Updated, 2, 2, 3, 4, 5));
            const int expectedPresure = 4 * 5;

            report.ToBytes();

            byte[]       data   = report.Data;
            BinaryReader reader = new BinaryReader(new MemoryStream(data));

            Assert.AreEqual(3, reader.ReadByte());                           //tip, inrange
            Assert.AreEqual(0, reader.ReadByte());                           //
            Assert.AreEqual(Convert.ToUInt16(point.X), reader.ReadUInt16()); // x
            Assert.AreEqual(Convert.ToUInt16(point.Y), reader.ReadUInt16()); // y
            Assert.AreEqual(expectedPresure, reader.ReadUInt16());           // pressure
            Assert.AreEqual(4, reader.ReadUInt16());                         // width
            Assert.AreEqual(5, reader.ReadUInt16());                         // height
            Assert.AreEqual(1, reader.ReadUInt16());                         // id

            Assert.AreEqual(3, reader.ReadByte());                           //tip, inrange
            Assert.AreEqual(0, reader.ReadByte());                           //
            Assert.AreEqual(Convert.ToUInt16(point.X), reader.ReadUInt16()); // x
            Assert.AreEqual(Convert.ToUInt16(point.Y), reader.ReadUInt16()); // y
            Assert.AreEqual(expectedPresure, reader.ReadUInt16());           // pressure
            Assert.AreEqual(4, reader.ReadUInt16());                         // width
            Assert.AreEqual(5, reader.ReadUInt16());                         // height
            Assert.AreEqual(2, reader.ReadUInt16());                         // id


            Assert.AreEqual(2, reader.ReadByte());
        }
示例#4
0
        /// <summary>
        /// Append a contact to the list of contacts in this report.  Note you cannot call this more than 'MaxContactsPerReport' per report.
        /// </summary>
        /// <param name="pContact">The contact to add.</param>
        public void addContact(HidContactInfo pContact)
        {
            // If we have reached the maximum number of contacts - throw an error.
            if (lContacts.Count == MaxContactsPerReport)
                throw new InvalidOperationException("Cannot add more than " + MaxContactsPerReport + " to a MultiTouchReport.");

            // All is well so add it.
            lContacts.Add(pContact);
        }
示例#5
0
        /// <summary>
        /// This is called to enqueue a HID contact onto the list to send out.
        /// </summary>
        /// <param name="contactInfo"></param>
        private void enqueueContact(HidContactInfo pContact)
        {
            // Obtain mutual exclusion over the queue.
            this.pContactLock.WaitOne();

            // Add it to the queue.
            this.lCurrentContacts.Enqueue(pContact);

            // Release exclusion.
            this.pContactLock.ReleaseMutex();
        }
示例#6
0
		public void Enqueue(HidContactInfo contactInfo)
		{
			lock (lockCurrentContacts)
			{
				currentContacts.Enqueue(contactInfo);
			}
		}
		private HidContactInfo CreateContact(HidContactState state, int id, int x, int y, int width, int height)
		{
			long timestamp = Stopwatch.GetTimestamp();

			ContactData data = new ContactData();
			data.Id = id;
			data.Position = new Point(x, y);
			data.MajorAxis = width;
			data.MinorAxis = height;
			data.Area = width * height;
			Contact contact = new Contact(data, IntPtr.Zero, timestamp);
			HidContactInfo hidContactInfo = new HidContactInfo(state, contact);
			return hidContactInfo;
		}