- WIP Adding support for 3rd party controllers

This commit is contained in:
David Khachaturov 2020-06-12 16:04:24 +01:00
parent a291f0daf6
commit e1f3e573fd
5 changed files with 753 additions and 669 deletions

View file

@ -1,212 +1,206 @@
namespace BetterJoyForCemu {
partial class _3rdPartyControllers {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
partial class _3rdPartyControllers {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(_3rdPartyControllers));
this.list_allControllers = new System.Windows.Forms.ListBox();
this.list_customControllers = new System.Windows.Forms.ListBox();
this.btn_add = new System.Windows.Forms.Button();
this.btn_remove = new System.Windows.Forms.Button();
this.group_props = new System.Windows.Forms.GroupBox();
this.chk_isLeft = new System.Windows.Forms.CheckBox();
this.chk_isPro = new System.Windows.Forms.CheckBox();
this.btn_applyAndClose = new System.Windows.Forms.Button();
this.btn_apply = new System.Windows.Forms.Button();
this.lbl_all = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.tip_device = new System.Windows.Forms.ToolTip(this.components);
this.btn_refresh = new System.Windows.Forms.Button();
this.group_props.SuspendLayout();
this.SuspendLayout();
//
// list_allControllers
//
this.list_allControllers.FormattingEnabled = true;
this.list_allControllers.Location = new System.Drawing.Point(12, 27);
this.list_allControllers.Name = "list_allControllers";
this.list_allControllers.Size = new System.Drawing.Size(103, 225);
this.list_allControllers.TabIndex = 0;
this.list_allControllers.SelectedValueChanged += new System.EventHandler(this.list_allControllers_SelectedValueChanged);
this.list_allControllers.MouseDown += new System.Windows.Forms.MouseEventHandler(this.list_allControllers_MouseDown);
//
// list_customControllers
//
this.list_customControllers.FormattingEnabled = true;
this.list_customControllers.Location = new System.Drawing.Point(169, 27);
this.list_customControllers.Name = "list_customControllers";
this.list_customControllers.Size = new System.Drawing.Size(103, 108);
this.list_customControllers.TabIndex = 1;
this.list_customControllers.SelectedValueChanged += new System.EventHandler(this.list_customControllers_SelectedValueChanged);
this.list_customControllers.MouseDown += new System.Windows.Forms.MouseEventHandler(this.list_customControllers_MouseDown);
//
// btn_add
//
this.btn_add.Location = new System.Drawing.Point(121, 27);
this.btn_add.Name = "btn_add";
this.btn_add.Size = new System.Drawing.Size(42, 23);
this.btn_add.TabIndex = 2;
this.btn_add.Text = "->";
this.btn_add.UseVisualStyleBackColor = true;
this.btn_add.Click += new System.EventHandler(this.btn_add_Click);
//
// btn_remove
//
this.btn_remove.Location = new System.Drawing.Point(121, 112);
this.btn_remove.Name = "btn_remove";
this.btn_remove.Size = new System.Drawing.Size(42, 23);
this.btn_remove.TabIndex = 3;
this.btn_remove.Text = "<-";
this.btn_remove.UseVisualStyleBackColor = true;
this.btn_remove.Click += new System.EventHandler(this.btn_remove_Click);
//
// group_props
//
this.group_props.Controls.Add(this.chk_isLeft);
this.group_props.Controls.Add(this.chk_isPro);
this.group_props.Location = new System.Drawing.Point(122, 142);
this.group_props.Name = "group_props";
this.group_props.Size = new System.Drawing.Size(150, 81);
this.group_props.TabIndex = 4;
this.group_props.TabStop = false;
this.group_props.Text = "Settings";
//
// chk_isLeft
//
this.chk_isLeft.AutoSize = true;
this.chk_isLeft.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chk_isLeft.Location = new System.Drawing.Point(6, 42);
this.chk_isLeft.Name = "chk_isLeft";
this.chk_isLeft.Size = new System.Drawing.Size(96, 17);
this.chk_isLeft.TabIndex = 1;
this.chk_isLeft.Text = "Left Joycon? ";
this.chk_isLeft.UseVisualStyleBackColor = true;
this.chk_isLeft.CheckedChanged += new System.EventHandler(this.chk_isLeft_CheckedChanged);
//
// chk_isPro
//
this.chk_isPro.AutoSize = true;
this.chk_isPro.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chk_isPro.Location = new System.Drawing.Point(6, 19);
this.chk_isPro.Name = "chk_isPro";
this.chk_isPro.Size = new System.Drawing.Size(95, 17);
this.chk_isPro.TabIndex = 0;
this.chk_isPro.Text = "Pro Controller?";
this.chk_isPro.UseVisualStyleBackColor = true;
this.chk_isPro.CheckedChanged += new System.EventHandler(this.chk_isPro_CheckedChanged);
//
// btn_applyAndClose
//
this.btn_applyAndClose.Location = new System.Drawing.Point(203, 229);
this.btn_applyAndClose.Name = "btn_applyAndClose";
this.btn_applyAndClose.Size = new System.Drawing.Size(69, 23);
this.btn_applyAndClose.TabIndex = 5;
this.btn_applyAndClose.Text = "Close";
this.btn_applyAndClose.UseVisualStyleBackColor = true;
this.btn_applyAndClose.Click += new System.EventHandler(this.btn_applyAndClose_Click);
//
// btn_apply
//
this.btn_apply.Location = new System.Drawing.Point(121, 229);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(69, 23);
this.btn_apply.TabIndex = 6;
this.btn_apply.Text = "Apply";
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.btn_apply_Click);
//
// lbl_all
//
this.lbl_all.AutoSize = true;
this.lbl_all.Location = new System.Drawing.Point(12, 11);
this.lbl_all.Name = "lbl_all";
this.lbl_all.Size = new System.Drawing.Size(60, 13);
this.lbl_all.TabIndex = 7;
this.lbl_all.Text = "All Devices";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(166, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 13);
this.label1.TabIndex = 8;
this.label1.Text = "Switch Controllers";
//
// btn_refresh
//
this.btn_refresh.Location = new System.Drawing.Point(121, 56);
this.btn_refresh.Name = "btn_refresh";
this.btn_refresh.Size = new System.Drawing.Size(42, 50);
this.btn_refresh.TabIndex = 9;
this.btn_refresh.Text = "Re-\r\nfresh";
this.btn_refresh.UseVisualStyleBackColor = true;
this.btn_refresh.Click += new System.EventHandler(this.btn_refresh_Click);
//
// _3rdPartyControllers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.btn_refresh);
this.Controls.Add(this.label1);
this.Controls.Add(this.lbl_all);
this.Controls.Add(this.btn_apply);
this.Controls.Add(this.btn_applyAndClose);
this.Controls.Add(this.group_props);
this.Controls.Add(this.btn_remove);
this.Controls.Add(this.btn_add);
this.Controls.Add(this.list_customControllers);
this.Controls.Add(this.list_allControllers);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "_3rdPartyControllers";
this.Text = "Add 3rd-Party Controllers";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this._3rdPartyControllers_FormClosing);
this.group_props.ResumeLayout(false);
this.group_props.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(_3rdPartyControllers));
this.list_allControllers = new System.Windows.Forms.ListBox();
this.list_customControllers = new System.Windows.Forms.ListBox();
this.btn_add = new System.Windows.Forms.Button();
this.btn_remove = new System.Windows.Forms.Button();
this.group_props = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.chooseType = new System.Windows.Forms.ComboBox();
this.btn_applyAndClose = new System.Windows.Forms.Button();
this.btn_apply = new System.Windows.Forms.Button();
this.lbl_all = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.tip_device = new System.Windows.Forms.ToolTip(this.components);
this.btn_refresh = new System.Windows.Forms.Button();
this.group_props.SuspendLayout();
this.SuspendLayout();
//
// list_allControllers
//
this.list_allControllers.FormattingEnabled = true;
this.list_allControllers.Location = new System.Drawing.Point(12, 27);
this.list_allControllers.Name = "list_allControllers";
this.list_allControllers.Size = new System.Drawing.Size(103, 225);
this.list_allControllers.TabIndex = 0;
this.list_allControllers.SelectedValueChanged += new System.EventHandler(this.list_allControllers_SelectedValueChanged);
this.list_allControllers.MouseDown += new System.Windows.Forms.MouseEventHandler(this.list_allControllers_MouseDown);
//
// list_customControllers
//
this.list_customControllers.FormattingEnabled = true;
this.list_customControllers.Location = new System.Drawing.Point(169, 27);
this.list_customControllers.Name = "list_customControllers";
this.list_customControllers.Size = new System.Drawing.Size(103, 108);
this.list_customControllers.TabIndex = 1;
this.list_customControllers.SelectedValueChanged += new System.EventHandler(this.list_customControllers_SelectedValueChanged);
this.list_customControllers.MouseDown += new System.Windows.Forms.MouseEventHandler(this.list_customControllers_MouseDown);
//
// btn_add
//
this.btn_add.Location = new System.Drawing.Point(121, 27);
this.btn_add.Name = "btn_add";
this.btn_add.Size = new System.Drawing.Size(42, 23);
this.btn_add.TabIndex = 2;
this.btn_add.Text = "->";
this.btn_add.UseVisualStyleBackColor = true;
this.btn_add.Click += new System.EventHandler(this.btn_add_Click);
//
// btn_remove
//
this.btn_remove.Location = new System.Drawing.Point(121, 112);
this.btn_remove.Name = "btn_remove";
this.btn_remove.Size = new System.Drawing.Size(42, 23);
this.btn_remove.TabIndex = 3;
this.btn_remove.Text = "<-";
this.btn_remove.UseVisualStyleBackColor = true;
this.btn_remove.Click += new System.EventHandler(this.btn_remove_Click);
//
// group_props
//
this.group_props.Controls.Add(this.label2);
this.group_props.Controls.Add(this.chooseType);
this.group_props.Location = new System.Drawing.Point(122, 142);
this.group_props.Name = "group_props";
this.group_props.Size = new System.Drawing.Size(150, 81);
this.group_props.TabIndex = 4;
this.group_props.TabStop = false;
this.group_props.Text = "Settings";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 22);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(31, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Type";
//
// chooseType
//
this.chooseType.FormattingEnabled = true;
this.chooseType.Location = new System.Drawing.Point(47, 19);
this.chooseType.Name = "chooseType";
this.chooseType.Size = new System.Drawing.Size(97, 21);
this.chooseType.TabIndex = 0;
this.chooseType.SelectedValueChanged += new System.EventHandler(this.chooseType_SelectedValueChanged);
//
// btn_applyAndClose
//
this.btn_applyAndClose.Location = new System.Drawing.Point(203, 229);
this.btn_applyAndClose.Name = "btn_applyAndClose";
this.btn_applyAndClose.Size = new System.Drawing.Size(69, 23);
this.btn_applyAndClose.TabIndex = 5;
this.btn_applyAndClose.Text = "Close";
this.btn_applyAndClose.UseVisualStyleBackColor = true;
this.btn_applyAndClose.Click += new System.EventHandler(this.btn_applyAndClose_Click);
//
// btn_apply
//
this.btn_apply.Location = new System.Drawing.Point(121, 229);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(69, 23);
this.btn_apply.TabIndex = 6;
this.btn_apply.Text = "Apply";
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.btn_apply_Click);
//
// lbl_all
//
this.lbl_all.AutoSize = true;
this.lbl_all.Location = new System.Drawing.Point(12, 11);
this.lbl_all.Name = "lbl_all";
this.lbl_all.Size = new System.Drawing.Size(60, 13);
this.lbl_all.TabIndex = 7;
this.lbl_all.Text = "All Devices";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(166, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 13);
this.label1.TabIndex = 8;
this.label1.Text = "Switch Controllers";
//
// btn_refresh
//
this.btn_refresh.Location = new System.Drawing.Point(121, 56);
this.btn_refresh.Name = "btn_refresh";
this.btn_refresh.Size = new System.Drawing.Size(42, 50);
this.btn_refresh.TabIndex = 9;
this.btn_refresh.Text = "Re-\r\nfresh";
this.btn_refresh.UseVisualStyleBackColor = true;
this.btn_refresh.Click += new System.EventHandler(this.btn_refresh_Click);
//
// _3rdPartyControllers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.btn_refresh);
this.Controls.Add(this.label1);
this.Controls.Add(this.lbl_all);
this.Controls.Add(this.btn_apply);
this.Controls.Add(this.btn_applyAndClose);
this.Controls.Add(this.group_props);
this.Controls.Add(this.btn_remove);
this.Controls.Add(this.btn_add);
this.Controls.Add(this.list_customControllers);
this.Controls.Add(this.list_allControllers);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "_3rdPartyControllers";
this.Text = "Add 3rd-Party Controllers";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this._3rdPartyControllers_FormClosing);
this.group_props.ResumeLayout(false);
this.group_props.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
}
#endregion
#endregion
private System.Windows.Forms.ListBox list_allControllers;
private System.Windows.Forms.ListBox list_customControllers;
private System.Windows.Forms.Button btn_add;
private System.Windows.Forms.Button btn_remove;
private System.Windows.Forms.GroupBox group_props;
private System.Windows.Forms.Button btn_applyAndClose;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Label lbl_all;
private System.Windows.Forms.CheckBox chk_isPro;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox chk_isLeft;
private System.Windows.Forms.ToolTip tip_device;
private System.Windows.Forms.Button btn_refresh;
}
}
private System.Windows.Forms.ListBox list_allControllers;
private System.Windows.Forms.ListBox list_customControllers;
private System.Windows.Forms.Button btn_add;
private System.Windows.Forms.Button btn_remove;
private System.Windows.Forms.GroupBox group_props;
private System.Windows.Forms.Button btn_applyAndClose;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Label lbl_all;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ToolTip tip_device;
private System.Windows.Forms.Button btn_refresh;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox chooseType;
}
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -12,110 +13,179 @@ using System.Windows.Forms;
using static BetterJoyForCemu.HIDapi;
namespace BetterJoyForCemu {
public partial class _3rdPartyControllers : Form {
public _3rdPartyControllers() {
InitializeComponent();
list_allControllers.DisplayMember = "Text";
list_allControllers.ValueMember = "Value";
list_customControllers.DisplayMember = "Text";
list_customControllers.ValueMember = "Value";
public partial class _3rdPartyControllers : Form {
public class SController {
public String name;
public ushort product_id;
public ushort vendor_id;
public byte type; // 1 is pro, 2 is left joy, 3 is right joy
RefreshControllerList();
public SController(String name, ushort vendor_id, ushort product_id, byte type) {
this.product_id = product_id; this.vendor_id = vendor_id; this.type = type;
this.name = name;
}
group_props.Controls.Add(chk_isLeft);
group_props.Controls.Add(chk_isPro);
group_props.Enabled = false;
}
public override bool Equals(object obj) {
//Check for null and compare run-time types.
if ((obj == null) || !this.GetType().Equals(obj.GetType())) {
return false;
} else {
SController s = (SController)obj;
return (s.product_id == product_id) && (s.vendor_id == vendor_id);
}
}
private bool ContainsText(ListBox a, String manu) {
foreach (var v in a.Items) {
dynamic d = v as dynamic;
if (d.Text == null)
continue;
if (d.Text.Equals(manu))
return true;
}
return false;
}
public override int GetHashCode() {
return Tuple.Create(product_id, vendor_id).GetHashCode();
}
private void RefreshControllerList() {
list_allControllers.Items.Clear();
IntPtr ptr = HIDapi.hid_enumerate(0x0, 0x0);
IntPtr top_ptr = ptr;
public override string ToString() {
return name;
}
hid_device_info enumerate; // Add device to list
while (ptr != IntPtr.Zero) {
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
public string Serialise() {
return String.Format("{0}|{1}|{2}|{3}", name, product_id, vendor_id, type);
}
}
if (!ContainsText(list_customControllers, enumerate.product_string) && !ContainsText(list_allControllers, enumerate.product_string))
list_allControllers.Items.Add(new { Text = enumerate.product_string, Value = enumerate });
const string PATH = "3rdPartyControllers";
ptr = enumerate.next;
}
}
public _3rdPartyControllers() {
InitializeComponent();
/*list_allControllers.DisplayMember = "Text";
list_allControllers.ValueMember = "Value";
list_customControllers.DisplayMember = "Text";
list_customControllers.ValueMember = "Value";*/
list_allControllers.HorizontalScrollbar = true; list_customControllers.HorizontalScrollbar = true;
private void btn_add_Click(object sender, EventArgs e) {
if (list_allControllers.SelectedItem != null) {
list_customControllers.Items.Add(list_allControllers.SelectedItem);
list_allControllers.Items.Remove(list_allControllers.SelectedItem);
list_allControllers.ClearSelected();
}
}
chooseType.Items.AddRange(new String[] { "Pro Controller", "Left Joycon", "Right Joycon" });
private void btn_remove_Click(object sender, EventArgs e) {
if (list_customControllers.SelectedItem != null) {
list_allControllers.Items.Add(list_customControllers.SelectedItem);
list_customControllers.Items.Remove(list_customControllers.SelectedItem);
list_customControllers.ClearSelected();
}
}
chooseType.FormattingEnabled = true;
group_props.Controls.Add(chooseType);
group_props.Enabled = false;
private void chk_isPro_CheckedChanged(object sender, EventArgs e) {
if (File.Exists(PATH)) {
using (StreamReader file = new StreamReader(PATH)) {
string line = String.Empty;
while ((line = file.ReadLine()) != null && (line != String.Empty)) {
String[] split = line.Split('|');
list_customControllers.Items.Add(new SController(split[0], ushort.Parse(split[1]), ushort.Parse(split[2]), byte.Parse(split[3])));
}
}
}
}
CopyCustomControllers();
RefreshControllerList();
}
private void chk_isLeft_CheckedChanged(object sender, EventArgs e) {
public void CopyCustomControllers() {
Program.thirdPartyCons.Clear();
foreach (SController v in list_customControllers.Items) {
Program.thirdPartyCons.Add(v);
}
}
}
private bool ContainsText(ListBox a, String manu) {
foreach (SController v in a.Items) {
if (v == null)
continue;
if (v.name.Equals(manu))
return true;
}
return false;
}
private void btn_apply_Click(object sender, EventArgs e) {
private void RefreshControllerList() {
list_allControllers.Items.Clear();
IntPtr ptr = HIDapi.hid_enumerate(0x0, 0x0);
}
hid_device_info enumerate; // Add device to list
while (ptr != IntPtr.Zero) {
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
private void btn_applyAndClose_Click(object sender, EventArgs e) {
btn_apply_Click(sender, e);
Close();
}
if (!ContainsText(list_customControllers, enumerate.product_string) && !ContainsText(list_allControllers, enumerate.product_string)) {
list_allControllers.Items.Add(new SController(enumerate.product_string, enumerate.vendor_id, enumerate.product_id, 0));
// 0 type is undefined
}
private void _3rdPartyControllers_FormClosing(object sender, FormClosingEventArgs e) {
btn_apply_Click(sender, e);
}
ptr = enumerate.next;
}
}
private void btn_refresh_Click(object sender, EventArgs e) {
RefreshControllerList();
}
private void btn_add_Click(object sender, EventArgs e) {
if (list_allControllers.SelectedItem != null) {
list_customControllers.Items.Add(list_allControllers.SelectedItem);
list_allControllers.Items.Remove(list_allControllers.SelectedItem);
private void list_allControllers_SelectedValueChanged(object sender, EventArgs e) {
if (list_allControllers.SelectedItem != null)
tip_device.Show((list_allControllers.SelectedItem as dynamic).Text, list_allControllers);
}
list_allControllers.ClearSelected();
}
}
private void list_customControllers_SelectedValueChanged(object sender, EventArgs e) {
if (list_customControllers.SelectedItem != null) {
tip_device.Show((list_customControllers.SelectedItem as dynamic).Text, list_customControllers);
group_props.Enabled = true;
} else
group_props.Enabled = false;
}
private void btn_remove_Click(object sender, EventArgs e) {
if (list_customControllers.SelectedItem != null) {
list_allControllers.Items.Add(list_customControllers.SelectedItem);
list_customControllers.Items.Remove(list_customControllers.SelectedItem);
private void list_customControllers_MouseDown(object sender, MouseEventArgs e) {
if (e.Y > list_customControllers.ItemHeight * list_customControllers.Items.Count)
list_customControllers.SelectedItems.Clear();
}
list_customControllers.ClearSelected();
}
}
private void list_allControllers_MouseDown(object sender, MouseEventArgs e) {
if (e.Y > list_allControllers.ItemHeight * list_allControllers.Items.Count)
list_allControllers.SelectedItems.Clear();
}
}
private void btn_apply_Click(object sender, EventArgs e) {
String sc = "";
foreach (SController v in list_customControllers.Items) {
sc += v.Serialise() + "\r\n";
}
File.WriteAllText(PATH, sc);
CopyCustomControllers();
}
private void btn_applyAndClose_Click(object sender, EventArgs e) {
btn_apply_Click(sender, e);
Close();
}
private void _3rdPartyControllers_FormClosing(object sender, FormClosingEventArgs e) {
btn_apply_Click(sender, e);
}
private void btn_refresh_Click(object sender, EventArgs e) {
RefreshControllerList();
}
private void list_allControllers_SelectedValueChanged(object sender, EventArgs e) {
if (list_allControllers.SelectedItem != null)
tip_device.Show((list_allControllers.SelectedItem as SController).name, list_allControllers);
}
private void list_customControllers_SelectedValueChanged(object sender, EventArgs e) {
if (list_customControllers.SelectedItem != null) {
SController v = (list_customControllers.SelectedItem as SController);
tip_device.Show(v.name, list_customControllers);
chooseType.SelectedIndex = v.type - 1;
group_props.Enabled = true;
} else {
chooseType.SelectedIndex = -1;
group_props.Enabled = false;
}
}
private void list_customControllers_MouseDown(object sender, MouseEventArgs e) {
if (e.Y > list_customControllers.ItemHeight * list_customControllers.Items.Count)
list_customControllers.SelectedItems.Clear();
}
private void list_allControllers_MouseDown(object sender, MouseEventArgs e) {
if (e.Y > list_allControllers.ItemHeight * list_allControllers.Items.Count)
list_allControllers.SelectedItems.Clear();
}
private void chooseType_SelectedValueChanged(object sender, EventArgs e) {
if (list_customControllers.SelectedItem != null) {
SController v = (list_customControllers.SelectedItem as SController);
v.type = (byte)(chooseType.SelectedIndex + 1);
}
}
}
}

View file

@ -26,7 +26,6 @@
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.console = new System.Windows.Forms.TextBox();
this.console_lbl = new System.Windows.Forms.Label();
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -68,16 +67,6 @@
this.console.Size = new System.Drawing.Size(262, 100);
this.console.TabIndex = 2;
//
// console_lbl
//
this.console_lbl.AutoSize = true;
this.console_lbl.Location = new System.Drawing.Point(9, 116);
this.console_lbl.Name = "console_lbl";
this.console_lbl.Size = new System.Drawing.Size(80, 13);
this.console_lbl.TabIndex = 1;
this.console_lbl.Text = "Console Output";
this.console_lbl.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// notifyIcon
//
this.notifyIcon.BalloonTipText = "Double click the tray icon to maximise";
@ -265,7 +254,7 @@
//
// btn_open3rdP
//
this.btn_open3rdP.Location = new System.Drawing.Point(188, 112);
this.btn_open3rdP.Location = new System.Drawing.Point(93, 112);
this.btn_open3rdP.Name = "btn_open3rdP";
this.btn_open3rdP.Size = new System.Drawing.Size(86, 20);
this.btn_open3rdP.TabIndex = 7;
@ -337,7 +326,7 @@
//
// btn_reassign_open
//
this.btn_reassign_open.Location = new System.Drawing.Point(107, 112);
this.btn_reassign_open.Location = new System.Drawing.Point(12, 112);
this.btn_reassign_open.Name = "btn_reassign_open";
this.btn_reassign_open.Size = new System.Drawing.Size(75, 20);
this.btn_reassign_open.TabIndex = 13;
@ -362,7 +351,6 @@
this.Controls.Add(this.donationLink);
this.Controls.Add(this.passiveScanBox);
this.Controls.Add(this.version_lbl);
this.Controls.Add(this.console_lbl);
this.Controls.Add(this.console);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
@ -384,7 +372,6 @@
#endregion
public System.Windows.Forms.TextBox console;
private System.Windows.Forms.Label console_lbl;
private System.Windows.Forms.NotifyIcon notifyIcon;
private System.Windows.Forms.Label version_lbl;
private System.Windows.Forms.ContextMenuStrip contextMenu;

