コード例 #1
0
        public async Task <(List <T> records, int count)> FilterAsync(InputRange <long?> dateRange, MinorFilter filter)
        {
            var startTicks = dateRange?.Start;
            var endTicks   = dateRange?.End;
            var categories = filter?.Categories ?? new List <string>();
            var textSearch = filter?.TextSearch ?? string.Empty;
            var minAmount  = filter?.Amount?.Start;
            var maxAmount  = filter?.Amount?.End;

            var transactions = await MultipleAsync(x =>
                                                   (startTicks == null || x.Ticks >= startTicks) &&
                                                   (endTicks == null || x.Ticks <= endTicks) &&
                                                   (categories.Count() == 0 || categories.Contains(x.Category)) &&
                                                   (string.IsNullOrEmpty(textSearch) || x.Description.ToLower().StartsWith(textSearch.ToLower())) &&
                                                   (minAmount == null || x.Amount >= minAmount) &&
                                                   (maxAmount == null || x.Amount <= maxAmount));

            var total = transactions.Count;

            var skip = filter?.Skip ?? 0;
            var take = filter?.Take ?? total;

            var page = transactions.OrderByDescending(x => x.Ticks)
                       .Skip(skip).Take(take).ToList();

            return(records : page, count : total);
        }
コード例 #2
0
        public static int JSZAxis()
        {
            InputRange r = JSDevice.GetObjectPropertiesById(jsZId).Range;

            return(r.Maximum - JSState.Z
                   + r.Minimum);              //scale the values if the min range
            //is not 0
        }
コード例 #3
0
        /// <summary>
        ///Because values go up as the down slider is pressed, this method will reverse the slider output so that 0 means the slider is at
        ///the lower extreme value.
        /// </summary>
        /// <returns>The reversed slider output.</returns>
        public static int JSSlider()
        {
            InputRange r = JSDevice.GetObjectPropertiesById(JSSliderId).Range;

            return(r.Maximum - JSState.Sliders[0]
                   + r.Minimum);              //scale the values if the min range
            //is not 0
        }
コード例 #4
0
ファイル: Bot.cs プロジェクト: taguro/CustomizableBot
 internal void load()
 {
     Object obj = FileControl.load();
     if (obj == null) return;
     var loadBotData = (BotData)obj;
     this.inputRange = loadBotData.inputRange;
     this.inputPoints = loadBotData.inputPoints;
     showInputRange();
 }
コード例 #5
0
        public static bool CheckRequirement(InputRange requirement, float intensity)
        {
            bool none = requirement == InputRange.Zero && intensity == 0;
            bool any  = requirement == InputRange.Any && intensity != 0;
            bool less = requirement == InputRange.Negative && intensity < 0;
            bool more = requirement == InputRange.Positive && intensity > 0;

            return(any || less || more || none);
        }
コード例 #6
0
        protected async Task <(List <T> records, int count)> FilterAsync(InputRange <string> dateRange, MinorFilter filter)
        {
            InputRange <long?> tickRange = new InputRange <long?>();

            if (dateRange != null)
            {
                tickRange.Start = StringDateToTicks(dateRange.Start);
                tickRange.End   = StringDateToTicks(dateRange.End);
            }
            return(await _repo.FilterAsync(tickRange, filter));
        }
コード例 #7
0
ファイル: Bot.cs プロジェクト: taguro/CustomizableBot
 internal void setTrimRange(int left, int up, int right, int down)
 {
     inputRange = new InputRange(left, up, right, down);
     for (int y = inputRange.up; y < inputRange.down; y+= inputGranularity)
     {
         for (int x = inputRange.left; x < inputRange.right; x+= inputGranularity)
         {
             inputPoints.Add(new int[] {x,y});
         }
     }
     showInputRange();
 }
コード例 #8
0
ファイル: KeyInput.cs プロジェクト: emerlgx/GuiglParty
    void Awake()
    {
        int keyBottom = 36;
        int keyTop    = 96;

        ranges = new InputRange[4];
        for (int i = 0; i < 4; i++)
        {
            ranges[i] = new InputRange(keyBottom + 6 + 12 * i);
        }
        //	audioScript = audioObject.GetComponent<UnitySynthTest>();
    }
