public void Awake() { instance = this; j = new ConcurrentList <Joycon>(); HIDapi.hid_init(); }
public void Awake() { instance = this; int i = 0; j = new List <Joycon>(); bool isLeft = false; HIDapi.hid_init(); IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0); IntPtr top_ptr = ptr; if (ptr == IntPtr.Zero) { ptr = HIDapi.hid_enumerate(vendor_id_, 0x0); if (ptr == IntPtr.Zero) { HIDapi.hid_free_enumeration(ptr); Console.WriteLine("No Joy-Cons found!"); } } hid_device_info enumerate; while (ptr != IntPtr.Zero) { enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info)); if (enumerate.product_id == product_l || enumerate.product_id == product_r || enumerate.product_id == product_pro) { if (enumerate.product_id == product_l) { isLeft = true; Console.WriteLine("Left Joy-Con connected."); } else if (enumerate.product_id == product_r) { isLeft = false; Console.WriteLine("Right Joy-Con connected."); } else if (enumerate.product_id == product_pro) { isLeft = true; Console.WriteLine("Pro controller connected."); } else { Console.WriteLine("Non Joy-Con input device skipped."); } IntPtr handle = HIDapi.hid_open_path(enumerate.path); try { HIDapi.hid_set_nonblocking(handle, 1); } catch (Exception e) { Console.WriteLine("Unable to open path to device - are you using the correct (64 vs 32-bit) version for your PC?"); break; } j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001")); 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); } j[j.Count - 1].PadMacAddress = new PhysicalAddress(mac); ++i; } ptr = enumerate.next; } int found = 0; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { found++; } if (!v.isLeft && !v.isPro) { found++; } } if (found == 2) { Console.WriteLine("Both joycons successfully found."); Joycon temp = null; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } if (!v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } } // Join up the two joycons } else if (found != 0) { Console.WriteLine("Only one joycon found. Please connect both and then restart the program."); } HIDapi.hid_free_enumeration(top_ptr); }
public void Awake() { _instance = this; j = new List <Joycon>(); HIDapi.hid_init(); }
public void Awake() { instance = this; int i = 0; j = new List <Joycon>(); bool isLeft = false; HIDapi.hid_init(); IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0); IntPtr top_ptr = ptr; if (ptr == IntPtr.Zero) { ptr = HIDapi.hid_enumerate(vendor_id_, 0x0); if (ptr == IntPtr.Zero) { HIDapi.hid_free_enumeration(ptr); form.console.Text += "No Joy-Cons found!\r\n"; } } hid_device_info enumerate; while (ptr != IntPtr.Zero) { enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info)); if (enumerate.product_id == product_l || enumerate.product_id == product_r || enumerate.product_id == product_pro) { if (enumerate.product_id == product_l) { isLeft = true; form.console.Text += "Left Joy-Con connected.\r\n"; } else if (enumerate.product_id == product_r) { isLeft = false; form.console.Text += "Right Joy-Con connected.\r\n"; } else if (enumerate.product_id == product_pro) { isLeft = true; form.console.Text += "Pro controller connected.\r\n"; } else { form.console.Text += "Non Joy-Con input device skipped.\r\n"; } // Add controller to block-list for HidGuardian HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://*****:*****@"hwids=HID\" + enumerate.path.Split('#')[1].ToUpper(); var data = Encoding.UTF8.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length); try { var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); } catch (Exception e) { form.console.Text += "Unable to add controller to block-list.\r\n"; } // -------------------- // IntPtr handle = HIDapi.hid_open_path(enumerate.path); try { HIDapi.hid_set_nonblocking(handle, 1); } catch (Exception e) { form.console.Text += "Unable to open path to device - are you using the correct (64 vs 32-bit) version for your PC?\r\n"; break; } j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001")); j.Last().form = form; 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); } j[j.Count - 1].PadMacAddress = new PhysicalAddress(mac); ++i; } ptr = enumerate.next; } int found = 0; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { found++; } if (!v.isLeft && !v.isPro) { found++; } } if (found == 2) { form.console.Text += "Both joycons successfully found.\r\n"; Joycon temp = null; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } if (!v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } } // Join up the two joycons } else if (found != 0) { form.console.Text += "Only one joycon found. Please connect both and then restart the program.\r\n"; } HIDapi.hid_free_enumeration(top_ptr); }