Added ability to toggle for single/double joycon mode.

Reworked UI further.
Final commit for v5.
This commit is contained in:
David Khachaturov 2018-08-23 15:48:19 +03:00
parent be3c73bc96
commit 37aba95e81
9 changed files with 215 additions and 22 deletions

View file

@ -125,6 +125,8 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Icons\cross.png" />
<Content Include="Icons\jc_left_s.png" />
<Content Include="Icons\jc_right_s.png" />
<Resource Include="Icons\jc_left.png" />
<Resource Include="Icons\jc_right.png" />
<Resource Include="Icons\pro.png" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -205,7 +205,7 @@ namespace BetterJoyForCemu {
public int packetCounter = 0;
public Xbox360Controller xin;
Xbox360Report report;
public Xbox360Report report;
int rumblePeriod = Int32.Parse(ConfigurationManager.AppSettings["RumblePeriod"]);
int lowFreq = Int32.Parse(ConfigurationManager.AppSettings["LowFreqRumble"]);
@ -420,7 +420,7 @@ namespace BetterJoyForCemu {
return ret;
}
private Thread PollThreadObj;
private Thread PollThreadObj; // pro times out over time randomly if it was USB and then bluetooth??
private void Poll() {
int attempts = 0;
while (!stop_polling & state > state_.NO_JOYCONS) {

View file

@ -38,23 +38,27 @@
this.con3 = new System.Windows.Forms.Button();
this.con2 = new System.Windows.Forms.Button();
this.con1 = new System.Windows.Forms.Button();
this.loc1 = new System.Windows.Forms.Button();
this.loc2 = new System.Windows.Forms.Button();
this.loc3 = new System.Windows.Forms.Button();
this.loc4 = new System.Windows.Forms.Button();
this.contextMenu.SuspendLayout();
this.conCntrls.SuspendLayout();
this.SuspendLayout();
//
// console
//
this.console.Location = new System.Drawing.Point(12, 114);
this.console.Location = new System.Drawing.Point(12, 132);
this.console.Multiline = true;
this.console.Name = "console";
this.console.ReadOnly = true;
this.console.Size = new System.Drawing.Size(262, 118);
this.console.Size = new System.Drawing.Size(262, 100);
this.console.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 98);
this.label1.Location = new System.Drawing.Point(9, 116);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 13);
this.label1.TabIndex = 1;
@ -121,13 +125,17 @@
//
// conCntrls
//
this.conCntrls.Controls.Add(this.loc4);
this.conCntrls.Controls.Add(this.loc3);
this.conCntrls.Controls.Add(this.loc2);
this.conCntrls.Controls.Add(this.loc1);
this.conCntrls.Controls.Add(this.con4);
this.conCntrls.Controls.Add(this.con3);
this.conCntrls.Controls.Add(this.con2);
this.conCntrls.Controls.Add(this.con1);
this.conCntrls.Location = new System.Drawing.Point(12, 12);
this.conCntrls.Name = "conCntrls";
this.conCntrls.Size = new System.Drawing.Size(262, 83);
this.conCntrls.Size = new System.Drawing.Size(262, 100);
this.conCntrls.TabIndex = 0;
this.conCntrls.TabStop = false;
this.conCntrls.Text = "Connected Controllers";
@ -180,6 +188,42 @@
this.con1.TabStop = false;
this.con1.UseVisualStyleBackColor = true;
//
// loc1
//
this.loc1.Location = new System.Drawing.Point(6, 80);
this.loc1.Name = "loc1";
this.loc1.Size = new System.Drawing.Size(58, 20);
this.loc1.TabIndex = 4;
this.loc1.Text = "Locate";
this.loc1.UseVisualStyleBackColor = true;
//
// loc2
//
this.loc2.Location = new System.Drawing.Point(70, 80);
this.loc2.Name = "loc2";
this.loc2.Size = new System.Drawing.Size(58, 20);
this.loc2.TabIndex = 5;
this.loc2.Text = "Locate";
this.loc2.UseVisualStyleBackColor = true;
//
// loc3
//
this.loc3.Location = new System.Drawing.Point(134, 80);
this.loc3.Name = "loc3";
this.loc3.Size = new System.Drawing.Size(58, 20);
this.loc3.TabIndex = 6;
this.loc3.Text = "Locate";
this.loc3.UseVisualStyleBackColor = true;
//
// loc4
//
this.loc4.Location = new System.Drawing.Point(198, 80);
this.loc4.Name = "loc4";
this.loc4.Size = new System.Drawing.Size(58, 20);
this.loc4.TabIndex = 7;
this.loc4.Text = "Locate";
this.loc4.UseVisualStyleBackColor = true;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -191,6 +235,7 @@
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.console);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "MainForm";
@ -220,5 +265,9 @@
private System.Windows.Forms.Button con4;
private System.Windows.Forms.Button con3;
private System.Windows.Forms.Button con2;
private System.Windows.Forms.Button loc4;
private System.Windows.Forms.Button loc3;
private System.Windows.Forms.Button loc2;
private System.Windows.Forms.Button loc1;
}
}

