Beispiel #1
0
 private void SendRumble(byte[] buf)
 {
     byte[] buf_ = new byte[report_len];
     buf_[0] = 0x10;
     buf_[1] = global_count;
     if (global_count == 0xf)
     {
         global_count = 0;
     }
     else
     {
         ++global_count;
     }
     Array.Copy(buf, 0, buf_, 2, 8);
     PrintArray(buf_, format: "Rumble data sent: {0:S}");
     HIDapi.hid_write(handle, buf_, report_len);
 }
Beispiel #2
0
 public void Detach()
 {
     stop_polling = true;
     PrintArray(max, format: "Max {0:S}");
     PrintArray(sum, format: "Sum {0:S}");
     if (this.currentConnectionState > ConnectionState.NO_JOYCONS)
     {
         Subcommand(0x30, new byte[] { 0x0 }, 1);
         Subcommand(0x40, new byte[] { 0x0 }, 1);
         Subcommand(0x48, new byte[] { 0x0 }, 1);
         Subcommand(0x3, new byte[] { 0x3f }, 1);
     }
     if (this.currentConnectionState > ConnectionState.DROPPED)
     {
         HIDapi.hid_close(handle);
     }
     this.currentConnectionState = ConnectionState.NOT_ATTACHED;
 }
Beispiel #3
0
        private byte[] Subcommand(byte sc, byte[] buf, uint len, bool print = true)
        {
            byte[] buf_     = new byte[report_len];
            byte[] response = new byte[report_len];
            Array.Copy(default_buf, 0, buf_, 2, 8);
            Array.Copy(buf, 0, buf_, 11, len);
            buf_[10] = sc;
            buf_[1]  = global_count;
            buf_[0]  = 0x1;
            if (global_count == 0xf)
            {
                global_count = 0;
            }
            else
            {
                ++global_count;
            }
            if (print)
            {
                PrintArray(
                    buf_,
                    len,
                    11,
                    "Subcommand 0x" + string.Format("{0:X2}", sc) + " sent. Data: 0x{0:S}");
            }
            ;
            HIDapi.hid_write(handle, buf_, len + 11);
            int res = HIDapi.hid_read_timeout(handle, response, report_len, 50);

            if (res < 1)
            {
                DebugPrint("No response.");
            }
            else if (print)
            {
                PrintArray(
                    response,
                    report_len - 1,
                    1,
                    "Response ID 0x" + string.Format("{0:X2}", response[0]) + ". Data: 0x{0:S}");
            }
            return(response);
        }