public final synchronized void rumble(float intensity) { try { checkReleased(); if (intensity > 0) { int int_gain = (int)Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX); setGain(int_gain); start(1, 0); } else stop(); } catch (IOException e) { DirectInputEnvironmentPlugin.logln("Failed to set rumbler gain: " + e.getMessage()); } }
public final synchronized void release() { if (!released) { released = true; nRelease(address); } } private final static native void nRelease(long address);
private final void setGain(int gain) throws IOException { int res = nSetGain(address, gain); if (res != IDirectInputDevice.DI_DOWNLOADSKIPPED && res != IDirectInputDevice.DI_EFFECTRESTARTED && res != IDirectInputDevice.DI_OK && res != IDirectInputDevice.DI_TRUNCATED && res != IDirectInputDevice.DI_TRUNCATEDANDRESTARTED) { throw new IOException("Failed to set effect gain (0x" + Integer.toHexString(res) + ")"); } } private final static native int nSetGain(long address, int gain);
protected void finalize() { release(); } }
private final void start(int iterations, int flags) throws IOException { int res = nStart(address, iterations, flags); if (res != IDirectInputDevice.DI_OK) throw new IOException("Failed to start effect (0x" + Integer.toHexString(res) + ")"); } private final static native int nStart(long address, int iterations, int flags);
private final void stop() throws IOException { int res = nStop(address); if (res != IDirectInputDevice.DI_OK) throw new IOException("Failed to stop effect (0x" + Integer.toHexString(res) + ")"); } private final static native int nStop(long address);
private final Rumbler createPeriodicRumbler(DIDeviceObject[] axes, long[] directions, DIEffectInfo info) throws IOException { int[] axis_ids = new int[axes.length]; for (int i = 0; i < axis_ids.length; i++) { axis_ids[i] = axes[i].getDIIdentifier(); } long effect_address = nCreatePeriodicEffect(address, info.getGUID(), DIEFF_CARTESIAN | DIEFF_OBJECTIDS, INFINITE, 0, DI_FFNOMINALMAX, DIEB_NOTRIGGER, 0, axis_ids, directions, 0, 0, 0, 0, DI_FFNOMINALMAX, 0, 0, 50000, 0); return new IDirectInputEffect(effect_address, info); } private final static native long nCreatePeriodicEffect(long address, byte[] effect_guid, int flags, int duration, int sample_period, int gain, int trigger_button, int trigger_repeat_interval, int[] axis_ids, long[] directions, int envelope_attack_level, int envelope_attack_time, int envelope_fade_level, int envelope_fade_time, int periodic_magnitude, int periodic_offset, int periodic_phase, int periodic_period, int start_delay) throws IOException;
public synchronized final void release() { if (!released) { released = true; for (int i = 0; i < rumblers.size(); i++) { IDirectInputEffect effect = (IDirectInputEffect)rumblers.get(i); effect.release(); } nRelease(address); } } private final static native void nRelease(long address);