コード例 #9
0
ファイル: GamePad.cs プロジェクト: newton9278/MedLaunch
        //public static Capabilities DevCaps;

        public static void Initialize()
        {
            if (dinput == null)
            {
                dinput = new DirectInput();
            }

            Devices = new List <GamePad>();

            DIAxisInfo = new List <di_axis_info>();

            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);

                if (device.ProductName.Contains("XBOX 360"))
                {
                    continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)
                }
                var joystick = new Joystick(dinput, device.InstanceGuid);
                //joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);


                int count = 0;
                foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
                {
                    if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    {
                        joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                    }

                    InputRange diprg = joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).LogicalRange;
                    int        min   = diprg.Minimum;
                    int        max   = diprg.Maximum;

                    if (min < max)
                    {
                        di_axis_info dai = new di_axis_info();
                        dai.jd_logical_offset = count;
                        dai.maximum           = max;
                        dai.minimum           = min;
                        DIAxisInfo.Add(dai);
                    }
                    count++;
                }
                joystick.Acquire();


                GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick, DIAxisInfo);
                Devices.Add(p);
            }
        }
コード例 #10
0
        private void ConectarDispositivo()
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(_view);

            _dispositivo = new Device(DispositivoSelecionado.Guid);

            if (_dispositivo.DeviceInformation.InstanceName.Contains("XBOX"))
            {
                _controleXbox = true;
            }

            // Set joystick axis ranges.
            var eixos = _dispositivo.GetObjects(DeviceObjectTypeFlags.Axis);

            // Configura os eixos já para o PWM
            foreach (DeviceObjectInstance doi in eixos)
            {
                InputRange inputRange = new InputRange(0, 255);

                // Eixo do volante
                if (doi.Name.Contains("Wheel axis"))
                {
                    inputRange = new InputRange(-255, 255);
                }

                if (doi.Name.Contains("X Axis") && _controleXbox)
                {
                    inputRange = new InputRange(-255, 255);
                }

                if (doi.Name.Contains("Z Axis") && _controleXbox)
                {
                    inputRange = new InputRange(-255, 255);
                }

                _dispositivo.Properties.SetRange(ParameterHow.ById, doi.ObjectId, inputRange);
            }

            _dispositivo.Properties.AxisModeAbsolute = true;

            EffectList effects = _dispositivo.GetEffects(EffectType.All);

            // _dispositivo.SetCooperativeLevel(helper.Handle, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);

            _dispositivo.SetDataFormat(DeviceDataFormat.Joystick);

            // _dispositivo.Properties.BufferSize = 128;
            _dispositivo.Acquire();
        }
コード例 #11
0
        public override InternalResult <U> Parse(ref ParseState <TToken> state)
        {
            var start = state.Location;

            state.PushBookmark();    // don't discard input buffer
            var result = _parser.Parse(ref state);


            if (!result.Success)
            {
                state.PopBookmark();
                return(InternalResult.Failure <U>(result.ConsumedInput));
            }


            var delta      = state.Location - start;
            var inputRange = new InputRange <TToken>(state.LookBehind(delta), new Range(start, state.Location));
            var val        = _selector(inputRange, result.Value);

            state.PopBookmark();

            return(InternalResult.Success <U>(val, result.ConsumedInput));
        }
