private void btnPauseEffect_Click(object sender, EventArgs e) { DInputHandler dih = GetDInputHandler(); if (dih == null) { return; } int idx = cboxEffSlots.SelectedIndex; if (dih.GetEffectState(idx) == DInputHandler.EffectState.PAUSED) { if (dih.ResumeOneEffect(idx)) { MarkActiveSlot(); } } else if (dih.GetEffectState(idx) == DInputHandler.EffectState.ACTIVE) { if (dih.PauseOneEffect(idx)) { MarkPausedSlot(); } } }
/// <summary> /// Event handler: /// Toggles autocentering force /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbAutoCentering_CheckedChanged(object sender, EventArgs ea) { DInputHandler dih = GetDInputHandler(); if (dih == null) { return; } dih.SetAutoCenter(cbAutoCentering.Checked); }
/// <summary> /// Creates an instance of DInputHandler object for a FFB device and adds it to diHandlers dictionary under /// "devIdx" index. /// </summary> /// <param name="ffbDev"> /// DeviceInstance returned by DirectInput::GetDevices. /// </param> /// <param name="devIdx"> /// Index of the device in the enumeration of FFB devices. /// </param> private void HandleFFBDevice(DeviceInstance ffbDev, int devIdx) { DInputHandler dih = new DInputHandler(ffbDev.InstanceGuid); if (!dih.InitDevice(this.Handle, cbAutoCentering.Checked)) { return; } diHandlers.Add(devIdx, dih); cboxDevices.Items.Add(ffbDev.ProductName + " (" + ffbDev.InstanceGuid.ToString() + ")"); }
public Form1() { InitializeComponent(); lblVersion.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); effectSlotIndicators = new List <Label>(); effectSlotIndicators.Add(labelSlot1); effectSlotIndicators.Add(labelSlot2); effectSlotIndicators.Add(labelSlot3); effectSlotIndicators.Add(labelSlot4); effectSlotIndicators.Add(labelSlot5); effectSlotIndicators.Add(labelSlot6); effectSlotIndicators.Add(labelSlot7); effectSlotIndicators.Add(labelSlot8); CreateTooltips(); //Initialize DirectInput and enumerate all available force feedback devices if (!DInputHandler.InitDirectInput()) { //Close application if DirectInput initialization fails Close(); } IEnumerable <DeviceInstance> deviceList = DInputHandler.dInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.ForceFeedback); if (deviceList.Count() == 0) { MessageBox.Show("No force feedback devices found", "No devices", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { diHandlers = new Dictionary <int, DInputHandler>(deviceList.Count()); //Add all force feedback devices to cboxDevices and create DInputHandlers for them int devIdx = 0; foreach (DeviceInstance ffbDev in deviceList) { HandleFFBDevice(ffbDev, devIdx++); } cboxDevices.SelectedIndex = 0; //Select first device in the list } //Set effect slot "1" as default cboxEffSlots.SelectedIndex = 0; this.Activated += new EventHandler(Form1_onActivated); this.Deactivate += new EventHandler(Form1_onDeactivate); }
private void Form1_onClosing(object sender, FormClosingEventArgs e) { if (diHandlers == null) { return; } //Don't forget to stop any effect that might be still playing foreach (DInputHandler dih in diHandlers.Values) { dih.StopAllEffects(); } DInputHandler.DestroyDirectInput(); }
/// <summary> /// Returns DInputHandler of the device currently selected in the "Devices" dropdown menu /// </summary> /// <returns> /// Reference to DInputHandler if the selected device has been added to diHandlers dictionary, /// otherwise returns null. /// </returns> private DInputHandler GetDInputHandler() { if (diHandlers == null) { return(null); } int devIdx = cboxDevices.SelectedIndex; DInputHandler dih = GetDInputHandlerFromDict(devIdx); if (dih == null) { MessageBox.Show("Got null DIHandler, this is a bug.", FFBInspector.Properties.Resources.errCap_dihError, MessageBoxButtons.OK, MessageBoxIcon.Stop); return(null); } return(dih); }
/// <summary> /// Marks the effect indicators accordingly to the states of the effects /// </summary> /// <param name="dih"></param> private void MarkAllSlots(DInputHandler dih) { for (int i = 0; i < 8; i++) { if (dih.GetEffectState(i) == DInputHandler.EffectState.OFF) { effectSlotIndicators[i].BackColor = Control.DefaultBackColor; effectSlotIndicators[i].ForeColor = Control.DefaultForeColor; } else if (dih.GetEffectState(i) == DInputHandler.EffectState.PAUSED) { effectSlotIndicators[i].BackColor = Color.Yellow; effectSlotIndicators[i].ForeColor = Color.Black; } else { effectSlotIndicators[i].BackColor = Color.Green; effectSlotIndicators[i].ForeColor = Color.White; } } }
private void cboxEffSlots_SelectedIndexChanged(object sender, EventArgs e) { DInputHandler dih = GetDInputHandler(); if (dih == null) { return; } if (dih.GetEffectState(cboxEffSlots.SelectedIndex) == DInputHandler.EffectState.ACTIVE) { btnPauseEffect.Text = "Pause effect"; } else if (dih.GetEffectState(cboxEffSlots.SelectedIndex) == DInputHandler.EffectState.PAUSED) { btnPauseEffect.Text = "Resume effect"; } else { btnPauseEffect.Text = "(no effect)"; } }
/** Probes the selected FFB device and creates a list * of available FFB effects if successful. Also starts a timer * which periodically reads the status of device's axes and buttons */ private void cboxDevices_onDeviceSelected(object sender, EventArgs e) { ComboBox cbox = (ComboBox)sender; int selectedIdx = cbox.SelectedIndex; DInputHandler dih = GetDInputHandlerFromDict(selectedIdx); if (dih == null) { return; } //Get available effects for the currently selected device availableFFBEffects = dih.GetFFBEffects(); if (availableFFBEffects.Count == 0) { MessageBox.Show("No force feedback effects available for this device.", FFBInspector.Properties.Resources.errCap_noEffect, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { cboxEffects.Items.Clear(); foreach (EffectInfo ei in availableFFBEffects) { cboxEffects.Items.Add(ei.Name + " (" + ei.Guid.ToString() + ")"); } cboxEffects.SelectedIndex = 0; //Select first effect in the list } //Get available force feedback actuators and create respective UI elements int actuators = dih.GetFFBActuatorCount(); if (actuators == 0) { MessageBox.Show("No force feedback actuators found on this device.", FFBInspector.Properties.Resources.errCap_devError, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } /* Create textboxes in Directions groupbox to control * direction of the effect on each actuator */ if (axesControls != null) { panelAxes.Controls.Clear(); //Remove all existing textboxes } axesControls = new List <TextBox>(); for (int i = 0; i < actuators; i++) { axesControls.Add(new TextBox()); if (i == 0) { axesControls[i].Text = "1"; } else { axesControls[i].Text = "0"; axesControls[i].Top = axesControls[i - 1].Top + 25; } panelAxes.Controls.Add(axesControls[i]); } DataClasses.HardwareInfo dc = dih.GetHardwareInfo(); if (dc != null) { //Display hardware info on the "Info" tab axesCount.Text = dc.axesCount.ToString(); buttonCount.Text = dc.buttonCount.ToString(); povCount.Text = dc.povCount.ToString(); driverVersion.Text = dc.driverVersion.ToString(); fwVersion.Text = dc.fwVersion.ToString(); hwRevision.Text = dc.hwRevision.ToString(); ffbMinTime.Text = dc.ffbMinTime.ToString(); ffbSamplePeriod.Text = dc.ffbSamplePer.ToString(); } MarkAllSlots(dih); //Start the controls status updating timer if (updateDeviceStatus == null) { updateDeviceStatus = new Timer(); updateDeviceStatus.Interval = 75; updateDeviceStatus.Tick += new EventHandler(updateDeviceStatus_onTick); updateDeviceStatus.Enabled = true; } }
/// <summary> /// Creates an instance of DInputHandler object for a FFB device and adds it to diHandlers dictionary under /// "devIdx" index. /// </summary> /// <param name="ffbDev"> /// DeviceInstance returned by DirectInput::GetDevices. /// </param> /// <param name="devIdx"> /// Index of the device in the enumeration of FFB devices. /// </param> private void HandleFFBDevice(DeviceInstance ffbDev, int devIdx) { DInputHandler dih = new DInputHandler(ffbDev.InstanceGuid); if (!dih.InitDevice(this.Handle, cbAutoCentering.Checked)) return; diHandlers.Add(devIdx, dih); cboxDevices.Items.Add(ffbDev.ProductName + " (" + ffbDev.InstanceGuid.ToString() + ")"); }