public WacomTouchReport(byte[] report, ref TouchPoint[] prevTouches) { Raw = report; AuxButtons = Array.Empty <bool>(); Touches = prevTouches ?? new TouchPoint[MAX_POINTS]; if (report[2] == 0x81) { ApplyTouchMask((ushort)(Raw[3] | (Raw[4] << 8))); prevTouches = (TouchPoint[])Touches.Clone(); return; } var nChunks = Raw[1]; for (var i = 0; i < nChunks; i++) { var offset = (i << 3) + 2; var touchID = Raw[offset]; if (touchID == 0x80) { var auxByte = report[1 + offset]; AuxButtons = new bool[] { auxByte.IsBitSet(0), auxByte.IsBitSet(1), auxByte.IsBitSet(2), auxByte.IsBitSet(3), }; continue; } touchID -= 2; if (touchID >= MAX_POINTS) { continue; } var touchState = Raw[1 + offset]; if (touchState == 0x20) { Touches[touchID] = null; } else { Touches[touchID] = new TouchPoint { TouchID = touchID, Position = new Vector2 { X = (Raw[2 + offset] << 4) | (Raw[4 + offset] >> 4), Y = (Raw[3 + offset] << 4) | (Raw[4 + offset] & 0xF) }, }; } } prevTouches = (TouchPoint[])Touches.Clone(); }
public WacomTouchReport(byte[] report) { Raw = report; AuxButtons = new bool[0]; Touches = prevTouches ?? new TouchPoint[MAX_POINTS]; if (report[2] == 0x81) { ApplyTouchMask((ushort)(Raw[3] | (Raw[4] << 8))); prevTouches = (TouchPoint[])Touches.Clone(); return; } var nChunks = Raw[1]; for (var i = 0; i < nChunks; i++) { var offset = (i << 3) + 2; var touchID = Raw[offset]; if (touchID == 0x80) { AuxButtons = new bool[] { (report[1 + offset] & (1 << 0)) != 0, (report[1 + offset] & (1 << 1)) != 0, (report[1 + offset] & (1 << 2)) != 0, (report[1 + offset] & (1 << 3)) != 0 }; continue; } touchID -= 2; if (touchID >= MAX_POINTS) { continue; } var touchState = Raw[1 + offset]; if (touchState == 0x20) { Touches[touchID] = null; } else { Touches[touchID] = new TouchPoint { TouchID = touchID, Position = new Vector2 { X = (Raw[2 + offset] << 4) | (Raw[4 + offset] >> 4), Y = (Raw[3 + offset] << 4) | (Raw[4 + offset] & 0xF) }, }; } } prevTouches = (TouchPoint[])Touches.Clone(); }
public IntuosV2TouchReport(byte[] report) { Raw = report; Touches = prevTouches ?? new TouchPoint[MAX_POINTS]; for (var i = 0; i < 5; i++) { var offset = (i << 3) + 2; var touchID = Raw[offset]; if (touchID == 0) { continue; } touchID -= 1; if (touchID >= MAX_POINTS) { continue; } var touchState = Raw[1 + offset]; if (touchState == 0) { Touches[touchID] = null; } else { Touches[touchID] = new TouchPoint { TouchID = touchID, Position = new Vector2 { X = Unsafe.ReadUnaligned <ushort>(ref report[2 + offset]), Y = Unsafe.ReadUnaligned <ushort>(ref report[4 + offset]), }, }; } } prevTouches = (TouchPoint[])Touches.Clone(); }
public IntuosV3TouchReport(byte[] report) { Raw = report; Touches = prevTouches ?? new TouchPoint[MAX_POINTS]; for (var i = 0; i < 5; i++) { var offset = (i << 3) + 2; var touchID = Raw[offset]; if (touchID == 0) { continue; } touchID -= 1; if (touchID >= MAX_POINTS) { continue; } var touchState = Raw[1 + offset]; if (touchState == 0) { Touches[touchID] = null; } else { Touches[touchID] = new TouchPoint { TouchID = touchID, Position = new Vector2 { X = BitConverter.ToUInt16(Raw, 2 + offset), Y = BitConverter.ToUInt16(Raw, 4 + offset), }, }; } } prevTouches = (TouchPoint[])Touches.Clone(); }