コード例 #12
0
        public override string ToString()
        {
            var members = new List <string>();

            members.Add(Constructor);
            members.AddRange(InputRange.Select(GetInputAccessor));
            members.Add(AllInputsAccessor);
            members.AddRange(OutputRange.Select(GetOutputAccessor));
            members.Add(AllOutputsAccessor);
            members.Add(AsTupleMethod);
            members.Add(SendMethod);

            return($@"namespace Refactoring.Pipelines.InputsAndOutputs
{{
    public class {ClassName}<{CommaSeparated(InputTypeParameters)}, {CommaSeparated(OutputTypeParameters)}>
    {{
        private readonly InputsAndOutputs _inputsAndOutputs;

{members.JoinWith("\n")}
    }}
}}
");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitionSectionCreationFeature"/> class.
 /// </summary>
 public TransitionSectionCreationFeature()
     : base(TransitionSectionPlugin.PluginName, useFeatureContextualToolBar: true)
 {
     this.inputRange = InputRange.AtMost(2);
 }
コード例 #14
0
        void InitializeCallbacks()
        {
            const int dzp = 400;
            const int dzn = -400;

            names.Clear();
            actions.Clear();
            NumButtons = 0;

            // populate DIAXISINFO
            devObList = (joystick.GetObjects()
                         .Where(a => a.UsagePage == 1 && a.Usage > 0 && a.Usage != 4)
                         .GroupBy(x => x.Name).Select(x => x.First())
                         .OrderBy(o => o.Usage)
                         .ThenBy(o2 => o2.Offset)).ToArray();

            for (int axis = 0; axis < devObList.Count(); axis++)
            {
                DeviceObjectInstance deviceObject = joystick.GetObjects()[axis];
                InputRange           diprg        = joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).LogicalRange;
                int min = diprg.Minimum;
                int max = diprg.Maximum;

                if (min < max)
                {
                    di_axis_info dai = new di_axis_info();
                    dai.jd_logical_offset = axis;
                    dai.maximum           = max;
                    dai.minimum           = min;
                    dai.name         = deviceObject.Name;
                    dai.usage        = deviceObject.Usage;
                    dai.usagepage    = deviceObject.UsagePage;
                    dai.offset       = deviceObject.Offset / 4;
                    dai.offsetActual = deviceObject.Offset;
                    dai.device       = deviceObject;
                    DIAxisInfo.Add(dai);
                }

                //axis_config_type[axis] = 0;
            }


            num_rel_axes = 0;
            num_axes     = DIAxisInfo.Count(); // + joystick.Capabilities.PovCount * 2;
            num_buttons  = joystick.Capabilities.ButtonCount;

            /* States */
            axis_state.Resize(num_axes);
            rel_axis_state.Resize(num_rel_axes);
            button_state.Resize(num_buttons);

            // buttons
            for (int button = 0; button < joystick.Capabilities.ButtonCount; button++)
            {
                if (state.GetButtons()[button] == true)
                {
                    button_state[button] = true;
                }
                else
                {
                    button_state[button] = false;
                }
            }

            // axis
            unsafe
            {
                for (int axis = 0; axis < DIAxisInfo.Count; axis++)
                {
                    int   X  = state.X;
                    Int64 rv = (&X)[DIAxisInfo[axis].jd_logical_offset];

                    rv = (((rv - DIAxisInfo[axis].minimum) * 32767 * 2) / (DIAxisInfo[axis].maximum - DIAxisInfo[axis].minimum)) - 32767;
                    if (rv < -32767)
                    {
                        rv = -32767;
                    }

                    if (rv > 32767)
                    {
                        rv = 32767;
                    }
                    axis_state[axis] = Convert.ToInt16(rv);
                }
            }

            // hats

            /*
             * for (int hat = 0; hat < joystick.Capabilities.PovCount; hat++)
             * {
             *  uint hat_val = Convert.ToUInt32(state.GetPointOfViewControllers()[hat]);
             *
             *  if (hat_val >= 36000)
             *  {
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 0] = 0;
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 1] = 0;
             *  }
             *  else
             *  {
             *      int x = 0;
             *      int y = 0;
             *      uint octant = (hat_val / 4500) & 0x7;
             *      int octant_doff = Convert.ToInt32(hat_val) % 4500;
             *
             *      switch (octant)
             *      {
             *          case 0: x = octant_doff * 32767 / 4500; y = -32767; break;
             *          case 1: x = 32767; y = (-4500 + octant_doff) * 32767 / 4500; break;
             *
             *          case 2: x = 32767; y = octant_doff * 32767 / 4500; break;
             *          case 3: x = (4500 - octant_doff) * 32767 / 4500; y = 32767; break;
             *
             *          case 4: x = (-octant_doff) * 32767 / 4500; y = 32767; break;
             *          case 5: x = -32767; y = (4500 - octant_doff) * 32767 / 4500; break;
             *
             *          case 6: x = -32767; y = (-octant_doff) * 32767 / 4500; break;
             *          case 7: x = (-4500 + octant_doff) * 32767 / 4500; y = -32767; break;
             *      }
             *
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 0] = Convert.ToInt16(x);
             *      axis_state[(DIAxisInfo.Count + hat * 2) + 1] = Convert.ToInt16(y);
             *  }
             *
             * }
             */

            //string iD = IdGenerator.CalcOldStyleID(DIAxisInfo.Count, 0, joystick.Capabilities.PovCount, joystick.Capabilities.ButtonCount).ToString();
            //string iD = IdGenerator.CalcOldStyleID(num_axes, 0, num_hats, num_buttons).ToString();

            /* populate objects */

            // buttons first

            if (VersionChecker.Instance.IsNewConfig)
            {
                // new stype
                for (int i = 0; i < num_buttons; i++)
                {
                    int    j            = i;
                    bool   button_state = state.GetButtons()[i];
                    UInt32 butnameint   = Convert.ToUInt32(i);
                    string buttStr      = "button_" + i;

                    BConfig.Add(butnameint);

                    AddItem("joystick " + id + " " + buttStr, () => state.IsPressed(j));
                }
            }
            else
            {
                // old style
                for (int i = 0; i < num_buttons; i++)
                {
                    int    j            = i;
                    bool   button_state = state.GetButtons()[i];
                    UInt32 butnameint   = Convert.ToUInt32(i);
                    string buttonnum    = butnameint.ToString("X8");

                    BConfig.Add(butnameint);

                    AddItem("joystick " + id + " " + butnameint.ToString("X8").ToLower(), () => state.IsPressed(j));
                }
            }

            Func <bool> cbPos;
            Func <bool> cbNeg;

            // names
            int buttNamePos;
            int buttNameNeg;

            string buttNamePosString;
            string buttNameNegString;

            // axis
            for (int axis = 0; axis < num_axes; axis++)
            {
                Int16 a_state           = axis_state[axis];
                DeviceObjectInstance di = devObList[axis];

                // dynamically create callback

                if (VersionChecker.Instance.IsNewConfig)
                {
                    // new style
                    string abs = "abs_";

                    // new config format
                    switch (di.Usage)
                    {
                    case 0x30:          // X Axis
                        cbPos             = () => state.X >= dzp;
                        cbNeg             = () => state.X <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x31:          // y Axis
                        cbPos             = () => state.Y >= dzp;
                        cbNeg             = () => state.Y <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x32:          // Z Axis
                        cbPos             = () => state.Z >= dzp;
                        cbNeg             = () => state.Z <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x33:          // X Rotation
                        cbPos             = () => state.RotationX >= dzp;
                        cbNeg             = () => state.RotationX <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x34:          // Y Rotation
                        cbPos             = () => state.RotationY >= dzp;
                        cbNeg             = () => state.RotationY <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x35:          // Z Rotation
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x40:          // X Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x41:          // Y Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x42:          // Z Velocity
                        cbPos             = () => state.RotationZ >= dzp;
                        cbNeg             = () => state.RotationZ <= dzn;
                        buttNamePosString = abs + axis + "+";
                        buttNameNegString = abs + axis + "-";
                        buttNamePos       = 0x8000 + axis;
                        buttNameNeg       = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePosString, cbPos);
                        AddItem("joystick " + id + " " + buttNameNegString, cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x39:          // Hat Switch (contains 2 actual axis)

                        // skip

                        /*
                         * povTmpCount++;
                         * // L - R
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         *
                         * // U - D
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         */
                        break;

                    default:
                        cbPos = null;
                        cbNeg = null;
                        break;
                    }
                }
                else
                {
                    // old style
                    switch (di.Usage)
                    {
                    case 0x30:          // X Axis
                        cbPos       = () => state.X >= dzp;
                        cbNeg       = () => state.X <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x31:          // y Axis
                        cbPos       = () => state.Y >= dzp;
                        cbNeg       = () => state.Y <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x32:          // Z Axis
                        cbPos       = () => state.Z >= dzp;
                        cbNeg       = () => state.Z <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x33:          // X Rotation
                        cbPos       = () => state.RotationX >= dzp;
                        cbNeg       = () => state.RotationX <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x34:          // Y Rotation
                        cbPos       = () => state.RotationY >= dzp;
                        cbNeg       = () => state.RotationY <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x35:          // Z Rotation
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x40:          // X Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x41:          // Y Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x42:          // Z Velocity
                        cbPos       = () => state.RotationZ >= dzp;
                        cbNeg       = () => state.RotationZ <= dzn;
                        buttNamePos = 0x8000 + axis;
                        buttNameNeg = 0xc000 + axis;
                        AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), cbPos);
                        AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), cbNeg);
                        BConfig.Add(Convert.ToUInt32(buttNamePos));
                        BConfig.Add(Convert.ToUInt32(buttNameNeg));
                        break;

                    case 0x39:          // Hat Switch (contains 2 actual axis)

                        // skip

                        /*
                         * povTmpCount++;
                         * // L - R
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         *
                         * // U - D
                         * buttNamePos = 0x8000 + axis;
                         * buttNameNeg = 0xc000 + axis;
                         * AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                         * AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                         * BConfig.Add(Convert.ToUInt32(buttNamePos));
                         * BConfig.Add(Convert.ToUInt32(buttNameNeg));
                         */
                        break;

                    default:
                        cbPos = null;
                        cbNeg = null;
                        break;
                    }
                }
            }


            /*
             *
             * AddItem("AccelerationX+", () => state.AccelerationX >= dzp);
             * AddItem("AccelerationX-", () => state.AccelerationX <= dzn);
             * AddItem("AccelerationY+", () => state.AccelerationY >= dzp);
             * AddItem("AccelerationY-", () => state.AccelerationY <= dzn);
             * AddItem("AccelerationZ+", () => state.AccelerationZ >= dzp);
             * AddItem("AccelerationZ-", () => state.AccelerationZ <= dzn);
             * AddItem("AngularAccelerationX+", () => state.AngularAccelerationX >= dzp);
             * AddItem("AngularAccelerationX-", () => state.AngularAccelerationX <= dzn);
             * AddItem("AngularAccelerationY+", () => state.AngularAccelerationY >= dzp);
             * AddItem("AngularAccelerationY-", () => state.AngularAccelerationY <= dzn);
             * AddItem("AngularAccelerationZ+", () => state.AngularAccelerationZ >= dzp);
             * AddItem("AngularAccelerationZ-", () => state.AngularAccelerationZ <= dzn);
             * AddItem("AngularVelocityX+", () => state.AngularVelocityX >= dzp);
             * AddItem("AngularVelocityX-", () => state.AngularVelocityX <= dzn);
             * AddItem("AngularVelocityY+", () => state.AngularVelocityY >= dzp);
             * AddItem("AngularVelocityY-", () => state.AngularVelocityY <= dzn);
             * AddItem("AngularVelocityZ+", () => state.AngularVelocityZ >= dzp);
             * AddItem("AngularVelocityZ-", () => state.AngularVelocityZ <= dzn);
             * AddItem("ForceX+", () => state.ForceX >= dzp);
             * AddItem("ForceX-", () => state.ForceX <= dzn);
             * AddItem("ForceY+", () => state.ForceY >= dzp);
             * AddItem("ForceY-", () => state.ForceY <= dzn);
             * AddItem("ForceZ+", () => state.ForceZ >= dzp);
             * AddItem("ForceZ-", () => state.ForceZ <= dzn);
             * AddItem("RotationX+", () => state.RotationX >= dzp);
             * AddItem("RotationX-", () => state.RotationX <= dzn);
             * AddItem("RotationY+", () => state.RotationY >= dzp);
             * AddItem("RotationY-", () => state.RotationY <= dzn);
             * AddItem("00008003", () => state.RotationZ >= dzp); //AddItem("RotationZ+", () => state.RotationZ >= dzp);
             * AddItem("0000c003", () => state.RotationZ <= dzn); //AddItem("RotationZ-", () => state.RotationZ <= dzn);
             * AddItem("TorqueX+", () => state.TorqueX >= dzp);
             * AddItem("TorqueX-", () => state.TorqueX <= dzn);
             * AddItem("TorqueY+", () => state.TorqueY >= dzp);
             * AddItem("TorqueY-", () => state.TorqueY <= dzn);
             * AddItem("TorqueZ+", () => state.TorqueZ >= dzp);
             * AddItem("TorqueZ-", () => state.TorqueZ <= dzn);
             * AddItem("VelocityX+", () => state.VelocityX >= dzp);
             * AddItem("VelocityX-", () => state.VelocityX <= dzn);
             * AddItem("VelocityY+", () => state.VelocityY >= dzp);
             * AddItem("VelocityY-", () => state.VelocityY <= dzn);
             * AddItem("VelocityZ+", () => state.VelocityZ >= dzp);
             * AddItem("VelocityZ-", () => state.VelocityZ <= dzn);
             * AddItem("00008000", () => state.X >= dzp); //AddItem("X+", () => state.X >= dzp);
             * AddItem("0000c000", () => state.X <= dzn); //AddItem("X-", () => state.X <= dzn);
             * AddItem("00008001", () => state.Y >= dzp); //AddItem("Y+", () => state.Y >= dzp);
             * AddItem("0000c001", () => state.Y <= dzn); //AddItem("Y-", () => state.Y <= dzn);
             * AddItem("00008002", () => state.Z >= dzp); //AddItem("Z+", () => state.Z >= dzp);
             * AddItem("0000c002", () => state.Z <= dzn); //AddItem("Z-", () => state.Z <= dzn);
             *
             */

            // i don't know what the "Slider"s do, so they're omitted for the moment

            for (int i = 0; i < state.GetButtons().Length; i++)
            {
                //int j = i;
                //AddItem(string.Format("B{0}", i + 1), () => state.IsPressed(j));
            }


            // add sliders
            int povCount  = state.GetPointOfViewControllers().Length;
            int nPovCount = joystick.Capabilities.PovCount;
            int axiscount = DevCaps.AxesCount;

            for (int i = 0; i < nPovCount; i++)
            {
                int j    = i;
                int axis = axiscount - nPovCount + i;

                if (VersionChecker.Instance.IsNewConfig)
                {
                    // new style

                    // L - R
                    buttNamePos = 0x8000 + axis;
                    buttNameNeg = 0xc000 + axis;

                    buttNamePosString = "abs_" + axis + "+";
                    buttNameNegString = "abs_" + axis + "-";

                    AddItem("joystick " + id + " " + buttNamePosString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 22500 && t <= 31500); });

                    AddItem("joystick " + id + " " + buttNameNegString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 4500 && t <= 13500); });

                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // U - D
                    buttNamePos = 0x8000 + (axis + 1);
                    buttNameNeg = 0xc000 + (axis + 1);

                    buttNamePosString = "abs_" + (axis + 1) + "+";
                    buttNameNegString = "abs_" + (axis + 1) + "-";

                    AddItem("joystick " + id + " " + buttNamePosString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return((t >= 0 && t <= 4500) || (t >= 31500 && t < 36000)); });

                    AddItem("joystick " + id + " " + buttNameNegString,
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 13500 && t <= 22500); });

                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // increment axis count (as there are effectively two axis in a POV Hat)
                    axiscount++;
                }
                else
                {
                    // old style
                    // L - R
                    buttNamePos = 0x8000 + axis;
                    buttNameNeg = 0xc000 + axis;
                    //AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 22500 && t <= 31500; });
                    AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(),  //string.Format("joystick " + id + " " + "POV{0}L", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 22500 && t <= 31500); });
                    //AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 4500 && t <= 13500; });
                    AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(),  //string.Format("joystick " + id + " " + "POV{0}R", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 4500 && t <= 13500); });
                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // U - D
                    buttNamePos = 0x8000 + (axis + 1);
                    buttNameNeg = 0xc000 + (axis + 1);
                    //AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return (t >= 0 && t <= 4500) || (t >= 31500 && t < 36000); });
                    AddItem("joystick " + id + " " + buttNamePos.ToString("X8").ToLower(),   //string.Format("joystick " + id + " " + "POV{0}U", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return((t >= 0 && t <= 4500) || (t >= 31500 && t < 36000)); });
                    //AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(), () => { int t = state.GetPointOfViewControllers()[povTmpCount]; return t >= 13500 && t <= 22500; });
                    AddItem("joystick " + id + " " + buttNameNeg.ToString("X8").ToLower(),   //string.Format("joystick " + id + " " + "POV{0}D", i + 1),
                            () => { int t = state.GetPointOfViewControllers()[j]; return(t >= 13500 && t <= 22500); });
                    BConfig.Add(Convert.ToUInt32(buttNamePos));
                    BConfig.Add(Convert.ToUInt32(buttNameNeg));

                    // increment axis count (as there are effectively two axis in a POV Hat)
                    axiscount++;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BeamPluginCreationFeature"/> class.
 /// </summary>
 public BeamPluginCreationFeature()
     : base(BasicPlugin.BeamPlugin.PluginName)
 {
     this.inputRange = InputRange.AtMost(2);
 }
コード例 #16
0
        private void ConectarDispositivo()
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(_view);

            _dispositivo = new Device(DispositivoSelecionado.Guid);

            if (_dispositivo.DeviceInformation.InstanceName.Contains("XBOX"))
            {
                _controleXbox = true;
            }

            // Set joystick axis ranges.
            var eixos = _dispositivo.GetObjects(DeviceObjectTypeFlags.Axis);

            // Configura os eixos já para o PWM
            foreach (DeviceObjectInstance doi in eixos)
            {
                InputRange inputRange = new InputRange(0, 255);

                // Eixo do volante
                if (doi.Name.Contains("Wheel axis"))
                {
                    inputRange = new InputRange(-255, 255);
                }

                if (doi.Name.Contains("X Axis") && _controleXbox)
                {
                    inputRange = new InputRange(-255, 255);
                }

                if (doi.Name.Contains("Z Axis") && _controleXbox)
                {
                    inputRange = new InputRange(-255, 255);
                }

                _dispositivo.Properties.SetRange(ParameterHow.ById, doi.ObjectId, inputRange);
            }

            _dispositivo.Properties.AxisModeAbsolute = true;

            // _dispositivo.SetCooperativeLevel(helper.Handle, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);

            _dispositivo.SetDataFormat(DeviceDataFormat.Joystick);

            // _dispositivo.Properties.BufferSize = 128;
            _dispositivo.Acquire();
        }
コード例 #17
0
ファイル: Bot.cs プロジェクト: taguro/CustomizableBot
 //...etc
 public BotData(InputRange inputRange, List<int[]> inputPoints)
 {
     this.inputRange = inputRange;
     this.inputPoints = inputPoints;
 }
コード例 #18
0
        private void InputRunner()
        {
            Dictionary <Device, Dictionary <int, int> >        objectInitial = new Dictionary <Device, Dictionary <int, int> >();
            Dictionary <Device, Dictionary <int, InputRange> > objectRanges  = new Dictionary <Device, Dictionary <int, InputRange> >();
            Dictionary <Device, HashSet <int> > buttons = new Dictionary <Device, HashSet <int> >();

            Key[] keyValues = new Key[237];
            for (int i = 0; i < keyValues.Length; ++i)
            {
                keyValues[i] = (Key)i;
            }

            bool[] keyRecordedState = null;

            lock (this.syncRoot)
            {
                foreach (Device d in this.joysticks.Values)
                {
                    objectInitial.Add(d, new Dictionary <int, int>());
                    objectRanges.Add(d, new Dictionary <int, InputRange>());
                    buttons.Add(d, new HashSet <int>());

                    foreach (DeviceObjectInstance o in d.GetObjects(DeviceObjectTypeFlags.Button))
                    {
                        buttons[d].Add(o.Offset);
                    }
                }
            }

            Dictionary <Key[], bool> keybindingStates   = new Dictionary <Key[], bool>();
            Dictionary <int, bool>   mousebindingStates = new Dictionary <int, bool>();

            while (this.running)
            {
                int waited = WaitHandle.WaitAny(this.waits);
                lock (this.syncRoot)
                {
                    switch (waited)
                    {
                    case 0:                             // Keyboard
                    {
                        KeyboardState state = this.keyboard.GetCurrentState();

                        if (!this.recording && this.keyboardBindings != null)
                        {
                            foreach (var kvp in this.keyboardBindings)
                            {
                                int match = 0;
                                for (int i = 0; i < kvp.Key.Length; ++i)
                                {
                                    if (state.IsPressed(kvp.Key[i]))
                                    {
                                        match++;
                                    }
                                }

                                bool nowState = (match == kvp.Key.Length);
                                bool currentState;
                                if (keybindingStates.TryGetValue(kvp.Key, out currentState))
                                {
                                    if (nowState != currentState)
                                    {
                                        OnInputStateChanged(new CommandStateChangedEventArgs(kvp.Value, nowState));
                                        keybindingStates[kvp.Key] = nowState;
                                    }
                                }
                                else if (nowState)
                                {
                                    OnInputStateChanged(new CommandStateChangedEventArgs(kvp.Value, true));
                                    keybindingStates[kvp.Key] = true;
                                }
                            }
                        }
                        else
                        {
                            bool[] currentState = new bool[keyValues.Length];
                            for (int i = 0; i < keyValues.Length; ++i)
                            {
                                currentState[i] = state.IsPressed(keyValues[i]);
                            }

                            bool up = false;
                            if (keyRecordedState != null)
                            {
                                for (int i = 0; i < keyRecordedState.Length; ++i)
                                {
                                    if (!keyRecordedState[i] || currentState[i])
                                    {
                                        continue;
                                    }

                                    up = true;
                                    break;
                                }
                            }
                            else
                            {
                                keyRecordedState = currentState;
                            }

                            if (up)
                            {
                                string currentRecording = KeyboardGuid + "|";
                                for (int i = 0; i < keyValues.Length; ++i)
                                {
                                    if (!keyRecordedState[i])
                                    {
                                        continue;
                                    }

                                    if (currentRecording != KeyboardGuid + "|")
                                    {
                                        currentRecording += "+";
                                    }

                                    currentRecording += keyValues[i].ToString();
                                }

                                keyRecordedState = null;
                                OnNewRecording(new RecordingEventArgs(this, currentRecording));
                            }
                            else
                            {
                                keyRecordedState = currentState;
                            }
                        }

                        break;
                    }

                    case 1:                             // Mouse
                    {
                        if (!this.recording && this.mouseBindings.Count == 0)
                        {
                            continue;
                        }

                        bool[] state = this.mouse.GetCurrentState().Buttons;

                        if (!this.recording)
                        {
                            for (int i = 0; i < state.Length; ++i)
                            {
                                Command c;
                                if (!this.mouseBindings.TryGetValue(i, out c))
                                {
                                    continue;
                                }

                                bool newState = state[i];
                                bool currentState;
                                if (mousebindingStates.TryGetValue(i, out currentState))
                                {
                                    if (currentState != newState)
                                    {
                                        OnInputStateChanged(new CommandStateChangedEventArgs(c, newState));
                                        mousebindingStates[i] = newState;
                                    }
                                }
                                else if (newState)
                                {
                                    OnInputStateChanged(new CommandStateChangedEventArgs(c, true));
                                    mousebindingStates[i] = true;
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < state.Length; ++i)
                            {
                                if (!state[i])
                                {
                                    continue;
                                }

                                OnNewRecording(new RecordingEventArgs(this, MouseGuid + "|" + i));
                                break;
                            }
                        }

                        break;
                    }

                    default:
                        if (!this.recording && this.joystickBindings.Count == 0)
                        {
                            continue;
                        }

                        var d = this.joysticks[this.joystickIndexes[waited]];
                        var currentButtons  = buttons[d];
                        var currentInitials = objectInitial[d];
                        var currentRanges   = objectRanges[d];

                        JoystickUpdate[] updates = d.GetBufferedData();
                        if (updates == null)
                        {
                            continue;
                        }

                        for (int i = 0; i < updates.Length; i++)
                        {
                            JoystickUpdate update = updates[i];
                            if (this.recording)
                            {
                                int initial;
                                if (!currentInitials.TryGetValue(update.RawOffset, out initial))
                                {
                                    if (!currentButtons.Contains(update.RawOffset))
                                    {
                                        try
                                        {
                                            currentRanges.Add(update.RawOffset, d.Properties.Range);
                                            currentInitials[update.RawOffset] = update.Value;
                                        }
                                        catch (NotSupportedException)
                                        {
                                        }
                                    }
                                    else
                                    {
                                        OnNewRecording(new RecordingEventArgs(this, String.Format("{0}|{1}", d.Information.InstanceGuid, update.Offset)));
                                    }
                                }
                                else
                                {
                                    InputRange range = currentRanges[update.RawOffset];
                                    int        delta = Math.Abs(initial - update.Value);
                                    if (((float)delta / (range.Maximum - range.Minimum)) > 0.25)                                             // >25% change
                                    {
                                        OnNewRecording(new RecordingEventArgs(this, String.Format("{0}|{1};{2}", d.Information.InstanceGuid, update.Offset, ((initial > update.Value) ? "+" : "-"))));
                                    }
                                }
                            }
                            else
                            {
                                Dictionary <int, Command> binds;
                                if (!this.joystickBindings.TryGetValue(d.Information.InstanceGuid, out binds) || binds.Count == 0)
                                {
                                    continue;
                                }

                                Command c;
                                if (!binds.TryGetValue(update.RawOffset, out c))
                                {
                                    continue;
                                }

                                if (currentButtons.Contains(update.RawOffset))
                                {
                                    OnInputStateChanged(new CommandStateChangedEventArgs(c, (update.Value == 128)));
                                }
                                else
                                {
                                    InputRange range = currentRanges[update.RawOffset];

                                    double value = (update.Value != -1) ? update.Value : range.Maximum;
                                    OnInputStateChanged(new CommandStateChangedEventArgs(c, (value / (range.Maximum - range.Minimum)) * 100));
                                }
                            }
                        }

                        break;
                    }
                }
            }
        }