View file

@ -14,423 +14,420 @@ using System.Windows.Forms;
using System.Xml.Linq;
namespace BetterJoyForCemu {
public partial class MainForm : Form {
public bool nonOriginal = Boolean.Parse(ConfigurationManager.AppSettings["NonOriginalController"]);
public List<Button> con, loc;
public bool calibrate;
public List<KeyValuePair<string, float[]>> caliData;
private Timer countDown;
private int count;
public List<int> xG, yG, zG, xA, yA, zA;
public partial class MainForm : Form {
public bool nonOriginal = Boolean.Parse(ConfigurationManager.AppSettings["NonOriginalController"]);
public List<Button> con, loc;
public bool calibrate;
public List<KeyValuePair<string, float[]>> caliData;
private Timer countDown;
private int count;
public List<int> xG, yG, zG, xA, yA, zA;
public MainForm() {
xG = new List<int>(); yG = new List<int>(); zG = new List<int>();
xA = new List<int>(); yA = new List<int>(); zA = new List<int>();
caliData = new List<KeyValuePair<string, float[]>> {
new KeyValuePair<string, float[]>("0", new float[6] {0,0,0,-710,0,0})
};
public MainForm() {
xG = new List<int>(); yG = new List<int>(); zG = new List<int>();
xA = new List<int>(); yA = new List<int>(); zA = new List<int>();
caliData = new List<KeyValuePair<string, float[]>> {
new KeyValuePair<string, float[]>("0", new float[6] {0,0,0,-710,0,0})
};
InitializeComponent();
InitializeComponent();
if (!nonOriginal)
AutoCalibrate.Hide();
if (!nonOriginal)
AutoCalibrate.Hide();
// Feature not yet implemented - hide
btn_open3rdP.Hide();
con = new List<Button> { con1, con2, con3, con4 };
loc = new List<Button> { loc1, loc2, loc3, loc4 };
con = new List<Button> { con1, con2, con3, con4 };
loc = new List<Button> { loc1, loc2, loc3, loc4 };
//list all options
string[] myConfigs = ConfigurationManager.AppSettings.AllKeys;
Size childSize = new Size(87, 20);
for (int i = 0; i != myConfigs.Length; i++) {
settingsTable.RowCount++;
settingsTable.Controls.Add(new Label() { Text = myConfigs[i], TextAlign = ContentAlignment.BottomLeft, AutoEllipsis = true, Size = childSize }, 0, i);
//list all options
string[] myConfigs = ConfigurationManager.AppSettings.AllKeys;
Size childSize = new Size(87, 20);
for (int i = 0; i != myConfigs.Length; i++) {
settingsTable.RowCount++;
settingsTable.Controls.Add(new Label() { Text = myConfigs[i], TextAlign = ContentAlignment.BottomLeft, AutoEllipsis = true, Size = childSize }, 0, i);
var value = ConfigurationManager.AppSettings[myConfigs[i]];
Control childControl;
if (value == "true" || value == "false") {
childControl = new CheckBox() { Checked = Boolean.Parse(value), Size = childSize };
} else {
childControl = new TextBox() { Text = value, Size = childSize };
}
var value = ConfigurationManager.AppSettings[myConfigs[i]];
Control childControl;
if (value == "true" || value == "false") {
childControl = new CheckBox() { Checked = Boolean.Parse(value), Size = childSize };
} else {
childControl = new TextBox() { Text = value, Size = childSize };
}
childControl.MouseClick += cbBox_Changed;
settingsTable.Controls.Add(childControl, 1, i);
}
}
childControl.MouseClick += cbBox_Changed;
settingsTable.Controls.Add(childControl, 1, i);
}
}
private void HideToTray() {
this.WindowState = FormWindowState.Minimized;
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(1);
this.ShowInTaskbar = false;
this.Hide();
}
private void HideToTray() {
this.WindowState = FormWindowState.Minimized;
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(1);
this.ShowInTaskbar = false;
this.Hide();
}
private void ShowFromTray() {
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.Icon = Properties.Resources.betterjoyforcemu_icon;
notifyIcon.Visible = false;
}
private void ShowFromTray() {
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.Icon = Properties.Resources.betterjoyforcemu_icon;
notifyIcon.Visible = false;
}
private void MainForm_Resize(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Minimized) {
HideToTray();
}
}
private void MainForm_Resize(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Minimized) {
HideToTray();
}
}
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) {
ShowFromTray();
}
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) {
ShowFromTray();
}
private void MainForm_Load(object sender, EventArgs e) {
Config.Init(caliData);
private void MainForm_Load(object sender, EventArgs e) {
Config.Init(caliData);
Program.Start();
Program.Start();
passiveScanBox.Checked = Config.IntValue("ProgressiveScan") == 1;
startInTrayBox.Checked = Config.IntValue("StartInTray") == 1;
passiveScanBox.Checked = Config.IntValue("ProgressiveScan") == 1;
startInTrayBox.Checked = Config.IntValue("StartInTray") == 1;
if (Config.IntValue("StartInTray") == 1) {
HideToTray();
} else {
ShowFromTray();
}
}
if (Config.IntValue("StartInTray") == 1) {
HideToTray();
} else {
ShowFromTray();
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
try {
Program.Stop();
Environment.Exit(0);
} catch { }
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
try {
Program.Stop();
Environment.Exit(0);
} catch { }
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // this does not work, for some reason. Fix before release
try {
Program.Stop();
Close();
Environment.Exit(0);
} catch { }
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // this does not work, for some reason. Fix before release
try {
Program.Stop();
Close();
Environment.Exit(0);
} catch { }
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
donationLink.LinkVisited = true;
System.Diagnostics.Process.Start("http://paypal.me/DavidKhachaturov/5");
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
donationLink.LinkVisited = true;
System.Diagnostics.Process.Start("http://paypal.me/DavidKhachaturov/5");
}
private void passiveScanBox_CheckedChanged(object sender, EventArgs e) {
Config.SetValue("ProgressiveScan", passiveScanBox.Checked ? "1" : "0");
Config.Save();
}
private void passiveScanBox_CheckedChanged(object sender, EventArgs e) {
Config.SetValue("ProgressiveScan", passiveScanBox.Checked ? "1" : "0");
Config.Save();
}
public void AppendTextBox(string value) { // https://stackoverflow.com/questions/519233/writing-to-a-textbox-from-another-thread
if (InvokeRequired) {
this.Invoke(new Action<string>(AppendTextBox), new object[] { value });
return;
}
console.AppendText(value);
}
public void AppendTextBox(string value) { // https://stackoverflow.com/questions/519233/writing-to-a-textbox-from-another-thread
if (InvokeRequired) {
this.Invoke(new Action<string>(AppendTextBox), new object[] { value });
return;
}
console.AppendText(value);
}
bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
bool showAsDS4 = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsDS4"]);
bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
bool showAsDS4 = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsDS4"]);
public void locBtnClick(object sender, EventArgs e) {
Button bb = sender as Button;
public void locBtnClick(object sender, EventArgs e) {
Button bb = sender as Button;
if (bb.Tag.GetType() == typeof(Button)) {
Button button = bb.Tag as Button;
if (bb.Tag.GetType() == typeof(Button)) {
Button button = bb.Tag as Button;
if (button.Tag.GetType() == typeof(Joycon)) {
Joycon v = (Joycon)button.Tag;
v.SetRumble(20.0f, 400.0f, 1.0f, 300);
}
}
}
if (button.Tag.GetType() == typeof(Joycon)) {
Joycon v = (Joycon)button.Tag;
v.SetRumble(20.0f, 400.0f, 1.0f, 300);
}
}
}
public void conBtnClick(object sender, EventArgs e) {
Button button = sender as Button;
public void conBtnClick(object sender, EventArgs e) {
Button button = sender as Button;
if (button.Tag.GetType() == typeof(Joycon)) {
Joycon v = (Joycon)button.Tag;
if (button.Tag.GetType() == typeof(Joycon)) {
Joycon v = (Joycon)button.Tag;
if (v.other == null && !v.isPro) { // needs connecting to other joycon (so messy omg)
bool succ = false;
if (v.other == null && !v.isPro) { // needs connecting to other joycon (so messy omg)
bool succ = false;
if (Program.mgr.j.Count == 1) { // when want to have a single joycon in vertical mode
v.other = v; // hacky; implement check in Joycon.cs to account for this
succ = true;
} else {
foreach (Joycon jc in Program.mgr.j) {
if (!jc.isPro && jc.isLeft != v.isLeft && jc != v && jc.other == null) {
v.other = jc;
jc.other = v;
if (Program.mgr.j.Count == 1) { // when want to have a single joycon in vertical mode
v.other = v; // hacky; implement check in Joycon.cs to account for this
succ = true;
} else {
foreach (Joycon jc in Program.mgr.j) {
if (!jc.isPro && jc.isLeft != v.isLeft && jc != v && jc.other == null) {
v.other = jc;
jc.other = v;
//Set both Joycon LEDs to the one with the lowest ID
byte led = jc.LED <= v.LED ? jc.LED : v.LED;
jc.LED = led;
v.LED = led;
jc.SetPlayerLED(led);
v.SetPlayerLED(led);
//Set both Joycon LEDs to the one with the lowest ID
byte led = jc.LED <= v.LED ? jc.LED : v.LED;
jc.LED = led;
v.LED = led;
jc.SetPlayerLED(led);
v.SetPlayerLED(led);
if (v.out_xbox != null) {
v.out_xbox.Disconnect();
v.out_xbox = null;
}
if (v.out_xbox != null) {
v.out_xbox.Disconnect();
v.out_xbox = null;
}
if (v.out_ds4 != null) {
v.out_ds4.Disconnect();
v.out_ds4 = null;
}
if (v.out_ds4 != null) {
v.out_ds4.Disconnect();
v.out_ds4 = null;
}
// setting the other joycon's button image
foreach (Button b in con)
if (b.Tag == jc)
b.BackgroundImage = jc.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
// setting the other joycon's button image
foreach (Button b in con)
if (b.Tag == jc)
b.BackgroundImage = jc.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
succ = true;
break;
}
}
}
succ = true;
break;
}
}
}
if (succ)
foreach (Button b in con)
if (b.Tag == v)
b.BackgroundImage = v.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
} else if (v.other != null && !v.isPro) { // needs disconnecting from other joycon
ReenableViGEm(v);
ReenableViGEm(v.other);
if (succ)
foreach (Button b in con)
if (b.Tag == v)
b.BackgroundImage = v.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
} else if (v.other != null && !v.isPro) { // needs disconnecting from other joycon
ReenableViGEm(v);
ReenableViGEm(v.other);
button.BackgroundImage = v.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
button.BackgroundImage = v.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
foreach (Button b in con)
if (b.Tag == v.other)
b.BackgroundImage = v.other.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
foreach (Button b in con)
if (b.Tag == v.other)
b.BackgroundImage = v.other.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
//Set original Joycon LEDs
v.other.LED = (byte)(0x1 << v.other.PadId);
v.LED = (byte)(0x1 << v.PadId);
v.other.SetPlayerLED(v.other.LED);
v.SetPlayerLED(v.LED);
//Set original Joycon LEDs
v.other.LED = (byte)(0x1 << v.other.PadId);
v.LED = (byte)(0x1 << v.PadId);
v.other.SetPlayerLED(v.other.LED);
v.SetPlayerLED(v.LED);
v.other.other = null;
v.other = null;
}
}
}
v.other.other = null;
v.other = null;
}
}
}
private void startInTrayBox_CheckedChanged(object sender, EventArgs e) {
Config.SetValue("StartInTray", startInTrayBox.Checked ? "1" : "0");
Config.Save();
}
private void startInTrayBox_CheckedChanged(object sender, EventArgs e) {
Config.SetValue("StartInTray", startInTrayBox.Checked ? "1" : "0");
Config.Save();
}
private void btn_open3rdP_Click(object sender, EventArgs e) {
_3rdPartyControllers partyForm = new _3rdPartyControllers();
partyForm.ShowDialog();
}
private void btn_open3rdP_Click(object sender, EventArgs e) {
_3rdPartyControllers partyForm = new _3rdPartyControllers();
partyForm.ShowDialog();
}
private void settingsApply_Click(object sender, EventArgs e) {
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
private void settingsApply_Click(object sender, EventArgs e) {
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
for (int row = 0; row < ConfigurationManager.AppSettings.AllKeys.Length; row++) {
var valCtl = settingsTable.GetControlFromPosition(1, row);
var KeyCtl = settingsTable.GetControlFromPosition(0, row).Text;
for (int row = 0; row < ConfigurationManager.AppSettings.AllKeys.Length; row++) {
var valCtl = settingsTable.GetControlFromPosition(1, row);
var KeyCtl = settingsTable.GetControlFromPosition(0, row).Text;
if (valCtl.GetType() == typeof(CheckBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((CheckBox)valCtl).Checked.ToString().ToLower();
} else if (valCtl.GetType() == typeof(TextBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((TextBox)valCtl).Text.ToLower();
}
}
if (valCtl.GetType() == typeof(CheckBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((CheckBox)valCtl).Checked.ToString().ToLower();
} else if (valCtl.GetType() == typeof(TextBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((TextBox)valCtl).Text.ToLower();
}
}
try {
configFile.Save(ConfigurationSaveMode.Modified);
} catch (ConfigurationErrorsException) {
AppendTextBox("Error writing app settings.\r\n");
}
try {
configFile.Save(ConfigurationSaveMode.Modified);
} catch (ConfigurationErrorsException) {
AppendTextBox("Error writing app settings.\r\n");
}
ConfigurationManager.AppSettings["AutoPowerOff"] = "false"; // Prevent joycons poweroff when applying settings
Application.Restart();
Environment.Exit(0);
}
ConfigurationManager.AppSettings["AutoPowerOff"] = "false"; // Prevent joycons poweroff when applying settings
Application.Restart();
Environment.Exit(0);
}
void ReenableViGEm(Joycon v) {
if (showAsXInput && v.out_xbox == null) {
v.out_xbox = new Controller.OutputControllerXbox360();
void ReenableViGEm(Joycon v) {
if (showAsXInput && v.out_xbox == null) {
v.out_xbox = new Controller.OutputControllerXbox360();
if (toRumble)
v.out_xbox.FeedbackReceived += v.ReceiveRumble;
v.out_xbox.Connect();
}
if (toRumble)
v.out_xbox.FeedbackReceived += v.ReceiveRumble;
v.out_xbox.Connect();
}
if (showAsDS4 && v.out_ds4 == null) {
v.out_ds4 = new Controller.OutputControllerDualShock4();
if (showAsDS4 && v.out_ds4 == null) {
v.out_ds4 = new Controller.OutputControllerDualShock4();
if (toRumble)
v.out_ds4.FeedbackReceived += v.Ds4_FeedbackReceived;
v.out_ds4.Connect();
}
}
if (toRumble)
v.out_ds4.FeedbackReceived += v.Ds4_FeedbackReceived;
v.out_ds4.Connect();
}
}
private void foldLbl_Click(object sender, EventArgs e) {
rightPanel.Visible = !rightPanel.Visible;
foldLbl.Text = rightPanel.Visible ? "<" : ">";
}
private void foldLbl_Click(object sender, EventArgs e) {
rightPanel.Visible = !rightPanel.Visible;
foldLbl.Text = rightPanel.Visible ? "<" : ">";
}
private void cbBox_Changed(object sender, EventArgs e) {
var coord = settingsTable.GetPositionFromControl(sender as Control);
private void cbBox_Changed(object sender, EventArgs e) {
var coord = settingsTable.GetPositionFromControl(sender as Control);
var valCtl = settingsTable.GetControlFromPosition(coord.Column, coord.Row);
var KeyCtl = settingsTable.GetControlFromPosition(coord.Column - 1, coord.Row).Text;
var valCtl = settingsTable.GetControlFromPosition(coord.Column, coord.Row);
var KeyCtl = settingsTable.GetControlFromPosition(coord.Column - 1, coord.Row).Text;
try {
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (valCtl.GetType() == typeof(CheckBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((CheckBox)valCtl).Checked.ToString().ToLower();
} else if (valCtl.GetType() == typeof(TextBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((TextBox)valCtl).Text.ToLower();
}
try {
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (valCtl.GetType() == typeof(CheckBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((CheckBox)valCtl).Checked.ToString().ToLower();
} else if (valCtl.GetType() == typeof(TextBox) && settings[KeyCtl] != null) {
settings[KeyCtl].Value = ((TextBox)valCtl).Text.ToLower();
}
if (KeyCtl == "HomeLEDOn") {
bool on = settings[KeyCtl].Value.ToLower() == "true";
foreach (Joycon j in Program.mgr.j) {
j.SetHomeLight(on);
}
}
if (KeyCtl == "HomeLEDOn") {
bool on = settings[KeyCtl].Value.ToLower() == "true";
foreach (Joycon j in Program.mgr.j) {
j.SetHomeLight(on);
}
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
} catch (ConfigurationErrorsException) {
AppendTextBox("Error writing app settings\r\n");
Trace.WriteLine(String.Format("rw {0}, column {1}, {2}, {3}", coord.Row, coord.Column, sender.GetType(), KeyCtl));
}
}
private void StartCalibrate(object sender, EventArgs e) {
if (Program.mgr.j.Count == 0) {
this.console.Text = "Please connect a single pro controller.";
return;
}
if (Program.mgr.j.Count > 1) {
this.console.Text = "Please calibrate one controller at a time (disconnect others).";
return;
}
this.AutoCalibrate.Enabled = false;
countDown = new Timer();
this.count = 4;
this.CountDown(null, null);
countDown.Tick += new EventHandler(CountDown);
countDown.Interval = 1000;
countDown.Enabled = true;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
} catch (ConfigurationErrorsException) {
AppendTextBox("Error writing app settings\r\n");
Trace.WriteLine(String.Format("rw {0}, column {1}, {2}, {3}", coord.Row, coord.Column, sender.GetType(), KeyCtl));
}
}
private void StartCalibrate(object sender, EventArgs e) {
if (Program.mgr.j.Count == 0) {
this.console.Text = "Please connect a single pro controller.";
return;
}
if (Program.mgr.j.Count > 1) {
this.console.Text = "Please calibrate one controller at a time (disconnect others).";
return;
}
this.AutoCalibrate.Enabled = false;
countDown = new Timer();
this.count = 4;
this.CountDown(null, null);
countDown.Tick += new EventHandler(CountDown);
countDown.Interval = 1000;
countDown.Enabled = true;
}
private void StartGetData() {
this.xG.Clear(); this.yG.Clear(); this.zG.Clear();
this.xA.Clear(); this.yA.Clear(); this.zA.Clear();
countDown = new Timer();
this.count = 3;
this.calibrate = true;
countDown.Tick += new EventHandler(CalcData);
countDown.Interval = 1000;
countDown.Enabled = true;
}
private void StartGetData() {
this.xG.Clear(); this.yG.Clear(); this.zG.Clear();
this.xA.Clear(); this.yA.Clear(); this.zA.Clear();
countDown = new Timer();
this.count = 3;
this.calibrate = true;
countDown.Tick += new EventHandler(CalcData);
countDown.Interval = 1000;
countDown.Enabled = true;
}
private void btn_reassign_open_Click(object sender, EventArgs e) {
Reassign mapForm = new Reassign();
mapForm.ShowDialog();
}
private void btn_reassign_open_Click(object sender, EventArgs e) {
Reassign mapForm = new Reassign();
mapForm.ShowDialog();
}
private void CountDown(object sender, EventArgs e) {
if (this.count == 0) {
this.console.Text = "Calibrating...";
countDown.Stop();
this.StartGetData();
} else {
this.console.Text = "Plese keep the controller flat." + "\r\n";
this.console.Text += "Calibration will start in " + this.count + " seconds.";
this.count--;
}
}
private void CalcData(object sender, EventArgs e) {
if (this.count == 0) {
countDown.Stop();
this.calibrate = false;
string serNum = Program.mgr.j.First().serial_number;
int serIndex = this.findSer(serNum);
float[] Arr = new float[6] { 0, 0, 0, 0, 0, 0 };
if (serIndex == -1) {
this.caliData.Add(new KeyValuePair<string, float[]>(
serNum,
Arr
));
} else {
Arr = this.caliData[serIndex].Value;
}
Random rnd = new Random();
Arr[0] = (float)quickselect_median(this.xG, rnd.Next);
Arr[1] = (float)quickselect_median(this.yG, rnd.Next);
Arr[2] = (float)quickselect_median(this.zG, rnd.Next);
Arr[3] = (float)quickselect_median(this.xA, rnd.Next);
Arr[4] = (float)quickselect_median(this.yA, rnd.Next);
Arr[5] = (float)quickselect_median(this.zA, rnd.Next) - 4010; //Joycon.cs acc_sen 16384
this.console.Text += "Calibration completed!!!" + "\r\n";
Config.SaveCaliData(this.caliData);
Program.mgr.j.First().getActiveData();
this.AutoCalibrate.Enabled = true;
} else {
this.count--;
}
private void CountDown(object sender, EventArgs e) {
if (this.count == 0) {
this.console.Text = "Calibrating...";
countDown.Stop();
this.StartGetData();
} else {
this.console.Text = "Plese keep the controller flat." + "\r\n";
this.console.Text += "Calibration will start in " + this.count + " seconds.";
this.count--;
}
}
private void CalcData(object sender, EventArgs e) {
if (this.count == 0) {
countDown.Stop();
this.calibrate = false;
string serNum = Program.mgr.j.First().serial_number;
int serIndex = this.findSer(serNum);
float[] Arr = new float[6] { 0, 0, 0, 0, 0, 0 };
if (serIndex == -1) {
this.caliData.Add(new KeyValuePair<string, float[]>(
serNum,
Arr
));
} else {
Arr = this.caliData[serIndex].Value;
}
Random rnd = new Random();
Arr[0] = (float)quickselect_median(this.xG, rnd.Next);
Arr[1] = (float)quickselect_median(this.yG, rnd.Next);
Arr[2] = (float)quickselect_median(this.zG, rnd.Next);
Arr[3] = (float)quickselect_median(this.xA, rnd.Next);
Arr[4] = (float)quickselect_median(this.yA, rnd.Next);
Arr[5] = (float)quickselect_median(this.zA, rnd.Next) - 4010; //Joycon.cs acc_sen 16384
this.console.Text += "Calibration completed!!!" + "\r\n";
Config.SaveCaliData(this.caliData);
Program.mgr.j.First().getActiveData();
this.AutoCalibrate.Enabled = true;
} else {
this.count--;
}
}
private double quickselect_median(List<int> l, Func<int, int> pivot_fn) {
int ll = l.Count;
if (ll % 2 == 1) {
return this.quickselect(l, ll / 2, pivot_fn);
} else {
return 0.5 * (quickselect(l, ll / 2 - 1, pivot_fn) + quickselect(l, ll / 2, pivot_fn));
}
}
}
private double quickselect_median(List<int> l, Func<int, int> pivot_fn) {
int ll = l.Count;
if (ll % 2 == 1) {
return this.quickselect(l, ll / 2, pivot_fn);
} else {
return 0.5 * (quickselect(l, ll / 2 - 1, pivot_fn) + quickselect(l, ll / 2, pivot_fn));
}
}
private int quickselect(List<int> l, int k, Func<int, int> pivot_fn) {
if (l.Count == 1 && k == 0) {
return l[0];
}
int pivot = l[pivot_fn(l.Count)];
List<int> lows = l.Where(x => x < pivot).ToList();
List<int> highs = l.Where(x => x > pivot).ToList();
List<int> pivots = l.Where(x => x == pivot).ToList();
if (k < lows.Count) {
return quickselect(lows, k, pivot_fn);
} else if (k < (lows.Count + pivots.Count)) {
return pivots[0];
} else {
return quickselect(highs, k - lows.Count - pivots.Count, pivot_fn);
}
}
private int quickselect(List<int> l, int k, Func<int, int> pivot_fn) {
if (l.Count == 1 && k == 0) {
return l[0];
}
int pivot = l[pivot_fn(l.Count)];
List<int> lows = l.Where(x => x < pivot).ToList();
List<int> highs = l.Where(x => x > pivot).ToList();
List<int> pivots = l.Where(x => x == pivot).ToList();
if (k < lows.Count) {
return quickselect(lows, k, pivot_fn);
} else if (k < (lows.Count + pivots.Count)) {
return pivots[0];
} else {
return quickselect(highs, k - lows.Count - pivots.Count, pivot_fn);
}
}
public float[] activeCaliData(string serNum) {
for (int i = 0; i < this.caliData.Count; i++) {
if (this.caliData[i].Key == serNum) {
return this.caliData[i].Value;
}
}
return this.caliData[0].Value;
}
public float[] activeCaliData(string serNum) {
for (int i = 0; i < this.caliData.Count; i++) {
if (this.caliData[i].Key == serNum) {
return this.caliData[i].Value;
}
}
return this.caliData[0].Value;
}
private int findSer(string serNum) {
for (int i = 0; i < this.caliData.Count; i++) {
if (this.caliData[i].Key == serNum) {
return i;
}
}
return -1;
}
}
private int findSer(string serNum) {
for (int i = 0; i < this.caliData.Count; i++) {
if (this.caliData[i].Key == serNum) {
return i;
}
}
return -1;
}
}
}

View file

@ -15,6 +15,7 @@ using System.Timers;
using System.Web.Configuration;
using System.Windows.Forms;
using Nefarius.ViGEm.Client;
using static BetterJoyForCemu._3rdPartyControllers;
using static BetterJoyForCemu.HIDapi;
namespace BetterJoyForCemu {
@ -95,15 +96,28 @@ namespace BetterJoyForCemu {
}
}
private ushort TypeToProdId(byte type) {
switch (type) {
case 1:
return product_pro;
case 2:
return product_l;
case 3:
return product_r;
}
return 0;
}
public void CheckForNewControllers() {
// move all code for initializing devices here and well as the initial code from Start()
bool isLeft = false;
IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0);
IntPtr ptr = HIDapi.hid_enumerate(0x0, 0x0);
IntPtr top_ptr = ptr;
hid_device_info enumerate; // Add device to list
bool foundNew = false;
while (ptr != IntPtr.Zero) {
SController thirdParty = null;
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
if (enumerate.serial_number == null) {
@ -117,9 +131,21 @@ namespace BetterJoyForCemu {
}
bool validController = (enumerate.product_id == product_l || enumerate.product_id == product_r ||
enumerate.product_id == product_pro || enumerate.product_id == product_snes);
enumerate.product_id == product_pro || enumerate.product_id == product_snes) && enumerate.vendor_id == vendor_id;
// check list of custom controllers specified
foreach (SController v in Program.thirdPartyCons) {
if (enumerate.vendor_id == v.vendor_id && enumerate.product_id == v.product_id) {
validController = true;
thirdParty = v;
break;
}
}
ushort prod_id = thirdParty == null ? enumerate.product_id : TypeToProdId(thirdParty.type);
if (prod_id == 0)
continue; // controller was not assigned a type
if (validController && !ControllerAlreadyAdded(enumerate.path)) {
switch (enumerate.product_id) {
switch (prod_id) {
case product_l:
isLeft = true;
form.AppendTextBox("Left Joy-Con connected.\r\n"); break;
@ -166,8 +192,8 @@ namespace BetterJoyForCemu {
break;
}
bool isPro = enumerate.product_id == product_pro;
bool isSnes = enumerate.product_id == product_snes;
bool isPro = prod_id == product_pro;
bool isSnes = prod_id == product_snes;
j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, enumerate.serial_number, j.Count, isPro, isSnes));
foundNew = true;
@ -179,7 +205,7 @@ namespace BetterJoyForCemu {
ii++;
if (!v.Enabled) {
System.Drawing.Bitmap temp;
switch (enumerate.product_id) {
switch (prod_id) {
case (product_l):
temp = Properties.Resources.jc_left_s; break;
case (product_r):
@ -210,8 +236,12 @@ namespace BetterJoyForCemu {
}
byte[] mac = new byte[6];
for (int n = 0; n < 6; n++)
mac[n] = byte.Parse(enumerate.serial_number.Substring(n * 2, 2), System.Globalization.NumberStyles.HexNumber);
try {
for (int n = 0; n < 6; n++)
mac[n] = byte.Parse(enumerate.serial_number.Substring(n * 2, 2), System.Globalization.NumberStyles.HexNumber);
} catch (Exception e) {
// could not parse mac address
}
j[j.Count - 1].PadMacAddress = new PhysicalAddress(mac);
}
@ -330,6 +360,8 @@ namespace BetterJoyForCemu {
static public bool useHIDG = Boolean.Parse(ConfigurationManager.AppSettings["UseHIDG"]);
public static List<SController> thirdPartyCons = new List<SController>();
private static WindowsInput.Events.Sources.IKeyboardEventSource keyboard;
private static WindowsInput.Events.Sources.IMouseEventSource mouse;
@ -390,6 +422,10 @@ namespace BetterJoyForCemu {
}
}
// a bit hacky
_3rdPartyControllers partyForm = new _3rdPartyControllers();
partyForm.CopyCustomControllers();
mgr = new JoyconManager();
mgr.form = form;
mgr.Awake();