public void DpnupUpdateDeviceState() { if (_device == IntPtr.Zero) { return; } if (Time.frameCount == FrameNum) { return; } else { FrameNum = Time.frameCount; } prevperipheralstatus.CopyFrom(peripheralstatus); peripheralstatus.cacheLock.EnterWriteLock(); try { IntPtr temp = Marshal.AllocHGlobal(sizeof(int)); DpnupReadDeviceAttribute(DPNP_VALUE_TYPE.DPNP_VALUE_TYPE_ATTRIBUTE_DEVICE_STATUS - DPNP_VALUE_TYPE.DPNP_VALUE_TYPE_ATTRIBUTE , temp, sizeof(int)); peripheralstatus.device_status = Marshal.ReadInt32(temp); Marshal.FreeHGlobal(temp); if (peripheralInfo.pose_count > 0) { for (int i = 0; i < peripheralInfo.pose_count; i++) { float[] pose = peripheralstatus.pose_state[i]; DpnupReadDevicePose(i, pose); } } if (peripheralInfo.position_count > 0) { for (int i = 0; i < peripheralInfo.position_count; i++) { float[] position = peripheralstatus.position_state[i]; DpnupReadDevicePosition(i, position); } } if (peripheralInfo.time_count > 0) { for (int i = 0; i < peripheralInfo.time_count; i++) { double[] time = peripheralstatus.time_state[i]; time[0] = DpnupReadDeviceTime(i); } } if (peripheralInfo.quaternion_count > 0) { for (int i = 0; i < peripheralInfo.quaternion_count; i++) { float[] quaternion = peripheralstatus.quaternion_state[i]; DpnupReadDeviceQuaternion(i, quaternion); } } if (peripheralInfo.vector_count > 0) { for (int i = 0; i < peripheralInfo.vector_count; i++) { float[] vector = peripheralstatus.vector_state[i]; DpnupReadDeviceVector(i, vector); } } if (peripheralInfo.axis_count > 0) { for (int i = 0; i < peripheralInfo.axis_count; i++) { float[] axis = peripheralstatus.axis_state[i]; axis[0] = DpnupReadDeviceAxis(i); } } if (peripheralInfo.button_count > 0) { for (int i = 0; i < peripheralInfo.button_count; i++) { int[] button = peripheralstatus.button_state[i]; button[0] = DpnupReadDeviceButton(i); } } } finally { peripheralstatus.cacheLock.ExitWriteLock(); } }
public void DpnupGetDeviceInfo() { if (_device == IntPtr.Zero) { return; } peripheralInfo = new PeripheralInfo(); peripheralInfo.pose_count = DpnupGetDevicePoseCount(); peripheralInfo.position_count = DpnupGetDevicePositionCount(); peripheralInfo.time_count = DpnupGetDeviceTimeCount(); peripheralInfo.quaternion_count = DpnupGetDeviceQuaternionCount(); peripheralInfo.vector_count = DpnupGetDeviceVectorCount(); peripheralInfo.axis_count = DpnupGetDeviceAxisCount(); peripheralInfo.button_count = DpnupGetDeviceButtonCount(); peripheralstatus = new Peripheralstatus(); peripheralstatus.device_status = 0; if (peripheralInfo.pose_count != 0) { peripheralstatus.pose_state = new float[peripheralInfo.pose_count][]; for (int i = 0; i < peripheralInfo.pose_count; i++) { peripheralstatus.pose_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSE]; } } else { peripheralstatus.pose_state = null; } if (peripheralInfo.position_count != 0) { peripheralstatus.position_state = new float[peripheralInfo.position_count][]; for (int i = 0; i < peripheralInfo.position_count; i++) { peripheralstatus.position_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_POSITION]; } } else { peripheralstatus.position_state = null; } if (peripheralInfo.time_count != 0) { peripheralstatus.time_state = new double[peripheralInfo.time_count][]; for (int i = 0; i < peripheralInfo.time_count; i++) { peripheralstatus.time_state[i] = new double[DpnpUnity.DPNP_VALUE_TYPE_SIZE_TIME]; } } else { peripheralstatus.time_state = null; } if (peripheralInfo.quaternion_count != 0) { peripheralstatus.quaternion_state = new float[peripheralInfo.quaternion_count][]; for (int i = 0; i < peripheralInfo.quaternion_count; i++) { peripheralstatus.quaternion_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_QUATERNION]; } } else { peripheralstatus.quaternion_state = null; } if (peripheralInfo.vector_count != 0) { peripheralstatus.vector_state = new float[peripheralInfo.vector_count][]; for (int i = 0; i < peripheralInfo.vector_count; i++) { peripheralstatus.vector_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_VECTOR]; } } else { peripheralstatus.vector_state = null; } if (peripheralInfo.axis_count != 0) { peripheralstatus.axis_state = new float[peripheralInfo.axis_count][]; for (int i = 0; i < peripheralInfo.axis_count; i++) { peripheralstatus.axis_state[i] = new float[DpnpUnity.DPNP_VALUE_TYPE_SIZE_AXIS]; } } else { peripheralstatus.axis_state = null; } if (peripheralInfo.button_count != 0) { Debug.Log("button number " + peripheralInfo.button_count); peripheralstatus.button_state = new int[peripheralInfo.button_count][]; for (int i = 0; i < peripheralInfo.button_count; i++) { peripheralstatus.button_state[i] = new int[DpnpUnity.DPNP_VALUE_TYPE_SIZE_BUTTON]; } } else { peripheralstatus.button_state = null; } prevperipheralstatus = new Peripheralstatus(); prevperipheralstatus.CopyFrom(peripheralstatus); }