private final void poll() throws IOException { int res = nPoll(address); if (res != DI_OK && res != DI_NOEFFECT) { if (res == DIERR_NOTACQUIRED) { acquire(); return; } throw new IOException("Failed to poll device (" + Integer.toHexString(res) + ")"); } } private final static native int nPoll(long address) throws IOException;
public final synchronized int getRelativeEventValue(int current_abs_value) { if (device.areAxesRelative()) return current_abs_value; int rel_value = current_abs_value - last_event_value; last_event_value = current_abs_value; return rel_value; }
public final synchronized void pollAll() throws IOException { checkReleased(); poll(); getDeviceState(device_state); queue.compact(); getDeviceData(queue); queue.flip(); }
public final synchronized int getDeadzoneProperty(int object_identifier) throws IOException { checkReleased(); return nGetDeadzoneProperty(address, object_identifier); } private final static native int nGetDeadzoneProperty(long address, int object_id) throws IOException;
public final synchronized long[] getRangeProperty(int object_identifier) throws IOException { checkReleased(); long[] range = new long[2]; int res = nGetRangeProperty(address, object_identifier, range); if (res != DI_OK) throw new IOException("Failed to get object range (" + res + ")"); return range; } private final static native int nGetRangeProperty(long address, int object_id, long[] range);
this.dev_subtype = dev_subtype; enumObjects(); try { enumEffects(); createRumblers(); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to create rumblers: " + e.getMessage()); setDataFormat(axis_mode); if (rumblers.size() > 0) { try { setCooperativeLevel(DISCL_BACKGROUND | DISCL_EXCLUSIVE); } catch (IOException e) { setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); setCooperativeLevel(DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); setBufferSize(AbstractController.EVENT_QUEUE_DEPTH); acquire(); this.device_state = new int[objects.size()];
public final synchronized void setBufferSize(int size) throws IOException { checkReleased(); unacquire(); int res = nSetBufferSize(address, size); if (res != DI_OK && res != DI_PROPNOEFFECT && res != DI_POLLEDDEVICE) throw new IOException("Failed to set buffer size (" + Integer.toHexString(res) + ")"); queue = new DataQueue(size, DIDeviceObjectData.class); queue.position(queue.limit()); acquire(); } private final static native int nSetBufferSize(long address, int size);
private final void getDeviceState(int[] device_state) throws IOException { int res = nGetDeviceState(address, device_state); if (res != DI_OK) { if (res == DIERR_NOTACQUIRED) { Arrays.fill(device_state, 0); acquire(); return; } throw new IOException("Failed to get device state (" + Integer.toHexString(res) + ")"); } } private final static native int nGetDeviceState(long address, int[] device_state);
public final synchronized void setCooperativeLevel(int flags) throws IOException { checkReleased(); int res = nSetCooperativeLevel(address, window.getHwnd(), flags); if (res != DI_OK) throw new IOException("Failed to set cooperative level (" + Integer.toHexString(res) + ")"); } private final static native int nSetCooperativeLevel(long address, long hwnd_address, int flags);
private final List createRumblers() throws IOException { DIDeviceObject x_axis = lookupObjectByGUID(GUID_XAxis); // DIDeviceObject y_axis = lookupObjectByGUID(GUID_YAxis); if(x_axis == null/* || y_axis == null*/) return rumblers; DIDeviceObject[] axes = {x_axis/*, y_axis*/}; long[] directions = {0/*, 0*/}; for (int i = 0; i < effects.size(); i++) { DIEffectInfo info = (DIEffectInfo)effects.get(i); if ((info.getEffectType() & 0xff) == DIEFT_PERIODIC && (info.getDynamicParams() & DIEP_GAIN) != 0) { rumblers.add(createPeriodicRumbler(axes, directions, info)); } } return rumblers; }
private final boolean getDeviceData(DataQueue queue) throws IOException { int res = nGetDeviceData(address, 0, queue, queue.getElements(), queue.position(), queue.remaining()); if (res != DI_OK && res != DI_BUFFEROVERFLOW) { if (res == DIERR_NOTACQUIRED) { acquire(); return false; } throw new IOException("Failed to get device data (" + Integer.toHexString(res) + ")"); } return true; } private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining);
public DIDeviceObject(IDirectInputDevice device, Component.Identifier id, byte[] guid, int guid_type, int identifier, int type, int instance, int flags, String name, int format_offset) throws IOException { this.device = device; this.id = id; this.guid = guid; this.identifier = identifier; this.type = type; this.instance = instance; this.guid_type = guid_type; this.flags = flags; this.name = name; this.format_offset = format_offset; if (isAxis() && !isRelative()) { long[] range = device.getRangeProperty(identifier); this.min = range[0]; this.max = range[1]; this.deadzone = device.getDeadzoneProperty(identifier); } else { this.min = IDirectInputDevice.DIPROPRANGE_NOMIN; this.max = IDirectInputDevice.DIPROPRANGE_NOMAX; this.deadzone = 0; } }
private final void addDevice(long address, byte[] instance_guid, byte[] product_guid, int dev_type, int dev_subtype, String instance_name, String product_name) throws IOException { try { IDirectInputDevice device = new IDirectInputDevice(window, address, instance_guid, product_guid, dev_type, dev_subtype, instance_name, product_name); devices.add(device); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to initialize device " + product_name + " because of: " + e); } }
public final synchronized int getRelativePollValue(int current_abs_value) { if (device.areAxesRelative()) return current_abs_value; int rel_value = current_abs_value - last_poll_value; last_poll_value = current_abs_value; return rel_value; }