View file

@ -1,4 +1,6 @@
using System;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.Xbox360;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
@ -12,12 +14,13 @@ using System.Xml.Linq;
namespace BetterJoyForCemu {
public partial class MainForm : Form {
public List<Button> con;
public List<Button> con, loc;
public MainForm() {
InitializeComponent();
con = new List<Button> { con1, con2, con3, con4 };
loc = new List<Button> { loc1, loc2, loc3, loc4 };
}
private void MainForm_Resize(object sender, EventArgs e) {
@ -52,7 +55,7 @@ namespace BetterJoyForCemu {
} catch { }
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // this does not work, for some reason. Fix before release
try {
Program.Stop();
Close();
@ -77,16 +80,107 @@ namespace BetterJoyForCemu {
console.AppendText(value);
}
public void conBtnClick(object sender, EventArgs e) {
Button button = sender as Button;
bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
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 (button.ClientRectangle.Contains(PointToClient(Control.MousePosition))) { // hacky but allows both l&r clicks
if (button.Tag.GetType() == typeof(Joycon)) {
Joycon v = (Joycon)button.Tag;
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;
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)
int found = 0;
int minPadID = 10;
foreach (Joycon jc in Program.mgr.j) { // current system is designed for a maximum of two joycons connected to the PC
if (!jc.isPro) {
found++;
minPadID = Math.Min(jc.PadId, minPadID);
}
jc.LED = (byte)(0x1 << jc.PadId);
}
if (found == 2) {
AppendTextBox("Both joycons successfully found.\r\n");
Joycon temp = null;
foreach (Joycon jc in Program.mgr.j) {
if (!jc.isPro) {
jc.LED = (byte)(0x1 << minPadID);
if (temp == null)
temp = jc;
else {
temp.other = jc;
jc.other = temp;
temp.xin.Dispose();
temp.xin = null;
}
foreach (Button b in con) {
if (b.Tag == jc) {
if (jc.isLeft)
b.BackgroundImage = Properties.Resources.jc_left;
else
b.BackgroundImage = Properties.Resources.jc_right;
}
}
}
} // Join up the two joycons
}
} else if (v.other != null && !v.isPro) { // needs disconnecting from other joycon
if (v.xin == null) {
ReenableXinput(v);
v.xin.Connect();
}
if (v.other.xin == null) {
ReenableXinput(v.other);
v.other.xin.Connect();
}
if (v.isLeft)
button.BackgroundImage = Properties.Resources.jc_left_s;
else
button.BackgroundImage = Properties.Resources.jc_right_s;
foreach (Button b in con) {
if (b.Tag == v.other) {
if (v.other.isLeft)
b.BackgroundImage = Properties.Resources.jc_left_s;
else
b.BackgroundImage = Properties.Resources.jc_right_s;
}
}
v.other.other = null;
v.other = null;
}
}
}
void ReenableXinput(Joycon v) {
if (showAsXInput) {
v.xin = new Xbox360Controller(Program.emClient);
if (toRumble)
v.xin.FeedbackReceived += v.ReceiveRumble;
v.report = new Xbox360Report();
}
}
}
}

View file

@ -71,12 +71,16 @@ namespace BetterJoyForCemu {
for (int i = 0; i < j.Count; i++) {
Joycon v = j[i];
if (v.state == Joycon.state_.DROPPED) {
if (v.other != null)
v.other.other = null; // The other of the other is the joycon itself
v.Detach(); rem.Add(v);
foreach (Button b in form.con) {
if (b.Enabled & b.Tag == v) {
b.Invoke(new MethodInvoker(delegate {
b.Enabled = false;
b.BackgroundImage = Properties.Resources.cross;
}));
break;
}
@ -105,6 +109,7 @@ namespace BetterJoyForCemu {
IntPtr top_ptr = ptr;
hid_device_info enumerate; // Add device to list
bool foundNew = false;
while (ptr != IntPtr.Zero) {
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
@ -159,17 +164,20 @@ namespace BetterJoyForCemu {
j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001"));
foundNew = true;
j.Last().form = form;
if (j.Count < 5) {
int ii = -1;
foreach (Button v in form.con) {
ii++;
if (!v.Enabled) {
System.Drawing.Bitmap temp;
switch (enumerate.product_id) {
case (product_l):
temp = Properties.Resources.jc_left; break;
temp = Properties.Resources.jc_left_s; break;
case (product_r):
temp = Properties.Resources.jc_right; break;
temp = Properties.Resources.jc_right_s; break;
case (product_pro):
temp = Properties.Resources.pro; break;
default:
@ -182,6 +190,12 @@ namespace BetterJoyForCemu {
v.Click += new EventHandler(form.conBtnClick);
v.BackgroundImage = temp;
}));
form.loc[ii].Invoke(new MethodInvoker(delegate {
form.loc[ii].Tag = v;
form.loc[ii].Click += new EventHandler(form.locBtnClick);
}));
break;
}
}
@ -202,12 +216,11 @@ namespace BetterJoyForCemu {
if (!v.isPro) {
found++;
minPadID = Math.Min(v.PadId, minPadID);
} else {
v.LED = (byte)(0x1 << v.PadId);
}
v.LED = (byte)(0x1 << v.PadId);
}
if (found == 2) {
if (found == 2 && foundNew) {
form.AppendTextBox("Both joycons successfully found.\r\n");
Joycon temp = null;
foreach (Joycon v in j) {
@ -223,6 +236,15 @@ namespace BetterJoyForCemu {
temp.xin.Dispose();
temp.xin = null;
}
foreach (Button b in form.con) {
if (b.Tag == v) {
if (v.isLeft)
b.BackgroundImage = Properties.Resources.jc_left;
else
b.BackgroundImage = Properties.Resources.jc_right;
}
}
}
} // Join up the two joycons
}
@ -308,7 +330,7 @@ namespace BetterJoyForCemu {
private static readonly HttpClient client = new HttpClient();
static JoyconManager mgr;
public static JoyconManager mgr;
static HighResTimer timer;
static string pid;

View file

@ -80,6 +80,16 @@ namespace BetterJoyForCemu.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap jc_left_s {
get {
object obj = ResourceManager.GetObject("jc_left_s", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@ -90,6 +100,16 @@ namespace BetterJoyForCemu.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap jc_right_s {
get {
object obj = ResourceManager.GetObject("jc_right_s", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -121,13 +121,19 @@
<data name="pro" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\pro.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="cross" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="jc_left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\jc_left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="jc_right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\jc_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="cross" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="jc_left_s" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\jc_left_s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="jc_right_s" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icons\jc_right_s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>