Merge pull request #149 from xqdoo00o/master
feat for non-original controller; thank you xqdoo00o
This commit is contained in:
commit
fa926f479f
6 changed files with 352 additions and 74 deletions
|
@ -44,5 +44,9 @@
|
|||
<!-- Should prevent any more issues of the controller being unusable after the program (even though this can be fixed if you read the README) -->
|
||||
<!-- Default: true -->
|
||||
<add key="PurgeAffectedDevices" value="true" />
|
||||
<!-- Determines whether or not the program will use mannually calibrate gyro data for non-original controller. -->
|
||||
<!-- When "true", click "Calibrate" button once to get gyro calibrate data.-->
|
||||
<!-- Default: false -->
|
||||
<add key="NonOriginalController" value="false" />
|
||||
</appSettings>
|
||||
</configuration>
|
|
@ -10,24 +10,48 @@ namespace BetterJoyForCemu {
|
|||
const string PATH = "settings";
|
||||
static Dictionary<string, bool> variables = new Dictionary<string, bool>();
|
||||
|
||||
public static void Init() {
|
||||
public static void Init(List<KeyValuePair<string, float[]>> caliData) {
|
||||
variables["ProgressiveScan"] = true;
|
||||
variables["StartInTray"] = false;
|
||||
|
||||
if (File.Exists(PATH)) {
|
||||
using (StreamReader file = new StreamReader(PATH)) {
|
||||
string line = String.Empty;
|
||||
int lineNO = 0;
|
||||
while ((line = file.ReadLine()) != null) {
|
||||
string[] vs = line.Split();
|
||||
try {
|
||||
variables[vs[0]] = Boolean.Parse(vs[1]);
|
||||
if (lineNO < 2){
|
||||
variables[vs[0]] = Boolean.Parse(vs[1]);
|
||||
} else {
|
||||
caliData.Clear();
|
||||
for (int i = 0; i < vs.Length; i++){
|
||||
string[] caliArr = vs[i].Split(',');
|
||||
float[] newArr = new float[6];
|
||||
for (int j = 1; j < caliArr.Length; j++){
|
||||
newArr[j-1] = float.Parse(caliArr[j]);
|
||||
}
|
||||
caliData.Add(new KeyValuePair<string, float[]>(
|
||||
caliArr[0],
|
||||
newArr
|
||||
));
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
lineNO++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
using (StreamWriter file = new StreamWriter(PATH)) {
|
||||
foreach (string k in variables.Keys)
|
||||
file.WriteLine(String.Format("{0} {1}", k, variables[k]));
|
||||
string caliStr = "";
|
||||
for(int i = 0; i < caliData.Count; i++){
|
||||
string space = " ";
|
||||
if (i == 0) space = "";
|
||||
caliStr += space + caliData[i].Key + "," + String.Join(",", caliData[i].Value);
|
||||
}
|
||||
file.WriteLine(caliStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,13 +63,28 @@ namespace BetterJoyForCemu {
|
|||
return variables[key];
|
||||
}
|
||||
|
||||
public static void SaveCaliData(List<KeyValuePair<string, float[]>> caliData){
|
||||
string[] txt = File.ReadAllLines(PATH);
|
||||
string caliStr = "";
|
||||
for (int i = 0; i < caliData.Count; i++){
|
||||
string space = " ";
|
||||
if (i == 0) space = "";
|
||||
caliStr += space + caliData[i].Key + "," + String.Join(",", caliData[i].Value);
|
||||
}
|
||||
txt[2] = caliStr;
|
||||
File.WriteAllLines(PATH, txt);
|
||||
}
|
||||
|
||||
public static void Save(string key, bool value) {
|
||||
variables[key] = value;
|
||||
|
||||
using (StreamWriter file = new StreamWriter(PATH, false)) {
|
||||
foreach (string k in variables.Keys)
|
||||
file.WriteLine(String.Format("{0} {1}", k, variables[k]));
|
||||
string[] txt = File.ReadAllLines(PATH);
|
||||
int NO = 0;
|
||||
foreach (string k in variables.Keys)
|
||||
{
|
||||
txt[NO] = String.Format("{0} {1}", k, variables[k]);
|
||||
NO++;
|
||||
}
|
||||
File.WriteAllLines(PATH, txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,6 +102,17 @@ namespace BetterJoyForCemu {
|
|||
private Int16[] gyr_sensiti = { 0, 0, 0 };
|
||||
private Vector3 gyr_g;
|
||||
|
||||
private short[] acc_sen = new short[3]{
|
||||
16384,
|
||||
16384,
|
||||
16384
|
||||
};
|
||||
private short[] gyr_sen = new short[3]{
|
||||
18642,
|
||||
18642,
|
||||
18642
|
||||
};
|
||||
|
||||
private Int16[] pro_hor_offset = { -710, 0, 0 };
|
||||
private Int16[] left_hor_offset = { 0, 0, 0 };
|
||||
private Int16[] right_hor_offset = { 0, 0, 0 };
|
||||
|
@ -219,7 +230,13 @@ namespace BetterJoyForCemu {
|
|||
|
||||
public byte LED = 0x0;
|
||||
|
||||
public Joycon(IntPtr handle_, bool imu, bool localize, float alpha, bool left, string path, int id = 0, bool isPro=false, bool usb = false) {
|
||||
public string serial_number;
|
||||
|
||||
private float[] activeData;
|
||||
|
||||
public Joycon(IntPtr handle_, bool imu, bool localize, float alpha, bool left, string path, string serialNum, int id = 0, bool isPro=false) {
|
||||
serial_number = serialNum;
|
||||
activeData = new float[6];
|
||||
handle = handle_;
|
||||
imu_enabled = imu;
|
||||
do_localize = localize;
|
||||
|
@ -230,7 +247,7 @@ namespace BetterJoyForCemu {
|
|||
PadId = id;
|
||||
LED = (byte)(0x1 << PadId);
|
||||
this.isPro = isPro;
|
||||
isUSB = usb;
|
||||
isUSB = serialNum == "000000000001";
|
||||
|
||||
this.path = path;
|
||||
|
||||
|
@ -245,6 +262,11 @@ namespace BetterJoyForCemu {
|
|||
}
|
||||
}
|
||||
|
||||
public void getActiveData()
|
||||
{
|
||||
this.activeData = form.activeCaliData(serial_number);
|
||||
}
|
||||
|
||||
public void ReceiveRumble(object sender, Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360FeedbackReceivedEventArgs e) {
|
||||
SetRumble(lowFreq, highFreq, (float) e.LargeMotor / (float) 255, rumblePeriod);
|
||||
|
||||
|
@ -520,13 +542,21 @@ namespace BetterJoyForCemu {
|
|||
|
||||
stick_precal[0] = (UInt16)(stick_raw[0] | ((stick_raw[1] & 0xf) << 8));
|
||||
stick_precal[1] = (UInt16)((stick_raw[1] >> 4) | (stick_raw[2] << 4));
|
||||
|
||||
stick = CenterSticks(stick_precal, stick_cal, deadzone);
|
||||
ushort[] cal = form.nonOriginal ? new ushort[6]{
|
||||
2048,
|
||||
2048,
|
||||
2048,
|
||||
2048,
|
||||
2048,
|
||||
2048
|
||||
}: stick_cal;
|
||||
ushort dz = form.nonOriginal ? (ushort)200 : deadzone;
|
||||
stick = CenterSticks(stick_precal, cal, dz);
|
||||
|
||||
if (isPro) {
|
||||
stick2_precal[0] = (UInt16)(stick2_raw[0] | ((stick2_raw[1] & 0xf) << 8));
|
||||
stick2_precal[1] = (UInt16)((stick2_raw[1] >> 4) | (stick2_raw[2] << 4));
|
||||
stick2 = CenterSticks(stick2_precal, stick2_cal, deadzone2);
|
||||
stick2 = CenterSticks(stick2_precal, form.nonOriginal ? cal : stick2_cal, deadzone2);
|
||||
}
|
||||
|
||||
// Read other Joycon's sticks
|
||||
|
@ -677,33 +707,74 @@ namespace BetterJoyForCemu {
|
|||
acc_r[1] = (Int16)(report_buf[15 + n * 12] | ((report_buf[16 + n * 12] << 8) & 0xff00));
|
||||
acc_r[2] = (Int16)(report_buf[17 + n * 12] | ((report_buf[18 + n * 12] << 8) & 0xff00));
|
||||
|
||||
Int16[] offset;
|
||||
if (isPro)
|
||||
offset = pro_hor_offset;
|
||||
else if (isLeft)
|
||||
offset = left_hor_offset;
|
||||
else
|
||||
offset = right_hor_offset;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
acc_g.X = (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.X = (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
if (form.nonOriginal)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
acc_g.X = (acc_r[i] - activeData[3]) * (1.0f / acc_sen[i]) * 4.0f;
|
||||
gyr_g.X = (gyr_r[i] - activeData[0]) * (816.0f / gyr_sen[i]);
|
||||
if (form.calibrate)
|
||||
{
|
||||
form.xA.Add(acc_r[i]);
|
||||
form.xG.Add(gyr_r[i]);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
acc_g.Y = (!isLeft ? -1 : 1) * (acc_r[i] - activeData[4]) * (1.0f / acc_sen[i]) * 4.0f;
|
||||
gyr_g.Y = -(!isLeft ? -1 : 1) * (gyr_r[i] - activeData[1]) * (816.0f / gyr_sen[i]);
|
||||
if (form.calibrate)
|
||||
{
|
||||
form.yA.Add(acc_r[i]);
|
||||
form.yG.Add(gyr_r[i]);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
acc_g.Z = (!isLeft ? -1 : 1) * (acc_r[i] - activeData[5]) * (1.0f / acc_sen[i]) * 4.0f;
|
||||
gyr_g.Z = -(!isLeft ? -1 : 1) * (gyr_r[i] - activeData[2]) * (816.0f / gyr_sen[i]);
|
||||
if (form.calibrate)
|
||||
{
|
||||
form.zA.Add(acc_r[i]);
|
||||
form.zG.Add(gyr_r[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Int16[] offset;
|
||||
if (isPro)
|
||||
offset = pro_hor_offset;
|
||||
else if (isLeft)
|
||||
offset = left_hor_offset;
|
||||
else
|
||||
offset = right_hor_offset;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
acc_g.Y = (!isLeft ? -1 : 1) * (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.Y = -(!isLeft ? -1 : 1) * (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
acc_g.X = (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.X = (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
|
||||
break;
|
||||
case 2:
|
||||
acc_g.Z = (!isLeft ? -1 : 1) * (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.Z = -(!isLeft ? -1 : 1) * (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
acc_g.Y = (!isLeft ? -1 : 1) * (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.Y = -(!isLeft ? -1 : 1) * (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
break;
|
||||
case 2:
|
||||
acc_g.Z = (!isLeft ? -1 : 1) * (acc_r[i] - offset[i]) * (1.0f / (acc_sensiti[i] - acc_neutral[i])) * 4.0f;
|
||||
gyr_g.Z = -(!isLeft ? -1 : 1) * (gyr_r[i] - gyr_neutral[i]) * (816.0f / (gyr_sensiti[i] - gyr_neutral[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (other == null && !isPro) { // single joycon mode; Z do not swap, rest do
|
||||
if (isLeft) {
|
||||
|
|
87
BetterJoyForCemu/MainForm.Designer.cs
generated
87
BetterJoyForCemu/MainForm.Designer.cs
generated
|
@ -50,6 +50,7 @@
|
|||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.rightPanel = new System.Windows.Forms.Panel();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.AutoCalibrate = new System.Windows.Forms.Button();
|
||||
this.contextMenu.SuspendLayout();
|
||||
this.conCntrls.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
|
@ -58,19 +59,19 @@
|
|||
//
|
||||
// console
|
||||
//
|
||||
this.console.Location = new System.Drawing.Point(12, 132);
|
||||
this.console.Location = new System.Drawing.Point(12, 122);
|
||||
this.console.Multiline = true;
|
||||
this.console.Name = "console";
|
||||
this.console.ReadOnly = true;
|
||||
this.console.Size = new System.Drawing.Size(262, 100);
|
||||
this.console.Size = new System.Drawing.Size(262, 93);
|
||||
this.console.TabIndex = 2;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(9, 116);
|
||||
this.label1.Location = new System.Drawing.Point(9, 107);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(80, 13);
|
||||
this.label1.Size = new System.Drawing.Size(89, 12);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Console Output";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
||||
|
@ -91,21 +92,21 @@
|
|||
this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.exitToolStripMenuItem});
|
||||
this.contextMenu.Name = "contextMenu";
|
||||
this.contextMenu.Size = new System.Drawing.Size(93, 26);
|
||||
this.contextMenu.Size = new System.Drawing.Size(97, 26);
|
||||
//
|
||||
// exitToolStripMenuItem
|
||||
//
|
||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(92, 22);
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(96, 22);
|
||||
this.exitToolStripMenuItem.Text = "Exit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
// version_lbl
|
||||
//
|
||||
this.version_lbl.AutoSize = true;
|
||||
this.version_lbl.Location = new System.Drawing.Point(246, 239);
|
||||
this.version_lbl.Location = new System.Drawing.Point(246, 221);
|
||||
this.version_lbl.Name = "version_lbl";
|
||||
this.version_lbl.Size = new System.Drawing.Size(28, 13);
|
||||
this.version_lbl.Size = new System.Drawing.Size(29, 12);
|
||||
this.version_lbl.TabIndex = 2;
|
||||
this.version_lbl.Text = "v6.0";
|
||||
//
|
||||
|
@ -114,10 +115,10 @@
|
|||
this.passiveScanBox.AutoSize = true;
|
||||
this.passiveScanBox.Checked = true;
|
||||
this.passiveScanBox.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.passiveScanBox.Location = new System.Drawing.Point(12, 238);
|
||||
this.passiveScanBox.Location = new System.Drawing.Point(12, 220);
|
||||
this.passiveScanBox.Name = "passiveScanBox";
|
||||
this.passiveScanBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
|
||||
this.passiveScanBox.Size = new System.Drawing.Size(91, 17);
|
||||
this.passiveScanBox.Size = new System.Drawing.Size(96, 16);
|
||||
this.passiveScanBox.TabIndex = 4;
|
||||
this.passiveScanBox.Text = "Passive Scan";
|
||||
this.passiveScanBox.UseVisualStyleBackColor = true;
|
||||
|
@ -126,9 +127,9 @@
|
|||
// linkLabel1
|
||||
//
|
||||
this.linkLabel1.AutoSize = true;
|
||||
this.linkLabel1.Location = new System.Drawing.Point(196, 239);
|
||||
this.linkLabel1.Location = new System.Drawing.Point(196, 221);
|
||||
this.linkLabel1.Name = "linkLabel1";
|
||||
this.linkLabel1.Size = new System.Drawing.Size(42, 13);
|
||||
this.linkLabel1.Size = new System.Drawing.Size(41, 12);
|
||||
this.linkLabel1.TabIndex = 5;
|
||||
this.linkLabel1.TabStop = true;
|
||||
this.linkLabel1.Text = "Donate";
|
||||
|
@ -144,45 +145,45 @@
|
|||
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.Location = new System.Drawing.Point(12, 11);
|
||||
this.conCntrls.Name = "conCntrls";
|
||||
this.conCntrls.Size = new System.Drawing.Size(262, 100);
|
||||
this.conCntrls.Size = new System.Drawing.Size(262, 92);
|
||||
this.conCntrls.TabIndex = 0;
|
||||
this.conCntrls.TabStop = false;
|
||||
this.conCntrls.Text = "Connected Controllers";
|
||||
//
|
||||
// loc4
|
||||
//
|
||||
this.loc4.Location = new System.Drawing.Point(198, 80);
|
||||
this.loc4.Location = new System.Drawing.Point(198, 74);
|
||||
this.loc4.Name = "loc4";
|
||||
this.loc4.Size = new System.Drawing.Size(58, 20);
|
||||
this.loc4.Size = new System.Drawing.Size(58, 18);
|
||||
this.loc4.TabIndex = 7;
|
||||
this.loc4.Text = "Locate";
|
||||
this.loc4.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// loc3
|
||||
//
|
||||
this.loc3.Location = new System.Drawing.Point(134, 80);
|
||||
this.loc3.Location = new System.Drawing.Point(134, 74);
|
||||
this.loc3.Name = "loc3";
|
||||
this.loc3.Size = new System.Drawing.Size(58, 20);
|
||||
this.loc3.Size = new System.Drawing.Size(58, 18);
|
||||
this.loc3.TabIndex = 6;
|
||||
this.loc3.Text = "Locate";
|
||||
this.loc3.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// loc2
|
||||
//
|
||||
this.loc2.Location = new System.Drawing.Point(70, 80);
|
||||
this.loc2.Location = new System.Drawing.Point(70, 74);
|
||||
this.loc2.Name = "loc2";
|
||||
this.loc2.Size = new System.Drawing.Size(58, 20);
|
||||
this.loc2.Size = new System.Drawing.Size(58, 18);
|
||||
this.loc2.TabIndex = 5;
|
||||
this.loc2.Text = "Locate";
|
||||
this.loc2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// loc1
|
||||
//
|
||||
this.loc1.Location = new System.Drawing.Point(6, 80);
|
||||
this.loc1.Location = new System.Drawing.Point(6, 74);
|
||||
this.loc1.Name = "loc1";
|
||||
this.loc1.Size = new System.Drawing.Size(58, 20);
|
||||
this.loc1.Size = new System.Drawing.Size(58, 18);
|
||||
this.loc1.TabIndex = 4;
|
||||
this.loc1.Text = "Locate";
|
||||
this.loc1.UseVisualStyleBackColor = true;
|
||||
|
@ -192,9 +193,9 @@
|
|||
this.con4.BackgroundImage = global::BetterJoyForCemu.Properties.Resources.cross;
|
||||
this.con4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.con4.Enabled = false;
|
||||
this.con4.Location = new System.Drawing.Point(198, 19);
|
||||
this.con4.Location = new System.Drawing.Point(198, 18);
|
||||
this.con4.Name = "con4";
|
||||
this.con4.Size = new System.Drawing.Size(58, 58);
|
||||
this.con4.Size = new System.Drawing.Size(58, 54);
|
||||
this.con4.TabIndex = 3;
|
||||
this.con4.TabStop = false;
|
||||
this.con4.UseVisualStyleBackColor = true;
|
||||
|
@ -204,9 +205,9 @@
|
|||
this.con3.BackgroundImage = global::BetterJoyForCemu.Properties.Resources.cross;
|
||||
this.con3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.con3.Enabled = false;
|
||||
this.con3.Location = new System.Drawing.Point(134, 19);
|
||||
this.con3.Location = new System.Drawing.Point(134, 18);
|
||||
this.con3.Name = "con3";
|
||||
this.con3.Size = new System.Drawing.Size(58, 58);
|
||||
this.con3.Size = new System.Drawing.Size(58, 54);
|
||||
this.con3.TabIndex = 2;
|
||||
this.con3.TabStop = false;
|
||||
this.con3.UseVisualStyleBackColor = true;
|
||||
|
@ -216,9 +217,9 @@
|
|||
this.con2.BackgroundImage = global::BetterJoyForCemu.Properties.Resources.cross;
|
||||
this.con2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.con2.Enabled = false;
|
||||
this.con2.Location = new System.Drawing.Point(70, 19);
|
||||
this.con2.Location = new System.Drawing.Point(70, 18);
|
||||
this.con2.Name = "con2";
|
||||
this.con2.Size = new System.Drawing.Size(58, 58);
|
||||
this.con2.Size = new System.Drawing.Size(58, 54);
|
||||
this.con2.TabIndex = 1;
|
||||
this.con2.TabStop = false;
|
||||
this.con2.UseVisualStyleBackColor = true;
|
||||
|
@ -228,9 +229,9 @@
|
|||
this.con1.BackgroundImage = global::BetterJoyForCemu.Properties.Resources.cross;
|
||||
this.con1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.con1.Enabled = false;
|
||||
this.con1.Location = new System.Drawing.Point(6, 19);
|
||||
this.con1.Location = new System.Drawing.Point(6, 18);
|
||||
this.con1.Name = "con1";
|
||||
this.con1.Size = new System.Drawing.Size(58, 58);
|
||||
this.con1.Size = new System.Drawing.Size(58, 54);
|
||||
this.con1.TabIndex = 0;
|
||||
this.con1.TabStop = false;
|
||||
this.btnTip.SetToolTip(this.con1, "Click on Joycons to join/split them");
|
||||
|
@ -251,10 +252,10 @@
|
|||
// startInTrayBox
|
||||
//
|
||||
this.startInTrayBox.AutoSize = true;
|
||||
this.startInTrayBox.Location = new System.Drawing.Point(107, 238);
|
||||
this.startInTrayBox.Location = new System.Drawing.Point(107, 220);
|
||||
this.startInTrayBox.Name = "startInTrayBox";
|
||||
this.startInTrayBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
|
||||
this.startInTrayBox.Size = new System.Drawing.Size(83, 17);
|
||||
this.startInTrayBox.Size = new System.Drawing.Size(102, 16);
|
||||
this.startInTrayBox.TabIndex = 6;
|
||||
this.startInTrayBox.Text = "Start in Tray";
|
||||
this.startInTrayBox.UseVisualStyleBackColor = true;
|
||||
|
@ -262,9 +263,9 @@
|
|||
//
|
||||
// btn_open3rdP
|
||||
//
|
||||
this.btn_open3rdP.Location = new System.Drawing.Point(188, 112);
|
||||
this.btn_open3rdP.Location = new System.Drawing.Point(188, 103);
|
||||
this.btn_open3rdP.Name = "btn_open3rdP";
|
||||
this.btn_open3rdP.Size = new System.Drawing.Size(86, 20);
|
||||
this.btn_open3rdP.Size = new System.Drawing.Size(86, 18);
|
||||
this.btn_open3rdP.TabIndex = 7;
|
||||
this.btn_open3rdP.Text = "Add Controllers";
|
||||
this.btn_open3rdP.UseVisualStyleBackColor = true;
|
||||
|
@ -321,16 +322,31 @@
|
|||
this.button1.Text = "Apply";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
// AutoCalibrate
|
||||
//
|
||||
this.AutoCalibrate.Location = new System.Drawing.Point(111, 103);
|
||||
this.AutoCalibrate.Name = "AutoCalibrate";
|
||||
this.AutoCalibrate.Size = new System.Drawing.Size(71, 18);
|
||||
this.AutoCalibrate.TabIndex = 8;
|
||||
this.AutoCalibrate.Text = "Calibrate";
|
||||
this.AutoCalibrate.UseVisualStyleBackColor = true;
|
||||
this.AutoCalibrate.Click += new System.EventHandler(this.StartCalibrate);
|
||||
if (!this.nonOriginal)
|
||||
{
|
||||
this.AutoCalibrate.Hide();
|
||||
}
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.AutoSize = true;
|
||||
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.ClientSize = new System.Drawing.Size(573, 261);
|
||||
this.Controls.Add(this.foldLbl);
|
||||
this.Controls.Add(this.rightPanel);
|
||||
this.ClientSize = new System.Drawing.Size(284, 241);
|
||||
this.Controls.Add(this.AutoCalibrate);
|
||||
this.Controls.Add(this.btn_open3rdP);
|
||||
this.Controls.Add(this.startInTrayBox);
|
||||
this.Controls.Add(this.conCntrls);
|
||||
|
@ -383,5 +399,6 @@
|
|||
private System.Windows.Forms.Panel rightPanel;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Label foldLbl;
|
||||
private System.Windows.Forms.Button AutoCalibrate;
|
||||
}
|
||||
}
|
|
@ -15,9 +15,29 @@ 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;
|
||||
public List<int> yG;
|
||||
public List<int> zG;
|
||||
public List<int> xA;
|
||||
public List<int> yA;
|
||||
public List<int> 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})
|
||||
};
|
||||
InitializeComponent();
|
||||
|
||||
con = new List<Button> { con1, con2, con3, con4 };
|
||||
|
@ -75,9 +95,9 @@ namespace BetterJoyForCemu {
|
|||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e) {
|
||||
Program.Start();
|
||||
Config.Init(caliData);
|
||||
|
||||
Config.Init();
|
||||
Program.Start();
|
||||
|
||||
passiveScanBox.Checked = Config.Value("ProgressiveScan");
|
||||
startInTrayBox.Checked = Config.Value("StartInTray");
|
||||
|
@ -263,5 +283,123 @@ namespace BetterJoyForCemu {
|
|||
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 to a controller.";
|
||||
return;
|
||||
}
|
||||
if (Program.mgr.j.Count > 1){
|
||||
this.console.Text = "Please only use one controller.";
|
||||
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 CountDown(object sender, EventArgs e){
|
||||
if(this.count == 0){
|
||||
this.console.Text = "Calibrating...";
|
||||
countDown.Stop();
|
||||
this.StartGetData();
|
||||
} else {
|
||||
this.console.Text = "Plese keep controller flat." + "\r\n";
|
||||
this.console.Text += "Calibrate 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 = "Calibrate 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 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;
|
||||
}
|
||||
|
||||
private int findSer(string serNum){
|
||||
for(int i = 0; i < this.caliData.Count; i++){
|
||||
if(this.caliData[i].Key== serNum){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,10 @@ namespace BetterJoyForCemu {
|
|||
bool foundNew = false;
|
||||
while (ptr != IntPtr.Zero) {
|
||||
enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));
|
||||
if (form.nonOriginal)
|
||||
{
|
||||
enumerate.product_id = product_pro;
|
||||
}
|
||||
|
||||
if ((enumerate.product_id == product_l || enumerate.product_id == product_r || enumerate.product_id == product_pro) && !ControllerAlreadyAdded(enumerate.path)) {
|
||||
switch (enumerate.product_id) {
|
||||
|
@ -163,7 +167,7 @@ namespace BetterJoyForCemu {
|
|||
break;
|
||||
}
|
||||
|
||||
j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001"));
|
||||
j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, enumerate.path, enumerate.serial_number, j.Count, enumerate.product_id == product_pro));
|
||||
|
||||
foundNew = true;
|
||||
j.Last().form = form;
|
||||
|
@ -252,6 +256,11 @@ namespace BetterJoyForCemu {
|
|||
|
||||
jc.Attach(leds_: jc.LED);
|
||||
jc.Begin();
|
||||
if (form.nonOriginal)
|
||||
{
|
||||
jc.getActiveData();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue