private void DisposeMonitor() { if (mon == null) { return; } batteryInfo.Text = "Disconnected"; mon.OnStateChanged -= keytarTranslator.ControllerEventHandler; mon.OnStateChanged -= drumTranslator.ControllerEventHandler; mon.OnStateChanged -= proGuitarTranslator.ControllerEventHandler; mon.Dispose(); mon = null; }
private void controllers_SelectedIndexChanged(object sender, EventArgs e) { if (mon != null) { mon.Dispose(); } var controller = controllers.SelectedItem as Controller; mon = new ControllerMonitor(controller); mon.OnStateChanged += Mon_OnStateChanged; XInput.BatteryInformation xbi = default; XInput.XInputGetBatteryInformation(controller.Index, XInput.BatteryDevType.Gamepad, ref xbi); label4.Text = $"Battery: {xbi.BatteryType} {xbi.BatteryLevel}"; }
private void controllers_SelectedIndexChanged(object sender, EventArgs e) { DisposeMonitor(); if (controllers.SelectedItem is Controller c) { mon = new ControllerMonitor(c); mon.OnDisconnect += Controller_OnDisconnect; if (c.Capabilities.SubType == XInput.DevSubType.Keytar) { mon.OnStateChanged += keytarTranslator.ControllerEventHandler; } else if (c.Capabilities.SubType == XInput.DevSubType.DrumKit) { mon.OnStateChanged += drumTranslator.ControllerEventHandler; } else if (c.Capabilities.SubType == XInput.DevSubType.ProGuitar) { mon.OnStateChanged += proGuitarTranslator.ControllerEventHandler; } XInput.BatteryInformation xbi = default; XInput.XInputGetBatteryInformation(((Controller)controllers.SelectedItem).Index, XInput.BatteryDevType.Gamepad, ref xbi); batteryInfo.Text = $"Connected. Battery: {xbi.BatteryType} {xbi.BatteryLevel}"; } }