Ejemplo n.º 1
0
        private void InitHIDDev()
        {
            byte devnumber = 0;

            this.dev = null;

            var devices = HIDBrowse.Browse();

            // Find all Steelseries Arcis 7 devices
            var devs = (HIDBrowse.Browse()).FindAll(x => (x.Pid == 4781 && x.Vid == 4152));


            if (devs.Count != 0)
            {
                byte batCharge = 0;
                do
                {
                    this.dev = new HIDDev();
                    dev.Open(devs.ElementAt(devnumber));
                    devnumber++;
                } while (devnumber < devs.Count && !this.ReadBattery(out batCharge));

                if (devnumber >= devs.Count)
                {
                    Console.WriteLine("None of the Arctis 7 HID Devices responded!");
                    exit = true;
                }
                else
                {   //if icons loaded correctly and everything else worked so far, exit is false
                    if (!exit)
                    {
                        //Update Tray Icon
                        this.icon.Icon = this.chargeIcons[batCharge];
                    }
                }
            }
            else
            {
                Console.WriteLine("Arctis 7 HID Device not found!");
                exit = true;
            }
        }
Ejemplo n.º 2
0
        /*public bool ReadTest(out byte[] test)
         * {
         *  test = new byte[32];
         *  try
         *  {
         *      // Set message to send
         *      byte[] report = new byte[32]; report[0] = 0x06;
         *      report[1] = 0x99;
         *      //0x24 reportIn[2] == game volume, 192 = none 255 && 0 = max/middle ground
         *      //0x24 reportIn[3] == voice volume, 192 = none 255 && 0 = max/middle ground
         *      //0x10 && 0x30 seems to react on game/voice volumes
         *      // Send request
         *      this.dev.Write(report);
         *
         *      // Prepare buffer for answer
         *      byte[] reportIn = new byte[31]; //neeed 31 (by testing)
         *
         *      // Read answer
         *      this.dev.Read(reportIn);
         *
         *      if (reportIn[0] == 0x06 && reportIn[1] == report[1])
         *      {
         *          test = reportIn;
         *          return true;
         *      }
         *  }
         *  catch (Exception)
         *  {   //if the read doesn't work, return false
         *      return false;
         *  }
         *
         *  return false;
         * }*/

        public void InitHIDDev()
        {
            byte devnumber = 0;

            this.dev = null;

            var devices = HIDBrowse.Browse();

            // Find all Steelseries Arcis 7 devices
            var devs = (HIDBrowse.Browse()).FindAll(x => (x.Pid == 4781 && x.Vid == 4152));


            if (devs.Count != 0)
            {
                byte batCharge = 0;
                do
                {
                    this.dev = new HIDDev();
                    dev.Open(devs.ElementAt(devnumber));
                    devnumber++;
                } while (devnumber < devs.Count && !this.ReadBattery(out batCharge));
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            /* hello, world! */
            Console.WriteLine("List of USB HID devices:");
            /* browse for hid devices */
            var devs = HIDBrowse.Browse();

            /* display VID and PID for every device found */
            foreach (var dev in devs)
            {
                Console.WriteLine("VID = " + dev.Vid.ToString("X4") +
                                  " PID = " + dev.Pid.ToString("X4") +
                                  " Product: " + dev.Product);
            }

            /* try to connect to first device */
            if (devs.Count > 0)
            {
                /* new device */
                HIDDev dev = new HIDDev();
                /* connect */
                dev.Open(devs[0]);

                /* an example of hid report, report id is always located
                 * at the beginning of every report. Here it was set to 0x01.
                 * adjust this report so it does meet your hid device reports */
                byte[] report = new byte[32]; report[0] = 0x01;
                /* send report */
                dev.Write(report);
                /* get response */
                dev.Read(report);
            }

            /* bye bye! */
            Console.Read();
        }
Ejemplo n.º 4
0
        //private float axisScale = 1;

        private void MonitorForm_Load(object sender, EventArgs e)
        {
            //var err = EVRInitError.Driver_Failed;
            //_vrSystem = OpenVR.Init(ref err, EVRApplicationType.VRApplication_Overlay);
            //OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref err);
            //OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref err);

            axis         = new Axes(100);
            axis.Center  = new Point3d((pb.Width) / 2, (pb.Height) / 2, 0);
            cam.Location = new Point3d(axis.Center.X, axis.Center.Y, -500);

            grav        = new Gravity(100);
            grav.Center = new Point3d((pb.Width) / 2, (pb.Height) / 2, 0);

            testSensor.MaxPoints = pb.Width - 10;

            InfoRow        = dgData.Rows[dgData.Rows.Add()]; InfoRow.Cells[0].Value = "Info";
            RotationRow    = dgData.Rows[dgData.Rows.Add()]; RotationRow.Cells[0].Value = "Rotation";  RotationRow.Tag = axis;
            PositionRow    = dgData.Rows[dgData.Rows.Add()]; PositionRow.Cells[0].Value = "Position"; PositionRow.Tag = RotationRow.Tag;
            AccelRow       = dgData.Rows[dgData.Rows.Add()]; AccelRow.Cells[0].Value = "Accel/Gravity"; AccelRow.Tag = new KalmanGroup(pb.Width - 10, 2, 2, 0, 0f);
            AccelOffsetRow = dgData.Rows[dgData.Rows.Add()]; AccelOffsetRow.Cells[0].Value = "Averages"; AccelOffsetRow.Tag = new float[3];
            GyroRow        = dgData.Rows[dgData.Rows.Add()]; GyroRow.Cells[0].Value = "Gyro/CompAccel"; GyroRow.Tag = new KalmanGroup(pb.Width - 10, 2, 2, 0, 0f);
            GyroOffsetRow  = dgData.Rows[dgData.Rows.Add()]; GyroOffsetRow.Cells[0].Value = "Averages"; GyroOffsetRow.Tag = new float[3];
            MagRow         = dgData.Rows[dgData.Rows.Add()]; MagRow.Cells[0].Value = "Mag/Velocity"; MagRow.Tag = new KalmanGroup(pb.Width - 10, 2, 2, 0, 0f);
            MagOffsetRow   = dgData.Rows[dgData.Rows.Add()]; MagOffsetRow.Cells[0].Value = "Averages"; MagOffsetRow.Tag = new float[3];

            ResetOffsets();

            foreach (var item in Enum.GetValues(typeof(DebugModes)))
            {
                comboBox1.Items.Add(item);
            }


            _thread = new Thread(() =>
            {
                HIDDev _usb = null;
                var data    = new byte[33];
                while (_running)
                {
                    if (_usb == null)
                    {
                        var hd = HIDBrowse.Browse().FirstOrDefault(h => h.Vid == 0x1974 && h.Pid == 0x001);
                        if (hd != null)
                        {
                            _usb = new HIDDev();
                            _usb.Open(hd);
                        }
                    }
                    try
                    {
                        if (_usb != null)
                        {
                            lock (_outgoing)
                                if (_outgoing.Count > 0)
                                {
                                    var p = _outgoing.Dequeue();
                                    var d = StructToBytes(p);
                                    SetPacketCrc(ref d);
                                    _usb.Write(d);
                                }
                            _usb.Read(data);
                            if (CheckPacketCrc(data, 1))
                            {
                                var packet = StructFromBytes <USBPacket>(data, 1);
                                packet.ParseFields();
                                lock (_incoming)
                                    _incoming.Enqueue(packet);
                            }
                        }
                    }
                    catch
                    {
                        _usb.Close();
                        _usb.Dispose();
                        _usb = null;
                        Thread.Sleep(100);
                    }
                }
            })
            {
                IsBackground = true
            };
            _running = true;
            _thread.Start();
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            /* hello, world! */
            Console.WriteLine("Looking for DsHidMini devices");
            /* browse for hid devices */
            var devs = HIDBrowse.Browse().Where(d => d.Vid == 0x054C && d.Pid == 0x0268);

            if (!devs.Any())
            {
                Console.WriteLine("None found, nothing to do");
                return;
            }

            Console.WriteLine("Found one");

            var instructions = ((IList <dynamic>)Config.Global.Instructions)
                               .Select(i => new ReplayEntry((string)i.OutputReport, (int)i.WaitPeriodMs, (int)i.SendXTimes, (int)i.RepeatDelay)).ToList();

            /* new device */
            var dev = new HIDDev();

            /* connect */
            dev.Open(devs.First());

            /* send report */

            String userin;

            Console.Write("Execute how many times? (0 = indefinitely): ");
            userin = Console.ReadLine();
            int FullRepeat = Convert.ToInt32(userin);

            Console.WriteLine();

            int FR = 1;

            while (FullRepeat == 0 || FR <= FullRepeat)
            {
                Console.Clear();

                if (FullRepeat >= 1)
                {
                    Console.WriteLine("===== EXECUTING (" + FR + "/" + FullRepeat + ") =====");
                    Console.WriteLine();
                }

                int CurrentI = 0;

                foreach (var instruction in instructions)
                {
                    Console.WriteLine("Executing instructions block number " + CurrentI);

                    int P = 1;

                    while (P <= instruction.TimesToSend)
                    {
                        dev.Write(instruction.Report);
                        Console.Write(".");               // Print "." to inform that a command has been sent

                        if (P == instruction.TimesToSend) // Break; if on the last repeat to prevent an aditional delay on Thread.Sleep(instruction.RepDelay)
                        {
                            Console.WriteLine();
                            Console.WriteLine(P + " command(s) sent"); // informs the number of sent commands
                            break;
                        }
                        if (instruction.RepDelay > TimeSpan.Zero) // Print "-" if RepDelay > 0
                        {
                            Console.Write("-");
                            Thread.Sleep(instruction.RepDelay);
                        }
                        P++;
                    }

                    if (instruction.WaitPeriod > TimeSpan.Zero)
                    {
                        Console.WriteLine("Waiting for " + instruction.WaitPeriod + "ms");
                        Thread.Sleep(instruction.WaitPeriod);
                    }
                    else
                    {
                        Console.WriteLine("Not waiting");
                    }
                    CurrentI++;
                    Console.WriteLine();
                }

                if (FullRepeat >= 1)
                {
                    FR++;
                }
            }


            Console.WriteLine("Done!");
            Console.Read();
        }
Ejemplo n.º 6
0
        private void USBProcessor()
        {
            List <byte[]> outgoingPackets = null;
            HIDDev        _usb            = null;
            var           data            = new byte[33];
            DateTime      lastOutgoing    = DateTime.MinValue;

            while (_running)
            {
                if (_usb == null)
                {
                    var hd = HIDBrowse.Browse().FirstOrDefault(h => h.Vid == 0x1974 && h.Pid == 0x001);
                    if (hd != null)
                    {
                        _usb = new HIDDev();
                        _usb.Open(hd);
                        State = CommState.Connected;
                        _sharedMem.SetState(State);
                    }
                }
                try
                {
                    if (_usb != null)
                    {
                        outgoingPackets = _sharedMem.ReadOutgoingPackets();
                        if (outgoingPackets != null)
                        {
                            lock (OutgoingPackets)
                                foreach (var item in outgoingPackets)
                                {
                                    OutgoingPackets.Enqueue(item);
                                }
                        }
                        lock (OutgoingPackets)
                            if (OutgoingPackets.Count > 0 && (DateTime.Now - lastOutgoing).TotalMilliseconds >= 100)
                            {
                                lastOutgoing = DateTime.Now;
                                var d = OutgoingPackets.Dequeue(); //33 byte packets in queue
                                _usb.Write(d);                     //send before monitor process
                                if (IsDebug && IsVisible)
                                {
                                    var packet = StructFromBytes <USBPacket>(d, 1);
                                    packet.ParseFields();
                                    lock (OutPacketMonitor)
                                        OutPacketMonitor.Add(packet);
                                }
                            }

                        _usb.Read(data);
                        if (CheckPacketCrc(data, 1))
                        {
                            _sharedMem.WriteIncomingPacket(data); //send before monitor process
                            State = _sharedMem.IsDriverActive ? CommState.Active : CommState.ActiveNoDriver;
                            if (IsDebug && IsVisible)
                            {
                                //var x = Marshal.SizeOf(typeof(USBPacket));
                                var packet = StructFromBytes <USBPacket>(data, 1);
                                packet.ParseFields();
                                lock (InPacketMonitor)
                                    InPacketMonitor.Add(packet);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    if (_usb != null)
                    {
                        _usb.Close();
                        _usb.Dispose();
                    }
                    _usb  = null;
                    State = CommState.Disconnected;
                    _sharedMem.SetState(State);

                    Thread.Sleep(100);
                }
            }
            if (_usb != null)
            {
                _usb.Close();
                _usb.Dispose();
            }
            _usb  = null;
            State = CommState.Disconnected;
            _sharedMem.SetState(CommState.Disconnected);
        }