예제 #1
0
        public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame)
        {
            // Speed is pixels per second
            var    speed = MovementConfiguration.Speed * frame.TimeDelta / 1000d;
            var    accel = MovementConfiguration.Acceleration;
            double x, y;

            if (accel != 0d && accel != 1d)
            {
                var angle    = state.Angle;
                var distance = Math.Pow(1d + state.Distance, accel) - 1d;
                x = distance * Math.Cos(angle);
                y = -distance *Math.Sin(angle);
            }
            else
            {
                x = state.X;
                y = -state.Y;
            }

            if (MovementConfiguration.InvertX)
            {
                x = -x;
            }

            if (MovementConfiguration.InvertY)
            {
                y = -y;
            }

            MovementActuator.Move(x * speed, y * speed);
        }
        public void Update(ButtonState state, InputKey inputKey, FrameDetails frame)
        {
            if (state.IsPressed)
            {
                if (!isPressed)
                {
                    Action.Execute();
                    isPressed = true;
                    timeLeft  = RepeatConfiguration.Delay;
                }
                else
                {
                    var pressure = state.Pressure;
                    var accel    = RepeatConfiguration.PressureAcceleration;
                    if (accel != 0d && accel != 1d)
                    {
                        pressure = Math.Pow(pressure, accel);
                    }

                    timeLeft -= frame.TimeDelta * pressure;
                    if (timeLeft <= 0d)
                    {
                        Action.Execute();
                        timeLeft = RepeatConfiguration.Interval;
                    }
                }
            }
            else
            {
                isPressed = false;
            }
        }
예제 #3
0
        public HttpResponseMessage GetCustomFrame(
            string officeNumber,
            string frameItemId)
        {
            FrameDetails result = this.frameIt2Manager.GetCustomFrame(frameItemId, this.companyId);

            return(this.Request.CreateResponse(
                       HttpStatusCode.OK, result));
        }
예제 #4
0
        public void Update(FrameDetails frame)
        {
            if (isOpen != previousIsOpen)
            {
                Raise(IsOpenChanged);
                previousIsOpen = isOpen;
            }

            if (isPointerVisible != previousIsPointerVisible)
            {
                Raise(IsPointerVisibleChanged);
                previousIsPointerVisible = isPointerVisible;
            }

            if (itemFocused != previousItemFocused)
            {
                Raise(ItemFocusedChanged);
                previousItemFocused = itemFocused;
            }

            if (Math.Abs(pointerAngle - previousPointerAngle) > 0.1d)
            {
                Raise(PointerAngleChanged);
                previousPointerAngle = pointerAngle;
            }

            var raiseHelp = false;

            if (currentMenu != previousCurrentMenu)
            {
                Raise(CurrentMenuChanged);
                previousCurrentMenu = currentMenu;
                raiseHelp           = true;
            }

            if (currentPage != previousCurrentPage)
            {
                Raise(CurrentPageChanged);
                Raise(PointerWidthChanged);
                previousCurrentPage = currentPage;
                raiseHelp           = true;
            }

            if (currentItem != previousCurrentItem)
            {
                Raise(CurrentItemChanged);
                previousCurrentItem = currentItem;
                raiseHelp           = true;
            }

            if (raiseHelp)
            {
                Raise(HelpScreenChanged);
                Raise(HelpScreen2Changed);
            }
        }
예제 #5
0
 public void Update(ButtonState state, InputKey inputKey, FrameDetails frame)
 {
     if (state.IsPressed)
     {
         if (!isPressed)
         {
             Action.Execute();
             isPressed = true;
         }
     }
     else
     {
         isPressed = false;
     }
 }
예제 #6
0
        public HttpResponseMessage SaveCustomFrame(string officeNumber, FrameDetails items)
        {
            var token = new AuthorizationTicketHelper().GetToken();
            var frame = this.frameIt2Manager.SaveCustomFrameItems(items, this.companyId, this.dataSourceId, token);

            ////return Request.CreateResponse(HttpStatusCode.OK, frame);
            return(Request.CreateResponse(
                       HttpStatusCode.OK,
                       new
            {
                ManufacturerId = frame.Style.Collection.Manufacturer.ID,
                CollectionId = frame.Style.Collection.ID,
                ModelId = frame.Style.ID,
                ItemId = frame.ID
            }));
        }
예제 #7
0
        private static void UpdateProfile(Profile profile, InputState inputState, FrameDetails frame, HashSet <Button> dirtyButtons)
        {
            const int modA           = (int)InputKey.ModA;
            var       isModifierDown = false;

            foreach (var modifierKey in profile.Modifiers)
            {
                if (inputState.ButtonStates[modifierKey].IsPressed)
                {
                    isModifierDown = true;
                    break;
                }
            }

            profile.LeftAnalogHandler?.Update(inputState.LeftAnalogState, ThumbStick.Left, frame);
            profile.RightAnalogHandler?.Update(inputState.RightAnalogState, ThumbStick.Right, frame);
            var nonPressedKey = new ButtonState();

            // Some enum hacking is done below...
            // Button is converted to InputKey 1 to 1, and for converting to Mod<Button> it's added by an offset.
            foreach (var pair in inputState.ButtonStates)
            {
                if (profile.Modifiers.Contains(pair.Key))
                {
                    // Modifiers are ignored.
                    continue;
                }

                if (dirtyButtons.Contains(pair.Key))
                {
                    continue;
                }

                var button    = (InputKey)pair.Key;
                var modButton = (InputKey)(modA + (int)pair.Key);
                if (profile.ButtonHandlers.TryGetValue(button, out var buttonHandler))
                {
                    buttonHandler?.Update(isModifierDown ? nonPressedKey : pair.Value, button, frame);
                }

                if (profile.ButtonHandlers.TryGetValue(modButton, out var modButtonHandler))
                {
                    modButtonHandler?.Update(isModifierDown ? pair.Value : nonPressedKey, modButton, frame);
                }
            }
        }
