//////////////////////////////////////////////////////////////////////////// /// <summary> /// Removes device of the specified ID. /// </summary> /// <param name="deviceID_I">Touch device identifier</param> public void RemoveDevice(Int32 deviceID_I) { IntPtr devBuf = IntPtr.Zero; try { if (mDeviceCapsMap.ContainsKey(deviceID_I)) { mDeviceCapsMap.Remove(deviceID_I); // Make sure we're in sync with system's view of #attached devices. devBuf = CMemUtils.AllocUnmanagedBuf(mDeviceIDArray); Marshal.StructureToPtr(mDeviceIDArray, devBuf, false); mNumDevices = CWacomMTInterface.WacomMTGetAttachedDeviceIDs(devBuf, mMaxNumTouchDevices * sizeof(Int32)); if (mNumDevices > 0) { mDeviceIDArray = (WacomMTDeviceIDArray)Marshal.PtrToStructure(devBuf, typeof(WacomMTDeviceIDArray)); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { CMemUtils.FreeUnmanagedBuf(ref devBuf); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Registers an MTAPI raw data client over the entire tablet surface /// (no hitrect or HWND required). /// </summary> /// <param name="deviceID_I">touch device identifier</param> /// <param name="callback_I">callback function used by MTAPI to send touch data</param> /// <param name="userData_I">custom user data</param> public void RegisterClient(Int32 deviceID_I, ref WacomMTCallback callback_I, IntPtr userData_I) { try { InitWacomMTClientParams(deviceID_I, ref callback_I, userData_I); WacomMTError res = CWacomMTInterface.WacomMTRegisterRawReadCallback( mDeviceID, mClientMode, mTouchCallback, mUserData); if (WacomMTError.WMTErrorSuccess != res) { String errMsg = "Oops - failed WacomMTRegisterRawReadCallback with error: " + res.ToString(); throw new Exception(errMsg); } #if TRACE_CLIENT DumpClient("RegisterClient"); #endif //TRACE_CLIENT } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to unregister an MTAPI blob client by a hitrect. /// </summary> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoUnregisterHitRectCallback() { return(CWacomMTInterface.WacomMTUnRegisterBlobReadCallback( mDeviceID, ref mHitRect, mClientMode, mUserData)); }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to move an MTAPI blob callback by hitrect. /// </summary> /// <param name="newHitRect_I">rectangle tracked by MTAPI for touch contacts</param> /// <param name="userData_I">custom user data</param> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoMoveHitRectCallback( WacomMTHitRect newHitRect_I, IntPtr userData_I) { WacomMTHitRect oldHitRect = mHitRect; return(CWacomMTInterface.WacomMTMoveRegisteredBlobReadCallback( mDeviceID, ref oldHitRect, mClientMode, ref newHitRect_I, userData_I )); }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Disconnect from MTAPI. /// </summary> public void Quit() { try { CWacomMTInterface.WacomMTQuit(); mNumDevices = 0; // The GC should remove mDeviceIDArray.data. mDeviceIDArray.data = null; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Find capabilities for all attached touch devices. /// If successful, this will populate mDeviceCapsMap. /// </summary> /// <returns> true if all device capabilities updated</returns> private bool UpdateDeviceCaps() { IntPtr devBuf = IntPtr.Zero; try { if (mNumDevices > 0) { for (int idx = 0; idx < mNumDevices; idx++) { Int32 devID = mDeviceIDArray.data[idx]; WacomMTCapability devCaps = new WacomMTCapability(); devBuf = CMemUtils.AllocUnmanagedBuf(devCaps); Marshal.StructureToPtr(devCaps, devBuf, false); if (WacomMTError.WMTErrorSuccess == CWacomMTInterface.WacomMTGetDeviceCapabilities(devID, devBuf)) { devCaps = (WacomMTCapability)Marshal.PtrToStructure(devBuf, typeof(WacomMTCapability)); mDeviceCapsMap[devID] = devCaps; DumpDeviceCaps(devID); CMemUtils.FreeUnmanagedBuf(ref devBuf);; } else { throw new Exception("Oops - failed WacomMTGetDeviceCapabilities"); } } return(true); } } catch (Exception ex) { throw ex; } finally { if (devBuf != IntPtr.Zero) { CMemUtils.FreeUnmanagedBuf(ref devBuf); } } return(false); }
private void Form1_Load(object sender, EventArgs e) { WacomMTError status = WacomMTError.WMTErrorSuccess; IntPtr userDataBuf = IntPtr.Zero; try { mWacomMTConfig.Init(); //Delegate called when events come to tablet mUpdateRealTimeLabel = new UpdateDelegate(this.DoUpdateGraphicsControl); mUpdateRealTimeLabel += this.DoSendMidiMessage; // crée un nouveau callback attach et abonne a ce callback mAttachCallback = new WacomMTAttachCallback(this.DoAttachWindowClientCallback); status = CWacomMTInterface.WacomMTRegisterAttachCallback(this.mAttachCallback, IntPtr.Zero); if (status != WacomMTError.WMTErrorSuccess) { throw new Exception("Failed to register for device attaches - err: " + status.ToString()); } // crée un nouveau callback detack et abonne a ce callback mDetachCallback = new WacomMTDetachCallback(this.DoDetachWindowClientCallback); status = CWacomMTInterface.WacomMTRegisterDetachCallback(this.mDetachCallback, IntPtr.Zero); if (status != WacomMTError.WMTErrorSuccess) { throw new Exception("Failed to register for device detaches - err: " + status.ToString()); } //crée un nouveau callback de type Finger Read et abonne a celui-ci WacomMTHitRect HR = new WacomMTHitRect(0, 0, 0, 0); mTouchDataCallback = new WacomMTCallback(this.DoFingerDataUpdateCallback); status = CWacomMTInterface.WacomMTRegisterFingerReadCallback(0, ref HR, _processingMode, mTouchDataCallback, IntPtr.Zero); UpdateLabelText(); } catch (Exception ex) { MessageBox.Show("Error : " + ex.ToString()); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Adds touch device with the specified device capability to the current /// list of attached devices. /// </summary> /// <param name="deviceCapability_I"></param> public void AddDevice(WacomMTCapability deviceCapability_I) { IntPtr devBuf = IntPtr.Zero; try { Int32 deviceID = deviceCapability_I.DeviceID; // Only add device if not already added. if (!mDeviceCapsMap.ContainsKey(deviceID)) { mDeviceCapsMap[deviceID] = deviceCapability_I; // Make sure we're in sync with system's view of #attached devices. devBuf = CMemUtils.AllocUnmanagedBuf(mDeviceIDArray); Marshal.StructureToPtr(mDeviceIDArray, devBuf, false); if (mNumDevices > WacomMTConstants.MAX_NUMBER_TOUCH_DEVICES) { throw new Exception("Too many touch devices attached"); } mNumDevices = CWacomMTInterface.WacomMTGetAttachedDeviceIDs(devBuf, mMaxNumTouchDevices * sizeof(Int32)); if (mNumDevices > 0) { mDeviceIDArray = (WacomMTDeviceIDArray)Marshal.PtrToStructure(devBuf, typeof(WacomMTDeviceIDArray)); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { CMemUtils.FreeUnmanagedBuf(ref devBuf); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Unregisters an MTAPI raw data client /// </summary> public void UnregisterClient() { try { ThrowIfInvalidDeviceID(mDeviceID); WacomMTError res = CWacomMTInterface.WacomMTUnRegisterRawReadCallback( mDeviceID, mClientMode, mUserData); if (res != WacomMTError.WMTErrorSuccess) { throw new Exception("Failed UnregisterClient"); } ClearWacomMTClientParams(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to unregister and MTAPI blob client by its HWND. /// </summary> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoUnregisterHwndCallback() { return(CWacomMTInterface.WacomMTUnRegisterBlobReadHWND(mHwnd)); }
// ------------------------------------------------------------------------- // Hwnd methods // ----------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to register an MTAPI blob client by its HWND. /// </summary> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoRegisterHwndCallback() { return(CWacomMTInterface.WacomMTRegisterBlobReadHWND( mDeviceID, mClientMode, mHwnd, mBufferDepth)); }
// ------------------------------------------------------------------------- // HitRect methods // ------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to register an MTAPI finger client by a hitrect. /// </summary> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoRegisterHitRectCallback() { return(CWacomMTInterface.WacomMTRegisterFingerReadCallback( mDeviceID, ref mHitRect, mClientMode, mTouchCallback, mUserData)); }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Initialize MTAPI, find/cache connected devices /// and their capabilities. /// </summary> public void Init() { IntPtr devBuf = IntPtr.Zero; try { WacomMTError res = WacomMTError.WMTErrorSuccess; // ---------------------------------------------------------------- // Initialize the MTAPI. // res = CWacomMTInterface.WacomMTInitialize(WacomMTConstants.WACOM_MULTI_TOUCH_API_VERSION); if (WacomMTError.WMTErrorSuccess != res) { throw new Exception("Oops - failed WacomMTInitialize - is the tablet touch driver running?"); } Trace.WriteLine("WacomMTDN: WacomMTInitialize successful."); // ---------------------------------------------------------------- // Find all attached touch devices. // If successful, this will populate mDeviceIDArray.data. // devBuf = CMemUtils.AllocUnmanagedBuf(mDeviceIDArray); Marshal.StructureToPtr(mDeviceIDArray, devBuf, false); if (mNumDevices > WacomMTConstants.MAX_NUMBER_TOUCH_DEVICES) { throw new Exception("Too many touch devices attached"); } mNumDevices = CWacomMTInterface.WacomMTGetAttachedDeviceIDs(devBuf, mMaxNumTouchDevices * sizeof(Int32)); if (mNumDevices > 0) { mDeviceIDArray = (WacomMTDeviceIDArray)Marshal.PtrToStructure(devBuf, typeof(WacomMTDeviceIDArray)); DumpDeviceIDArray(); } else { Trace.WriteLine("WacomMTDN: NO TOUCH DEVICES FOUND!"); } CMemUtils.FreeUnmanagedBuf(ref devBuf); // ---------------------------------------------------------------- // Find capabilities for all attached touch devices. // If successful, this will populate mDeviceCapsMap. // if ((mNumDevices > 0) && !UpdateDeviceCaps()) { throw new Exception("Oops - could not complete query for capabilities"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { if (devBuf != IntPtr.Zero) { CMemUtils.FreeUnmanagedBuf(ref devBuf); } } }