Exemplo n.º 1
0
        /// <summary>
        /// Buzz device button pressed or released : Called when read terminates normally on the background
        /// thread from the async read. Must use standard invokerequired/invoke practice.
        /// </summary>
        private void BuzzDevice_OnButtonChanged(object sender, BuzzButtonChangedEventArgs args)
        {
            if (InvokeRequired)
            {
                Invoke(new BuzzButtonChangedEventHandler(BuzzDevice_OnButtonChanged), new object[] { sender, args });
            }
            else
            {
                Buzzer     buzzer         = (Buzzer)sender;
                int        subBuzzerIndex = 0;
                List <int> indexes        = new List <int>();
                indexes.Add(0);
                indexes.Add(1);
                indexes.Add(2);
                indexes.Add(3);

                while (indexes.Count > 0)
                {
                    // Randomly go through players to ensure that Player 1 doesn't have the advantage in outright ties
                    subBuzzerIndex = indexes[random.Next(indexes.Count)];
                    indexes.Remove(subBuzzerIndex);
                    ButtonStates button = args.Buttons[subBuzzerIndex];
                    Player       player = buzzer.Players[subBuzzerIndex];
                    HandleRegularGameBuzzerInput(player, button);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks to see if there the device has been plugged in
        /// </summary>
        private void CheckIfBuzzHandsetsPresent()
        {
            if (this.Buzzers != null)
            {
                foreach (Buzzer buzzer in this.Buzzers)
                {
                    if (buzzer.OutputFile != null)
                    {
                        buzzer.Dispose();
                    }
                }
            }

            if (this.settings.BuzzerType == "PS2")
            {
                try
                {
                    List <Buzzer> newBuzzers = Buzzer.FindBuzzHandsets();

                    int index = 0;
                    foreach (Buzzer buzzer in newBuzzers)
                    {
                        buzzer.OnDeviceRemoved += new EventHandler(BuzzDevice_OnDeviceRemoved);
                        buzzer.OnButtonChanged += new BuzzButtonChangedEventHandler(BuzzDevice_OnButtonChanged);
                        buzzer.BuzzerIndex      = index;
                        index++;
                    }

                    this.lblBuzzersDetected.Text = (index * 4).ToString();
                    this.Buzzers           = newBuzzers;
                    this.previousBuzzStack = new Stack <Player>();
                    this.Reset();

                    // Get rid of any handles for the arcade buzzers
                    if (this.arcadeBuzzTimer != null)
                    {
                        this.arcadeBuzzTimer.Stop();
                        this.arcadeBuzzTimer.Dispose();
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Something went wrong finding the buzzers.  Try plugging the buzzers back in and/or restarting the program in administrator mode.  Refer to the help screen for more troubleshooting tips.");
                    this.Buzzers           = new List <Buzzer>();
                    this.previousBuzzStack = new Stack <Player>();
                }
            }
            else
            {
                this.SetupArcadeInputs();
                this.previousBuzzStack = new Stack <Player>();
                this.Reset();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set up the inputs for running in arcade board mode
        /// </summary>
        private void SetupArcadeInputs()
        {
            this.Buzzers = new List <Buzzer>();

            this.arcadeJoystick = null;

            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
            }

            if (joystickGuid != Guid.Empty)
            {
                this.arcadeJoystick = new Joystick(directInput, joystickGuid);
                this.arcadeJoystick.Properties.BufferSize = 128;
                this.arcadeJoystick.Acquire();

                int buzzerCount = 0;

                var buzzer = new Buzzer();

                // Figure out how many players there are
                foreach (var joystickObject in this.arcadeJoystick.GetObjects())
                {
                    if (joystickObject.Name != null && joystickObject.Name.Contains("Button"))
                    {
                        buzzerCount++;
                    }
                }

                this.lblBuzzersDetected.Text = buzzerCount.ToString();
                buzzer.BuzzerIndex           = 0;
                buzzer.AddPlayers(buzzerCount);
                this.Buzzers.Add(buzzer);
            }

            if (this.arcadeBuzzTimer != null)
            {
                this.arcadeBuzzTimer.Stop();
                this.arcadeBuzzTimer.Dispose();
            }

            this.arcadeBuzzTimer          = new System.Timers.Timer();
            this.arcadeBuzzTimer.Elapsed += new ElapsedEventHandler(this.HandleArcadeBuzzes);
            this.arcadeBuzzTimer.Interval = 1;
            this.arcadeBuzzTimer.Start();
        }
Exemplo n.º 4
0
 public Buzzer(Buzzer b)
 {
     this.OutputReportLength = b.OutputReportLength;
     this.InputReportLength  = b.InputReportLength;
     this.OutputFile         = b.OutputFile;
     this.BuzzerIndex        = b.BuzzerIndex;
     this.m_hHandle          = b.m_hHandle;
     this.Players            = new List <Player>();
     for (int i = 0; i < 4; i++)
     {
         this.Players.Add(new Player(this.BuzzerIndex, i));
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Finds all buzz handsets.
        /// </summary>
        /// <returns>A list of all new buzz handsets.</returns>
        public static List <Buzzer> FindBuzzHandsets()
        {
            // VID and PID for Buzz device are 0x054c and 0x1000 respectively
            List <HIDDevice> devices = FindDevices(0x054c, 0x1000, typeof(Buzzer));
            List <Buzzer>    buzzers = new List <Buzzer>();
            int index = 0;

            foreach (HIDDevice device in devices)
            {
                Buzzer buzzer = (Buzzer)device;
                buzzer.BuzzerIndex = index;
                buzzer.AddPlayers();
                buzzers.Add(buzzer);
                index++;
            }

            return(buzzers);
        }