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 Form1_FormClosing(object sender, FormClosingEventArgs e) { mon?.Dispose(); device?.Close(); }