예제 #8
0
 public void Update(ButtonState state, InputKey inputKey, FrameDetails frame)
 {
     if (state.IsPressed)
     {
         if (!isPressed)
         {
             Mapping.Activate();
             isPressed = true;
         }
     }
     else
     {
         if (isPressed)
         {
             Mapping.Deactivate();
             isPressed = false;
         }
     }
 }
예제 #9
0
        public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame)
        {
            var x        = Configuration.InvertX ? -state.X : state.X;
            var y        = Configuration.InvertY ? state.Y : -state.Y;
            var distance = Math.Sqrt(x * x + y * y);

            if (distance <= Configuration.MinRadius)
            {
                memory.Clear();
                distance = 0d;
            }
            else
            {
                distance = (distance - Configuration.MinRadius) / (1d - Configuration.MinRadius);
            }

            var angle = Math.Atan2(y, x);

            memory.Enqueue(new AngleData(angle));
            var avgCos = 0d;
            var avgSin = 0d;

            foreach (var item in memory)
            {
                avgCos += item.Cos;
                avgSin += item.Sin;
            }

            avgCos /= memory.Count;
            avgSin /= memory.Count;
            var avgAngle = Math.Atan2(avgSin, avgCos);

            while (memory.Count > Configuration.Smoothing / frame.FrameTime)
            {
                memory.Dequeue();
            }

            RadialActuator.Update((avgAngle * 180d / Math.PI + 90d) % 360d, distance);
        }
        public void Update(ButtonState state, InputKey inputKey, FrameDetails frame)
        {
            if (state.IsPressed)
            {
                if (isPressed)
                {
                    // Down -> down
                    holdDuration += frame.TimeDelta;
                    if (!holdHandled && holdDuration >= Configuration.Duration)
                    {
                        HoldAction.Execute();
                        holdHandled = true;
                    }
                }
                else
                {
                    // Up -> down
                    holdDuration = 0d;
                    isPressed    = true;
                }
            }
            else
            {
                if (isPressed)
                {
                    // Down -> up
                    if (holdDuration < Configuration.Duration)
                    {
                        PressAction.Execute();
                    }

                    holdHandled = false;
                    isPressed   = false;
                }

                holdDuration = 0d;
            }
        }
예제 #11
0
        public async Task Run(CancellationToken cancellation)
        {
            var     connected    = false;
            var     isEnabled    = true;
            var     lastBack     = false;
            var     lastStart    = false;
            var     lastFrame    = DateTime.Now;
            var     dirtyButtons = new HashSet <Button>();
            Profile profile      = null;

            await Task.Delay(TimeSpan.FromMilliseconds(1000d / Configuration.Fps), cancellation);

            while (!cancellation.IsCancellationRequested)
            {
                var    frameStart = DateTime.Now;
                double fps;

                if (!TryGetLowestIndex(out var state, out var playerIndex))
                {
                    if (connected)
                    {
                        // If we were connected, clear state to prevent stuck keys.
                        profile?.ClearState();
                        dirtyButtons.Clear();
                        MenuController.FlashMessage(null, "Connection lost", null);
                    }

                    connected = false;
                    fps       = 5d;
                }
                else
                {
                    if (!connected)
                    {
                        MenuController.FlashMessage($"Profile: {Configuration.CurrentProfile ?? "None"}", "Connected", null);
                    }

                    connected = true;
                    fps       = Configuration.Fps;
                }

                var inputState = InputState.FromGamePadState(state, Configuration.Deadzone);
                var frame      = new FrameDetails(playerIndex, profile, frameStart, (frameStart - lastFrame).TotalMilliseconds, fps, inputState, connected);
                if (connected)
                {
                    if (dirtyButtons.Count != 0)
                    {
                        // Clear dirty buttons.
                        foreach (var pair in inputState.ButtonStates)
                        {
                            if (pair.Value.IsPressed)
                            {
                                continue;
                            }

                            if (dirtyButtons.Remove(pair.Key) && dirtyButtons.Count == 0)
                            {
                                break;
                            }
                        }
                    }

                    // Profile switching
                    var newProfile = GetCurrentProfile();
                    if (!ReferenceEquals(profile, newProfile))
                    {
                        profile?.ClearState();
                        foreach (var pair in inputState.ButtonStates)
                        {
                            if (pair.Value.IsPressed)
                            {
                                dirtyButtons.Add(pair.Key);
                            }
                        }

                        profile = newProfile;
                    }

                    // Input disabling
                    var back  = state.Buttons.Back == XInputDotNetPure.ButtonState.Pressed;
                    var start = state.Buttons.Start == XInputDotNetPure.ButtonState.Pressed;
                    if (back && start)
                    {
                        if (!lastBack || !lastStart)
                        {
                            isEnabled = !isEnabled;
                            dirtyButtons.Add(Button.Back);
                            dirtyButtons.Add(Button.Start);
                            profile?.ClearState();
                        }
                    }

                    lastBack  = back;
                    lastStart = start;
                    if (profile != null && isEnabled)
                    {
                        UpdateProfile(profile, inputState, frame, dirtyButtons);
                    }
                }

                MenuController.Update(frame);

                lastFrame = frameStart;

                // Try to keep a constant frame rate.
                await Task.Delay(TimeSpan.FromMilliseconds(
                                     Math.Max(1000d / fps - (DateTime.Now - frameStart).TotalMilliseconds, 1d)),
                                 cancellation);
            }
        }