From b2890c49ba31704f812a76d4a7e09e334e9dbf4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Weinm=C3=BCllner?= Date: Fri, 27 Jul 2018 10:02:53 +0200 Subject: [PATCH 001/105] Implemented Nonlinear Axis Sensitivity --- UCR.Core/Utilities/Functions.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 222e3623..7ea9e0a8 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -15,8 +15,17 @@ public static long ApplyRangeDeadZone(long value, int deadZonePercentage) public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) { var sensitivityPercent = (sensitivity / 100.0); - if (linear) return (long)(value * sensitivityPercent); - // TODO https://github.com/evilC/UCR/blob/master/Libraries/StickOps/StickOps.ahk#L60 + if (linear) return (long)(value * sensitivityPercent); + + var sens = sensitivityPercent / 100d; + double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); + // Map value to -1 .. 1 + double val11 = (((value - Constants.AxisMinValue) / AxisRange) * 2) - 1; + // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) + double valout = (sens * val11) + ((1 - sens) * Math.Pow( val11, 3 )); + // Map value back to AxisRange + value = (long) Math.Round( ((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue) ); + return value; } From 95e341bb7695fe276a776c36130b95da9d8e239e Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Tue, 31 Jul 2018 00:14:05 +0200 Subject: [PATCH 002/105] DeviceBinding preview values added --- UCR.Core/Models/Binding/DeviceBinding.cs | 45 +- UCR.Core/Properties/Annotations.cs | 1065 +++++++++++++++++ UCR.Core/UCR.Core.csproj | 1 + UCR.sln.DotSettings | 1 + .../DeviceBindingViewModel.cs | 45 +- UCR/Views/Controls/DeviceBindingControl.xaml | 2 + .../Controls/DeviceBindingControl.xaml.cs | 3 +- UCR/Views/Controls/MappingControl.xaml | 2 +- UCR/Views/Controls/PluginControl.xaml | 2 +- 9 files changed, 1158 insertions(+), 8 deletions(-) create mode 100644 UCR.Core/Properties/Annotations.cs diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index 57f39c35..b3cbe9fd 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -1,6 +1,9 @@ using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; using System.Xml.Serialization; using HidWizards.IOWrapper.DataTransferObjects; +using HidWizards.UCR.Core.Annotations; namespace HidWizards.UCR.Core.Models.Binding { @@ -12,7 +15,7 @@ public enum DeviceBindingCategory Delta } - public class DeviceBinding + public class DeviceBinding : INotifyPropertyChanged { /* Persistence */ public bool IsBound { get; set; } @@ -35,11 +38,34 @@ public class DeviceBinding public delegate void ValueChanged(long value); + + private ValueChanged _callback; + [XmlIgnore] - public ValueChanged Callback { get; set; } + public ValueChanged Callback + { + get => InputChanged; + set + { + _callback = value; + OnPropertyChanged(); + } + } [XmlIgnore] public ValueChanged OutputSink { get; set; } + private long _currentValue; + [XmlIgnore] + public long CurrentValue + { + get => _currentValue; + set + { + _currentValue = value; + OnPropertyChanged(); + } + } + public DeviceBinding() { Guid = Guid.NewGuid(); @@ -105,7 +131,22 @@ public static DeviceBindingCategory MapCategory(BindingCategory bindingInfoCateg public void WriteOutput(long value) { + CurrentValue = value; OutputSink?.Invoke(value); } + + private void InputChanged(long value) + { + CurrentValue = value; + _callback(value); + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } diff --git a/UCR.Core/Properties/Annotations.cs b/UCR.Core/Properties/Annotations.cs new file mode 100644 index 00000000..7148462f --- /dev/null +++ b/UCR.Core/Properties/Annotations.cs @@ -0,0 +1,1065 @@ +/* MIT License + +Copyright (c) 2016 JetBrains http://www.jetbrains.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. */ + +using System; + +#pragma warning disable 1591 +// ReSharper disable UnusedMember.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable IntroduceOptionalParameters.Global +// ReSharper disable MemberCanBeProtected.Global +// ReSharper disable InconsistentNaming + +namespace HidWizards.UCR.Core.Annotations +{ + /// + /// Indicates that the value of the marked element could be null sometimes, + /// so the check for null is necessary before its usage. + /// + /// + /// [CanBeNull] object Test() => null; + /// + /// void UseTest() { + /// var p = Test(); + /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' + /// } + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] + public sealed class CanBeNullAttribute : Attribute { } + + /// + /// Indicates that the value of the marked element could never be null. + /// + /// + /// [NotNull] object Foo() { + /// return null; // Warning: Possible 'null' assignment + /// } + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] + public sealed class NotNullAttribute : Attribute { } + + /// + /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property + /// or of the Lazy.Value property can never be null. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field)] + public sealed class ItemNotNullAttribute : Attribute { } + + /// + /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property + /// or of the Lazy.Value property can be null. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field)] + public sealed class ItemCanBeNullAttribute : Attribute { } + + /// + /// Indicates that the marked method builds string by format pattern and (optional) arguments. + /// Parameter, which contains format string, should be given in constructor. The format string + /// should be in -like form. + /// + /// + /// [StringFormatMethod("message")] + /// void ShowError(string message, params object[] args) { /* do something */ } + /// + /// void Foo() { + /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string + /// } + /// + [AttributeUsage( + AttributeTargets.Constructor | AttributeTargets.Method | + AttributeTargets.Property | AttributeTargets.Delegate)] + public sealed class StringFormatMethodAttribute : Attribute + { + /// + /// Specifies which parameter of an annotated method should be treated as format-string + /// + public StringFormatMethodAttribute([NotNull] string formatParameterName) + { + FormatParameterName = formatParameterName; + } + + [NotNull] public string FormatParameterName { get; private set; } + } + + /// + /// For a parameter that is expected to be one of the limited set of values. + /// Specify fields of which type should be used as values for this parameter. + /// + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field, + AllowMultiple = true)] + public sealed class ValueProviderAttribute : Attribute + { + public ValueProviderAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + /// + /// Indicates that the function argument should be string literal and match one + /// of the parameters of the caller function. For example, ReSharper annotates + /// the parameter of . + /// + /// + /// void Foo(string param) { + /// if (param == null) + /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol + /// } + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class InvokerParameterNameAttribute : Attribute { } + + /// + /// Indicates that the method is contained in a type that implements + /// System.ComponentModel.INotifyPropertyChanged interface and this method + /// is used to notify that some property value changed. + /// + /// + /// The method should be non-static and conform to one of the supported signatures: + /// + /// NotifyChanged(string) + /// NotifyChanged(params string[]) + /// NotifyChanged{T}(Expression{Func{T}}) + /// NotifyChanged{T,U}(Expression{Func{T,U}}) + /// SetProperty{T}(ref T, T, string) + /// + /// + /// + /// public class Foo : INotifyPropertyChanged { + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// [NotifyPropertyChangedInvocator] + /// protected virtual void NotifyChanged(string propertyName) { ... } + /// + /// string _name; + /// + /// public string Name { + /// get { return _name; } + /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } + /// } + /// } + /// + /// Examples of generated notifications: + /// + /// NotifyChanged("Property") + /// NotifyChanged(() => Property) + /// NotifyChanged((VM x) => x.Property) + /// SetProperty(ref myField, value, "Property") + /// + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute + { + public NotifyPropertyChangedInvocatorAttribute() { } + public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) + { + ParameterName = parameterName; + } + + [CanBeNull] public string ParameterName { get; private set; } + } + + /// + /// Describes dependency between method input and output. + /// + /// + ///

Function Definition Table syntax:

+ /// + /// FDT ::= FDTRow [;FDTRow]* + /// FDTRow ::= Input => Output | Output <= Input + /// Input ::= ParameterName: Value [, Input]* + /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} + /// Value ::= true | false | null | notnull | canbenull + /// + /// If method has single input parameter, it's name could be omitted.
+ /// Using halt (or void/nothing, which is the same) for method output + /// means that the methos doesn't return normally (throws or terminates the process).
+ /// Value canbenull is only applicable for output parameters.
+ /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute + /// with rows separated by semicolon. There is no notion of order rows, all rows are checked + /// for applicability and applied per each program state tracked by R# analysis.
+ ///
+ /// + /// + /// [ContractAnnotation("=> halt")] + /// public void TerminationMethod() + /// + /// + /// [ContractAnnotation("halt <= condition: false")] + /// public void Assert(bool condition, string text) // regular assertion method + /// + /// + /// [ContractAnnotation("s:null => true")] + /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() + /// + /// + /// // A method that returns null if the parameter is null, + /// // and not null if the parameter is not null + /// [ContractAnnotation("null => null; notnull => notnull")] + /// public object Transform(object data) + /// + /// + /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] + /// public bool TryParse(string s, out Person result) + /// + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public sealed class ContractAnnotationAttribute : Attribute + { + public ContractAnnotationAttribute([NotNull] string contract) + : this(contract, false) { } + + public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) + { + Contract = contract; + ForceFullStates = forceFullStates; + } + + [NotNull] public string Contract { get; private set; } + + public bool ForceFullStates { get; private set; } + } + + /// + /// Indicates that marked element should be localized or not. + /// + /// + /// [LocalizationRequiredAttribute(true)] + /// class Foo { + /// string str = "my string"; // Warning: Localizable string + /// } + /// + [AttributeUsage(AttributeTargets.All)] + public sealed class LocalizationRequiredAttribute : Attribute + { + public LocalizationRequiredAttribute() : this(true) { } + + public LocalizationRequiredAttribute(bool required) + { + Required = required; + } + + public bool Required { get; private set; } + } + + /// + /// Indicates that the value of the marked type (or its derivatives) + /// cannot be compared using '==' or '!=' operators and Equals() + /// should be used instead. However, using '==' or '!=' for comparison + /// with null is always permitted. + /// + /// + /// [CannotApplyEqualityOperator] + /// class NoEquality { } + /// + /// class UsesNoEquality { + /// void Test() { + /// var ca1 = new NoEquality(); + /// var ca2 = new NoEquality(); + /// if (ca1 != null) { // OK + /// bool condition = ca1 == ca2; // Warning + /// } + /// } + /// } + /// + [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] + public sealed class CannotApplyEqualityOperatorAttribute : Attribute { } + + /// + /// When applied to a target attribute, specifies a requirement for any type marked + /// with the target attribute to implement or inherit specific type or types. + /// + /// + /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement + /// class ComponentAttribute : Attribute { } + /// + /// [Component] // ComponentAttribute requires implementing IComponent interface + /// class MyComponent : IComponent { } + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + [BaseTypeRequired(typeof(Attribute))] + public sealed class BaseTypeRequiredAttribute : Attribute + { + public BaseTypeRequiredAttribute([NotNull] Type baseType) + { + BaseType = baseType; + } + + [NotNull] public Type BaseType { get; private set; } + } + + /// + /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), + /// so this symbol will not be marked as unused (as well as by other usage inspections). + /// + [AttributeUsage(AttributeTargets.All)] + public sealed class UsedImplicitlyAttribute : Attribute + { + public UsedImplicitlyAttribute() + : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } + + public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) + : this(useKindFlags, ImplicitUseTargetFlags.Default) { } + + public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) + : this(ImplicitUseKindFlags.Default, targetFlags) { } + + public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) + { + UseKindFlags = useKindFlags; + TargetFlags = targetFlags; + } + + public ImplicitUseKindFlags UseKindFlags { get; private set; } + + public ImplicitUseTargetFlags TargetFlags { get; private set; } + } + + /// + /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes + /// as unused (as well as by other usage inspections) + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)] + public sealed class MeansImplicitUseAttribute : Attribute + { + public MeansImplicitUseAttribute() + : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) + : this(useKindFlags, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) + : this(ImplicitUseKindFlags.Default, targetFlags) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) + { + UseKindFlags = useKindFlags; + TargetFlags = targetFlags; + } + + [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; private set; } + + [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; private set; } + } + + [Flags] + public enum ImplicitUseKindFlags + { + Default = Access | Assign | InstantiatedWithFixedConstructorSignature, + /// Only entity marked with attribute considered used. + Access = 1, + /// Indicates implicit assignment to a member. + Assign = 2, + /// + /// Indicates implicit instantiation of a type with fixed constructor signature. + /// That means any unused constructor parameters won't be reported as such. + /// + InstantiatedWithFixedConstructorSignature = 4, + /// Indicates implicit instantiation of a type. + InstantiatedNoFixedConstructorSignature = 8, + } + + /// + /// Specify what is considered used implicitly when marked + /// with or . + /// + [Flags] + public enum ImplicitUseTargetFlags + { + Default = Itself, + Itself = 1, + /// Members of entity marked with attribute are considered used. + Members = 2, + /// Entity marked with attribute and all its members considered used. + WithMembers = Itself | Members + } + + /// + /// This attribute is intended to mark publicly available API + /// which should not be removed and so is treated as used. + /// + [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] + public sealed class PublicAPIAttribute : Attribute + { + public PublicAPIAttribute() { } + + public PublicAPIAttribute([NotNull] string comment) + { + Comment = comment; + } + + [CanBeNull] public string Comment { get; private set; } + } + + /// + /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack. + /// If the parameter is a delegate, indicates that delegate is executed while the method is executed. + /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class InstantHandleAttribute : Attribute { } + + /// + /// Indicates that a method does not make any observable state changes. + /// The same as System.Diagnostics.Contracts.PureAttribute. + /// + /// + /// [Pure] int Multiply(int x, int y) => x * y; + /// + /// void M() { + /// Multiply(123, 42); // Waring: Return value of pure method is not used + /// } + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class PureAttribute : Attribute { } + + /// + /// Indicates that the return value of method invocation must be used. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class MustUseReturnValueAttribute : Attribute + { + public MustUseReturnValueAttribute() { } + + public MustUseReturnValueAttribute([NotNull] string justification) + { + Justification = justification; + } + + [CanBeNull] public string Justification { get; private set; } + } + + /// + /// Indicates the type member or parameter of some type, that should be used instead of all other ways + /// to get the value that type. This annotation is useful when you have some "context" value evaluated + /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one. + /// + /// + /// class Foo { + /// [ProvidesContext] IBarService _barService = ...; + /// + /// void ProcessNode(INode node) { + /// DoSomething(node, node.GetGlobalServices().Bar); + /// // ^ Warning: use value of '_barService' field + /// } + /// } + /// + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.GenericParameter)] + public sealed class ProvidesContextAttribute : Attribute { } + + /// + /// Indicates that a parameter is a path to a file or a folder within a web project. + /// Path can be relative or absolute, starting from web root (~). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class PathReferenceAttribute : Attribute + { + public PathReferenceAttribute() { } + + public PathReferenceAttribute([NotNull, PathReference] string basePath) + { + BasePath = basePath; + } + + [CanBeNull] public string BasePath { get; private set; } + } + + /// + /// An extension method marked with this attribute is processed by ReSharper code completion + /// as a 'Source Template'. When extension method is completed over some expression, it's source code + /// is automatically expanded like a template at call site. + /// + /// + /// Template method body can contain valid source code and/or special comments starting with '$'. + /// Text inside these comments is added as source code when the template is applied. Template parameters + /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs. + /// Use the attribute to specify macros for parameters. + /// + /// + /// In this example, the 'forEach' method is a source template available over all values + /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block: + /// + /// [SourceTemplate] + /// public static void forEach<T>(this IEnumerable<T> xs) { + /// foreach (var x in xs) { + /// //$ $END$ + /// } + /// } + /// + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class SourceTemplateAttribute : Attribute { } + + /// + /// Allows specifying a macro for a parameter of a source template. + /// + /// + /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression + /// is defined in the property. When applied on a method, the target + /// template parameter is defined in the property. To apply the macro silently + /// for the parameter, set the property value = -1. + /// + /// + /// Applying the attribute on a source template method: + /// + /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")] + /// public static void forEach<T>(this IEnumerable<T> collection) { + /// foreach (var item in collection) { + /// //$ $END$ + /// } + /// } + /// + /// Applying the attribute on a template method parameter: + /// + /// [SourceTemplate] + /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) { + /// /*$ var $x$Id = "$newguid$" + x.ToString(); + /// x.DoSomething($x$Id); */ + /// } + /// + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)] + public sealed class MacroAttribute : Attribute + { + /// + /// Allows specifying a macro that will be executed for a source template + /// parameter when the template is expanded. + /// + [CanBeNull] public string Expression { get; set; } + + /// + /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. + /// + /// + /// If the target parameter is used several times in the template, only one occurrence becomes editable; + /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence, + /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1. + /// > + public int Editable { get; set; } + + /// + /// Identifies the target parameter of a source template if the + /// is applied on a template method. + /// + [CanBeNull] public string Target { get; set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute + { + public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute + { + public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute + { + public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcMasterLocationFormatAttribute : Attribute + { + public AspMvcMasterLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute + { + public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] + public sealed class AspMvcViewLocationFormatAttribute : Attribute + { + public AspMvcViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC action. If applied to a method, the MVC action name is calculated + /// implicitly from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcActionAttribute : Attribute + { + public AspMvcActionAttribute() { } + + public AspMvcActionAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcAreaAttribute : Attribute + { + public AspMvcAreaAttribute() { } + + public AspMvcAreaAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is + /// an MVC controller. If applied to a method, the MVC controller name is calculated + /// implicitly from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcControllerAttribute : Attribute + { + public AspMvcControllerAttribute() { } + + public AspMvcControllerAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. Use this attribute + /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcMasterAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. Use this attribute + /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, Object). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcModelTypeAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC + /// partial view. If applied to a method, the MVC partial view name is calculated implicitly + /// from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcPartialViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] + public sealed class AspMvcSuppressViewErrorAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcDisplayTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcEditorTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template. + /// Use this attribute for custom wrappers similar to + /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly + /// from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Controller.View(Object). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component name. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcViewComponentAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component view. If applied to a method, the MVC view component view name is default. + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcViewComponentViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. When applied to a parameter of an attribute, + /// indicates that this parameter is an MVC action name. + /// + /// + /// [ActionName("Foo")] + /// public ActionResult Login(string returnUrl) { + /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK + /// return RedirectToAction("Bar"); // Error: Cannot resolve action + /// } + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] + public sealed class AspMvcActionSelectorAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)] + public sealed class HtmlElementAttributesAttribute : Attribute + { + public HtmlElementAttributesAttribute() { } + + public HtmlElementAttributesAttribute([NotNull] string name) + { + Name = name; + } + + [CanBeNull] public string Name { get; private set; } + } + + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] + public sealed class HtmlAttributeValueAttribute : Attribute + { + public HtmlAttributeValueAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + /// + /// Razor attribute. Indicates that a parameter or a method is a Razor section. + /// Use this attribute for custom wrappers similar to + /// System.Web.WebPages.WebPageBase.RenderSection(String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class RazorSectionAttribute : Attribute { } + + /// + /// Indicates how method, constructor invocation or property access + /// over collection type affects content of the collection. + /// + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] + public sealed class CollectionAccessAttribute : Attribute + { + public CollectionAccessAttribute(CollectionAccessType collectionAccessType) + { + CollectionAccessType = collectionAccessType; + } + + public CollectionAccessType CollectionAccessType { get; private set; } + } + + [Flags] + public enum CollectionAccessType + { + /// Method does not use or modify content of the collection. + None = 0, + /// Method only reads content of the collection but does not modify it. + Read = 1, + /// Method can change content of the collection but does not add new elements. + ModifyExistingContent = 2, + /// Method can add new elements to the collection. + UpdatedContent = ModifyExistingContent | 4 + } + + /// + /// Indicates that the marked method is assertion method, i.e. it halts control flow if + /// one of the conditions is satisfied. To set the condition, mark one of the parameters with + /// attribute. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class AssertionMethodAttribute : Attribute { } + + /// + /// Indicates the condition parameter of the assertion method. The method itself should be + /// marked by attribute. The mandatory argument of + /// the attribute is the assertion type. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AssertionConditionAttribute : Attribute + { + public AssertionConditionAttribute(AssertionConditionType conditionType) + { + ConditionType = conditionType; + } + + public AssertionConditionType ConditionType { get; private set; } + } + + /// + /// Specifies assertion type. If the assertion method argument satisfies the condition, + /// then the execution continues. Otherwise, execution is assumed to be halted. + /// + public enum AssertionConditionType + { + /// Marked parameter should be evaluated to true. + IS_TRUE = 0, + /// Marked parameter should be evaluated to false. + IS_FALSE = 1, + /// Marked parameter should be evaluated to null value. + IS_NULL = 2, + /// Marked parameter should be evaluated to not null value. + IS_NOT_NULL = 3, + } + + /// + /// Indicates that the marked method unconditionally terminates control flow execution. + /// For example, it could unconditionally throw exception. + /// + [Obsolete("Use [ContractAnnotation('=> halt')] instead")] + [AttributeUsage(AttributeTargets.Method)] + public sealed class TerminatesProgramAttribute : Attribute { } + + /// + /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select, + /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters + /// of delegate type by analyzing LINQ method chains. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class LinqTunnelAttribute : Attribute { } + + /// + /// Indicates that IEnumerable, passed as parameter, is not enumerated. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class NoEnumerationAttribute : Attribute { } + + /// + /// Indicates that parameter is regular expression pattern. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class RegexPatternAttribute : Attribute { } + + /// + /// Prevents the Member Reordering feature from tossing members of the marked class. + /// + /// + /// The attribute must be mentioned in your member reordering patterns + /// + [AttributeUsage( + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)] + public sealed class NoReorderAttribute : Attribute { } + + /// + /// XAML attribute. Indicates the type that has ItemsSource property and should be treated + /// as ItemsControl-derived type, to enable inner items DataContext type resolve. + /// + [AttributeUsage(AttributeTargets.Class)] + public sealed class XamlItemsControlAttribute : Attribute { } + + /// + /// XAML attribute. Indicates the property of some BindingBase-derived type, that + /// is used to bind some item of ItemsControl-derived type. This annotation will + /// enable the DataContext type resolve for XAML bindings for such properties. + /// + /// + /// Property should have the tree ancestor of the ItemsControl type or + /// marked with the attribute. + /// + [AttributeUsage(AttributeTargets.Property)] + public sealed class XamlItemBindingOfItemsControlAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class AspChildControlTypeAttribute : Attribute + { + public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) + { + TagName = tagName; + ControlType = controlType; + } + + [NotNull] public string TagName { get; private set; } + + [NotNull] public Type ControlType { get; private set; } + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] + public sealed class AspDataFieldAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] + public sealed class AspDataFieldsAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class AspMethodPropertyAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class AspRequiredAttributeAttribute : Attribute + { + public AspRequiredAttributeAttribute([NotNull] string attribute) + { + Attribute = attribute; + } + + [NotNull] public string Attribute { get; private set; } + } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class AspTypePropertyAttribute : Attribute + { + public bool CreateConstructorReferences { get; private set; } + + public AspTypePropertyAttribute(bool createConstructorReferences) + { + CreateConstructorReferences = createConstructorReferences; + } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorImportNamespaceAttribute : Attribute + { + public RazorImportNamespaceAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorInjectionAttribute : Attribute + { + public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) + { + Type = type; + FieldName = fieldName; + } + + [NotNull] public string Type { get; private set; } + + [NotNull] public string FieldName { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorDirectiveAttribute : Attribute + { + public RazorDirectiveAttribute([NotNull] string directive) + { + Directive = directive; + } + + [NotNull] public string Directive { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorPageBaseTypeAttribute : Attribute + { + public RazorPageBaseTypeAttribute([NotNull] string baseType) + { + BaseType = baseType; + } + public RazorPageBaseTypeAttribute([NotNull] string baseType, string pageName) + { + BaseType = baseType; + PageName = pageName; + } + + [NotNull] public string BaseType { get; private set; } + [CanBeNull] public string PageName { get; private set; } + } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorHelperCommonAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class RazorLayoutAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorWriteLiteralMethodAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorWriteMethodAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class RazorWriteMethodParameterAttribute : Attribute { } +} \ No newline at end of file diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 0c687e08..706c2ac9 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -84,6 +84,7 @@ + diff --git a/UCR.sln.DotSettings b/UCR.sln.DotSettings index 2f4bbee6..048f113f 100644 --- a/UCR.sln.DotSettings +++ b/UCR.sln.DotSettings @@ -1,2 +1,3 @@  + True True \ No newline at end of file diff --git a/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs index 5c9d11ef..240f371f 100644 --- a/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs +++ b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs @@ -1,11 +1,50 @@ -using HidWizards.UCR.Core.Models.Binding; +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using HidWizards.UCR.Core.Annotations; +using HidWizards.UCR.Core.Models.Binding; namespace HidWizards.UCR.ViewModels.ProfileViewModels { - public class DeviceBindingViewModel + public class DeviceBindingViewModel : INotifyPropertyChanged { public string DeviceBindingName { get; set; } public DeviceBindingCategory DeviceBindingCategory { get; set; } - public DeviceBinding DeviceBinding { get; set; } + + private DeviceBinding _deviceBinding; + public DeviceBinding DeviceBinding + { + get => _deviceBinding; + set + { + _deviceBinding = value; + _deviceBinding.PropertyChanged += DeviceBindingOnPropertyChanged; + } + } + + private long _currentValue; + public long CurrentValue + { + get => _currentValue; + set + { + _currentValue = value; + OnPropertyChanged(); + } + } + + private void DeviceBindingOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) + { + var deviceBinding = (DeviceBinding) sender; + CurrentValue = deviceBinding.CurrentValue; + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } diff --git a/UCR/Views/Controls/DeviceBindingControl.xaml b/UCR/Views/Controls/DeviceBindingControl.xaml index f0388a47..cd8ad5b9 100644 --- a/UCR/Views/Controls/DeviceBindingControl.xaml +++ b/UCR/Views/Controls/DeviceBindingControl.xaml @@ -11,6 +11,7 @@ + + diff --git a/UCR/Views/Controls/DeviceBindingControl.xaml.cs b/UCR/Views/Controls/DeviceBindingControl.xaml.cs index 260711bd..23950be5 100644 --- a/UCR/Views/Controls/DeviceBindingControl.xaml.cs +++ b/UCR/Views/Controls/DeviceBindingControl.xaml.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; using HidWizards.UCR.Utilities.Commands; using HidWizards.UCR.ViewModels; +using HidWizards.UCR.ViewModels.ProfileViewModels; namespace HidWizards.UCR.Views.Controls { @@ -27,7 +29,6 @@ public partial class DeviceBindingControl : UserControl private bool HasLoaded = false; public static readonly DependencyProperty CategoryProperty = DependencyProperty.Register("Category", typeof(DeviceBindingCategory?), typeof(DeviceBindingControl), new PropertyMetadata(default(DeviceBindingCategory?))); - public DeviceBindingControl() { BindMenu = new ObservableCollection(); diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index 1eda0d28..030b7a07 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -62,7 +62,7 @@ - + diff --git a/UCR/Views/Controls/PluginControl.xaml b/UCR/Views/Controls/PluginControl.xaml index 8d4ff355..2d9ec5c4 100644 --- a/UCR/Views/Controls/PluginControl.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -56,7 +56,7 @@ - + From 4933a269799f87edaa507e54eec6a042a4c75f08 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Tue, 31 Jul 2018 22:28:58 +0200 Subject: [PATCH 003/105] Previews for Range and Momentary values in DeviceBinding implemented --- UCR/UCR.csproj | 10 +++++ .../DeviceBindingViewModel.cs | 1 + UCR/Views/Controls/DeviceBindingControl.xaml | 2 +- UCR/Views/Controls/PreviewControl.xaml | 39 +++++++++++++++++++ UCR/Views/Controls/PreviewControl.xaml.cs | 28 +++++++++++++ .../PreviewControlTemplateSelector.cs | 33 ++++++++++++++++ .../Controls/preview/MomentaryConverter.cs | 22 +++++++++++ UCR/Views/Controls/preview/RangeConverter.cs | 22 +++++++++++ 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 UCR/Views/Controls/PreviewControl.xaml create mode 100644 UCR/Views/Controls/PreviewControl.xaml.cs create mode 100644 UCR/Views/Controls/PreviewControlTemplateSelector.cs create mode 100644 UCR/Views/Controls/preview/MomentaryConverter.cs create mode 100644 UCR/Views/Controls/preview/RangeConverter.cs diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index 1a346a5c..334080a7 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -112,11 +112,17 @@ PluginControl.xaml + EnumControl.xaml + + PreviewControl.xaml + + + StateControl.xaml @@ -187,6 +193,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs index 240f371f..018e06ea 100644 --- a/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs +++ b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs @@ -19,6 +19,7 @@ public DeviceBinding DeviceBinding { _deviceBinding = value; _deviceBinding.PropertyChanged += DeviceBindingOnPropertyChanged; + CurrentValue = _deviceBinding.CurrentValue; } } diff --git a/UCR/Views/Controls/DeviceBindingControl.xaml b/UCR/Views/Controls/DeviceBindingControl.xaml index cd8ad5b9..464e7929 100644 --- a/UCR/Views/Controls/DeviceBindingControl.xaml +++ b/UCR/Views/Controls/DeviceBindingControl.xaml @@ -28,7 +28,7 @@ - + diff --git a/UCR/Views/Controls/PreviewControl.xaml b/UCR/Views/Controls/PreviewControl.xaml new file mode 100644 index 00000000..c9bd57eb --- /dev/null +++ b/UCR/Views/Controls/PreviewControl.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UCR/Views/Controls/PreviewControl.xaml.cs b/UCR/Views/Controls/PreviewControl.xaml.cs new file mode 100644 index 00000000..a2e2b3fe --- /dev/null +++ b/UCR/Views/Controls/PreviewControl.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace HidWizards.UCR.Views.Controls +{ + /// + /// Interaction logic for PreviewControl.xaml + /// + public partial class PreviewControl : UserControl + { + public PreviewControl() + { + InitializeComponent(); + } + } +} diff --git a/UCR/Views/Controls/PreviewControlTemplateSelector.cs b/UCR/Views/Controls/PreviewControlTemplateSelector.cs new file mode 100644 index 00000000..2db4b487 --- /dev/null +++ b/UCR/Views/Controls/PreviewControlTemplateSelector.cs @@ -0,0 +1,33 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.ViewModels.ProfileViewModels; + +namespace HidWizards.UCR.Views.Controls +{ + class PreviewControlTemplateSelector : DataTemplateSelector + { + public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) + { + var element = container as FrameworkElement; + + if (element == null || !(item is DeviceBindingViewModel)) return null; + var deviceBindingViewModel = (DeviceBindingViewModel) item; + + switch (deviceBindingViewModel.DeviceBindingCategory) + { + case DeviceBindingCategory.Event: + return element.FindResource("EventPreview") as DataTemplate; + case DeviceBindingCategory.Momentary: + return element.FindResource("MomentaryPreview") as DataTemplate; + case DeviceBindingCategory.Range: + return element.FindResource("RangePreview") as DataTemplate; + case DeviceBindingCategory.Delta: + return element.FindResource("DeltaPreview") as DataTemplate; + default: + return null; + } + } + } +} diff --git a/UCR/Views/Controls/preview/MomentaryConverter.cs b/UCR/Views/Controls/preview/MomentaryConverter.cs new file mode 100644 index 00000000..5b5d97b8 --- /dev/null +++ b/UCR/Views/Controls/preview/MomentaryConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; + +using System.Windows.Data; +using HidWizards.UCR.Core.Utilities; + +namespace HidWizards.UCR.Views.Controls.preview +{ + class MomentaryConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var pressed = (long) value; + return 100.0 * pressed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/UCR/Views/Controls/preview/RangeConverter.cs b/UCR/Views/Controls/preview/RangeConverter.cs new file mode 100644 index 00000000..9302e841 --- /dev/null +++ b/UCR/Views/Controls/preview/RangeConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; + +using System.Windows.Data; +using HidWizards.UCR.Core.Utilities; + +namespace HidWizards.UCR.Views.Controls.preview +{ + class RangeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var range = (long) value; + return 50.0 + ((double)range / Constants.AxisMaxValue) * 50; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} From 4c315dfde6c706cdf051b734f345e0cf8f9a295c Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Thu, 2 Aug 2018 19:52:55 +0200 Subject: [PATCH 004/105] Added Absolute mode to Button to axis plugin to properly support Xbox and DS4 analog triggers --- UCR.Plugins/Remapper/ButtonToAxis.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/UCR.Plugins/Remapper/ButtonToAxis.cs b/UCR.Plugins/Remapper/ButtonToAxis.cs index 88f78412..47738ad2 100644 --- a/UCR.Plugins/Remapper/ButtonToAxis.cs +++ b/UCR.Plugins/Remapper/ButtonToAxis.cs @@ -13,9 +13,13 @@ public class ButtonToAxis : Plugin [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } - [PluginGui("Range target", ColumnOrder = 1)] + [PluginGui("Absolute", ColumnOrder = 1)] + public bool Absolute { get; set; } + + [PluginGui("Range target", ColumnOrder = 2)] public int Range { get; set; } + public ButtonToAxis() { Range = 100; @@ -23,8 +27,18 @@ public ButtonToAxis() public override void Update(params long[] values) { - if (Invert) values[0] = values[0] * - 1; - WriteOutput(0, values[0] * (long)(Constants.AxisMaxValue * ( Range / 100.0 ))); + var value = values[0]; + var inverse = value == 0 ^ Invert; + + if (Absolute) + { + WriteOutput(0, (long)((Constants.AxisMinValue + value * Constants.AxisMaxValue * 2 * (Range / 100.0))) * (Invert ? -1 : 1)); + } + else + { + WriteOutput(0, value * (long)((inverse ? Constants.AxisMinValue : Constants.AxisMaxValue) * (Range / 100.0))); + } } + } } From 084e2d10f4834da59512cb332242e3d472bfd2f0 Mon Sep 17 00:00:00 2001 From: spadino Date: Sat, 18 Aug 2018 17:45:03 -0300 Subject: [PATCH 005/105] add a relative plugin --- UCR.Core/Utilities/Functions.cs | 15 +++++-- UCR.Plugins/Remapper/AxisToRelativeAxis.cs | 47 ++++++++++++++++++++++ UCR.Plugins/UCR.Plugins.csproj | 1 + 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 UCR.Plugins/Remapper/AxisToRelativeAxis.cs diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 222e3623..b170d4e3 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -20,6 +20,13 @@ public static long ApplyRangeSensitivity(long value, int sensitivity, bool linea return value; } + public static long ApplyRelativeIncrement(long value) + { + var output = 0.0; + output += value; + return (long)output; + } + public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) { long value; @@ -31,10 +38,10 @@ public static long HalfAxisToFullRange(long axis, bool positiveRange, bool inver { value = axis < 0 ? axis * -1 : 0L; } - + value = Constants.AxisMinValue + value * 2; - - return invert ? value * -1 : value; + + return invert ? value * -1 : value; } } -} +} \ No newline at end of file diff --git a/UCR.Plugins/Remapper/AxisToRelativeAxis.cs b/UCR.Plugins/Remapper/AxisToRelativeAxis.cs new file mode 100644 index 00000000..2e083600 --- /dev/null +++ b/UCR.Plugins/Remapper/AxisToRelativeAxis.cs @@ -0,0 +1,47 @@ +using System; +using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.Core.Utilities; + +namespace HidWizards.UCR.Plugins.Remapper +{ + [Plugin("Axis to Relative axis")] + [PluginInput(DeviceBindingCategory.Range, "Axis")] + [PluginOutput(DeviceBindingCategory.Range, "Axis")] + public class AxisToRelativeAxis : Plugin + { + [PluginGui("Invert", ColumnOrder = 0)] + public bool Invert { get; set; } + + [PluginGui("Linear", ColumnOrder = 3)] + public bool Linear { get; set; } + + [PluginGui("Dead zone", ColumnOrder = 1)] + public int DeadZone { get; set; } + + [PluginGui("Sensitivity", ColumnOrder = 2)] + public int Sensitivity { get; set; } + + [PluginGui("Relative", ColumnOrder = 3)] + public bool Relative { get; set; } + + public AxisToRelativeAxis() + { + DeadZone = 0; + Sensitivity = 100; + Relative = true; + } + + public override void Update(params long[] values) + { + var value = values[0]; + if (Invert) value *= -1; + if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); + if (Relative) value = Functions.ApplyRelativeIncrement(value); + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + WriteOutput(0, value); + } + } +} \ No newline at end of file diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 573a3c93..eaf343c4 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -48,6 +48,7 @@ + From ac36c30aaab6693596bd34a32b72d0e8bb96f56c Mon Sep 17 00:00:00 2001 From: spadino Date: Sat, 18 Aug 2018 20:20:53 -0300 Subject: [PATCH 006/105] Added a relative axis plugin --- UCR.Core/Utilities/Functions.cs | 18 +++++++--- ...xisToRelativeAxis.cs => AxisToRelative.cs} | 36 +++++++++++++------ UCR.Plugins/UCR.Plugins.csproj | 2 +- 3 files changed, 40 insertions(+), 16 deletions(-) rename UCR.Plugins/Remapper/{AxisToRelativeAxis.cs => AxisToRelative.cs} (54%) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index b170d4e3..13c73ea4 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -20,11 +20,21 @@ public static long ApplyRangeSensitivity(long value, int sensitivity, bool linea return value; } - public static long ApplyRelativeIncrement(long value) + public static long ApplyRelativeIncrement(long last, long prev, int sensitivity) { - var output = 0.0; - output += value; - return (long)output; + var sensitivityPercent = (sensitivity / 100.0); + last = (long)(last * sensitivityPercent); + return last + prev; + } + + public static long ApplyContinueRelativeIncrement(long last, long prev, int sensitivity) + { + // placeholder! + var sensitivityPercent = (sensitivity / 100.0); + last = (long)(last * sensitivityPercent); + long output = 0; + output += (last + prev); + return output; } public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) diff --git a/UCR.Plugins/Remapper/AxisToRelativeAxis.cs b/UCR.Plugins/Remapper/AxisToRelative.cs similarity index 54% rename from UCR.Plugins/Remapper/AxisToRelativeAxis.cs rename to UCR.Plugins/Remapper/AxisToRelative.cs index 2e083600..7513afcf 100644 --- a/UCR.Plugins/Remapper/AxisToRelativeAxis.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -6,42 +6,56 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to Relative axis")] + [Plugin("Axis to relative")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] - public class AxisToRelativeAxis : Plugin + public class AxisToRelative : Plugin { [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } - [PluginGui("Linear", ColumnOrder = 3)] - public bool Linear { get; set; } - [PluginGui("Dead zone", ColumnOrder = 1)] public int DeadZone { get; set; } [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } - [PluginGui("Relative", ColumnOrder = 3)] - public bool Relative { get; set; } + /// + /// To constantly add current axis values to the output - WORK IN PROGRESS!!! + /// + [PluginGui("Continue", ColumnOrder = 3)] + public bool Continue { get; set; } + + /// + /// Create the previous values field, which will be updated on each iteration. + /// + private long previousValue = 0; - public AxisToRelativeAxis() + public AxisToRelative() { DeadZone = 0; Sensitivity = 100; - Relative = true; + Continue = false; } public override void Update(params long[] values) { var value = values[0]; + if (Invert) value *= -1; if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); - if (Relative) value = Functions.ApplyRelativeIncrement(value); + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); + + if (Continue) value = Functions.ApplyContinueRelativeIncrement(value, previousValue, Sensitivity); + else value = Functions.ApplyRelativeIncrement(value, previousValue, Sensitivity); + + // Respect the axis min and max ranges. value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + WriteOutput(0, value); + + // Store the last value and use it as previous, on next iteration. + previousValue = value; } } } \ No newline at end of file diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index eaf343c4..791b6469 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -48,7 +48,7 @@ - + From 743e2d3e592375711ac50b4b89070e626f79e302 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 15:41:56 +0200 Subject: [PATCH 007/105] nuke updated to 6.2 --- .nuke | Bin 24 -> 7 bytes build.ps1 | 63 +++++++++++++++++++------------- build.sh | 62 ++++++++++++++++++++----------- build/.build.csproj | 33 ++++++++++------- build/.build.csproj.DotSettings | 2 +- build/Build.cs | 59 +++++++++++------------------- 6 files changed, 121 insertions(+), 98 deletions(-) diff --git a/.nuke b/.nuke index a12280b71bb74ee8a48af4269a086f83560ec38c..9cfbd94f1aa3f0e83fada3ad1bab6a46868f26db 100644 GIT binary patch literal 7 OcmWG_4$>>m$pZig-2!F+ literal 24 fcmezWPme*LA(X+HA&5bbp_n0uA&-HVfr|kEQThbe diff --git a/build.ps1 b/build.ps1 index 2a581ef0..2758f36a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,52 +1,65 @@ [CmdletBinding()] Param( - [switch]$NoInit, + #[switch]$CustomParam, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$BuildArguments ) -Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { $host.SetShouldExit(0) } +Write-Output "Windows PowerShell $($Host.Version)" + +Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { $host.SetShouldExit(1) } $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### # CONFIGURATION ########################################################################### -$NuGetVersion = "latest" -$SolutionDirectory = "$PSScriptRoot\..\UCR" -$BuildProjectFile = "$PSScriptRoot\.\build\.build.csproj" -$BuildExeFile = "$PSScriptRoot\.\build\bin\debug\.build.exe" +$BuildProjectFile = "$PSScriptRoot\build\.build.csproj" +$TempDirectory = "$PSScriptRoot\\.tmp" -$TempDirectory = "$PSScriptRoot\.tmp" +$DotNetGlobalFile = "$PSScriptRoot\\global.json" +$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1" +$DotNetReleasesUrl = "https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json" -$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/$NuGetVersion/nuget.exe" -$NuGetFile = "$TempDirectory\nuget.exe" -$env:NUGET_EXE = $NuGetFile +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 +$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$env:NUGET_XMLDOC_MODE = "skip" ########################################################################### -# PREPARE BUILD +# EXECUTION ########################################################################### function ExecSafe([scriptblock] $cmd) { & $cmd - if ($LastExitCode -ne 0) { throw "The following call failed with exit code $LastExitCode. '$cmd'" } + if ($LASTEXITCODE) { exit $LASTEXITCODE } } -if (!$NoInit) { - md -force $TempDirectory > $null - - if (!(Test-Path $NuGetFile)) { (New-Object System.Net.WebClient).DownloadFile($NuGetUrl, $NuGetFile) } - elseif ($NuGetVersion -eq "latest") { & $NuGetFile update -Self } +# If global.json exists, load expected version +if (Test-Path $DotNetGlobalFile) { + $DotNetVersion = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json).sdk.version +} - ExecSafe { & $NuGetFile restore $BuildProjectFile -SolutionDirectory $SolutionDirectory } - ExecSafe { & $NuGetFile install Nuke.MSBuildLocator -ExcludeVersion -OutputDirectory $TempDirectory -SolutionDirectory $SolutionDirectory } +# If dotnet is installed locally, and expected version is not set or installation matches the expected version +if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -ne $null -and ` + (!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) { + $env:DOTNET_EXE = (Get-Command "dotnet").Path } +else { + $DotNetDirectory = "$TempDirectory\dotnet-win" + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" -$MSBuildFile = & "$TempDirectory\Nuke.MSBuildLocator\tools\Nuke.MSBuildLocator.exe" -ExecSafe { & $MSBuildFile $BuildProjectFile } + # If expected version is not set, get latest version + if (!(Test-Path variable:DotNetVersion)) { + $DotNetVersion = $(Invoke-WebRequest -UseBasicParsing $DotNetReleasesUrl | ConvertFrom-Json)[0]."version-sdk" + } -########################################################################### -# EXECUTE BUILD -########################################################################### + # Download and execute install script + $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" + md -force $TempDirectory > $null + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) + ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } +} + +Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" -ExecSafe { & $BuildExeFile $BuildArguments } +ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile -- $BuildArguments } diff --git a/build.sh b/build.sh index 659e9b09..40b3305a 100644 --- a/build.sh +++ b/build.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash -NOINIT=0 +echo $(bash --version 2>&1 | head -n 1) + +#CUSTOMPARAM=0 BUILD_ARGUMENTS=() for i in "$@"; do case $(echo $1 | awk '{print tolower($0)}') in - -noinit) NOINIT=1;; + # -custom-param) CUSTOMPARAM=1;; *) BUILD_ARGUMENTS+=("$1") ;; esac shift @@ -17,34 +19,50 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) # CONFIGURATION ########################################################################### -NUGET_VERSION="latest" -SOLUTION_DIRECTORY="$SCRIPT_DIR/../UCR" -BUILD_PROJECT_FILE="$SCRIPT_DIR/./build/.build.csproj" -BUILD_EXE_FILE="$SCRIPT_DIR/./build/bin/Debug/.build.exe" +BUILD_PROJECT_FILE="$SCRIPT_DIR/build/.build.csproj" +TEMP_DIRECTORY="$SCRIPT_DIR//.tmp" -TEMP_DIRECTORY="$SCRIPT_DIR/.tmp" +DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" +DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh" +DOTNET_RELEASES_URL="https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json" -NUGET_URL="https://dist.nuget.org/win-x86-commandline/$NUGET_VERSION/nuget.exe" -NUGET_FILE="$TEMP_DIRECTORY/nuget.exe" -export NUGET_EXE="$NUGET_FILE" +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export NUGET_XMLDOC_MODE="skip" ########################################################################### -# PREPARE BUILD +# EXECUTION ########################################################################### -if ! ((NOINIT)); then - mkdir -p "$TEMP_DIRECTORY" - - if [ ! -f "$NUGET_FILE" ]; then curl -Lsfo "$NUGET_FILE" $NUGET_URL; - elif [ $NUGET_VERSION == "latest" ]; then mono "$NUGET_FILE" update -Self; fi +function FirstJsonValue { + perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2} +} - mono "$NUGET_FILE" restore "$BUILD_PROJECT_FILE" -SolutionDirectory $SOLUTION_DIRECTORY +# If global.json exists, load expected version +if [ -f "$DOTNET_GLOBAL_FILE" ]; then + DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE")) fi -msbuild "$BUILD_PROJECT_FILE" +# If dotnet is installed locally, and expected version is not set or installation matches the expected version +if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then + export DOTNET_EXE="$(command -v dotnet)" +else + DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" + export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" + + # If expected version is not set, get latest version + if [ -z ${DOTNET_VERSION+x} ]; then + DOTNET_VERSION=$(FirstJsonValue "version-sdk" $(curl -s "$DOTNET_RELEASES_URL")) + fi + + # Download and execute install script + DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" + mkdir -p "$TEMP_DIRECTORY" + curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" + chmod +x "$DOTNET_INSTALL_FILE" + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path +fi -########################################################################### -# EXECUTE BUILD -########################################################################### +echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)" -mono "$BUILD_EXE_FILE" ${BUILD_ARGUMENTS[@]} +"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" -- ${BUILD_ARGUMENTS[@]} diff --git a/build/.build.csproj b/build/.build.csproj index 84ad6b3c..ce83cb9b 100644 --- a/build/.build.csproj +++ b/build/.build.csproj @@ -2,30 +2,37 @@ Exe - net461 + netcoreapp2.1 false False CS0649;CS0169 - - - * - False - - - - - - + + + + + + - + + - + + + + + + + + + + + diff --git a/build/.build.csproj.DotSettings b/build/.build.csproj.DotSettings index 5af2bdc9..96e392e6 100644 --- a/build/.build.csproj.DotSettings +++ b/build/.build.csproj.DotSettings @@ -1,4 +1,4 @@ - + False Implicit Implicit diff --git a/build/Build.cs b/build/Build.cs index 00aef004..5675a97d 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,43 +1,28 @@ -using System; +using System; using System.Linq; using Nuke.Common; -using Nuke.Common.Git; -using Nuke.Common.Gitter; -using Nuke.Common.Tools.DotNet; -using Nuke.Common.Tools.GitVersion; +using Nuke.Common.ProjectModel; using Nuke.Common.Tools.MSBuild; using Nuke.Common.Tools.NuGet; -using Nuke.Core; using Nuke.Core.Tooling; using static Nuke.Common.Tools.Git.GitTasks; using static Nuke.Common.Tools.MSBuild.MSBuildTasks; -using static Nuke.Core.IO.FileSystemTasks; -using static Nuke.Core.IO.PathConstruction; -using static Nuke.Core.EnvironmentInfo; +using static Nuke.Common.EnvironmentInfo; +using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.IO.PathConstruction; +using ToolSettingsExtensions = Nuke.Common.Tooling.ToolSettingsExtensions; class Build : NukeBuild { - // Console application entry. Also defines the default target. - public static int Main() => Execute(x => x.Test); + public static int Main () => Execute(x => x.Test); - // Auto-injection fields: - - // [GitVersion] readonly GitVersion GitVersion; - // Semantic versioning. Must have 'GitVersion.CommandLine' referenced. - - // [GitRepository] readonly GitRepository GitRepository; - // Parses origin, branch name and head from git config. - - // [Parameter] readonly string MyGetApiKey; - // Returns command-line arguments and environment variables. + [Solution] readonly Solution Solution; string IoWrapper => "IOWrapper"; AbsolutePath IoWrapperDirectory => RootDirectory / "submodules" / IoWrapper; AbsolutePath IoWrapperSolution => IoWrapperDirectory / (IoWrapper + ".sln"); - MSBuildSettings DefaultIoWrapperMSBuild => DefaultMSBuild - .SetWorkingDirectory(IoWrapperDirectory) - .SetSolutionFile(IoWrapperSolution); + MSBuildSettings DefaultIoWrapperMSBuild => ToolSettingsExtensions.SetWorkingDirectory(DefaultMSBuildCompile, IoWrapperDirectory).SetSolutionFile(IoWrapperSolution); Target Clean => _ => _ @@ -72,23 +57,23 @@ class Build : NukeBuild .DependsOn(RestoreSubmodules) .DependsOn(CompileSubmodules) .Executes(() => - { - CopyRecursively(IoWrapperDirectory / "Artifacts", SolutionDirectory / "dependencies", FileExistsPolicy.Overwrite); - }); + { + CopyDirectoryRecursively(IoWrapperDirectory / "Artifacts", SolutionDirectory / "dependencies", FileExistsPolicy.Overwrite); + }); Target Restore => _ => _ - .DependsOn(Clean) - .Executes(() => - { - MSBuild(s => DefaultMSBuildRestore); - }); + .DependsOn(Clean) + .Executes(() => + { + MSBuild(s => DefaultMSBuildRestore); + }); Target Compile => _ => _ - .DependsOn(Restore) - .Executes(() => - { - MSBuild(s => DefaultMSBuildCompile); - }); + .DependsOn(Restore) + .Executes(() => + { + MSBuild(s => DefaultMSBuildCompile); + }); Target Test => _ => _ .DependsOn(Compile) From 488b2e5516a2a09601ffac710359aadb4a8690f1 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 16:11:17 +0200 Subject: [PATCH 008/105] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37ece1c2..45bbe1e2 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,8 @@ UCR supports input and output devices through plugins using the [IOWrapper](http - Keyboard (using [interception](https://github.com/oblitum/Interception)) - Mouse (using [interception](https://github.com/oblitum/Interception)) - +## Build ## +It is required to run the build script before building with Visual Studio. Run `.\build.ps1 InitProject` from powershell to initialize the required dependencies. All subsequent builds can be done from Visual Studio 2017 ## License ## From 413037a1ad82b8b98dff278a7838bca2b89065c0 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 15:41:00 +0100 Subject: [PATCH 009/105] Implement thread for relative mode --- UCR.Core/Utilities/Functions.cs | 10 ----- UCR.Plugins/Remapper/AxisToRelative.cs | 59 ++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 13c73ea4..4df138ae 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -27,16 +27,6 @@ public static long ApplyRelativeIncrement(long last, long prev, int sensitivity) return last + prev; } - public static long ApplyContinueRelativeIncrement(long last, long prev, int sensitivity) - { - // placeholder! - var sensitivityPercent = (sensitivity / 100.0); - last = (long)(last * sensitivityPercent); - long output = 0; - output += (last + prev); - return output; - } - public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) { long value; diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index 7513afcf..83421186 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Threading; using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; @@ -26,10 +28,12 @@ public class AxisToRelative : Plugin [PluginGui("Continue", ColumnOrder = 3)] public bool Continue { get; set; } - /// - /// Create the previous values field, which will be updated on each iteration. - /// - private long previousValue = 0; + private long _currentOutputValue; + private long _currentInputValue; + private readonly object _threadLock = new object(); + + private Thread _relativeThread; + private bool _relativeThreadState = false; public AxisToRelative() { @@ -46,16 +50,53 @@ public override void Update(params long[] values) if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); - if (Continue) value = Functions.ApplyContinueRelativeIncrement(value, previousValue, Sensitivity); - else value = Functions.ApplyRelativeIncrement(value, previousValue, Sensitivity); + lock (_threadLock) + { + if (value != 0 && !_relativeThreadState) + { + SetRelativeThreadState(true); + //Debug.WriteLine("UCR| Started Thread"); + } + else if (value == 0 && _relativeThreadState) + { + SetRelativeThreadState(false); + //Debug.WriteLine("UCR| Stopped Thread"); + } + } // Respect the axis min and max ranges. value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + _currentInputValue = value; + } - WriteOutput(0, value); + private void SetRelativeThreadState(bool state) + { + if (_relativeThreadState == state) return; + if (!_relativeThreadState && state) + { + _relativeThread = new Thread(RelativeThread); + _relativeThread.Start(); + } + else if (_relativeThreadState && !state) + { + _relativeThread.Abort(); + _relativeThread.Join(); + _relativeThread = null; + } - // Store the last value and use it as previous, on next iteration. - previousValue = value; + _relativeThreadState = state; + } + + public void RelativeThread() + { + while (true) + { + var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, Sensitivity); + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + WriteOutput(0, value); + _currentOutputValue = value; + Thread.Sleep(10); + } } } } \ No newline at end of file From eb812092cab41a19ca23d1bdaa6843e1453488c7 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 16:09:20 +0100 Subject: [PATCH 010/105] Implement Continue on/off --- UCR.Plugins/Remapper/AxisToRelative.cs | 54 +++++++++++++++++--------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index 83421186..59af43b3 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -50,23 +50,30 @@ public override void Update(params long[] values) if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); - lock (_threadLock) + // Respect the axis min and max ranges. + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + _currentInputValue = value; + + if (Continue) { - if (value != 0 && !_relativeThreadState) + lock (_threadLock) { - SetRelativeThreadState(true); - //Debug.WriteLine("UCR| Started Thread"); - } - else if (value == 0 && _relativeThreadState) - { - SetRelativeThreadState(false); - //Debug.WriteLine("UCR| Stopped Thread"); + if (value != 0 && !_relativeThreadState) + { + SetRelativeThreadState(true); + //Debug.WriteLine("UCR| Started Thread"); + } + else if (value == 0 && _relativeThreadState) + { + SetRelativeThreadState(false); + //Debug.WriteLine("UCR| Stopped Thread"); + } } } - - // Respect the axis min and max ranges. - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - _currentInputValue = value; + else + { + RelativeUpdate(); + } } private void SetRelativeThreadState(bool state) @@ -89,14 +96,25 @@ private void SetRelativeThreadState(bool state) public void RelativeThread() { - while (true) + while (Continue) { - var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, Sensitivity); - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - WriteOutput(0, value); - _currentOutputValue = value; + RelativeUpdate(); Thread.Sleep(10); } + + lock (_threadLock) + { + _relativeThreadState = false; + } + } + + private void RelativeUpdate() + { + var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, Sensitivity); + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + WriteOutput(0, value); + _currentOutputValue = value; + } } } \ No newline at end of file From 059434c8fd27a31244795fdc28d04308ba8a67b7 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 17:49:51 +0200 Subject: [PATCH 011/105] Subscription tests, ReadOutput available for Plugins, Decimal and Double now supported in Plugin GUI --- UCR.Core/Managers/SubscriptionsManager.cs | 2 +- UCR.Core/Models/Plugin.cs | 15 +++++ UCR.Tests/ModelTests/SubscriptionTest.cs | 63 +++++++++++++++++++ UCR.Tests/UCR.Tests.csproj | 1 + .../Controls/DeviceBindingControl.xaml.cs | 3 - .../Controls/PluginGuiTemplateSelector.cs | 2 + 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 UCR.Tests/ModelTests/SubscriptionTest.cs diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index f351d8e5..8f4220c9 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -13,7 +13,7 @@ public class SubscriptionsManager : IDisposable { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private SubscriptionState SubscriptionState { get; set; } + internal SubscriptionState SubscriptionState { get; set; } private readonly Context _context; public SubscriptionsManager(Context context) diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index 9242202e..a911c5ca 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -105,6 +105,16 @@ public virtual void OnDeactivate() #region Plugin methods + protected virtual void OnStart() + { + + } + + protected virtual void OnStop() + { + + } + protected void WriteOutput(int number, long value) { Outputs[number].WriteOutput(value); @@ -120,6 +130,11 @@ protected bool GetState(Guid stateGuid) return Profile.GetRuntimeState(stateGuid); } + protected long ReadOutput(int number) + { + return Outputs[number].CurrentValue; + } + #endregion public void SetProfile(Profile profile) diff --git a/UCR.Tests/ModelTests/SubscriptionTest.cs b/UCR.Tests/ModelTests/SubscriptionTest.cs new file mode 100644 index 00000000..7c2575e8 --- /dev/null +++ b/UCR.Tests/ModelTests/SubscriptionTest.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Subscription; +using HidWizards.UCR.Plugins.Remapper; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.ModelTests +{ + [TestFixture] + internal class SubscriptionTest + { + + private Context _context; + private Profile _profile; + private Mapping _mapping; + private string _profileName; + + [SetUp] + public void Setup() + { + _context = new Context(); + _profileName = "Test"; + _context.ProfilesManager.AddProfile(_profileName); + _profile = _context.Profiles[0]; + } + + [Test] + public void TestEmptyProfile() + { + Assert.IsTrue(_context.SubscriptionsManager.ActivateProfile(_profile)); + + var state = getSubscriptionState(); + Assert.IsTrue(state.IsActive); + Assert.AreEqual(0, state.MappingSubscriptions.Count); + } + + [Test] + public void TestOneBindingProfile() + { + var mapping = _profile.AddMapping("Button"); + var plugin = new ButtonToButton(); + mapping.AddPlugin(plugin, null); + + Assert.IsTrue(_context.SubscriptionsManager.ActivateProfile(_profile)); + + var state = getSubscriptionState(); + Assert.IsTrue(state.IsActive); + Assert.AreEqual(1, state.MappingSubscriptions.Count); + Assert.AreEqual(1, state.MappingSubscriptions[0].PluginSubscriptions.Count); + Assert.AreEqual(plugin, state.MappingSubscriptions[0].PluginSubscriptions[0].Plugin); + } + + private SubscriptionState getSubscriptionState() + { + return _context.SubscriptionsManager.SubscriptionState; + } + } +} diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index af8e0ae4..b01b17bb 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -50,6 +50,7 @@ + diff --git a/UCR/Views/Controls/DeviceBindingControl.xaml.cs b/UCR/Views/Controls/DeviceBindingControl.xaml.cs index 23950be5..f60ee0b8 100644 --- a/UCR/Views/Controls/DeviceBindingControl.xaml.cs +++ b/UCR/Views/Controls/DeviceBindingControl.xaml.cs @@ -1,14 +1,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; using System.Windows; using System.Windows.Controls; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Utilities; using HidWizards.UCR.Utilities.Commands; using HidWizards.UCR.ViewModels; -using HidWizards.UCR.ViewModels.ProfileViewModels; namespace HidWizards.UCR.Views.Controls { diff --git a/UCR/Views/Controls/PluginGuiTemplateSelector.cs b/UCR/Views/Controls/PluginGuiTemplateSelector.cs index 8fc990b3..74830cd5 100644 --- a/UCR/Views/Controls/PluginGuiTemplateSelector.cs +++ b/UCR/Views/Controls/PluginGuiTemplateSelector.cs @@ -24,6 +24,8 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: + case TypeCode.Decimal: + case TypeCode.Double: if (pluginProperty.Property is Enum) { return element.FindResource("EnumTemplate") as DataTemplate; From a00a4506081585ecc921ee39dc9e06d2211fa576 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 16:56:02 +0100 Subject: [PATCH 012/105] Tweak scaling --- UCR.Plugins/Remapper/AxisToRelative.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index 59af43b3..dde2005d 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -16,12 +16,18 @@ public class AxisToRelative : Plugin [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } + [PluginGui("Linear", ColumnOrder = 3)] + public bool Linear { get; set; } + [PluginGui("Dead zone", ColumnOrder = 1)] public int DeadZone { get; set; } [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } + [PluginGui("Relative Divider", ColumnOrder = 4)] + public int RelativeDivider { get; set; } + /// /// To constantly add current axis values to the output - WORK IN PROGRESS!!! /// @@ -40,6 +46,7 @@ public AxisToRelative() DeadZone = 0; Sensitivity = 100; Continue = false; + RelativeDivider = 50; } public override void Update(params long[] values) @@ -48,7 +55,7 @@ public override void Update(params long[] values) if (Invert) value *= -1; if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); // Respect the axis min and max ranges. value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); @@ -110,11 +117,11 @@ public void RelativeThread() private void RelativeUpdate() { - var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, Sensitivity); + //var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, RelativeDivider); + var value = (_currentInputValue / RelativeDivider) + _currentOutputValue; value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); WriteOutput(0, value); _currentOutputValue = value; - } } } \ No newline at end of file From 5428faa2470f9052eb33aa6f908786da3139413f Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 18:04:36 +0200 Subject: [PATCH 013/105] Double and Decimal now has proper text input validation in Plugin GUI --- UCR/Views/Controls/PluginControl.xaml | 5 +++++ UCR/Views/Controls/PluginControl.xaml.cs | 6 ++++++ UCR/Views/Controls/PluginGuiTemplateSelector.cs | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UCR/Views/Controls/PluginControl.xaml b/UCR/Views/Controls/PluginControl.xaml index 2d9ec5c4..050e769b 100644 --- a/UCR/Views/Controls/PluginControl.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -83,6 +83,11 @@ + + + + + diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index c83e29ad..3d0e3019 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -26,5 +26,11 @@ private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) Regex regex = new Regex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); } + + private void DecimalValidationTextBox(object sender, TextCompositionEventArgs e) + { + Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); + e.Handled = regex.IsMatch(e.Text); + } } } diff --git a/UCR/Views/Controls/PluginGuiTemplateSelector.cs b/UCR/Views/Controls/PluginGuiTemplateSelector.cs index 74830cd5..7f31a11f 100644 --- a/UCR/Views/Controls/PluginGuiTemplateSelector.cs +++ b/UCR/Views/Controls/PluginGuiTemplateSelector.cs @@ -24,13 +24,14 @@ public override DataTemplate SelectTemplate(object item, DependencyObject contai case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: - case TypeCode.Decimal: - case TypeCode.Double: if (pluginProperty.Property is Enum) { return element.FindResource("EnumTemplate") as DataTemplate; } return element.FindResource("NumberTemplate") as DataTemplate; + case TypeCode.Decimal: + case TypeCode.Double: + return element.FindResource("DecimalTemplate") as DataTemplate; case TypeCode.String: return element.FindResource("StringTemplate") as DataTemplate; case TypeCode.Object: From 5dff5962083e41ed6671d0cf6d53cf91683ed015 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 19:00:18 +0100 Subject: [PATCH 014/105] Relative now uses sensitivity % --- UCR.Plugins/Remapper/AxisToRelative.cs | 23 ++++++++++++----------- UCR/Views/Controls/PluginControl.xaml.cs | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index dde2005d..5229330c 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -25,14 +25,15 @@ public class AxisToRelative : Plugin [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } - [PluginGui("Relative Divider", ColumnOrder = 4)] - public int RelativeDivider { get; set; } - /// /// To constantly add current axis values to the output - WORK IN PROGRESS!!! /// - [PluginGui("Continue", ColumnOrder = 3)] - public bool Continue { get; set; } + [PluginGui("Relative RelativeContinue", ColumnOrder = 1, RowOrder = 2)] + public bool RelativeContinue { get; set; } + + [PluginGui("Relative Sensitivity", ColumnOrder = 2, RowOrder = 2)] + public long RelativeSensitivity { get; set; } + private long _currentOutputValue; private long _currentInputValue; @@ -45,8 +46,8 @@ public AxisToRelative() { DeadZone = 0; Sensitivity = 100; - Continue = false; - RelativeDivider = 50; + RelativeContinue = true; + RelativeSensitivity = 2; } public override void Update(params long[] values) @@ -61,7 +62,7 @@ public override void Update(params long[] values) value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); _currentInputValue = value; - if (Continue) + if (RelativeContinue) { lock (_threadLock) { @@ -103,7 +104,7 @@ private void SetRelativeThreadState(bool state) public void RelativeThread() { - while (Continue) + while (RelativeContinue) { RelativeUpdate(); Thread.Sleep(10); @@ -117,8 +118,8 @@ public void RelativeThread() private void RelativeUpdate() { - //var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, RelativeDivider); - var value = (_currentInputValue / RelativeDivider) + _currentOutputValue; + //var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, RelativeSensitivity); + var value = (long)((_currentInputValue * (float)(RelativeSensitivity / 100.0)) + _currentOutputValue); value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); WriteOutput(0, value); _currentOutputValue = value; diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index 3d0e3019..89a8532e 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -29,7 +29,8 @@ private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) private void DecimalValidationTextBox(object sender, TextCompositionEventArgs e) { - Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); + //Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); + Regex regex = new Regex(".*"); e.Handled = regex.IsMatch(e.Text); } } From 432b4e789ae857842056114affc6922537299216 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 20:15:20 +0200 Subject: [PATCH 015/105] Added Property setter validation for GUI properties with TextBox --- UCR.Core/Models/PluginProperty.cs | 4 +++- UCR/UCR.csproj | 2 ++ .../Validators/DecimalBindingValidator.cs | 20 ++++++++++++++++++ .../Validators/NumberBindingValidator.cs | 20 ++++++++++++++++++ UCR/Views/Controls/PluginControl.xaml | 21 +++++++++++++++++-- UCR/Views/Controls/PluginControl.xaml.cs | 4 ++-- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 UCR/Utilities/Validators/DecimalBindingValidator.cs create mode 100644 UCR/Utilities/Validators/NumberBindingValidator.cs diff --git a/UCR.Core/Models/PluginProperty.cs b/UCR.Core/Models/PluginProperty.cs index 32748cd6..0454fa06 100644 --- a/UCR.Core/Models/PluginProperty.cs +++ b/UCR.Core/Models/PluginProperty.cs @@ -1,4 +1,6 @@ using System; +using System.CodeDom; +using System.Globalization; using System.Reflection; namespace HidWizards.UCR.Core.Models @@ -17,7 +19,7 @@ public dynamic Property set { if (value.Equals(PropertyInfo.GetValue(Plugin))) return; - PropertyInfo.SetValue(Plugin, Convert.ChangeType(value, PropertyInfo.PropertyType)); + PropertyInfo.SetValue(Plugin, Convert.ChangeType(value, PropertyInfo.PropertyType, CultureInfo.InvariantCulture)); Plugin.ContextChanged(); } } diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index 334080a7..43b67ea1 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -87,6 +87,8 @@ + + diff --git a/UCR/Utilities/Validators/DecimalBindingValidator.cs b/UCR/Utilities/Validators/DecimalBindingValidator.cs new file mode 100644 index 00000000..7aab9017 --- /dev/null +++ b/UCR/Utilities/Validators/DecimalBindingValidator.cs @@ -0,0 +1,20 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace HidWizards.UCR.Utilities.Validators +{ + public class DecimalBindingValidator : ValidationRule + { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + var text = (string) value; + if (text == null) return new ValidationResult(false, "No input"); + + var regex = new Regex(@"[-+]?[0-9]+\.?[0-9]?"); + if (!regex.IsMatch(text)) return new ValidationResult(false, "Invalid input for decimal"); + + return ValidationResult.ValidResult; + } + } +} \ No newline at end of file diff --git a/UCR/Utilities/Validators/NumberBindingValidator.cs b/UCR/Utilities/Validators/NumberBindingValidator.cs new file mode 100644 index 00000000..03b71e2f --- /dev/null +++ b/UCR/Utilities/Validators/NumberBindingValidator.cs @@ -0,0 +1,20 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace HidWizards.UCR.Utilities.Validators +{ + public class NumberBindingValidator : ValidationRule + { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + var text = (string) value; + if (text == null) return new ValidationResult(false, "No input"); + + var regex = new Regex("[0-9]+"); + if (!regex.IsMatch(text)) return new ValidationResult(false, "Invalid input for number"); + + return ValidationResult.ValidResult; + } + } +} \ No newline at end of file diff --git a/UCR/Views/Controls/PluginControl.xaml b/UCR/Views/Controls/PluginControl.xaml index 050e769b..6378230a 100644 --- a/UCR/Views/Controls/PluginControl.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HidWizards.UCR.Views.Controls" xmlns:controls="clr-namespace:HidWizards.UCR.Views.Controls" + xmlns:validators="clr-namespace:HidWizards.UCR.Utilities.Validators" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="300" x:Name="PluginViewName" Margin="0,0,0,5"> @@ -80,12 +81,28 @@ - + + + + + + + + + - + + + + + + + + + diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index 3d0e3019..8cf240b9 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -29,8 +29,8 @@ private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) private void DecimalValidationTextBox(object sender, TextCompositionEventArgs e) { - Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); - e.Handled = regex.IsMatch(e.Text); + Regex regex = new Regex(@"([0-9]|\.)+"); + e.Handled = !regex.IsMatch(e.Text); } } } From 6a77bff8e73d550d2a61b67280834e22a0cc22b9 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 19 Aug 2018 21:56:57 +0200 Subject: [PATCH 016/105] Plugin life cycle: OnActive should now happen correctly after OnDeactive has triggered on the previous active profile --- UCR.Core/Managers/SubscriptionsManager.cs | 28 +++++++++++++++-------- UCR.Core/Models/Mapping.cs | 1 + UCR.Core/Models/Plugin.cs | 10 -------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index 8f4220c9..8e95e2e9 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -49,17 +49,32 @@ public bool ActivateProfile(Profile profile) Logger.Debug("SubscriptionState successfully activated"); if (!DeactivateProfile()) Logger.Error("Failed to deactivate previous profile successfully"); + + FinalizeNewState(profile, state); - _context.IOController.SetProfileState(state.StateGuid, true); + return true; + } - SubscriptionState = state; + private void FinalizeNewState(Profile profile, SubscriptionState subscriptionState) + { + // Set new active profile + _context.IOController.SetProfileState(subscriptionState.StateGuid, true); + SubscriptionState = subscriptionState; _context.ActiveProfile = profile; + + // Activate plugins + foreach (var mapping in subscriptionState.MappingSubscriptions) + { + foreach (var pluginSubscription in mapping.PluginSubscriptions) + { + pluginSubscription.Plugin.OnActivate(); + } + } + foreach (var action in _context.ActiveProfileCallbacks) { action(); } - - return true; } public bool DeactivateProfile() @@ -161,11 +176,6 @@ private bool ActivateSubscriptionState(SubscriptionState state) { success &= SubscribeDeviceBindingInput(state, deviceBindingSubscription); } - - foreach (var pluginSubscription in mappingSubscription.PluginSubscriptions) - { - pluginSubscription.Plugin.OnActivate(); - } } state.IsActive = true; diff --git a/UCR.Core/Models/Mapping.cs b/UCR.Core/Models/Mapping.cs index fb8f4dfe..d7b436e7 100644 --- a/UCR.Core/Models/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -62,6 +62,7 @@ internal void PrepareMapping() var cm = new CallbackMultiplexer(InputCache, i, Update); Multiplexer.Add(cm); DeviceBindings[i].Callback = cm.Update; + DeviceBindings[i].CurrentValue = 0; } } diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index a911c5ca..f77032ba 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -105,16 +105,6 @@ public virtual void OnDeactivate() #region Plugin methods - protected virtual void OnStart() - { - - } - - protected virtual void OnStop() - { - - } - protected void WriteOutput(int number, long value) { Outputs[number].WriteOutput(value); From 0922ae8200e3213efbfb90d680e3c3c2291dc92e Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 22:39:39 +0100 Subject: [PATCH 017/105] revert out changes --- UCR/Views/Controls/PluginControl.xaml.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index 89a8532e..3d0e3019 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -29,8 +29,7 @@ private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) private void DecimalValidationTextBox(object sender, TextCompositionEventArgs e) { - //Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); - Regex regex = new Regex(".*"); + Regex regex = new Regex("[+-]?([0-9]*[.])?[0-9]+"); e.Handled = regex.IsMatch(e.Text); } } From 6a81aedd1d12157404f92c3402ba5637ac483062 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 23:34:46 +0100 Subject: [PATCH 018/105] Tidy threading, implement OnDeactivate --- UCR.Plugins/Remapper/AxisToRelative.cs | 67 ++++++++++++-------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index 5229330c..33fe61ed 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -8,7 +8,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to relative")] + [Plugin("Axis to axis (Relative)")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class AxisToRelative : Plugin @@ -28,19 +28,18 @@ public class AxisToRelative : Plugin /// /// To constantly add current axis values to the output - WORK IN PROGRESS!!! /// - [PluginGui("Relative RelativeContinue", ColumnOrder = 1, RowOrder = 2)] + [PluginGui("Relative Continue", ColumnOrder = 1, RowOrder = 2)] public bool RelativeContinue { get; set; } [PluginGui("Relative Sensitivity", ColumnOrder = 2, RowOrder = 2)] - public long RelativeSensitivity { get; set; } + public decimal RelativeSensitivity { get; set; } private long _currentOutputValue; private long _currentInputValue; private readonly object _threadLock = new object(); - + private Thread _relativeThread; - private bool _relativeThreadState = false; public AxisToRelative() { @@ -48,6 +47,7 @@ public AxisToRelative() Sensitivity = 100; RelativeContinue = true; RelativeSensitivity = 2; + _relativeThread = new Thread(RelativeThread); } public override void Update(params long[] values) @@ -64,19 +64,7 @@ public override void Update(params long[] values) if (RelativeContinue) { - lock (_threadLock) - { - if (value != 0 && !_relativeThreadState) - { - SetRelativeThreadState(true); - //Debug.WriteLine("UCR| Started Thread"); - } - else if (value == 0 && _relativeThreadState) - { - SetRelativeThreadState(false); - //Debug.WriteLine("UCR| Stopped Thread"); - } - } + SetRelativeThreadState(value != 0); } else { @@ -84,22 +72,35 @@ public override void Update(params long[] values) } } + public override void OnDeactivate() + { + SetRelativeThreadState(false); + } + private void SetRelativeThreadState(bool state) { - if (_relativeThreadState == state) return; - if (!_relativeThreadState && state) - { - _relativeThread = new Thread(RelativeThread); - _relativeThread.Start(); - } - else if (_relativeThreadState && !state) + lock (_threadLock) { - _relativeThread.Abort(); - _relativeThread.Join(); - _relativeThread = null; + var relativeThreadActive = RelativeThreadActive(); + if (!relativeThreadActive && state) + { + _relativeThread = new Thread(RelativeThread); + _relativeThread.Start(); + Debug.WriteLine("UCR| Started Relative Thread"); + } + else if (relativeThreadActive && !state) + { + _relativeThread.Abort(); + _relativeThread.Join(); + _relativeThread = null; + Debug.WriteLine("UCR| Stopped Relative Thread"); + } } + } - _relativeThreadState = state; + private bool RelativeThreadActive() + { + return _relativeThread != null && _relativeThread.IsAlive; } public void RelativeThread() @@ -109,17 +110,11 @@ public void RelativeThread() RelativeUpdate(); Thread.Sleep(10); } - - lock (_threadLock) - { - _relativeThreadState = false; - } } private void RelativeUpdate() { - //var value = Functions.ApplyRelativeIncrement(_currentInputValue, _currentOutputValue, RelativeSensitivity); - var value = (long)((_currentInputValue * (float)(RelativeSensitivity / 100.0)) + _currentOutputValue); + var value = (long)((_currentInputValue * (RelativeSensitivity / 100)) + _currentOutputValue); value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); WriteOutput(0, value); _currentOutputValue = value; From 9052985bd44bb212edcf2a0747dfa019d721d780 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 19 Aug 2018 23:45:34 +0100 Subject: [PATCH 019/105] Fix decimal validation regex Add anchors to ensure only one match, else 1.2.3.4 could be matched by two matches - `1.2` and `3.4` Also allow multiple numbers after the decimal point --- UCR/Utilities/Validators/DecimalBindingValidator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR/Utilities/Validators/DecimalBindingValidator.cs b/UCR/Utilities/Validators/DecimalBindingValidator.cs index 7aab9017..97a73047 100644 --- a/UCR/Utilities/Validators/DecimalBindingValidator.cs +++ b/UCR/Utilities/Validators/DecimalBindingValidator.cs @@ -11,7 +11,7 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo) var text = (string) value; if (text == null) return new ValidationResult(false, "No input"); - var regex = new Regex(@"[-+]?[0-9]+\.?[0-9]?"); + var regex = new Regex(@"^[-+]?[0-9]+\.?[0-9]+?$"); if (!regex.IsMatch(text)) return new ValidationResult(false, "Invalid input for decimal"); return ValidationResult.ValidResult; From 9cbddcf4c3cc7de97baba11b06c6d24ea4c0be11 Mon Sep 17 00:00:00 2001 From: evilC Date: Fri, 31 Aug 2018 18:28:02 +0100 Subject: [PATCH 020/105] Implement Delta to Axis --- UCR.Plugins/Remapper/DeltaToAxis.cs | 85 +++++++++++++++++++++++++++++ UCR.Plugins/Remapper/MouseToAxis.cs | 21 ------- UCR.Plugins/UCR.Plugins.csproj | 2 +- 3 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 UCR.Plugins/Remapper/DeltaToAxis.cs delete mode 100644 UCR.Plugins/Remapper/MouseToAxis.cs diff --git a/UCR.Plugins/Remapper/DeltaToAxis.cs b/UCR.Plugins/Remapper/DeltaToAxis.cs new file mode 100644 index 00000000..c1d57351 --- /dev/null +++ b/UCR.Plugins/Remapper/DeltaToAxis.cs @@ -0,0 +1,85 @@ +using System; +using System.Timers; +using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.Core.Utilities; + +namespace HidWizards.UCR.Plugins.Remapper +{ + [Plugin("Delta to Axis")] + [PluginInput(DeviceBindingCategory.Delta, "Delta")] + [PluginOutput(DeviceBindingCategory.Range, "Axis")] + public class DeltaToAxis : Plugin + { + [PluginGui("Deadzone", ColumnOrder = 0, RowOrder = 0)] + public int Deadzone { get; set; } + + [PluginGui("Relative Sensitivity", ColumnOrder = 1, RowOrder = 0)] + public double RelativeSensitivity { get; set; } + + [PluginGui("Absolute Mode", ColumnOrder = 0, RowOrder = 1)] + public bool AbsoluteMode { get; set; } + + [PluginGui("Absolute Sensitivity", ColumnOrder = 1, RowOrder = 1)] + public double AbsoluteSensitivity { get; set; } + + [PluginGui("Absolute Timeout", ColumnOrder = 2, RowOrder = 1)] + public int AbsoluteTimeout { get; set; } + + private long _currentValue; + private static System.Timers.Timer _absoluteModeTimer; + + public DeltaToAxis() + { + AbsoluteMode = false; + Deadzone = 0; + RelativeSensitivity = 100; + AbsoluteSensitivity = 10000; + AbsoluteTimeout = 100; + _absoluteModeTimer = new System.Timers.Timer(); + _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; + } + + private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) + { + SetAbsoluteTimerState(false); + WriteOutput(0, 0); + } + + public override void Update(params long[] values) + { + if (Math.Abs(values[0]) < Deadzone) return; + long value; + if (AbsoluteMode) + { + value = (long)(values[0] * AbsoluteSensitivity); + SetAbsoluteTimerState(true); + } + else + { + value = _currentValue + (long)(values[0] * RelativeSensitivity); + } + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + _currentValue = value; + WriteOutput(0, value); + } + + public void SetAbsoluteTimerState(bool state) + { + if (state) + { + if (_absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Stop(); + } + _absoluteModeTimer.Interval = AbsoluteTimeout; + _absoluteModeTimer.Start(); + } + else if (_absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Stop(); + } + } + } +} diff --git a/UCR.Plugins/Remapper/MouseToAxis.cs b/UCR.Plugins/Remapper/MouseToAxis.cs deleted file mode 100644 index 47005ac0..00000000 --- a/UCR.Plugins/Remapper/MouseToAxis.cs +++ /dev/null @@ -1,21 +0,0 @@ -using HidWizards.UCR.Core.Attributes; -using HidWizards.UCR.Core.Models; -using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Utilities; - -namespace HidWizards.UCR.Plugins.Remapper -{ - [Plugin("Mouse to Axis", Disabled = true)] - [PluginInput(DeviceBindingCategory.Delta, "Mouse axis")] - [PluginOutput(DeviceBindingCategory.Range, "Axis")] - public class MouseToAxis: Plugin - { - [PluginGui("Invert", RowOrder = 0, ColumnOrder = 0)] - public bool Invert { get; set; } - - public override void Update(params long[] values) - { - WriteOutput(0, values[0]*(Constants.AxisMaxValue/1000)); - } - } -} diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 573a3c93..aba72491 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -53,8 +53,8 @@ + - From 231f2933a0857b24454b729122d24d2598772885 Mon Sep 17 00:00:00 2001 From: evilC Date: Fri, 31 Aug 2018 19:06:21 +0100 Subject: [PATCH 021/105] tidy --- UCR.Plugins/Remapper/DeltaToAxis.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UCR.Plugins/Remapper/DeltaToAxis.cs b/UCR.Plugins/Remapper/DeltaToAxis.cs index c1d57351..815e21e2 100644 --- a/UCR.Plugins/Remapper/DeltaToAxis.cs +++ b/UCR.Plugins/Remapper/DeltaToAxis.cs @@ -28,7 +28,7 @@ public class DeltaToAxis : Plugin public int AbsoluteTimeout { get; set; } private long _currentValue; - private static System.Timers.Timer _absoluteModeTimer; + private static Timer _absoluteModeTimer; public DeltaToAxis() { @@ -37,7 +37,7 @@ public DeltaToAxis() RelativeSensitivity = 100; AbsoluteSensitivity = 10000; AbsoluteTimeout = 100; - _absoluteModeTimer = new System.Timers.Timer(); + _absoluteModeTimer = new Timer(); _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; } From 659357a49156d27704cf14a0912ee7732e38caa2 Mon Sep 17 00:00:00 2001 From: evilC Date: Fri, 31 Aug 2018 19:06:55 +0100 Subject: [PATCH 022/105] Axis to Delta POC --- .../Remapper/{AxisToMouse.cs => AxisToDelta.cs} | 15 ++++++++++----- UCR.Plugins/UCR.Plugins.csproj | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) rename UCR.Plugins/Remapper/{AxisToMouse.cs => AxisToDelta.cs} (77%) diff --git a/UCR.Plugins/Remapper/AxisToMouse.cs b/UCR.Plugins/Remapper/AxisToDelta.cs similarity index 77% rename from UCR.Plugins/Remapper/AxisToMouse.cs rename to UCR.Plugins/Remapper/AxisToDelta.cs index 8171a909..4d47fcbd 100644 --- a/UCR.Plugins/Remapper/AxisToMouse.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -6,10 +6,10 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to mouse", Disabled = true)] + [Plugin("Axis to Delta")] [PluginInput(DeviceBindingCategory.Range, "Axis")] - [PluginOutput(DeviceBindingCategory.Delta, "Mouse")] - public class AxisToMouse : Plugin + [PluginOutput(DeviceBindingCategory.Delta, "Delta")] + public class AxisToDelta : Plugin { [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } @@ -20,7 +20,9 @@ public class AxisToMouse : Plugin [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } - public AxisToMouse() + private long _currentValue; + + public AxisToDelta() { DeadZone = 0; Sensitivity = 1; @@ -33,7 +35,10 @@ public override void Update(params long[] values) if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - WriteOutput(0, value); + + var delta = value - _currentValue; + _currentValue = value; + WriteOutput(0, delta); } } } diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index aba72491..9a7d923f 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -50,7 +50,7 @@ - + From 4c2c8d25fec8eb3dbf86649b9d21b8d61071e2d5 Mon Sep 17 00:00:00 2001 From: evilC Date: Fri, 31 Aug 2018 20:30:17 +0100 Subject: [PATCH 023/105] Update IOWrapper version --- submodules/IOWrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/IOWrapper b/submodules/IOWrapper index f2e9f2b0..34088383 160000 --- a/submodules/IOWrapper +++ b/submodules/IOWrapper @@ -1 +1 @@ -Subproject commit f2e9f2b0fab682e710a1e450794a45427065c2f4 +Subproject commit 340883836a0cdc93a03d0e43a2f6b39b7c81b1a7 From 7fe035fca216edfd4e1da33101434b410b6c1328 Mon Sep 17 00:00:00 2001 From: evilC Date: Fri, 31 Aug 2018 20:35:15 +0100 Subject: [PATCH 024/105] Stop timer on deactivate --- UCR.Plugins/Remapper/DeltaToAxis.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UCR.Plugins/Remapper/DeltaToAxis.cs b/UCR.Plugins/Remapper/DeltaToAxis.cs index 815e21e2..c9b90f9f 100644 --- a/UCR.Plugins/Remapper/DeltaToAxis.cs +++ b/UCR.Plugins/Remapper/DeltaToAxis.cs @@ -81,5 +81,11 @@ public void SetAbsoluteTimerState(bool state) _absoluteModeTimer.Stop(); } } + + public override void OnDeactivate() + { + base.OnDeactivate(); + SetAbsoluteTimerState(false); + } } } From b988623d7387021f79f27f187a99ddcc2cf2533a Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 01:48:47 +0100 Subject: [PATCH 025/105] Fix axis splitter range clamping --- UCR.Core/Utilities/Functions.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 7ea9e0a8..bd574aee 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace HidWizards.UCR.Core.Utilities { @@ -40,10 +41,11 @@ public static long HalfAxisToFullRange(long axis, bool positiveRange, bool inver { value = axis < 0 ? axis * -1 : 0L; } - + value = Constants.AxisMinValue + value * 2; - - return invert ? value * -1 : value; + value = invert ? value * -1 : value; + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + return value; } } } From 1955113e3ff81a88a1fa74ffd09c2467b981b9f9 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 19:15:24 +0100 Subject: [PATCH 026/105] Implement AxisToDelta --- UCR.Plugins/Remapper/AxisToDelta.cs | 98 ++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 4d47fcbd..12c4de04 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Timers; using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; @@ -11,21 +13,56 @@ namespace HidWizards.UCR.Plugins.Remapper [PluginOutput(DeviceBindingCategory.Delta, "Delta")] public class AxisToDelta : Plugin { - [PluginGui("Invert", ColumnOrder = 0)] + [PluginGui("Invert", RowOrder = 0, ColumnOrder = 0)] public bool Invert { get; set; } - [PluginGui("Dead zone", ColumnOrder = 1)] + [PluginGui("Dead zone", RowOrder = 0, ColumnOrder = 1)] public int DeadZone { get; set; } - [PluginGui("Sensitivity", ColumnOrder = 2)] + [PluginGui("Sensitivity", RowOrder = 0, ColumnOrder = 2)] public int Sensitivity { get; set; } - private long _currentValue; + [PluginGui("Min", RowOrder = 1, ColumnOrder = 0)] + public int Min + { + get => _min; + set + { + _min = value; + PrecalculateValues(); + } + } + private int _min; + + [PluginGui("Max", RowOrder = 1, ColumnOrder = 1)] + public int Max + { + get => _max; + set + { + _max = value; + PrecalculateValues(); + } + } + private int _max; + + private static Timer _absoluteModeTimer; + private long _currentDelta; + private float _scaleFactor; public AxisToDelta() { DeadZone = 0; Sensitivity = 1; + Min = 1; + Max = 20; + _absoluteModeTimer = new Timer(10); + _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; + } + + private void PrecalculateValues() + { + _scaleFactor = (float)(Max - (Min - 1)) / 32767; } public override void Update(params long[] values) @@ -33,12 +70,55 @@ public override void Update(params long[] values) var value = values[0]; if (Invert) value *= -1; if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - var delta = value - _currentValue; - _currentValue = value; - WriteOutput(0, delta); + if (value == 0) + { + SetAbsoluteTimerState(false); + _currentDelta = 0; + } + else + { + var sign = Math.Sign(value); + + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + _currentDelta = (long)(Min + (Math.Abs(value) * _scaleFactor)) * sign; + //Debug.WriteLine($"New Delta: {_currentDelta}"); + SetAbsoluteTimerState(true); + } + } + + public override void OnActivate() + { + base.OnActivate(); + if (_currentDelta != 0) + { + SetAbsoluteTimerState(true); + } + } + + public override void OnDeactivate() + { + base.OnDeactivate(); + SetAbsoluteTimerState(false); } + + public void SetAbsoluteTimerState(bool state) + { + if (state && !_absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Start(); + } + else if (!state && _absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Stop(); + } + } + + private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) + { + WriteOutput(0, _currentDelta); + } + } } From 8a7c1adf7534df953fe19e5f8ea1119a27e5b550 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 19:24:55 +0100 Subject: [PATCH 027/105] Update to new IOWrapper --- submodules/IOWrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/IOWrapper b/submodules/IOWrapper index f2e9f2b0..34088383 160000 --- a/submodules/IOWrapper +++ b/submodules/IOWrapper @@ -1 +1 @@ -Subproject commit f2e9f2b0fab682e710a1e450794a45427065c2f4 +Subproject commit 340883836a0cdc93a03d0e43a2f6b39b7c81b1a7 From 99a364613e312aac03ba2b21ce878bc0a1a6f762 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 19:28:13 +0100 Subject: [PATCH 028/105] Normalize line endings --- UCR.Core/Utilities/Functions.cs | 92 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index bd574aee..f916deed 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -1,51 +1,51 @@ -using System; -using System.Diagnostics; - -namespace HidWizards.UCR.Core.Utilities -{ - public static class Functions - { - public static long ApplyRangeDeadZone(long value, int deadZonePercentage) - { - var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; - var remainder = Constants.AxisMaxValue - gap; - var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; - return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); - } - - public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) - { - var sensitivityPercent = (sensitivity / 100.0); +using System; +using System.Diagnostics; + +namespace HidWizards.UCR.Core.Utilities +{ + public static class Functions + { + public static long ApplyRangeDeadZone(long value, int deadZonePercentage) + { + var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; + var remainder = Constants.AxisMaxValue - gap; + var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; + return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); + } + + public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) + { + var sensitivityPercent = (sensitivity / 100.0); if (linear) return (long)(value * sensitivityPercent); var sens = sensitivityPercent / 100d; double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); // Map value to -1 .. 1 - double val11 = (((value - Constants.AxisMinValue) / AxisRange) * 2) - 1; - // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) - double valout = (sens * val11) + ((1 - sens) * Math.Pow( val11, 3 )); - // Map value back to AxisRange - value = (long) Math.Round( ((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue) ); - - return value; - } - - public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) - { - long value; - if (positiveRange) - { - value = axis > 0L ? axis : 0L; - } - else - { - value = axis < 0 ? axis * -1 : 0L; - } - - value = Constants.AxisMinValue + value * 2; - value = invert ? value * -1 : value; - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - return value; - } - } -} + double val11 = (((value - Constants.AxisMinValue) / AxisRange) * 2) - 1; + // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) + double valout = (sens * val11) + ((1 - sens) * Math.Pow( val11, 3 )); + // Map value back to AxisRange + value = (long) Math.Round( ((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue) ); + + return value; + } + + public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) + { + long value; + if (positiveRange) + { + value = axis > 0L ? axis : 0L; + } + else + { + value = axis < 0 ? axis * -1 : 0L; + } + + value = Constants.AxisMinValue + value * 2; + value = invert ? value * -1 : value; + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + return value; + } + } +} From 5b144b4608b59438d21bc30ed81c85923115a0d0 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 19:29:27 +0100 Subject: [PATCH 029/105] Copy in changes from develop --- UCR.Core/Utilities/Functions.cs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 9291666a..a90b2f2a 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace HidWizards.UCR.Core.Utilities { @@ -15,27 +16,20 @@ public static long ApplyRangeDeadZone(long value, int deadZonePercentage) public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) { var sensitivityPercent = (sensitivity / 100.0); - if (linear) return (long)(value * sensitivityPercent); - - var sens = sensitivityPercent / 100d; - double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); - // Map value to -1 .. 1 + if (linear) return (long)(value * sensitivityPercent); + + var sens = sensitivityPercent / 100d; + double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); + // Map value to -1 .. 1 double val11 = (((value - Constants.AxisMinValue) / AxisRange) * 2) - 1; // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) - double valout = (sens * val11) + ((1 - sens) * Math.Pow( val11, 3 )); + double valout = (sens * val11) + ((1 - sens) * Math.Pow(val11, 3)); // Map value back to AxisRange - value = (long) Math.Round( ((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue) ); + value = (long)Math.Round(((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue)); return value; } - public static long ApplyRelativeIncrement(long last, long prev, int sensitivity) - { - var sensitivityPercent = (sensitivity / 100.0); - last = (long)(last * sensitivityPercent); - return last + prev; - } - public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) { long value; @@ -49,8 +43,9 @@ public static long HalfAxisToFullRange(long axis, bool positiveRange, bool inver } value = Constants.AxisMinValue + value * 2; - - return invert ? value * -1 : value; + value = invert ? value * -1 : value; + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + return value; } } -} \ No newline at end of file +} From ff1d281cf0a8d968a399c9c15c5d3dda42e985fa Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 20:05:12 +0100 Subject: [PATCH 030/105] Plugin names to Title Case --- UCR.Plugins/Remapper/AxisMerger.cs | 2 +- UCR.Plugins/Remapper/AxisSplitter.cs | 2 +- UCR.Plugins/Remapper/AxisToAxis.cs | 2 +- UCR.Plugins/Remapper/AxisToButton.cs | 2 +- UCR.Plugins/Remapper/AxisToRelative.cs | 2 +- UCR.Plugins/Remapper/ButtonToAxis.cs | 2 +- UCR.Plugins/Remapper/ButtonToButton.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisMerger.cs b/UCR.Plugins/Remapper/AxisMerger.cs index 33311c89..b9612aca 100644 --- a/UCR.Plugins/Remapper/AxisMerger.cs +++ b/UCR.Plugins/Remapper/AxisMerger.cs @@ -6,7 +6,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis merger")] + [Plugin("Axis Merger")] [PluginInput(DeviceBindingCategory.Range, "Axis high")] [PluginInput(DeviceBindingCategory.Range, "Axis low")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] diff --git a/UCR.Plugins/Remapper/AxisSplitter.cs b/UCR.Plugins/Remapper/AxisSplitter.cs index c317a5f0..a7888da7 100644 --- a/UCR.Plugins/Remapper/AxisSplitter.cs +++ b/UCR.Plugins/Remapper/AxisSplitter.cs @@ -5,7 +5,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis splitter")] + [Plugin("Axis Splitter")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis high")] [PluginOutput(DeviceBindingCategory.Range, "Axis low")] diff --git a/UCR.Plugins/Remapper/AxisToAxis.cs b/UCR.Plugins/Remapper/AxisToAxis.cs index 526c1f22..6602c320 100644 --- a/UCR.Plugins/Remapper/AxisToAxis.cs +++ b/UCR.Plugins/Remapper/AxisToAxis.cs @@ -6,7 +6,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to axis")] + [Plugin("Axis to Axis")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class AxisToAxis : Plugin diff --git a/UCR.Plugins/Remapper/AxisToButton.cs b/UCR.Plugins/Remapper/AxisToButton.cs index 04566b6d..4cd28e65 100644 --- a/UCR.Plugins/Remapper/AxisToButton.cs +++ b/UCR.Plugins/Remapper/AxisToButton.cs @@ -6,7 +6,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to button")] + [Plugin("Axis to Button")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Momentary, "Button high")] [PluginOutput(DeviceBindingCategory.Momentary, "Button low")] diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToRelative.cs index 33fe61ed..b51bcd0b 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToRelative.cs @@ -8,7 +8,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to axis (Relative)")] + [Plugin("Axis to Axis (Relative)")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class AxisToRelative : Plugin diff --git a/UCR.Plugins/Remapper/ButtonToAxis.cs b/UCR.Plugins/Remapper/ButtonToAxis.cs index 47738ad2..5d00e69c 100644 --- a/UCR.Plugins/Remapper/ButtonToAxis.cs +++ b/UCR.Plugins/Remapper/ButtonToAxis.cs @@ -5,7 +5,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Button to axis")] + [Plugin("Button to Axis")] [PluginInput(DeviceBindingCategory.Momentary, "Button")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class ButtonToAxis : Plugin diff --git a/UCR.Plugins/Remapper/ButtonToButton.cs b/UCR.Plugins/Remapper/ButtonToButton.cs index a8733e1f..f41634a7 100644 --- a/UCR.Plugins/Remapper/ButtonToButton.cs +++ b/UCR.Plugins/Remapper/ButtonToButton.cs @@ -4,7 +4,7 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Button to button")] + [Plugin("Button to Button")] [PluginInput(DeviceBindingCategory.Momentary, "Button")] [PluginOutput(DeviceBindingCategory.Momentary, "Button")] public class ButtonToButton : Plugin From 25f32834655ca8970eb3a12dc01c2f3eee913375 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 20:08:59 +0100 Subject: [PATCH 031/105] Rename AxisToRelative -> AxisToAxisRelative --- .../Remapper/{AxisToRelative.cs => AxisToAxisRelative.cs} | 4 ++-- UCR.Plugins/UCR.Plugins.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename UCR.Plugins/Remapper/{AxisToRelative.cs => AxisToAxisRelative.cs} (97%) diff --git a/UCR.Plugins/Remapper/AxisToRelative.cs b/UCR.Plugins/Remapper/AxisToAxisRelative.cs similarity index 97% rename from UCR.Plugins/Remapper/AxisToRelative.cs rename to UCR.Plugins/Remapper/AxisToAxisRelative.cs index b51bcd0b..db5237f7 100644 --- a/UCR.Plugins/Remapper/AxisToRelative.cs +++ b/UCR.Plugins/Remapper/AxisToAxisRelative.cs @@ -11,7 +11,7 @@ namespace HidWizards.UCR.Plugins.Remapper [Plugin("Axis to Axis (Relative)")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] - public class AxisToRelative : Plugin + public class AxisToAxisRelative : Plugin { [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } @@ -41,7 +41,7 @@ public class AxisToRelative : Plugin private Thread _relativeThread; - public AxisToRelative() + public AxisToAxisRelative() { DeadZone = 0; Sensitivity = 100; diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 12f0ec5f..54fd730d 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -48,7 +48,7 @@ - + From 9119a894f4656c4313a2eebe4d47d25c2eced9f1 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sat, 1 Sep 2018 21:13:40 +0200 Subject: [PATCH 032/105] Plugins now support OnPropertyChanged() --- UCR.Core/Models/Plugin.cs | 5 +++++ UCR.Core/Models/PluginProperty.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index f77032ba..732c96a5 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -91,6 +91,11 @@ public virtual void OnActivate() } + public virtual void OnPropertyChanged() + { + + } + public virtual void Update(params long[] values) { diff --git a/UCR.Core/Models/PluginProperty.cs b/UCR.Core/Models/PluginProperty.cs index 0454fa06..8c898294 100644 --- a/UCR.Core/Models/PluginProperty.cs +++ b/UCR.Core/Models/PluginProperty.cs @@ -20,6 +20,7 @@ public dynamic Property { if (value.Equals(PropertyInfo.GetValue(Plugin))) return; PropertyInfo.SetValue(Plugin, Convert.ChangeType(value, PropertyInfo.PropertyType, CultureInfo.InvariantCulture)); + Plugin.OnPropertyChanged(); Plugin.ContextChanged(); } } From 8e198dc35af54eb5bfa9022f677317899c089509 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 20:30:13 +0100 Subject: [PATCH 033/105] ToDo --- UCR.Core/Utilities/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Core/Utilities/Constants.cs b/UCR.Core/Utilities/Constants.cs index 7805f340..0d3be979 100644 --- a/UCR.Core/Utilities/Constants.cs +++ b/UCR.Core/Utilities/Constants.cs @@ -3,7 +3,7 @@ public static class Constants { public const int MaxDevices = 16; - public const int AxisMaxValue = short.MaxValue; + public const int AxisMaxValue = short.MaxValue; // ToDo: This will be 32767, meaning that negative scaling does not go to -32768. Fix. public const int AxisMinValue = short.MinValue; } } From bd1e7da4c6597411147c2cab479705bcf79e98f1 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 20:40:19 +0100 Subject: [PATCH 034/105] Add AxisMaxAbsValue constant --- UCR.Core/Utilities/Constants.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UCR.Core/Utilities/Constants.cs b/UCR.Core/Utilities/Constants.cs index 0d3be979..343dbdb3 100644 --- a/UCR.Core/Utilities/Constants.cs +++ b/UCR.Core/Utilities/Constants.cs @@ -3,6 +3,13 @@ public static class Constants { public const int MaxDevices = 16; + /// + /// When doing calculations using the size of the range from the mid-point to the extreme... + /// ...use NOT . + /// Signed numbers are larger on the negative side, so perform calculations using the size of the negative scale... + /// ...and then clamp the value + /// + public const int AxisMaxAbsValue = short.MinValue * -1; // For short, this should be 32768 public const int AxisMaxValue = short.MaxValue; // ToDo: This will be 32767, meaning that negative scaling does not go to -32768. Fix. public const int AxisMinValue = short.MinValue; } From baa16c8d3a2162ccd3846a48312dc73ffed42dfb Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 21:48:34 +0100 Subject: [PATCH 035/105] Format summary --- UCR.Core/Utilities/Constants.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UCR.Core/Utilities/Constants.cs b/UCR.Core/Utilities/Constants.cs index 343dbdb3..4b7954fc 100644 --- a/UCR.Core/Utilities/Constants.cs +++ b/UCR.Core/Utilities/Constants.cs @@ -4,10 +4,10 @@ public static class Constants { public const int MaxDevices = 16; /// - /// When doing calculations using the size of the range from the mid-point to the extreme... - /// ...use NOT . - /// Signed numbers are larger on the negative side, so perform calculations using the size of the negative scale... - /// ...and then clamp the value + /// When doing calculations using the size of the range from the mid-point to the extreme, + /// use NOT + /// Signed numbers are larger on the negative side, so perform calculations using the size of the negative scale, + /// and then clamp the value /// public const int AxisMaxAbsValue = short.MinValue * -1; // For short, this should be 32768 public const int AxisMaxValue = short.MaxValue; // ToDo: This will be 32767, meaning that negative scaling does not go to -32768. Fix. From 079718c577992cb9493ed35b7059f9ec9800fcbe Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 21:49:59 +0100 Subject: [PATCH 036/105] Add DeadzoneHelper --- UCR.Core/UCR.Core.csproj | 1 + UCR.Core/Utilities/AxisHelpers.cs | 57 +++++++++++++++++++++++++++++ UCR.Plugins/Remapper/AxisToDelta.cs | 28 +++++++++++++- 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 UCR.Core/Utilities/AxisHelpers.cs diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 706c2ac9..145a6469 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -86,6 +86,7 @@ + diff --git a/UCR.Core/Utilities/AxisHelpers.cs b/UCR.Core/Utilities/AxisHelpers.cs new file mode 100644 index 00000000..77dfa6fe --- /dev/null +++ b/UCR.Core/Utilities/AxisHelpers.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HidWizards.UCR.Core.Utilities +{ + public class DeadzoneHelper + { + //private double gapPercent; + private int _percentage; + private double _scaleFactor; + private long _deadzoneCutoff; + + public int Percentage + { + get => _percentage; + set + { + _percentage = value; + PrecalculateValues(); + } + } + + private void PrecalculateValues() + { + if (_percentage == 0) + { + _deadzoneCutoff = 0; + _scaleFactor = 100.0; + } + else + { + // work out how much we have to deform the input scale by the output scale + _scaleFactor = 100.0 / (100 - _percentage); + _deadzoneCutoff = (long)((_percentage / 100.0) * Constants.AxisMaxAbsValue); + } + } + + public long ApplyRangeDeadZone(long value) + { + var absValue = Math.Abs(value); + if (absValue <= _deadzoneCutoff) + { + return 0; + } + + var sign = Math.Sign(value); + var adjustedValue = (absValue - _deadzoneCutoff) * sign; + var newValue = (long)(adjustedValue * _scaleFactor); + //Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); + return newValue; + } + } +} diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 12c4de04..457ff51a 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -17,11 +17,28 @@ public class AxisToDelta : Plugin public bool Invert { get; set; } [PluginGui("Dead zone", RowOrder = 0, ColumnOrder = 1)] - public int DeadZone { get; set; } + //public int DeadZone { get; set; } + public int DeadZone + { + get => _deadZone; + set + { + _deadZone = value; + _deadzoneHelper.Percentage = _deadZone; + } + } + private int _deadZone; + [PluginGui("Sensitivity", RowOrder = 0, ColumnOrder = 2)] public int Sensitivity { get; set; } + //[PluginGui("Min", RowOrder = 1, ColumnOrder = 0)] + //public int Min { get; set; } + + //[PluginGui("Max", RowOrder = 1, ColumnOrder = 1)] + //public int Max { get; set; } + [PluginGui("Min", RowOrder = 1, ColumnOrder = 0)] public int Min { @@ -49,6 +66,7 @@ public int Max private static Timer _absoluteModeTimer; private long _currentDelta; private float _scaleFactor; + private readonly DeadzoneHelper _deadzoneHelper = new DeadzoneHelper(); public AxisToDelta() { @@ -60,6 +78,12 @@ public AxisToDelta() _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; } + //public override void OnPropertyChanged() + //{ + // base.OnPropertyChanged(); + // PrecalculateValues(); + //} + private void PrecalculateValues() { _scaleFactor = (float)(Max - (Min - 1)) / 32767; @@ -68,8 +92,8 @@ private void PrecalculateValues() public override void Update(params long[] values) { var value = values[0]; + if (value != 0) value = _deadzoneHelper.ApplyRangeDeadZone(value); if (Invert) value *= -1; - if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); if (value == 0) { From 4e829a573e713983a4faafe7bb4b2857ecbe6f6f Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 22:26:29 +0100 Subject: [PATCH 037/105] Move to OnPropertyChanged --- UCR.Plugins/Remapper/AxisToDelta.cs | 52 ++++++----------------------- 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 457ff51a..c92cc9bc 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -17,51 +17,17 @@ public class AxisToDelta : Plugin public bool Invert { get; set; } [PluginGui("Dead zone", RowOrder = 0, ColumnOrder = 1)] - //public int DeadZone { get; set; } - public int DeadZone - { - get => _deadZone; - set - { - _deadZone = value; - _deadzoneHelper.Percentage = _deadZone; - } - } - private int _deadZone; + public int DeadZone { get; set; } [PluginGui("Sensitivity", RowOrder = 0, ColumnOrder = 2)] public int Sensitivity { get; set; } - //[PluginGui("Min", RowOrder = 1, ColumnOrder = 0)] - //public int Min { get; set; } - - //[PluginGui("Max", RowOrder = 1, ColumnOrder = 1)] - //public int Max { get; set; } - [PluginGui("Min", RowOrder = 1, ColumnOrder = 0)] - public int Min - { - get => _min; - set - { - _min = value; - PrecalculateValues(); - } - } - private int _min; + public int Min { get; set; } [PluginGui("Max", RowOrder = 1, ColumnOrder = 1)] - public int Max - { - get => _max; - set - { - _max = value; - PrecalculateValues(); - } - } - private int _max; + public int Max { get; set; } private static Timer _absoluteModeTimer; private long _currentDelta; @@ -74,19 +40,21 @@ public AxisToDelta() Sensitivity = 1; Min = 1; Max = 20; + PrecalculateValues(); _absoluteModeTimer = new Timer(10); _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; } - //public override void OnPropertyChanged() - //{ - // base.OnPropertyChanged(); - // PrecalculateValues(); - //} + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + PrecalculateValues(); + } private void PrecalculateValues() { _scaleFactor = (float)(Max - (Min - 1)) / 32767; + _deadzoneHelper.Percentage = DeadZone; } public override void Update(params long[] values) From 2ad195427e55c3e531179b4ee19dd98a01202c07 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 22:47:45 +0100 Subject: [PATCH 038/105] Move Precalculate to OnActivate --- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index c92cc9bc..2fa9b251 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -40,7 +40,6 @@ public AxisToDelta() Sensitivity = 1; Min = 1; Max = 20; - PrecalculateValues(); _absoluteModeTimer = new Timer(10); _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; } @@ -83,6 +82,7 @@ public override void Update(params long[] values) public override void OnActivate() { base.OnActivate(); + PrecalculateValues(); if (_currentDelta != 0) { SetAbsoluteTimerState(true); From a25199d8f9c96b514d4d4feb06968268c72c7b14 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 23:39:25 +0100 Subject: [PATCH 039/105] Remove comment --- UCR.Core/Utilities/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Core/Utilities/Constants.cs b/UCR.Core/Utilities/Constants.cs index 4b7954fc..a13048d6 100644 --- a/UCR.Core/Utilities/Constants.cs +++ b/UCR.Core/Utilities/Constants.cs @@ -10,7 +10,7 @@ public static class Constants /// and then clamp the value /// public const int AxisMaxAbsValue = short.MinValue * -1; // For short, this should be 32768 - public const int AxisMaxValue = short.MaxValue; // ToDo: This will be 32767, meaning that negative scaling does not go to -32768. Fix. + public const int AxisMaxValue = short.MaxValue; public const int AxisMinValue = short.MinValue; } } From 5caf94d2af912aa0845d9bc5f465f2c8ee393462 Mon Sep 17 00:00:00 2001 From: evilC Date: Sat, 1 Sep 2018 23:39:48 +0100 Subject: [PATCH 040/105] Add robust Invert --- UCR.Core/Utilities/Functions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 3a704b5b..dcc093a5 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -5,6 +5,22 @@ namespace HidWizards.UCR.Core.Utilities { public static class Functions { + public static long Invert(long value) + { + if (value == 0) return 0; + if (value >= Constants.AxisMaxValue) + { + return Constants.AxisMinValue; + } + + if (value <= Constants.AxisMinValue) + { + return Constants.AxisMaxValue; + } + + return value * -1; + } + public static long ApplyRangeDeadZone(long value, int deadZonePercentage) { var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; From c4104c2ea026e56b07a67595d2532369f49d21c5 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:09:18 +0100 Subject: [PATCH 041/105] AxisToDelta uses new Invert function --- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 2fa9b251..c90acb4a 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -60,7 +60,7 @@ public override void Update(params long[] values) { var value = values[0]; if (value != 0) value = _deadzoneHelper.ApplyRangeDeadZone(value); - if (Invert) value *= -1; + if (Invert) value = Functions.Invert(value); if (value == 0) { From 4f6e266a07fbf26a9b14ec1006a75378b714bec7 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:31:41 +0100 Subject: [PATCH 042/105] Create AxisHelpers namespace --- .../{AxisHelpers.cs => AxisHelpers/DeadZoneHelper.cs} | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) rename UCR.Core/Utilities/{AxisHelpers.cs => AxisHelpers/DeadZoneHelper.cs} (87%) diff --git a/UCR.Core/Utilities/AxisHelpers.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs similarity index 87% rename from UCR.Core/Utilities/AxisHelpers.cs rename to UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 77dfa6fe..397a02ee 100644 --- a/UCR.Core/Utilities/AxisHelpers.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -1,13 +1,8 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace HidWizards.UCR.Core.Utilities +namespace HidWizards.UCR.Core.Utilities.AxisHelpers { - public class DeadzoneHelper + public class DeadZoneHelper { //private double gapPercent; private int _percentage; From 393aa68f78e7db8032eaeb67ae330a9716884870 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:47:12 +0100 Subject: [PATCH 043/105] Add SensitivityHelper --- UCR.Core/UCR.Core.csproj | 3 +- .../Utilities/AxisHelpers/DeadZoneHelper.cs | 2 +- .../AxisHelpers/SensitivityHelper.cs | 64 +++++++++++++++++++ UCR.Plugins/Remapper/AxisToDelta.cs | 10 +-- 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 145a6469..d71d083e 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -86,7 +86,8 @@ - + + diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 397a02ee..02fab6d0 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -5,7 +5,6 @@ namespace HidWizards.UCR.Core.Utilities.AxisHelpers public class DeadZoneHelper { //private double gapPercent; - private int _percentage; private double _scaleFactor; private long _deadzoneCutoff; @@ -18,6 +17,7 @@ public int Percentage PrecalculateValues(); } } + private int _percentage; private void PrecalculateValues() { diff --git a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs new file mode 100644 index 00000000..4bc743ae --- /dev/null +++ b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HidWizards.UCR.Core.Utilities.AxisHelpers +{ + public class SensitivityHelper + { + private double _scaleFactor; + private double _axisRange; + private double _sens; + + public int Percentage + { + get => _percentage; + set + { + _percentage = value; + PrecalculateValues(); + } + } + + private int _percentage; + + public bool IsLinear + { + get => _isLinear; + set + { + _isLinear = value; + PrecalculateValues(); + } + } + + private bool _isLinear; + + private void PrecalculateValues() + { + _scaleFactor = _percentage / 100.0; + _axisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); + _sens = _scaleFactor / 100d; + } + + public long ApplyRangeSensitivity(long value, int sensitivity, bool linear) + { + //var sensitivityPercent = (sensitivity / 100.0); + if (_isLinear) return (long)(value * _scaleFactor); + + //var sens = _scaleFactor / 100d; + //double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); + // Map value to -1 .. 1 + double val11 = (((value - Constants.AxisMinValue) / _axisRange) * 2) - 1; + // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) + double valout = (_sens * val11) + ((1 - _sens) * Math.Pow(val11, 3)); + // Map value back to AxisRange + value = (long)Math.Round(((valout + 1) / 2d) * _axisRange + (1d * Constants.AxisMinValue)); + + return value; + } + + } +} diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index c90acb4a..88bb78bc 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -5,6 +5,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -19,7 +20,6 @@ public class AxisToDelta : Plugin [PluginGui("Dead zone", RowOrder = 0, ColumnOrder = 1)] public int DeadZone { get; set; } - [PluginGui("Sensitivity", RowOrder = 0, ColumnOrder = 2)] public int Sensitivity { get; set; } @@ -32,7 +32,8 @@ public class AxisToDelta : Plugin private static Timer _absoluteModeTimer; private long _currentDelta; private float _scaleFactor; - private readonly DeadzoneHelper _deadzoneHelper = new DeadzoneHelper(); + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + private readonly SensitivityHelper _sensitivityHelper = new SensitivityHelper(); public AxisToDelta() { @@ -53,13 +54,14 @@ public override void OnPropertyChanged() private void PrecalculateValues() { _scaleFactor = (float)(Max - (Min - 1)) / 32767; - _deadzoneHelper.Percentage = DeadZone; + _deadZoneHelper.Percentage = DeadZone; + _sensitivityHelper.Percentage = Sensitivity; } public override void Update(params long[] values) { var value = values[0]; - if (value != 0) value = _deadzoneHelper.ApplyRangeDeadZone(value); + if (value != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); if (Invert) value = Functions.Invert(value); if (value == 0) From a3447d82bff43beea88f0b104e76e9f42f812283 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:49:32 +0100 Subject: [PATCH 044/105] wire up SensitivityHelper --- UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs | 2 +- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs index 4bc743ae..778999af 100644 --- a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs @@ -43,7 +43,7 @@ private void PrecalculateValues() _sens = _scaleFactor / 100d; } - public long ApplyRangeSensitivity(long value, int sensitivity, bool linear) + public long ApplyRangeSensitivity(long value) { //var sensitivityPercent = (sensitivity / 100.0); if (_isLinear) return (long)(value * _scaleFactor); diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 88bb78bc..f7cd9014 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -73,7 +73,7 @@ public override void Update(params long[] values) { var sign = Math.Sign(value); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); + if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); _currentDelta = (long)(Min + (Math.Abs(value) * _scaleFactor)) * sign; //Debug.WriteLine($"New Delta: {_currentDelta}"); From 370801667768f4e2de0069ed4c69da5c1c5d788f Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:53:13 +0100 Subject: [PATCH 045/105] Add ClampAxisRange --- UCR.Core/Utilities/Functions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index dcc093a5..2c859e1e 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -21,6 +21,13 @@ public static long Invert(long value) return value * -1; } + public static long ClampAxisRange(long value) + { + if (value == 0) return value; + if (value <= Constants.AxisMinValue) return Constants.AxisMinValue; + return value >= Constants.AxisMaxValue ? Constants.AxisMaxValue : value; + } + public static long ApplyRangeDeadZone(long value, int deadZonePercentage) { var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; From c11a5a33eb6668dc98a3363d9666c368f9533360 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 01:54:56 +0100 Subject: [PATCH 046/105] AxisToDelta uses ClampAxisRange --- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index f7cd9014..3f4c63fb 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -74,7 +74,7 @@ public override void Update(params long[] values) var sign = Math.Sign(value); if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + value = Functions.ClampAxisRange(value); _currentDelta = (long)(Min + (Math.Abs(value) * _scaleFactor)) * sign; //Debug.WriteLine($"New Delta: {_currentDelta}"); SetAbsoluteTimerState(true); From b12af39ea2948cb8e8329e2eda0b592a2ada3dba Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 11:27:19 +0100 Subject: [PATCH 047/105] Fix DZ bug --- UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 02fab6d0..00eb59dc 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -24,7 +24,7 @@ private void PrecalculateValues() if (_percentage == 0) { _deadzoneCutoff = 0; - _scaleFactor = 100.0; + _scaleFactor = 1.0; } else { From bf1c6d871bd8fc8a7b0d90418f28494f6c762e47 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 11:56:59 +0100 Subject: [PATCH 048/105] Fix DZ calc --- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 3f4c63fb..c92de71f 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -53,7 +53,7 @@ public override void OnPropertyChanged() private void PrecalculateValues() { - _scaleFactor = (float)(Max - (Min - 1)) / 32767; + _scaleFactor = (float)(Max - (Min - 1)) / 32769; _deadZoneHelper.Percentage = DeadZone; _sensitivityHelper.Percentage = Sensitivity; } From 1dd7d5bf61e3e63c107e27a05f75452b22c2c776 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 12:14:06 +0100 Subject: [PATCH 049/105] Add Unit Test for Invert --- UCR.Tests/HelperTests/FunctionTests.cs | 24 ++++++++++++++++++++++++ UCR.Tests/UCR.Tests.csproj | 1 + 2 files changed, 25 insertions(+) create mode 100644 UCR.Tests/HelperTests/FunctionTests.cs diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs new file mode 100644 index 00000000..f8d8dcd3 --- /dev/null +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core.Utilities; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.HelperTests +{ + [TestFixture] + public class FunctionTests + { + [Test] + public void InvertTest() + { + Assert.AreEqual(Functions.Invert(0), 0); + Assert.AreEqual(Functions.Invert(32767), -32768); + Assert.AreEqual(Functions.Invert(-32768), 32767); + Assert.AreEqual(Functions.Invert(1), -1); + Assert.AreEqual(Functions.Invert(-1), 1); + } + } +} diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index b01b17bb..93d15f5d 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -46,6 +46,7 @@ + From c7a1e2e500022d4e39059b5a74dd1cbc3e48d414 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 12:22:27 +0100 Subject: [PATCH 050/105] Add Clamp Test, tidy Invert --- UCR.Tests/HelperTests/FunctionTests.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index f8d8dcd3..2f70f983 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -15,10 +15,22 @@ public class FunctionTests public void InvertTest() { Assert.AreEqual(Functions.Invert(0), 0); - Assert.AreEqual(Functions.Invert(32767), -32768); - Assert.AreEqual(Functions.Invert(-32768), 32767); + Assert.AreEqual(Functions.Invert(Constants.AxisMaxValue), Constants.AxisMinValue); + Assert.AreEqual(Functions.Invert(Constants.AxisMinValue), Constants.AxisMaxValue); Assert.AreEqual(Functions.Invert(1), -1); Assert.AreEqual(Functions.Invert(-1), 1); } + + [Test] + public void ClampTest() + { + Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMinValue - 1), Constants.AxisMinValue); + Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMaxValue + 1), Constants.AxisMaxValue); + Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMaxValue), Constants.AxisMaxValue); + Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMinValue), Constants.AxisMinValue); + Assert.AreEqual(Functions.ClampAxisRange(0), 0); + Assert.AreEqual(Functions.ClampAxisRange(1), 1); + Assert.AreEqual(Functions.ClampAxisRange(-1), -1); + } } } From 5e7d0348ca0ca6f4dbad132ad046a7cb5e8b26dd Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 12:29:13 +0100 Subject: [PATCH 051/105] Fix Initialization bug for DZ helper --- UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 00eb59dc..76cb58b2 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -19,6 +19,11 @@ public int Percentage } private int _percentage; + public DeadZoneHelper() + { + PrecalculateValues(); + } + private void PrecalculateValues() { if (_percentage == 0) From 1c914534239c08f26c2096c1e6112eb7c7f562a6 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 12:30:49 +0100 Subject: [PATCH 052/105] Add DZ Helper Test stub --- UCR.Tests/HelperTests/HelperTests.cs | 23 +++++++++++++++++++++++ UCR.Tests/UCR.Tests.csproj | 1 + 2 files changed, 24 insertions(+) create mode 100644 UCR.Tests/HelperTests/HelperTests.cs diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/HelperTests/HelperTests.cs new file mode 100644 index 00000000..fee445d3 --- /dev/null +++ b/UCR.Tests/HelperTests/HelperTests.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.HelperTests +{ + [TestFixture] + public class HelperTests + { + [Test] + public void DeadZoneHelperTest() + { + var helper = new DeadZoneHelper(); + // On initialize, the helper should work for DZ 0 without setting Percent + Assert.AreEqual(helper.ApplyRangeDeadZone(Constants.AxisMaxValue), Constants.AxisMaxValue); + } + } +} diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index 93d15f5d..10144324 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -47,6 +47,7 @@ + From 66d436d77a3cc2b34b89605ed1baf4e0a4807ad8 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 13:09:36 +0100 Subject: [PATCH 053/105] Switch expected, actual value in tests --- UCR.Tests/HelperTests/FunctionTests.cs | 18 +++++++++--------- UCR.Tests/HelperTests/HelperTests.cs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index 2f70f983..88238fa6 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -14,8 +14,8 @@ public class FunctionTests [Test] public void InvertTest() { - Assert.AreEqual(Functions.Invert(0), 0); - Assert.AreEqual(Functions.Invert(Constants.AxisMaxValue), Constants.AxisMinValue); + Assert.AreEqual(0, Functions.Invert(0)); + Assert.AreEqual(Constants.AxisMinValue, Functions.Invert(Constants.AxisMaxValue)); Assert.AreEqual(Functions.Invert(Constants.AxisMinValue), Constants.AxisMaxValue); Assert.AreEqual(Functions.Invert(1), -1); Assert.AreEqual(Functions.Invert(-1), 1); @@ -24,13 +24,13 @@ public void InvertTest() [Test] public void ClampTest() { - Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMinValue - 1), Constants.AxisMinValue); - Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMaxValue + 1), Constants.AxisMaxValue); - Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMaxValue), Constants.AxisMaxValue); - Assert.AreEqual(Functions.ClampAxisRange(Constants.AxisMinValue), Constants.AxisMinValue); - Assert.AreEqual(Functions.ClampAxisRange(0), 0); - Assert.AreEqual(Functions.ClampAxisRange(1), 1); - Assert.AreEqual(Functions.ClampAxisRange(-1), -1); + Assert.AreEqual(Constants.AxisMinValue, Functions.ClampAxisRange(Constants.AxisMinValue - 1)); + Assert.AreEqual(Constants.AxisMaxValue, Functions.ClampAxisRange(Constants.AxisMaxValue + 1)); + Assert.AreEqual(Constants.AxisMaxValue, Functions.ClampAxisRange(Constants.AxisMaxValue)); + Assert.AreEqual(Constants.AxisMinValue, Functions.ClampAxisRange(Constants.AxisMinValue)); + Assert.AreEqual(0, Functions.ClampAxisRange(0)); + Assert.AreEqual(1, Functions.ClampAxisRange(1)); + Assert.AreEqual(-1, Functions.ClampAxisRange(-1)); } } } diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/HelperTests/HelperTests.cs index fee445d3..62667127 100644 --- a/UCR.Tests/HelperTests/HelperTests.cs +++ b/UCR.Tests/HelperTests/HelperTests.cs @@ -13,11 +13,25 @@ namespace HidWizards.UCR.Tests.HelperTests public class HelperTests { [Test] - public void DeadZoneHelperTest() + public void DeadZoneHelperInitTest() { var helper = new DeadZoneHelper(); // On initialize, the helper should work for DZ 0 without setting Percent - Assert.AreEqual(helper.ApplyRangeDeadZone(Constants.AxisMaxValue), Constants.AxisMaxValue); + Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeDeadZone(Constants.AxisMaxValue)); + Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeDeadZone(Constants.AxisMinValue)); + Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); + Assert.AreEqual(1, helper.ApplyRangeDeadZone(1)); + Assert.AreEqual(-1, helper.ApplyRangeDeadZone(-1)); + } + + [Test] + public void DeadZoneHelperValuesTest() + { + var helper = new DeadZoneHelper {Percentage = 50}; + // At 50% DZ, we should still be able to reach extremes + //Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeDeadZone(Constants.AxisMaxValue)); + //Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeDeadZone(Constants.AxisMinValue)); + Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); } } } From c00681319e0178a8162a530acd658ea30ed0915a Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 14:22:16 +0100 Subject: [PATCH 054/105] Move FunctionTests to Data Driven --- UCR.Tests/HelperTests/FunctionTests.cs | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index 88238fa6..01e4de8a 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -11,26 +11,26 @@ namespace HidWizards.UCR.Tests.HelperTests [TestFixture] public class FunctionTests { - [Test] - public void InvertTest() + [TestCase(0, ExpectedResult = 0, TestName = "Invert 0 Should be 0")] + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMinValue, TestName = "Invert Max should be Min")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMaxValue, TestName = "Invert of Min should be Max")] + [TestCase(1, ExpectedResult = -1, TestName = "Invert of 1 should be -1")] + [TestCase(-1, ExpectedResult = 1, TestName = "Invert of -1 should be 1")] + public long InvertTests(long inputValue) { - Assert.AreEqual(0, Functions.Invert(0)); - Assert.AreEqual(Constants.AxisMinValue, Functions.Invert(Constants.AxisMaxValue)); - Assert.AreEqual(Functions.Invert(Constants.AxisMinValue), Constants.AxisMaxValue); - Assert.AreEqual(Functions.Invert(1), -1); - Assert.AreEqual(Functions.Invert(-1), 1); + return Functions.Invert(inputValue); } - [Test] - public void ClampTest() + [TestCase(Constants.AxisMinValue - 1, ExpectedResult = Constants.AxisMinValue, TestName = "Greater than Max Clamp should return Max")] + [TestCase(Constants.AxisMaxValue + 1, ExpectedResult = Constants.AxisMaxValue, TestName = "Less than Min Clamp should return Min")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "Min Clamp should return Min")] + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "Max Clamp should return Max")] + [TestCase(0, ExpectedResult = 0, TestName = "Clamping 0 should return 0")] + [TestCase(1, ExpectedResult = 1, TestName = "Clamping 1 should return 1")] + [TestCase(-1, ExpectedResult = -1, TestName = "Clamping -1 should return -1")] + public long ClampTests(long inputValue) { - Assert.AreEqual(Constants.AxisMinValue, Functions.ClampAxisRange(Constants.AxisMinValue - 1)); - Assert.AreEqual(Constants.AxisMaxValue, Functions.ClampAxisRange(Constants.AxisMaxValue + 1)); - Assert.AreEqual(Constants.AxisMaxValue, Functions.ClampAxisRange(Constants.AxisMaxValue)); - Assert.AreEqual(Constants.AxisMinValue, Functions.ClampAxisRange(Constants.AxisMinValue)); - Assert.AreEqual(0, Functions.ClampAxisRange(0)); - Assert.AreEqual(1, Functions.ClampAxisRange(1)); - Assert.AreEqual(-1, Functions.ClampAxisRange(-1)); + return Functions.ClampAxisRange(inputValue); } } } From 157da7232f3feb6181ab2e2ab98b380eb6e7ba6f Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 16:51:18 +0100 Subject: [PATCH 055/105] Tighten up DZ helper --- .../Utilities/AxisHelpers/DeadZoneHelper.cs | 36 +++++++++++++++---- UCR.Tests/HelperTests/HelperTests.cs | 6 ++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 76cb58b2..75691538 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace HidWizards.UCR.Core.Utilities.AxisHelpers { @@ -6,12 +7,13 @@ public class DeadZoneHelper { //private double gapPercent; private double _scaleFactor; - private long _deadzoneCutoff; + private double _deadzoneCutoff; public int Percentage { get => _percentage; set + //TODO CHECK FOR NEG { _percentage = value; PrecalculateValues(); @@ -33,25 +35,45 @@ private void PrecalculateValues() } else { + /* // work out how much we have to deform the input scale by the output scale - _scaleFactor = 100.0 / (100 - _percentage); - _deadzoneCutoff = (long)((_percentage / 100.0) * Constants.AxisMaxAbsValue); + _scaleFactor = 100.0 / (100 - 50);//_percentage); + _deadzoneCutoff = (long)(Math.Round((//_percentage + 50.0 / 100.0) * Constants.AxisMaxAbsValue)); + */ + _deadzoneCutoff = (Constants.AxisMaxValue - (Constants.AxisMaxValue * (_percentage / 100.0))); + _scaleFactor = Math.Round(Constants.AxisMaxValue / _deadzoneCutoff); } } public long ApplyRangeDeadZone(long value) { var absValue = Math.Abs(value); - if (absValue <= _deadzoneCutoff) + if (absValue < _deadzoneCutoff) { return 0; } var sign = Math.Sign(value); - var adjustedValue = (absValue - _deadzoneCutoff) * sign; - var newValue = (long)(adjustedValue * _scaleFactor); + var adjustedValue = (absValue - _deadzoneCutoff) * _scaleFactor; + var newValue = Math.Round(adjustedValue * (double)sign); + //var newValue = (long)Math.Round((adjustedValue * _scaleFactor)); + if (newValue == -32769) newValue = -32768; + Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); + return (long)newValue; + + + //var absValue = Math.Abs(value); + //if (absValue < _deadzoneCutoff) + //{ + // return 0; + //} + + //var sign = Math.Sign(value); + //var adjustedValue = (absValue - _deadzoneCutoff) * sign; + //var newValue = (long)Math.Round((adjustedValue * _scaleFactor)); //Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); - return newValue; + //return newValue; } } } diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/HelperTests/HelperTests.cs index 62667127..5fb06b05 100644 --- a/UCR.Tests/HelperTests/HelperTests.cs +++ b/UCR.Tests/HelperTests/HelperTests.cs @@ -29,8 +29,10 @@ public void DeadZoneHelperValuesTest() { var helper = new DeadZoneHelper {Percentage = 50}; // At 50% DZ, we should still be able to reach extremes - //Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeDeadZone(Constants.AxisMaxValue)); - //Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeDeadZone(Constants.AxisMinValue)); + var max = helper.ApplyRangeDeadZone(Constants.AxisMaxValue); + //Assert.AreEqual(Constants.AxisMaxValue, max); + var min = helper.ApplyRangeDeadZone(Constants.AxisMinValue); + Assert.AreEqual(Constants.AxisMinValue, min); Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); } } From bd4004a50afeaedd34f286ee1584b45563b66512 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 16:53:57 +0100 Subject: [PATCH 056/105] Tidy --- .../Utilities/AxisHelpers/DeadZoneHelper.cs | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 75691538..8ca9f409 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -35,12 +35,6 @@ private void PrecalculateValues() } else { - /* - // work out how much we have to deform the input scale by the output scale - _scaleFactor = 100.0 / (100 - 50);//_percentage); - _deadzoneCutoff = (long)(Math.Round((//_percentage - 50.0 / 100.0) * Constants.AxisMaxAbsValue)); - */ _deadzoneCutoff = (Constants.AxisMaxValue - (Constants.AxisMaxValue * (_percentage / 100.0))); _scaleFactor = Math.Round(Constants.AxisMaxValue / _deadzoneCutoff); } @@ -56,24 +50,10 @@ public long ApplyRangeDeadZone(long value) var sign = Math.Sign(value); var adjustedValue = (absValue - _deadzoneCutoff) * _scaleFactor; - var newValue = Math.Round(adjustedValue * (double)sign); - //var newValue = (long)Math.Round((adjustedValue * _scaleFactor)); + var newValue = (long) Math.Round(adjustedValue * sign); if (newValue == -32769) newValue = -32768; - Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); - return (long)newValue; - - - //var absValue = Math.Abs(value); - //if (absValue < _deadzoneCutoff) - //{ - // return 0; - //} - - //var sign = Math.Sign(value); - //var adjustedValue = (absValue - _deadzoneCutoff) * sign; - //var newValue = (long)Math.Round((adjustedValue * _scaleFactor)); //Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); - //return newValue; + return (long)newValue; } } } From 0e6aa2e6c75c492df38ce0eac56221b44dcca6cb Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 17:09:05 +0100 Subject: [PATCH 057/105] Apply rounding --- UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 8ca9f409..550f222b 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -43,7 +43,7 @@ private void PrecalculateValues() public long ApplyRangeDeadZone(long value) { var absValue = Math.Abs(value); - if (absValue < _deadzoneCutoff) + if (absValue < Math.Round(_deadzoneCutoff)) { return 0; } @@ -53,7 +53,7 @@ public long ApplyRangeDeadZone(long value) var newValue = (long) Math.Round(adjustedValue * sign); if (newValue == -32769) newValue = -32768; //Debug.WriteLine($"Pre-DZ: {value}, Post-DZ: {newValue}, Cutoff: {_deadzoneCutoff}"); - return (long)newValue; + return newValue; } } } From 2933f3677a90922371a075763d19772570041b99 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 17:41:20 +0100 Subject: [PATCH 058/105] Add SensitivityTest, fix sensitivity init --- .../AxisHelpers/SensitivityHelper.cs | 25 ++++++++----------- UCR.Tests/HelperTests/HelperTests.cs | 13 ++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs index 778999af..ba31637b 100644 --- a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs @@ -24,38 +24,33 @@ public int Percentage private int _percentage; - public bool IsLinear + public bool IsLinear { get; set; } + + public SensitivityHelper() { - get => _isLinear; - set - { - _isLinear = value; - PrecalculateValues(); - } + PrecalculateValues(); } - - private bool _isLinear; private void PrecalculateValues() { - _scaleFactor = _percentage / 100.0; - _axisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); + _scaleFactor = _percentage / 100d; + _axisRange = Constants.AxisMaxValue - Constants.AxisMinValue; _sens = _scaleFactor / 100d; } public long ApplyRangeSensitivity(long value) { //var sensitivityPercent = (sensitivity / 100.0); - if (_isLinear) return (long)(value * _scaleFactor); + if (IsLinear) return (long)Math.Round(value * _scaleFactor); //var sens = _scaleFactor / 100d; //double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); // Map value to -1 .. 1 - double val11 = (((value - Constants.AxisMinValue) / _axisRange) * 2) - 1; + double val11 = (((value - Constants.AxisMinValue) / _axisRange) * 2d) - 1d; // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) - double valout = (_sens * val11) + ((1 - _sens) * Math.Pow(val11, 3)); + double valout = (_sens * val11) + ((1d - _sens) * Math.Pow(val11, 3d)); // Map value back to AxisRange - value = (long)Math.Round(((valout + 1) / 2d) * _axisRange + (1d * Constants.AxisMinValue)); + value = (long)Math.Round(((valout + 1d) / 2d) * _axisRange + (1d * Constants.AxisMinValue)); return value; } diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/HelperTests/HelperTests.cs index 5fb06b05..7cb81608 100644 --- a/UCR.Tests/HelperTests/HelperTests.cs +++ b/UCR.Tests/HelperTests/HelperTests.cs @@ -35,5 +35,18 @@ public void DeadZoneHelperValuesTest() Assert.AreEqual(Constants.AxisMinValue, min); Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); } + + [Test] + public void SensitivityTest() + { + var helper = new SensitivityHelper(); + Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); + Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); + Assert.AreEqual(0, helper.ApplyRangeSensitivity(0)); + helper.Percentage = 50; + Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); + Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); + Assert.AreEqual(0, helper.ApplyRangeSensitivity(0)); + } } } From ecd627a8b5cb820656a31b9d4bb7e3295dbb5d15 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 21:00:14 +0100 Subject: [PATCH 059/105] Implement CircularDeadZone POC --- .../AxisHelpers/CircularDeadZoneHelper.cs | 0 UCR.Core/Utilities/Functions.cs | 24 +++++++++++++++++++ UCR.Tests/HelperTests/HelperTests.cs | 7 ++++++ 3 files changed, 31 insertions(+) create mode 100644 UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs diff --git a/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs new file mode 100644 index 00000000..e69de29b diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 2c859e1e..0326c9a0 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -21,6 +21,30 @@ public static long Invert(long value) return value * -1; } + public static long[] CircularDeadZone(long[] values, double deadZone) + { + var x = values[0]; + var y = values[1]; + const double max = (double)Constants.AxisMaxValue; + var deadzoneRadius = (deadZone / 100d) * max; + var inputRadius = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); + var inputAngle = Math.Atan2(x, y); + var scaleFactor = max / (max - deadzoneRadius); + if(inputRadius Date: Sun, 2 Sep 2018 21:10:27 +0100 Subject: [PATCH 060/105] Circular DZ to helper class with precalculated values --- UCR.Core/UCR.Core.csproj | 1 + .../AxisHelpers/CircularDeadZoneHelper.cs | 70 +++++++++++++++++++ UCR.Core/Utilities/Functions.cs | 24 ------- UCR.Tests/HelperTests/HelperTests.cs | 8 ++- 4 files changed, 77 insertions(+), 26 deletions(-) diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index d71d083e..c8f39a93 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -86,6 +86,7 @@ + diff --git a/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs index e69de29b..2ce165e0 100644 --- a/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/CircularDeadZoneHelper.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HidWizards.UCR.Core.Utilities.AxisHelpers +{ + public class CircularDeadZoneHelper + { + private double _scaleFactor; + private double _deadzoneRadius; + + public int Percentage + { + get => _percentage; + set + //TODO CHECK FOR NEG + { + _percentage = value; + PrecalculateValues(); + } + } + private int _percentage; + + public CircularDeadZoneHelper() + { + PrecalculateValues(); + } + + private void PrecalculateValues() + { + if (_percentage == 0) + { + _deadzoneRadius = 0; + _scaleFactor = 1; + } + else + { + const double max = Constants.AxisMaxValue; + _deadzoneRadius = (_percentage / 100d) * max; + _scaleFactor = max / (max - _deadzoneRadius); + } + } + + public long[] ApplyRangeDeadZone(long[] values) + { + var x = values[0]; + var y = values[1]; + + var inputRadius = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); + var inputAngle = Math.Atan2(x, y); + if (inputRadius < _deadzoneRadius) + { + return new long[] { 0, 0 }; + } + var adjustedRadius = inputRadius - _deadzoneRadius; + var outputRadius = adjustedRadius * _scaleFactor; + + var outX = (long)(outputRadius * Math.Sin(inputAngle)); + var outY = (long)(outputRadius * Math.Cos(inputAngle)); + if (outX == -32769) outX = -32768; + if (outY == -32769) outY = -32768; + + var output = new[] { outX, outY }; + return output; + + } + } +} diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 0326c9a0..2c859e1e 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -21,30 +21,6 @@ public static long Invert(long value) return value * -1; } - public static long[] CircularDeadZone(long[] values, double deadZone) - { - var x = values[0]; - var y = values[1]; - const double max = (double)Constants.AxisMaxValue; - var deadzoneRadius = (deadZone / 100d) * max; - var inputRadius = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); - var inputAngle = Math.Atan2(x, y); - var scaleFactor = max / (max - deadzoneRadius); - if(inputRadius Date: Sun, 2 Sep 2018 21:12:27 +0100 Subject: [PATCH 061/105] Add more tests --- UCR.Tests/HelperTests/HelperTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/HelperTests/HelperTests.cs index 84310929..422616e6 100644 --- a/UCR.Tests/HelperTests/HelperTests.cs +++ b/UCR.Tests/HelperTests/HelperTests.cs @@ -46,6 +46,9 @@ public void SensitivityTest() helper.Percentage = 50; Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); + helper.Percentage = 20; + Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); + Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); Assert.AreEqual(0, helper.ApplyRangeSensitivity(0)); } @@ -58,6 +61,9 @@ public void CircularDeadZoneTest() helper.Percentage = 50; Assert.AreEqual(new long[] {Constants.AxisMaxValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMaxValue, 0 })); Assert.AreEqual(new long[] {Constants.AxisMinValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMinValue, 0 })); + helper.Percentage = 20; + Assert.AreEqual(new long[] {Constants.AxisMaxValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMaxValue, 0 })); + Assert.AreEqual(new long[] {Constants.AxisMinValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMinValue, 0 })); } } } From 028a0e66d2b706d3ab67a0ac35351d226e290142 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 22:00:28 +0100 Subject: [PATCH 062/105] Fix absolute mode centering --- UCR.Plugins/Remapper/DeltaToAxis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/DeltaToAxis.cs b/UCR.Plugins/Remapper/DeltaToAxis.cs index c9b90f9f..7b9f8083 100644 --- a/UCR.Plugins/Remapper/DeltaToAxis.cs +++ b/UCR.Plugins/Remapper/DeltaToAxis.cs @@ -43,8 +43,8 @@ public DeltaToAxis() private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) { - SetAbsoluteTimerState(false); WriteOutput(0, 0); + SetAbsoluteTimerState(false); } public override void Update(params long[] values) From c3acf097057a870932431dc85bf3f7ba4842ae0f Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 22:00:45 +0100 Subject: [PATCH 063/105] Add AxesToAxes plugin --- UCR.Plugins/Remapper/AxesToAxes.cs | 102 +++++++++++++++++++++++++++++ UCR.Plugins/UCR.Plugins.csproj | 1 + 2 files changed, 103 insertions(+) create mode 100644 UCR.Plugins/Remapper/AxesToAxes.cs diff --git a/UCR.Plugins/Remapper/AxesToAxes.cs b/UCR.Plugins/Remapper/AxesToAxes.cs new file mode 100644 index 00000000..6e5be790 --- /dev/null +++ b/UCR.Plugins/Remapper/AxesToAxes.cs @@ -0,0 +1,102 @@ +using System; +using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; + +namespace HidWizards.UCR.Plugins.Remapper +{ + [Plugin("Axes to Axes")] + [PluginInput(DeviceBindingCategory.Range, "X Axis")] + [PluginInput(DeviceBindingCategory.Range, "Y Axis")] + [PluginOutput(DeviceBindingCategory.Range, "X Axis")] + [PluginOutput(DeviceBindingCategory.Range, "Y Axis")] + public class AxesToAxes : Plugin + { + private readonly CircularDeadZoneHelper _circularDeadZoneHelper = new CircularDeadZoneHelper(); + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + private readonly SensitivityHelper _sensitivityHelper = new SensitivityHelper(); + private double _linearSenstitivityScaleFactor; + + [PluginGui("Invert", ColumnOrder = 0)] + public bool Invert { get; set; } + + [PluginGui("Sensitivity", ColumnOrder = 1)] + public int Sensitivity { get; set; } + + [PluginGui("Linear", RowOrder = 0, ColumnOrder = 2)] + public bool Linear { get; set; } + + [PluginGui("Dead zone", RowOrder = 1, ColumnOrder = 0)] + public int DeadZone { get; set; } + + [PluginGui("Circular", RowOrder = 1, ColumnOrder = 2)] + public bool CircularDz { get; set; } + + + public AxesToAxes() + { + DeadZone = 0; + Sensitivity = 100; + PrecalculateValues(); + } + + private void PrecalculateValues() + { + _deadZoneHelper.Percentage = DeadZone; + _circularDeadZoneHelper.Percentage = DeadZone; + _sensitivityHelper.Percentage = Sensitivity; + _linearSenstitivityScaleFactor = ((double)Sensitivity / 100); + } + + public override void Update(params long[] values) + { + var outputValues = new long[] {values[0], values[1]}; + if (DeadZone != 0) + { + if (CircularDz) + { + outputValues = _circularDeadZoneHelper.ApplyRangeDeadZone(outputValues); + } + else + { + outputValues[0] = _deadZoneHelper.ApplyRangeDeadZone(outputValues[0]); + outputValues[1] = _deadZoneHelper.ApplyRangeDeadZone(outputValues[1]); + } + + } + if (Sensitivity != 100) + { + if (Linear) + { + outputValues[0] = (long)(outputValues[0] * _linearSenstitivityScaleFactor); + outputValues[1] = (long)(outputValues[1] * _linearSenstitivityScaleFactor); + } + else + { + outputValues[0] = _sensitivityHelper.ApplyRangeSensitivity(outputValues[0]); + outputValues[1] = _sensitivityHelper.ApplyRangeSensitivity(outputValues[1]); + } + } + + outputValues[0] = Functions.ClampAxisRange(outputValues[0]); + outputValues[1] = Functions.ClampAxisRange(outputValues[1]); + + WriteOutput(0, outputValues[0]); + WriteOutput(1, outputValues[1]); + } + + public override void OnActivate() + { + base.OnActivate(); + PrecalculateValues(); + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + PrecalculateValues(); + } + } +} diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 54fd730d..31e1c208 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -48,6 +48,7 @@ + From 235f68be30ae648db7dfa4ba52ed4468386d7e10 Mon Sep 17 00:00:00 2001 From: evilC Date: Sun, 2 Sep 2018 22:32:00 +0100 Subject: [PATCH 064/105] Move sensitivity calc --- UCR.Plugins/Remapper/AxisToDelta.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index c92de71f..48c3e733 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -63,6 +63,7 @@ public override void Update(params long[] values) var value = values[0]; if (value != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); if (Invert) value = Functions.Invert(value); + if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); if (value == 0) { @@ -73,7 +74,6 @@ public override void Update(params long[] values) { var sign = Math.Sign(value); - if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); value = Functions.ClampAxisRange(value); _currentDelta = (long)(Min + (Math.Abs(value) * _scaleFactor)) * sign; //Debug.WriteLine($"New Delta: {_currentDelta}"); From ed05b831408511b8cf7730695e1e8fed48351048 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 10:15:08 +0100 Subject: [PATCH 065/105] Remove AxisMaxAbsValue --- UCR.Core/Utilities/Constants.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/UCR.Core/Utilities/Constants.cs b/UCR.Core/Utilities/Constants.cs index a13048d6..7805f340 100644 --- a/UCR.Core/Utilities/Constants.cs +++ b/UCR.Core/Utilities/Constants.cs @@ -3,13 +3,6 @@ public static class Constants { public const int MaxDevices = 16; - /// - /// When doing calculations using the size of the range from the mid-point to the extreme, - /// use NOT - /// Signed numbers are larger on the negative side, so perform calculations using the size of the negative scale, - /// and then clamp the value - /// - public const int AxisMaxAbsValue = short.MinValue * -1; // For short, this should be 32768 public const int AxisMaxValue = short.MaxValue; public const int AxisMinValue = short.MinValue; } From cb2cefc3bf79d52d417d763e2d9a4ada21cfda4c Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 12:44:42 +0100 Subject: [PATCH 066/105] Deprecate old methods --- UCR.Core/Utilities/Functions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 2c859e1e..374db254 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -28,6 +28,7 @@ public static long ClampAxisRange(long value) return value >= Constants.AxisMaxValue ? Constants.AxisMaxValue : value; } + [Obsolete("Deprecated, use DeadZoneHelper instead.")] public static long ApplyRangeDeadZone(long value, int deadZonePercentage) { var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; @@ -36,6 +37,7 @@ public static long ApplyRangeDeadZone(long value, int deadZonePercentage) return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); } + [Obsolete("Deprecated, use SensitivityHelper instead.")] public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) { var sensitivityPercent = (sensitivity / 100.0); @@ -53,6 +55,7 @@ public static long ApplyRangeSensitivity(long value, int sensitivity, bool linea return value; } + //ToDo: Does not properly invert, may fail with -32768 public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) { long value; From 6b953ede7f1e45f96a98e2e7606b4b1fecca4c93 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 13:55:23 +0100 Subject: [PATCH 067/105] Deprecate HalfAxisToFullRange, add SplitAxis and Unit Tests --- UCR.Core/Utilities/Functions.cs | 26 ++++++++++++++++++++++++++ UCR.Tests/HelperTests/FunctionTests.cs | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 374db254..1c49c80a 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -28,6 +28,31 @@ public static long ClampAxisRange(long value) return value >= Constants.AxisMaxValue ? Constants.AxisMaxValue : value; } + public static long SplitAxis(long axis, bool positiveRange) + { + long value; + if (positiveRange) + { + if (axis < 0) return 0; + value = axis; + if (value == Constants.AxisMaxValue) value++; + //value = axis > 0L ? axis : 0L; + } + else + { + if (axis > 0) return 0; + value = axis * -1; + //value = axis < 0 ? axis * -1 : 0L; + } + + value *= 2; + value += Constants.AxisMinValue; + + if (value == 32768) value = 32767; + + return value; + } + [Obsolete("Deprecated, use DeadZoneHelper instead.")] public static long ApplyRangeDeadZone(long value, int deadZonePercentage) { @@ -56,6 +81,7 @@ public static long ApplyRangeSensitivity(long value, int sensitivity, bool linea } //ToDo: Does not properly invert, may fail with -32768 + [Obsolete("Deprecated, use SplitAxis instead.")] public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) { long value; diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index 01e4de8a..f9f97b30 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -32,5 +32,14 @@ public long ClampTests(long inputValue) { return Functions.ClampAxisRange(inputValue); } + + [TestCase(Constants.AxisMaxValue, true, ExpectedResult = Constants.AxisMaxValue, TestName = "Split High - Max maps to Max")] + [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "Split High - 0 maps to Min")] + [TestCase(Constants.AxisMinValue, false, ExpectedResult = Constants.AxisMaxValue, TestName = "Split Low - Min maps to Max")] + [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "Split Low - 0 maps to Min")] + public long SplitTests(long value, bool positiveRange) + { + return Functions.SplitAxis(value, positiveRange); + } } } From 516d10621d8f1a31b0232e311d44c44917c21034 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 14:00:25 +0100 Subject: [PATCH 068/105] Fix test naming --- UCR.Tests/HelperTests/FunctionTests.cs | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index f9f97b30..2d3485bd 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -11,32 +11,32 @@ namespace HidWizards.UCR.Tests.HelperTests [TestFixture] public class FunctionTests { - [TestCase(0, ExpectedResult = 0, TestName = "Invert 0 Should be 0")] - [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMinValue, TestName = "Invert Max should be Min")] - [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMaxValue, TestName = "Invert of Min should be Max")] - [TestCase(1, ExpectedResult = -1, TestName = "Invert of 1 should be -1")] - [TestCase(-1, ExpectedResult = 1, TestName = "Invert of -1 should be 1")] + [TestCase(0, ExpectedResult = 0, TestName = "Invert: 0 returns 0")] + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMinValue, TestName = "Invert: Max returns Min")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMaxValue, TestName = "Invert: Min returns Max")] + [TestCase(1, ExpectedResult = -1, TestName = "Invert: 1 returns -1")] + [TestCase(-1, ExpectedResult = 1, TestName = "Invert: -1 returns 1")] public long InvertTests(long inputValue) { return Functions.Invert(inputValue); } - [TestCase(Constants.AxisMinValue - 1, ExpectedResult = Constants.AxisMinValue, TestName = "Greater than Max Clamp should return Max")] - [TestCase(Constants.AxisMaxValue + 1, ExpectedResult = Constants.AxisMaxValue, TestName = "Less than Min Clamp should return Min")] - [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "Min Clamp should return Min")] - [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "Max Clamp should return Max")] - [TestCase(0, ExpectedResult = 0, TestName = "Clamping 0 should return 0")] - [TestCase(1, ExpectedResult = 1, TestName = "Clamping 1 should return 1")] - [TestCase(-1, ExpectedResult = -1, TestName = "Clamping -1 should return -1")] + [TestCase(Constants.AxisMinValue - 1, ExpectedResult = Constants.AxisMinValue, TestName = "ClampAxisRange: Greater than Max returns Max")] + [TestCase(Constants.AxisMaxValue + 1, ExpectedResult = Constants.AxisMaxValue, TestName = "ClampAxisRange: Less than Min returns Min")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "ClampAxisRange: Min returns Min")] + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "ClampAxisRange: Max returns Max")] + [TestCase(0, ExpectedResult = 0, TestName = "ClampAxisRange: 0 returns 0")] + [TestCase(1, ExpectedResult = 1, TestName = "ClampAxisRange: 1 returns 1")] + [TestCase(-1, ExpectedResult = -1, TestName = "ClampAxisRange: -1 returns -1")] public long ClampTests(long inputValue) { return Functions.ClampAxisRange(inputValue); } - [TestCase(Constants.AxisMaxValue, true, ExpectedResult = Constants.AxisMaxValue, TestName = "Split High - Max maps to Max")] - [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "Split High - 0 maps to Min")] - [TestCase(Constants.AxisMinValue, false, ExpectedResult = Constants.AxisMaxValue, TestName = "Split Low - Min maps to Max")] - [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "Split Low - 0 maps to Min")] + [TestCase(Constants.AxisMaxValue, true, ExpectedResult = Constants.AxisMaxValue, TestName = "SplitAxis (High): Max returns Max")] + [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (High): 0 returns Min")] + [TestCase(Constants.AxisMinValue, false, ExpectedResult = Constants.AxisMaxValue, TestName = "SplitAxis (Low): Min returns Max")] + [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (Low): 0 returns Min")] public long SplitTests(long value, bool positiveRange) { return Functions.SplitAxis(value, positiveRange); From 2617755d7520c7f693c3eb9bcc95a37573f0599d Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 14:01:27 +0100 Subject: [PATCH 069/105] Tidy --- UCR.Tests/HelperTests/FunctionTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/HelperTests/FunctionTests.cs index 2d3485bd..894b93b5 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/HelperTests/FunctionTests.cs @@ -37,9 +37,9 @@ public long ClampTests(long inputValue) [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (High): 0 returns Min")] [TestCase(Constants.AxisMinValue, false, ExpectedResult = Constants.AxisMaxValue, TestName = "SplitAxis (Low): Min returns Max")] [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (Low): 0 returns Min")] - public long SplitTests(long value, bool positiveRange) + public long SplitTests(long inputValue, bool positiveRange) { - return Functions.SplitAxis(value, positiveRange); + return Functions.SplitAxis(inputValue, positiveRange); } } } From e69ae4b515ce7f51feb04236c9ae6361ca515443 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 14:51:18 +0100 Subject: [PATCH 070/105] Organize code --- UCR.Plugins/Remapper/AxisToDelta.cs | 63 ++++++++++++++++------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 48c3e733..25310b59 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -45,19 +45,7 @@ public AxisToDelta() _absoluteModeTimer.Elapsed += AbsoluteModeTimerElapsed; } - public override void OnPropertyChanged() - { - base.OnPropertyChanged(); - PrecalculateValues(); - } - - private void PrecalculateValues() - { - _scaleFactor = (float)(Max - (Min - 1)) / 32769; - _deadZoneHelper.Percentage = DeadZone; - _sensitivityHelper.Percentage = Sensitivity; - } - + #region Input Processing public override void Update(params long[] values) { var value = values[0]; @@ -81,6 +69,36 @@ public override void Update(params long[] values) } } + public void SetAbsoluteTimerState(bool state) + { + if (state && !_absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Start(); + } + else if (!state && _absoluteModeTimer.Enabled) + { + _absoluteModeTimer.Stop(); + } + } + + private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) + { + WriteOutput(0, _currentDelta); + } + #endregion + + #region Settings configuration + + private void PrecalculateValues() + { + _scaleFactor = (float)(Max - (Min - 1)) / 32769; + _deadZoneHelper.Percentage = DeadZone; + _sensitivityHelper.Percentage = Sensitivity; + } + + #endregion + + #region Event Handling public override void OnActivate() { base.OnActivate(); @@ -97,22 +115,11 @@ public override void OnDeactivate() SetAbsoluteTimerState(false); } - public void SetAbsoluteTimerState(bool state) - { - if (state && !_absoluteModeTimer.Enabled) - { - _absoluteModeTimer.Start(); - } - else if (!state && _absoluteModeTimer.Enabled) - { - _absoluteModeTimer.Stop(); - } - } - - private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) + public override void OnPropertyChanged() { - WriteOutput(0, _currentDelta); + base.OnPropertyChanged(); + PrecalculateValues(); } - + #endregion } } From 6f82232f2acec8ce37a39c725e4bb2b986b4b41d Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 15:13:49 +0100 Subject: [PATCH 071/105] FunctionTests -> UtilityTests --- UCR.Tests/{HelperTests => UtilityTests}/FunctionTests.cs | 9 ++------- UCR.Tests/{HelperTests => UtilityTests}/HelperTests.cs | 0 2 files changed, 2 insertions(+), 7 deletions(-) rename UCR.Tests/{HelperTests => UtilityTests}/FunctionTests.cs (91%) rename UCR.Tests/{HelperTests => UtilityTests}/HelperTests.cs (100%) diff --git a/UCR.Tests/HelperTests/FunctionTests.cs b/UCR.Tests/UtilityTests/FunctionTests.cs similarity index 91% rename from UCR.Tests/HelperTests/FunctionTests.cs rename to UCR.Tests/UtilityTests/FunctionTests.cs index 894b93b5..cba0670b 100644 --- a/UCR.Tests/HelperTests/FunctionTests.cs +++ b/UCR.Tests/UtilityTests/FunctionTests.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities; using NUnit.Framework; -namespace HidWizards.UCR.Tests.HelperTests +namespace HidWizards.UCR.Tests.UtilityTests { [TestFixture] public class FunctionTests diff --git a/UCR.Tests/HelperTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs similarity index 100% rename from UCR.Tests/HelperTests/HelperTests.cs rename to UCR.Tests/UtilityTests/HelperTests.cs From f57eff41968bde47d7de25174228618bacff1439 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 15:16:39 +0100 Subject: [PATCH 072/105] Move namespace --- UCR.Tests/UCR.Tests.csproj | 4 ++-- UCR.Tests/UtilityTests/HelperTests.cs | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index 10144324..97749267 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -46,8 +46,8 @@ - - + + diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs index 422616e6..e478d3e0 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities; using HidWizards.UCR.Core.Utilities.AxisHelpers; using NUnit.Framework; -namespace HidWizards.UCR.Tests.HelperTests +namespace HidWizards.UCR.Tests.UtilityTests { [TestFixture] public class HelperTests @@ -15,7 +10,7 @@ public class HelperTests [Test] public void DeadZoneHelperInitTest() { - var helper = new DeadZoneHelper(); + var helper = new DeadZoneHelper {Percentage = 20}; // On initialize, the helper should work for DZ 0 without setting Percent Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeDeadZone(Constants.AxisMaxValue)); Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeDeadZone(Constants.AxisMinValue)); From a7aee848be486cb46a804db0a3ba8d41c3ae9974 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 15:52:10 +0100 Subject: [PATCH 073/105] Parameterize tests --- UCR.Tests/UtilityTests/HelperTests.cs | 86 ++++++++++++++------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs index e478d3e0..d8029d0b 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests.cs @@ -7,58 +7,64 @@ namespace HidWizards.UCR.Tests.UtilityTests [TestFixture] public class HelperTests { - [Test] - public void DeadZoneHelperInitTest() + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] + [TestCase(0, ExpectedResult = 0, TestName = "SensitivityHelper (Init): 0 returns 0")] + [TestCase(1, ExpectedResult = 1, TestName = "SensitivityHelper (Init): 1 returns 1")] + [TestCase(-1, ExpectedResult = -1, TestName = "SensitivityHelper (Init): -1 returns -1")] + public long DeadZoneHelperInitTests(long inputValue) { - var helper = new DeadZoneHelper {Percentage = 20}; - // On initialize, the helper should work for DZ 0 without setting Percent - Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeDeadZone(Constants.AxisMaxValue)); - Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeDeadZone(Constants.AxisMinValue)); - Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); - Assert.AreEqual(1, helper.ApplyRangeDeadZone(1)); - Assert.AreEqual(-1, helper.ApplyRangeDeadZone(-1)); + var helper = new DeadZoneHelper(); + return helper.ApplyRangeDeadZone(inputValue); } - [Test] - public void DeadZoneHelperValuesTest() + [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] + [TestCase(0, 50, ExpectedResult = 0, TestName = "SensitivityHelper (50): 0 returns 0")] + public long DeadZoneHelperValueTests(long inputValue, int percentage) { - var helper = new DeadZoneHelper {Percentage = 50}; - // At 50% DZ, we should still be able to reach extremes - var max = helper.ApplyRangeDeadZone(Constants.AxisMaxValue); - //Assert.AreEqual(Constants.AxisMaxValue, max); - var min = helper.ApplyRangeDeadZone(Constants.AxisMinValue); - Assert.AreEqual(Constants.AxisMinValue, min); - Assert.AreEqual(0, helper.ApplyRangeDeadZone(0)); + var helper = new DeadZoneHelper {Percentage = percentage}; + return helper.ApplyRangeDeadZone(inputValue); } - [Test] - public void SensitivityTest() + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] + [TestCase(0, ExpectedResult = 0, TestName = "SensitivityHelper (Init): 0 returns 0")] + public long SensitivityHelperInitTests(long inputValue) { var helper = new SensitivityHelper(); - Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); - Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); - Assert.AreEqual(0, helper.ApplyRangeSensitivity(0)); - helper.Percentage = 50; - Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); - Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); - helper.Percentage = 20; - Assert.AreEqual(Constants.AxisMinValue, helper.ApplyRangeSensitivity(Constants.AxisMinValue)); - Assert.AreEqual(Constants.AxisMaxValue, helper.ApplyRangeSensitivity(Constants.AxisMaxValue)); - Assert.AreEqual(0, helper.ApplyRangeSensitivity(0)); + return helper.ApplyRangeSensitivity(inputValue); } - [Test] - public void CircularDeadZoneTest() + [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] + [TestCase(Constants.AxisMaxValue, 20, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (20): Max returns Max")] + [TestCase(Constants.AxisMinValue, 20, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (20): Min returns Min")] + public long SensitivityHelperValueTests(long inputValue, int percentage) + { + var helper = new SensitivityHelper {Percentage = percentage}; + return helper.ApplyRangeSensitivity(inputValue); + } + + [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[]{Constants.AxisMaxValue, 0}, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[]{Constants.AxisMinValue, 0}, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] + [TestCase(0, 0, ExpectedResult = new long[]{0, 0}, TestName = "CircularDeadZoneHelper (Init): 0 returns 0")] + public long[] CircularDeadZoneInitTests(long x, long y) { var helper = new CircularDeadZoneHelper(); - Assert.AreEqual(new long[] { Constants.AxisMaxValue, 0 }, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMaxValue, 0 })); - Assert.AreEqual(new long[] { Constants.AxisMinValue, 0 }, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMinValue, 0 })); - helper.Percentage = 50; - Assert.AreEqual(new long[] {Constants.AxisMaxValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMaxValue, 0 })); - Assert.AreEqual(new long[] {Constants.AxisMinValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMinValue, 0 })); - helper.Percentage = 20; - Assert.AreEqual(new long[] {Constants.AxisMaxValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMaxValue, 0 })); - Assert.AreEqual(new long[] {Constants.AxisMinValue, 0}, helper.ApplyRangeDeadZone(new long[] { Constants.AxisMinValue, 0 })); + return helper.ApplyRangeDeadZone(new[] {x, y}); + } + + [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (50): Min returns Min")] + [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): 0 returns 0")] + [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (20): Max returns Max")] + [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (20): Min returns Min")] + [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (20): 0 returns 0")] + public long[] CircularDeadZoneValueTests(long x, long y, int percentage) + { + var helper = new CircularDeadZoneHelper {Percentage = percentage}; + return helper.ApplyRangeDeadZone(new[] {x, y}); } } } From c81987781e64ddab84ac4ea504515e84343c08d0 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 15:54:08 +0100 Subject: [PATCH 074/105] Fix test naming --- UCR.Tests/UtilityTests/HelperTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs index d8029d0b..7f498691 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests.cs @@ -7,20 +7,20 @@ namespace HidWizards.UCR.Tests.UtilityTests [TestFixture] public class HelperTests { - [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] - [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] - [TestCase(0, ExpectedResult = 0, TestName = "SensitivityHelper (Init): 0 returns 0")] - [TestCase(1, ExpectedResult = 1, TestName = "SensitivityHelper (Init): 1 returns 1")] - [TestCase(-1, ExpectedResult = -1, TestName = "SensitivityHelper (Init): -1 returns -1")] + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (Init): Min returns Min")] + [TestCase(0, ExpectedResult = 0, TestName = "DeadZoneHelper (Init): 0 returns 0")] + [TestCase(1, ExpectedResult = 1, TestName = "DeadZoneHelper (Init): 1 returns 1")] + [TestCase(-1, ExpectedResult = -1, TestName = "DeadZoneHelper (Init): -1 returns -1")] public long DeadZoneHelperInitTests(long inputValue) { var helper = new DeadZoneHelper(); return helper.ApplyRangeDeadZone(inputValue); } - [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (50): Max returns Max")] - [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] - [TestCase(0, 50, ExpectedResult = 0, TestName = "SensitivityHelper (50): 0 returns 0")] + [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")] + [TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")] public long DeadZoneHelperValueTests(long inputValue, int percentage) { var helper = new DeadZoneHelper {Percentage = percentage}; From 61a1e2f1eea7d7c9e514ef76ba6ad8088aed23d1 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:23:33 +0100 Subject: [PATCH 075/105] Add more tests --- UCR.Tests/UtilityTests/HelperTests.cs | 83 +++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs index 7f498691..3bfbd698 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests.cs @@ -21,6 +21,10 @@ public long DeadZoneHelperInitTests(long inputValue) [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")] [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")] [TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")] + [TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Positive values above 16383 are outside DZ")] + [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Negative values below 16383 are outside DZ")] + [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Positive values below 16384 are inside DZ")] + [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Negative values below 16384 are inside DZ")] public long DeadZoneHelperValueTests(long inputValue, int percentage) { var helper = new DeadZoneHelper {Percentage = percentage}; @@ -55,16 +59,83 @@ public long[] CircularDeadZoneInitTests(long x, long y) return helper.ApplyRangeDeadZone(new[] {x, y}); } - [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (50): Max returns Max")] - [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (50): Min returns Min")] - [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): 0 returns 0")] - [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (20): Max returns Max")] - [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (20): Min returns Min")] - [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (20): 0 returns 0")] + [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + TestName = "CircularDeadZoneHelper (50): Max X returns Max")] + + [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, + TestName = "CircularDeadZoneHelper (50): Min X returns Min")] + + [TestCase(0, Constants.AxisMaxValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + TestName = "CircularDeadZoneHelper (50): Max Y returns Max")] + + [TestCase(0, Constants.AxisMinValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, + TestName = "CircularDeadZoneHelper (50): Min Y returns Min")] + + [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): 0 returns 0")] + + [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + TestName = "CircularDeadZoneHelper (20): Max X returns Max")] + + [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, + TestName = "CircularDeadZoneHelper (20): Min X returns Min")] + + [TestCase(0, Constants.AxisMaxValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + TestName = "CircularDeadZoneHelper (20): Max Y returns Max")] + + [TestCase(0, Constants.AxisMinValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, + TestName = "CircularDeadZoneHelper (20): Min Y returns Min")] + + [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (20): 0 returns 0")] + + [TestCase(16384, 0, 50, ExpectedResult = new long[] { 1, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive X values above 16383 are outside DZ")] + + [TestCase(-16384, 0, 50, ExpectedResult = new long[] { -1, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative X values below 16383 are outside DZ")] + + [TestCase(16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive X values below 16384 are inside DZ")] + + [TestCase(-16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative X values below 16384 are inside DZ")] + + [TestCase(0, 16384, 50, ExpectedResult = new long[] { 0, 1 }, + TestName = "CircularDeadZoneHelper (50): Positive Y values above 16383 are outside DZ")] + + [TestCase(0, -16384, 50, ExpectedResult = new long[] { 0 , -1 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16383 are outside DZ")] + + [TestCase(0, 16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive Y values below 16384 are inside DZ")] + + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] + + [TestCase(-16383, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] + public long[] CircularDeadZoneValueTests(long x, long y, int percentage) { var helper = new CircularDeadZoneHelper {Percentage = percentage}; return helper.ApplyRangeDeadZone(new[] {x, y}); } + + // These test check that the deadzone is somewhat circular... + // If passing +/- 16383 was INSIDE the DZ when passed for one axis... + // (As tested by other tests) + // ... but OUTSIDE the DZ when passed for both axes... + // ... then the DZ cannot be square. + [TestCase(-16383, -16383, 50, + TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Negative)")] + [TestCase(16383, 16383, 50, + TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Positive)")] + public void CircularDzOutsideTests(long x, long y, int percentage) + { + var helper = new CircularDeadZoneHelper { Percentage = percentage }; + var result = helper.ApplyRangeDeadZone(new long[] { -16383, -16383 }); + Assert.AreNotEqual(new long[] { 0, 0 }, result); + } } } From 2058aecad2c49787704847cc5a8803a4dc91f953 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:25:03 +0100 Subject: [PATCH 076/105] Fix test --- UCR.Tests/UtilityTests/HelperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests.cs index 3bfbd698..ac31b6b8 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests.cs @@ -113,7 +113,7 @@ public long[] CircularDeadZoneInitTests(long x, long y) [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] - [TestCase(-16383, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] public long[] CircularDeadZoneValueTests(long x, long y, int percentage) From be21ffeb973fc86681d57e33261ed868b8822d7e Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:30:20 +0100 Subject: [PATCH 077/105] Reorg tests --- UCR.Tests/UCR.Tests.csproj | 6 +- .../{ => FunctionTests}/FunctionTests.cs | 2 +- .../CircularDeadzonHelperTests.cs} | 92 ++++++------------- .../HelperTests/DeadZoneHelperTests.cs | 39 ++++++++ .../SensitivityHelperHelperTests.cs | 29 ++++++ 5 files changed, 100 insertions(+), 68 deletions(-) rename UCR.Tests/UtilityTests/{ => FunctionTests}/FunctionTests.cs (97%) rename UCR.Tests/UtilityTests/{HelperTests.cs => HelperTests/CircularDeadzonHelperTests.cs} (50%) create mode 100644 UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs create mode 100644 UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index 97749267..e6ba0a2e 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -46,8 +46,10 @@ - - + + + + diff --git a/UCR.Tests/UtilityTests/FunctionTests.cs b/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs similarity index 97% rename from UCR.Tests/UtilityTests/FunctionTests.cs rename to UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs index cba0670b..948218c5 100644 --- a/UCR.Tests/UtilityTests/FunctionTests.cs +++ b/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs @@ -1,7 +1,7 @@ using HidWizards.UCR.Core.Utilities; using NUnit.Framework; -namespace HidWizards.UCR.Tests.UtilityTests +namespace HidWizards.UCR.Tests.UtilityTests.FunctionTests { [TestFixture] public class FunctionTests diff --git a/UCR.Tests/UtilityTests/HelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs similarity index 50% rename from UCR.Tests/UtilityTests/HelperTests.cs rename to UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs index ac31b6b8..186fd7e0 100644 --- a/UCR.Tests/UtilityTests/HelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs @@ -1,95 +1,57 @@ -using HidWizards.UCR.Core.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core.Utilities; using HidWizards.UCR.Core.Utilities.AxisHelpers; using NUnit.Framework; -namespace HidWizards.UCR.Tests.UtilityTests +namespace HidWizards.UCR.Tests.UtilityTests.HelperTests { [TestFixture] - public class HelperTests + public class CircularDeadzonHelperTests { - [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (Init): Max returns Max")] - [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (Init): Min returns Min")] - [TestCase(0, ExpectedResult = 0, TestName = "DeadZoneHelper (Init): 0 returns 0")] - [TestCase(1, ExpectedResult = 1, TestName = "DeadZoneHelper (Init): 1 returns 1")] - [TestCase(-1, ExpectedResult = -1, TestName = "DeadZoneHelper (Init): -1 returns -1")] - public long DeadZoneHelperInitTests(long inputValue) - { - var helper = new DeadZoneHelper(); - return helper.ApplyRangeDeadZone(inputValue); - } - - [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")] - [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")] - [TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")] - [TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Positive values above 16383 are outside DZ")] - [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Negative values below 16383 are outside DZ")] - [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Positive values below 16384 are inside DZ")] - [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Negative values below 16384 are inside DZ")] - public long DeadZoneHelperValueTests(long inputValue, int percentage) - { - var helper = new DeadZoneHelper {Percentage = percentage}; - return helper.ApplyRangeDeadZone(inputValue); - } - - [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] - [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] - [TestCase(0, ExpectedResult = 0, TestName = "SensitivityHelper (Init): 0 returns 0")] - public long SensitivityHelperInitTests(long inputValue) - { - var helper = new SensitivityHelper(); - return helper.ApplyRangeSensitivity(inputValue); - } - - [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (50): Max returns Max")] - [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] - [TestCase(Constants.AxisMaxValue, 20, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (20): Max returns Max")] - [TestCase(Constants.AxisMinValue, 20, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (20): Min returns Min")] - public long SensitivityHelperValueTests(long inputValue, int percentage) - { - var helper = new SensitivityHelper {Percentage = percentage}; - return helper.ApplyRangeSensitivity(inputValue); - } - - [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[]{Constants.AxisMaxValue, 0}, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] - [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[]{Constants.AxisMinValue, 0}, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] - [TestCase(0, 0, ExpectedResult = new long[]{0, 0}, TestName = "CircularDeadZoneHelper (Init): 0 returns 0")] + [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] + [TestCase(0, 0, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (Init): 0 returns 0")] public long[] CircularDeadZoneInitTests(long x, long y) { var helper = new CircularDeadZoneHelper(); - return helper.ApplyRangeDeadZone(new[] {x, y}); + return helper.ApplyRangeDeadZone(new[] { x, y }); } - [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (50): Max X returns Max")] [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (50): Min X returns Min")] - [TestCase(0, Constants.AxisMaxValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + [TestCase(0, Constants.AxisMaxValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, TestName = "CircularDeadZoneHelper (50): Max Y returns Max")] [TestCase(0, Constants.AxisMinValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, TestName = "CircularDeadZoneHelper (50): Min Y returns Min")] - [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, + [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): 0 returns 0")] - [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (20): Max X returns Max")] - [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, + [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (20): Min X returns Min")] - [TestCase(0, Constants.AxisMaxValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + [TestCase(0, Constants.AxisMaxValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, TestName = "CircularDeadZoneHelper (20): Max Y returns Max")] - [TestCase(0, Constants.AxisMinValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, + [TestCase(0, Constants.AxisMinValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, TestName = "CircularDeadZoneHelper (20): Min Y returns Min")] [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (20): 0 returns 0")] - [TestCase(16384, 0, 50, ExpectedResult = new long[] { 1, 0 }, + [TestCase(16384, 0, 50, ExpectedResult = new long[] { 1, 0 }, TestName = "CircularDeadZoneHelper (50): Positive X values above 16383 are outside DZ")] [TestCase(-16384, 0, 50, ExpectedResult = new long[] { -1, 0 }, @@ -98,28 +60,28 @@ public long[] CircularDeadZoneInitTests(long x, long y) [TestCase(16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Positive X values below 16384 are inside DZ")] - [TestCase(-16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, + [TestCase(-16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Negative X values below 16384 are inside DZ")] - [TestCase(0, 16384, 50, ExpectedResult = new long[] { 0, 1 }, + [TestCase(0, 16384, 50, ExpectedResult = new long[] { 0, 1 }, TestName = "CircularDeadZoneHelper (50): Positive Y values above 16383 are outside DZ")] - [TestCase(0, -16384, 50, ExpectedResult = new long[] { 0 , -1 }, + [TestCase(0, -16384, 50, ExpectedResult = new long[] { 0, -1 }, TestName = "CircularDeadZoneHelper (50): Negative Y values below 16383 are outside DZ")] [TestCase(0, 16383, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Positive Y values below 16384 are inside DZ")] - [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] - [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] public long[] CircularDeadZoneValueTests(long x, long y, int percentage) { - var helper = new CircularDeadZoneHelper {Percentage = percentage}; - return helper.ApplyRangeDeadZone(new[] {x, y}); + var helper = new CircularDeadZoneHelper { Percentage = percentage }; + return helper.ApplyRangeDeadZone(new[] { x, y }); } // These test check that the deadzone is somewhat circular... diff --git a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs new file mode 100644 index 00000000..a5417949 --- /dev/null +++ b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.UtilityTests.HelperTests +{ + [TestFixture] + public class DeadZoneHelperTests + { + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (Init): Min returns Min")] + [TestCase(0, ExpectedResult = 0, TestName = "DeadZoneHelper (Init): 0 returns 0")] + [TestCase(1, ExpectedResult = 1, TestName = "DeadZoneHelper (Init): 1 returns 1")] + [TestCase(-1, ExpectedResult = -1, TestName = "DeadZoneHelper (Init): -1 returns -1")] + public long DeadZoneHelperInitTests(long inputValue) + { + var helper = new DeadZoneHelper(); + return helper.ApplyRangeDeadZone(inputValue); + } + + [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")] + [TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")] + [TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Positive values above 16383 are outside DZ")] + [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Negative values below 16383 are outside DZ")] + [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Positive values below 16384 are inside DZ")] + [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Negative values below 16384 are inside DZ")] + public long DeadZoneHelperValueTests(long inputValue, int percentage) + { + var helper = new DeadZoneHelper { Percentage = percentage }; + return helper.ApplyRangeDeadZone(inputValue); + } + } +} diff --git a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs new file mode 100644 index 00000000..e443c449 --- /dev/null +++ b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs @@ -0,0 +1,29 @@ +using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.UtilityTests.HelperTests +{ + [TestFixture] + public class SensitivityHelperHelperTests + { + [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] + [TestCase(0, ExpectedResult = 0, TestName = "SensitivityHelper (Init): 0 returns 0")] + public long SensitivityHelperInitTests(long inputValue) + { + var helper = new SensitivityHelper(); + return helper.ApplyRangeSensitivity(inputValue); + } + + [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (50): Max returns Max")] + [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] + [TestCase(Constants.AxisMaxValue, 20, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (20): Max returns Max")] + [TestCase(Constants.AxisMinValue, 20, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (20): Min returns Min")] + public long SensitivityHelperValueTests(long inputValue, int percentage) + { + var helper = new SensitivityHelper {Percentage = percentage}; + return helper.ApplyRangeSensitivity(inputValue); + } + } +} From 281cf754c319cbd45e394975249a27af5bb0a1da Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:43:53 +0100 Subject: [PATCH 078/105] PrecalculateValues -> Initialize --- UCR.Plugins/Remapper/AxesToAxes.cs | 8 ++++---- UCR.Plugins/Remapper/AxisToDelta.cs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/UCR.Plugins/Remapper/AxesToAxes.cs b/UCR.Plugins/Remapper/AxesToAxes.cs index 6e5be790..3da93422 100644 --- a/UCR.Plugins/Remapper/AxesToAxes.cs +++ b/UCR.Plugins/Remapper/AxesToAxes.cs @@ -39,10 +39,10 @@ public AxesToAxes() { DeadZone = 0; Sensitivity = 100; - PrecalculateValues(); + Initialize(); } - private void PrecalculateValues() + private void Initialize() { _deadZoneHelper.Percentage = DeadZone; _circularDeadZoneHelper.Percentage = DeadZone; @@ -90,13 +90,13 @@ public override void Update(params long[] values) public override void OnActivate() { base.OnActivate(); - PrecalculateValues(); + Initialize(); } public override void OnPropertyChanged() { base.OnPropertyChanged(); - PrecalculateValues(); + Initialize(); } } } diff --git a/UCR.Plugins/Remapper/AxisToDelta.cs b/UCR.Plugins/Remapper/AxisToDelta.cs index 25310b59..8c8481ba 100644 --- a/UCR.Plugins/Remapper/AxisToDelta.cs +++ b/UCR.Plugins/Remapper/AxisToDelta.cs @@ -89,7 +89,7 @@ private void AbsoluteModeTimerElapsed(object sender, ElapsedEventArgs e) #region Settings configuration - private void PrecalculateValues() + private void Initialize() { _scaleFactor = (float)(Max - (Min - 1)) / 32769; _deadZoneHelper.Percentage = DeadZone; @@ -102,7 +102,7 @@ private void PrecalculateValues() public override void OnActivate() { base.OnActivate(); - PrecalculateValues(); + Initialize(); if (_currentDelta != 0) { SetAbsoluteTimerState(true); @@ -118,7 +118,7 @@ public override void OnDeactivate() public override void OnPropertyChanged() { base.OnPropertyChanged(); - PrecalculateValues(); + Initialize(); } #endregion } From d2fd0ca4a631c0e698ff9818417260feec5af0fc Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:45:10 +0100 Subject: [PATCH 079/105] Do not call init in Ctor --- UCR.Plugins/Remapper/AxesToAxes.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxesToAxes.cs b/UCR.Plugins/Remapper/AxesToAxes.cs index 3da93422..24138e2c 100644 --- a/UCR.Plugins/Remapper/AxesToAxes.cs +++ b/UCR.Plugins/Remapper/AxesToAxes.cs @@ -39,7 +39,6 @@ public AxesToAxes() { DeadZone = 0; Sensitivity = 100; - Initialize(); } private void Initialize() From 1f0470016883442f82ac39901fd0600868aa682a Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:45:22 +0100 Subject: [PATCH 080/105] Convert AxisMerger --- UCR.Plugins/Remapper/AxisMerger.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisMerger.cs b/UCR.Plugins/Remapper/AxisMerger.cs index b9612aca..09905d9e 100644 --- a/UCR.Plugins/Remapper/AxisMerger.cs +++ b/UCR.Plugins/Remapper/AxisMerger.cs @@ -3,6 +3,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -24,6 +25,8 @@ public class AxisMerger : Plugin [PluginGui("Invert low", RowOrder = 2)] public bool InvertLow { get; set; } + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + public AxisMerger() { DeadZone = 0; @@ -56,16 +59,36 @@ public override void Update(params long[] values) if (DeadZone != 0) { - valueOutput = Functions.ApplyRangeDeadZone(valueOutput, DeadZone); + valueOutput = _deadZoneHelper.ApplyRangeDeadZone(valueOutput); } WriteOutput(0, valueOutput); } + private void Initialize() + { + _deadZoneHelper.Percentage = DeadZone; + } + + public enum AxisMergerMode { Average, Greatest, Sum } + + #region Event Handling + public override void OnActivate() + { + base.OnActivate(); + _deadZoneHelper.Percentage = DeadZone; + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + Initialize(); + } + #endregion } } From ed29f67f4ab2e4063d96cba4e12ba3d7d4f4fc43 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:49:48 +0100 Subject: [PATCH 081/105] Convert AxisSplitter --- UCR.Plugins/Remapper/AxisSplitter.cs | 33 +++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisSplitter.cs b/UCR.Plugins/Remapper/AxisSplitter.cs index a7888da7..580b94e5 100644 --- a/UCR.Plugins/Remapper/AxisSplitter.cs +++ b/UCR.Plugins/Remapper/AxisSplitter.cs @@ -2,6 +2,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -20,6 +21,8 @@ public class AxisSplitter : Plugin [PluginGui("Dead zone")] public int DeadZone { get; set; } + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + public AxisSplitter() { DeadZone = 0; @@ -29,9 +32,33 @@ public override void Update(params long[] values) { var value = values[0]; - if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - WriteOutput(0, Functions.HalfAxisToFullRange(value, true, InvertHigh)); - WriteOutput(1, Functions.HalfAxisToFullRange(value, false, InvertLow)); + if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); + + var high = Functions.SplitAxis(value, true); + var low = Functions.SplitAxis(value, false); + if (InvertHigh) high = Functions.Invert(high); + if (InvertHigh) low = Functions.Invert(low); + WriteOutput(0, high); + WriteOutput(1, low); + } + + private void Initialize() + { + _deadZoneHelper.Percentage = DeadZone; + } + + #region Event Handling + public override void OnActivate() + { + base.OnActivate(); + _deadZoneHelper.Percentage = DeadZone; + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + Initialize(); } + #endregion } } From bc0a72b982632226bf5e7aeb6d2e52eac8344236 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:57:22 +0100 Subject: [PATCH 082/105] Fix test naming --- .../UtilityTests/HelperTests/CircularDeadzonHelperTests.cs | 2 +- ...ensitivityHelperHelperTests.cs => SensitivityHelperTests.cs} | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) rename UCR.Tests/UtilityTests/HelperTests/{SensitivityHelperHelperTests.cs => SensitivityHelperTests.cs} (84%) diff --git a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs index 186fd7e0..e68a4155 100644 --- a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs @@ -10,7 +10,7 @@ namespace HidWizards.UCR.Tests.UtilityTests.HelperTests { [TestFixture] - public class CircularDeadzonHelperTests + public class CircularDeadzoneHelperTests { [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] diff --git a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs similarity index 84% rename from UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs rename to UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs index e443c449..56eb107c 100644 --- a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs @@ -20,6 +20,8 @@ public long SensitivityHelperInitTests(long inputValue) [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (50): Min returns Min")] [TestCase(Constants.AxisMaxValue, 20, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (20): Max returns Max")] [TestCase(Constants.AxisMinValue, 20, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (20): Min returns Min")] + [TestCase(Constants.AxisMaxValue, 200, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (200): Min returns Min")] + [TestCase(Constants.AxisMinValue, 200, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (200): Min returns Min")] public long SensitivityHelperValueTests(long inputValue, int percentage) { var helper = new SensitivityHelper {Percentage = percentage}; From c68234dbdf1ee3d0217c3a3e6e3edefd74835fa0 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:57:58 +0100 Subject: [PATCH 083/105] Remove DZ init --- UCR.Plugins/Remapper/AxisMerger.cs | 2 +- UCR.Plugins/Remapper/AxisSplitter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisMerger.cs b/UCR.Plugins/Remapper/AxisMerger.cs index 09905d9e..13f8acbc 100644 --- a/UCR.Plugins/Remapper/AxisMerger.cs +++ b/UCR.Plugins/Remapper/AxisMerger.cs @@ -81,7 +81,7 @@ public enum AxisMergerMode public override void OnActivate() { base.OnActivate(); - _deadZoneHelper.Percentage = DeadZone; + Initialize(); } public override void OnPropertyChanged() diff --git a/UCR.Plugins/Remapper/AxisSplitter.cs b/UCR.Plugins/Remapper/AxisSplitter.cs index 580b94e5..f47bf038 100644 --- a/UCR.Plugins/Remapper/AxisSplitter.cs +++ b/UCR.Plugins/Remapper/AxisSplitter.cs @@ -51,7 +51,7 @@ private void Initialize() public override void OnActivate() { base.OnActivate(); - _deadZoneHelper.Percentage = DeadZone; + Initialize(); } public override void OnPropertyChanged() From fc0c2956b991f144712d21f8fbad3654eacb5072 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:58:07 +0100 Subject: [PATCH 084/105] Add regions --- UCR.Plugins/Remapper/AxesToAxes.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UCR.Plugins/Remapper/AxesToAxes.cs b/UCR.Plugins/Remapper/AxesToAxes.cs index 24138e2c..869d27a5 100644 --- a/UCR.Plugins/Remapper/AxesToAxes.cs +++ b/UCR.Plugins/Remapper/AxesToAxes.cs @@ -86,6 +86,7 @@ public override void Update(params long[] values) WriteOutput(1, outputValues[1]); } + #region Event Handling public override void OnActivate() { base.OnActivate(); @@ -97,5 +98,6 @@ public override void OnPropertyChanged() base.OnPropertyChanged(); Initialize(); } + #endregion } } From f70668b70a003bac810de16e74f25549e0de00fb Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 16:58:29 +0100 Subject: [PATCH 085/105] Convert AxisToAxis --- UCR.Plugins/Remapper/AxisToAxis.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToAxis.cs b/UCR.Plugins/Remapper/AxisToAxis.cs index 6602c320..3c1c0749 100644 --- a/UCR.Plugins/Remapper/AxisToAxis.cs +++ b/UCR.Plugins/Remapper/AxisToAxis.cs @@ -3,6 +3,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -23,6 +24,9 @@ public class AxisToAxis : Plugin [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + private readonly SensitivityHelper _sensitivityHelper = new SensitivityHelper(); + public AxisToAxis() { DeadZone = 0; @@ -33,10 +37,30 @@ public override void Update(params long[] values) { var value = values[0]; if (Invert) value *= -1; - if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); + if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); WriteOutput(0, value); } + + private void Initialize() + { + _deadZoneHelper.Percentage = DeadZone; + _sensitivityHelper.Percentage = Sensitivity; + _sensitivityHelper.IsLinear = Linear; + } + + #region Event Handling + public override void OnActivate() + { + base.OnActivate(); + Initialize(); + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + Initialize(); + } + #endregion } } From ef40497b114a7a57929cf1021734648a98b098cb Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:05:32 +0100 Subject: [PATCH 086/105] Fix Sensitivity Linear tests --- .../Utilities/AxisHelpers/SensitivityHelper.cs | 2 +- UCR.Tests/UCR.Tests.csproj | 2 +- .../HelperTests/SensitivityHelperTests.cs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs index ba31637b..ca7e336c 100644 --- a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs @@ -41,7 +41,7 @@ private void PrecalculateValues() public long ApplyRangeSensitivity(long value) { //var sensitivityPercent = (sensitivity / 100.0); - if (IsLinear) return (long)Math.Round(value * _scaleFactor); + if (IsLinear) return Functions.ClampAxisRange((long)Math.Round(value * _scaleFactor)); //var sens = _scaleFactor / 100d; //double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index e6ba0a2e..ee80bf9f 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -49,7 +49,7 @@ - + diff --git a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs index 56eb107c..e71a8fd5 100644 --- a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs @@ -5,7 +5,7 @@ namespace HidWizards.UCR.Tests.UtilityTests.HelperTests { [TestFixture] - public class SensitivityHelperHelperTests + public class SensitivityHelperTests { [TestCase(Constants.AxisMaxValue, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (Init): Max returns Max")] [TestCase(Constants.AxisMinValue, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (Init): Min returns Min")] @@ -27,5 +27,18 @@ public long SensitivityHelperValueTests(long inputValue, int percentage) var helper = new SensitivityHelper {Percentage = percentage}; return helper.ApplyRangeSensitivity(inputValue); } + + [TestCase(Constants.AxisMaxValue, 100, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (100, Linear): Max returns Max")] + [TestCase(Constants.AxisMinValue, 100, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (100, Linear): Min returns Min")] + [TestCase(Constants.AxisMaxValue, 100, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (100, Linear): Max returns Max")] + [TestCase(Constants.AxisMinValue, 100, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (100, Linear): Min returns Min")] + [TestCase(Constants.AxisMaxValue, 200, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (200, Linear): Min returns Min")] + [TestCase(Constants.AxisMinValue, 200, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (200, Linear): Min returns Min")] + public long SensitivityHelperValueLinearTests(long inputValue, int percentage) + { + var helper = new SensitivityHelper { Percentage = percentage, IsLinear = true}; + return helper.ApplyRangeSensitivity(inputValue); + } + } } From 604a65b54fd4cd82f2172e8148e68e15914481d0 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:08:37 +0100 Subject: [PATCH 087/105] Convert AxisToAxisRelative --- UCR.Plugins/Remapper/AxisToAxisRelative.cs | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToAxisRelative.cs b/UCR.Plugins/Remapper/AxisToAxisRelative.cs index db5237f7..7022b225 100644 --- a/UCR.Plugins/Remapper/AxisToAxisRelative.cs +++ b/UCR.Plugins/Remapper/AxisToAxisRelative.cs @@ -5,6 +5,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -34,6 +35,8 @@ public class AxisToAxisRelative : Plugin [PluginGui("Relative Sensitivity", ColumnOrder = 2, RowOrder = 2)] public decimal RelativeSensitivity { get; set; } + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + private readonly SensitivityHelper _sensitivityHelper = new SensitivityHelper(); private long _currentOutputValue; private long _currentInputValue; @@ -55,8 +58,8 @@ public override void Update(params long[] values) var value = values[0]; if (Invert) value *= -1; - if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); - if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); + if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); + if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); // Respect the axis min and max ranges. value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); @@ -72,10 +75,31 @@ public override void Update(params long[] values) } } + private void Initialize() + { + _deadZoneHelper.Percentage = DeadZone; + _sensitivityHelper.Percentage = Sensitivity; + _sensitivityHelper.IsLinear = Linear; + } + + #region Event Handling + public override void OnActivate() + { + base.OnActivate(); + Initialize(); + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + Initialize(); + } + public override void OnDeactivate() { SetRelativeThreadState(false); } + #endregion private void SetRelativeThreadState(bool state) { From 0715e6c41a66aba231d2816131d05b10adfa0888 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:12:13 +0100 Subject: [PATCH 088/105] Convert AxisToButton --- UCR.Plugins/Remapper/AxisToButton.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/UCR.Plugins/Remapper/AxisToButton.cs b/UCR.Plugins/Remapper/AxisToButton.cs index 4cd28e65..df4c0972 100644 --- a/UCR.Plugins/Remapper/AxisToButton.cs +++ b/UCR.Plugins/Remapper/AxisToButton.cs @@ -3,6 +3,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; namespace HidWizards.UCR.Plugins.Remapper { @@ -18,6 +19,8 @@ public class AxisToButton : Plugin [PluginGui("Dead zone", ColumnOrder = 1)] public int DeadZone { get; set; } + private readonly DeadZoneHelper _deadZoneHelper = new DeadZoneHelper(); + public AxisToButton() { DeadZone = 30; @@ -26,8 +29,8 @@ public AxisToButton() public override void Update(params long[] values) { var value = values[0]; - if (Invert) value *= -1; - value = Math.Sign(Functions.ApplyRangeDeadZone(value,DeadZone)); + if (Invert) value = Functions.Invert(value); + value = Math.Sign(_deadZoneHelper.ApplyRangeDeadZone(value)); switch (value) { case 0: @@ -44,5 +47,25 @@ public override void Update(params long[] values) break; } } + + private void Initialize() + { + _deadZoneHelper.Percentage = DeadZone; + } + + #region Event Handling + public override void OnActivate() + { + base.OnActivate(); + Initialize(); + } + + public override void OnPropertyChanged() + { + base.OnPropertyChanged(); + Initialize(); + } + #endregion + } } From 47b1904888b8660a5221329cc3f7c5df8732ce0e Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:18:51 +0100 Subject: [PATCH 089/105] Convert ButtonToAxis --- UCR.Plugins/Remapper/ButtonToAxis.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/UCR.Plugins/Remapper/ButtonToAxis.cs b/UCR.Plugins/Remapper/ButtonToAxis.cs index 5d00e69c..b8075561 100644 --- a/UCR.Plugins/Remapper/ButtonToAxis.cs +++ b/UCR.Plugins/Remapper/ButtonToAxis.cs @@ -28,14 +28,17 @@ public ButtonToAxis() public override void Update(params long[] values) { var value = values[0]; - var inverse = value == 0 ^ Invert; + // ToDo: Review logic, move off into Utilities and unit test if (Absolute) { - WriteOutput(0, (long)((Constants.AxisMinValue + value * Constants.AxisMaxValue * 2 * (Range / 100.0))) * (Invert ? -1 : 1)); + value = (long)(Constants.AxisMinValue + value * Constants.AxisMaxValue * 2 * (Range / 100.0)); + if (Invert) value = Functions.Invert(value); + WriteOutput(0, value); } else { + var inverse = value == 0 ^ Invert; WriteOutput(0, value * (long)((inverse ? Constants.AxisMinValue : Constants.AxisMaxValue) * (Range / 100.0))); } } From 5b0b3d8020f0613f9cdba3ba428176d924ae9e12 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:23:16 +0100 Subject: [PATCH 090/105] Fix naming --- ...ularDeadzonHelperTests.cs => CircularDeadzoneHelperTests.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename UCR.Tests/UtilityTests/HelperTests/{CircularDeadzonHelperTests.cs => CircularDeadzoneHelperTests.cs} (99%) diff --git a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs similarity index 99% rename from UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs rename to UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs index e68a4155..9f0d3ba7 100644 --- a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzonHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs @@ -10,7 +10,7 @@ namespace HidWizards.UCR.Tests.UtilityTests.HelperTests { [TestFixture] - public class CircularDeadzoneHelperTests + public class CircularDeadZoneHelperTests { [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] From bf9c415518515e109de8a9ea52771666e568d09d Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 17:26:56 +0100 Subject: [PATCH 091/105] Fix test naming --- UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs index a5417949..0cbe9f07 100644 --- a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs @@ -26,10 +26,10 @@ public long DeadZoneHelperInitTests(long inputValue) [TestCase(Constants.AxisMaxValue, 50, ExpectedResult = Constants.AxisMaxValue, TestName = "DeadZoneHelper (50): Max returns Max")] [TestCase(Constants.AxisMinValue, 50, ExpectedResult = Constants.AxisMinValue, TestName = "DeadZoneHelper (50): Min returns Min")] [TestCase(0, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): 0 returns 0")] - [TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Positive values above 16383 are outside DZ")] - [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Negative values below 16383 are outside DZ")] - [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Positive values below 16384 are inside DZ")] - [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Negative values below 16384 are inside DZ")] + [TestCase(16384, 50, ExpectedResult = 1, TestName = "DeadZoneHelper (50): Half Positive deflection is outside DZ")] + [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Half Negative deflection is outside DZ")] + [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Positive deflection is inside DZ")] + [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Negative deflection is inside DZ")] public long DeadZoneHelperValueTests(long inputValue, int percentage) { var helper = new DeadZoneHelper { Percentage = percentage }; From 92889f9150814ff00f21a14560e1c46f5cb019a3 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 18:51:48 +0100 Subject: [PATCH 092/105] Remove test to rename --- .../CircularDeadzoneHelperTests.cs | 103 ------------------ 1 file changed, 103 deletions(-) delete mode 100644 UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs diff --git a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs deleted file mode 100644 index 9f0d3ba7..00000000 --- a/UCR.Tests/UtilityTests/HelperTests/CircularDeadzoneHelperTests.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HidWizards.UCR.Core.Utilities; -using HidWizards.UCR.Core.Utilities.AxisHelpers; -using NUnit.Framework; - -namespace HidWizards.UCR.Tests.UtilityTests.HelperTests -{ - [TestFixture] - public class CircularDeadZoneHelperTests - { - [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] - [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] - [TestCase(0, 0, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (Init): 0 returns 0")] - public long[] CircularDeadZoneInitTests(long x, long y) - { - var helper = new CircularDeadZoneHelper(); - return helper.ApplyRangeDeadZone(new[] { x, y }); - } - - [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, - TestName = "CircularDeadZoneHelper (50): Max X returns Max")] - - [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, - TestName = "CircularDeadZoneHelper (50): Min X returns Min")] - - [TestCase(0, Constants.AxisMaxValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, - TestName = "CircularDeadZoneHelper (50): Max Y returns Max")] - - [TestCase(0, Constants.AxisMinValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, - TestName = "CircularDeadZoneHelper (50): Min Y returns Min")] - - [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): 0 returns 0")] - - [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, - TestName = "CircularDeadZoneHelper (20): Max X returns Max")] - - [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, - TestName = "CircularDeadZoneHelper (20): Min X returns Min")] - - [TestCase(0, Constants.AxisMaxValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, - TestName = "CircularDeadZoneHelper (20): Max Y returns Max")] - - [TestCase(0, Constants.AxisMinValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, - TestName = "CircularDeadZoneHelper (20): Min Y returns Min")] - - [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (20): 0 returns 0")] - - [TestCase(16384, 0, 50, ExpectedResult = new long[] { 1, 0 }, - TestName = "CircularDeadZoneHelper (50): Positive X values above 16383 are outside DZ")] - - [TestCase(-16384, 0, 50, ExpectedResult = new long[] { -1, 0 }, - TestName = "CircularDeadZoneHelper (50): Negative X values below 16383 are outside DZ")] - - [TestCase(16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): Positive X values below 16384 are inside DZ")] - - [TestCase(-16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): Negative X values below 16384 are inside DZ")] - - [TestCase(0, 16384, 50, ExpectedResult = new long[] { 0, 1 }, - TestName = "CircularDeadZoneHelper (50): Positive Y values above 16383 are outside DZ")] - - [TestCase(0, -16384, 50, ExpectedResult = new long[] { 0, -1 }, - TestName = "CircularDeadZoneHelper (50): Negative Y values below 16383 are outside DZ")] - - [TestCase(0, 16383, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): Positive Y values below 16384 are inside DZ")] - - [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] - - [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, - TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] - - public long[] CircularDeadZoneValueTests(long x, long y, int percentage) - { - var helper = new CircularDeadZoneHelper { Percentage = percentage }; - return helper.ApplyRangeDeadZone(new[] { x, y }); - } - - // These test check that the deadzone is somewhat circular... - // If passing +/- 16383 was INSIDE the DZ when passed for one axis... - // (As tested by other tests) - // ... but OUTSIDE the DZ when passed for both axes... - // ... then the DZ cannot be square. - [TestCase(-16383, -16383, 50, - TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Negative)")] - [TestCase(16383, 16383, 50, - TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Positive)")] - public void CircularDzOutsideTests(long x, long y, int percentage) - { - var helper = new CircularDeadZoneHelper { Percentage = percentage }; - var result = helper.ApplyRangeDeadZone(new long[] { -16383, -16383 }); - Assert.AreNotEqual(new long[] { 0, 0 }, result); - } - } -} From 4a2a3bb6b165261a2fa84bca7cd1babdc9288cbc Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 18:52:28 +0100 Subject: [PATCH 093/105] Re-add test --- UCR.Tests/UCR.Tests.csproj | 2 +- .../CircularDeadZoneHelperTests.cs | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 UCR.Tests/UtilityTests/HelperTests/CircularDeadZoneHelperTests.cs diff --git a/UCR.Tests/UCR.Tests.csproj b/UCR.Tests/UCR.Tests.csproj index ee80bf9f..dacba099 100644 --- a/UCR.Tests/UCR.Tests.csproj +++ b/UCR.Tests/UCR.Tests.csproj @@ -46,7 +46,7 @@ - + diff --git a/UCR.Tests/UtilityTests/HelperTests/CircularDeadZoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/CircularDeadZoneHelperTests.cs new file mode 100644 index 00000000..9f0d3ba7 --- /dev/null +++ b/UCR.Tests/UtilityTests/HelperTests/CircularDeadZoneHelperTests.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HidWizards.UCR.Core.Utilities; +using HidWizards.UCR.Core.Utilities.AxisHelpers; +using NUnit.Framework; + +namespace HidWizards.UCR.Tests.UtilityTests.HelperTests +{ + [TestFixture] + public class CircularDeadZoneHelperTests + { + [TestCase(Constants.AxisMaxValue, 0, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Max returns Max")] + [TestCase(Constants.AxisMinValue, 0, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, TestName = "CircularDeadZoneHelper (Init): Min returns Min")] + [TestCase(0, 0, ExpectedResult = new long[] { 0, 0 }, TestName = "CircularDeadZoneHelper (Init): 0 returns 0")] + public long[] CircularDeadZoneInitTests(long x, long y) + { + var helper = new CircularDeadZoneHelper(); + return helper.ApplyRangeDeadZone(new[] { x, y }); + } + + [TestCase(Constants.AxisMaxValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + TestName = "CircularDeadZoneHelper (50): Max X returns Max")] + + [TestCase(Constants.AxisMinValue, 0, 50, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, + TestName = "CircularDeadZoneHelper (50): Min X returns Min")] + + [TestCase(0, Constants.AxisMaxValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + TestName = "CircularDeadZoneHelper (50): Max Y returns Max")] + + [TestCase(0, Constants.AxisMinValue, 50, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, + TestName = "CircularDeadZoneHelper (50): Min Y returns Min")] + + [TestCase(0, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): 0 returns 0")] + + [TestCase(Constants.AxisMaxValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMaxValue, 0 }, + TestName = "CircularDeadZoneHelper (20): Max X returns Max")] + + [TestCase(Constants.AxisMinValue, 0, 20, ExpectedResult = new long[] { Constants.AxisMinValue, 0 }, + TestName = "CircularDeadZoneHelper (20): Min X returns Min")] + + [TestCase(0, Constants.AxisMaxValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMaxValue }, + TestName = "CircularDeadZoneHelper (20): Max Y returns Max")] + + [TestCase(0, Constants.AxisMinValue, 20, ExpectedResult = new long[] { 0, Constants.AxisMinValue }, + TestName = "CircularDeadZoneHelper (20): Min Y returns Min")] + + [TestCase(0, 0, 20, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (20): 0 returns 0")] + + [TestCase(16384, 0, 50, ExpectedResult = new long[] { 1, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive X values above 16383 are outside DZ")] + + [TestCase(-16384, 0, 50, ExpectedResult = new long[] { -1, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative X values below 16383 are outside DZ")] + + [TestCase(16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive X values below 16384 are inside DZ")] + + [TestCase(-16383, 0, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative X values below 16384 are inside DZ")] + + [TestCase(0, 16384, 50, ExpectedResult = new long[] { 0, 1 }, + TestName = "CircularDeadZoneHelper (50): Positive Y values above 16383 are outside DZ")] + + [TestCase(0, -16384, 50, ExpectedResult = new long[] { 0, -1 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16383 are outside DZ")] + + [TestCase(0, 16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Positive Y values below 16384 are inside DZ")] + + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] + + [TestCase(0, -16383, 50, ExpectedResult = new long[] { 0, 0 }, + TestName = "CircularDeadZoneHelper (50): Negative Y values below 16384 are inside DZ")] + + public long[] CircularDeadZoneValueTests(long x, long y, int percentage) + { + var helper = new CircularDeadZoneHelper { Percentage = percentage }; + return helper.ApplyRangeDeadZone(new[] { x, y }); + } + + // These test check that the deadzone is somewhat circular... + // If passing +/- 16383 was INSIDE the DZ when passed for one axis... + // (As tested by other tests) + // ... but OUTSIDE the DZ when passed for both axes... + // ... then the DZ cannot be square. + [TestCase(-16383, -16383, 50, + TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Negative)")] + [TestCase(16383, 16383, 50, + TestName = "CircularDeadZoneHelper (50): Deadzone appears Circular (Positive)")] + public void CircularDzOutsideTests(long x, long y, int percentage) + { + var helper = new CircularDeadZoneHelper { Percentage = percentage }; + var result = helper.ApplyRangeDeadZone(new long[] { -16383, -16383 }); + Assert.AreNotEqual(new long[] { 0, 0 }, result); + } + } +} From 10426dfc348133ee10dfe2431c5c88e7cc53ba38 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 18:54:23 +0100 Subject: [PATCH 094/105] Remove deprecated functions --- UCR.Core/Utilities/Functions.cs | 48 --------------------------------- 1 file changed, 48 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 1c49c80a..aee9061a 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -36,13 +36,11 @@ public static long SplitAxis(long axis, bool positiveRange) if (axis < 0) return 0; value = axis; if (value == Constants.AxisMaxValue) value++; - //value = axis > 0L ? axis : 0L; } else { if (axis > 0) return 0; value = axis * -1; - //value = axis < 0 ? axis * -1 : 0L; } value *= 2; @@ -53,51 +51,5 @@ public static long SplitAxis(long axis, bool positiveRange) return value; } - [Obsolete("Deprecated, use DeadZoneHelper instead.")] - public static long ApplyRangeDeadZone(long value, int deadZonePercentage) - { - var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; - var remainder = Constants.AxisMaxValue - gap; - var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; - return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); - } - - [Obsolete("Deprecated, use SensitivityHelper instead.")] - public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) - { - var sensitivityPercent = (sensitivity / 100.0); - if (linear) return (long)(value * sensitivityPercent); - - var sens = sensitivityPercent / 100d; - double AxisRange = 1d * (Constants.AxisMaxValue - Constants.AxisMinValue); - // Map value to -1 .. 1 - double val11 = (((value - Constants.AxisMinValue) / AxisRange) * 2) - 1; - // calculate (Sensitivity * Value) + ( (1-Sensitivity) * Value^3 ) - double valout = (sens * val11) + ((1 - sens) * Math.Pow( val11, 3 )); - // Map value back to AxisRange - value = (long) Math.Round( ((valout + 1) / 2d) * AxisRange + (1d * Constants.AxisMinValue) ); - - return value; - } - - //ToDo: Does not properly invert, may fail with -32768 - [Obsolete("Deprecated, use SplitAxis instead.")] - public static long HalfAxisToFullRange(long axis, bool positiveRange, bool invert) - { - long value; - if (positiveRange) - { - value = axis > 0L ? axis : 0L; - } - else - { - value = axis < 0 ? axis * -1 : 0L; - } - - value = Constants.AxisMinValue + value * 2; - value = invert ? value * -1 : value; - value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); - return value; - } } } From aec7f963b3f947700542ef41d13c7bc7452f395a Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 18:58:29 +0100 Subject: [PATCH 095/105] Comments --- UCR.Core/Utilities/Functions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index aee9061a..5918e95d 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -5,6 +5,13 @@ namespace HidWizards.UCR.Core.Utilities { public static class Functions { + /// + /// Inverts an axis. + /// Given Max or Min values, will return the opposite extreme. + /// Else returns value * -1 + /// + /// The raw value of the axis + /// The inverted value of the axis public static long Invert(long value) { if (value == 0) return 0; @@ -21,6 +28,11 @@ public static long Invert(long value) return value * -1; } + /// + /// Ensures that an axis value is within permitted range + /// + /// The raw axis value + /// The clamped axis value public static long ClampAxisRange(long value) { if (value == 0) return value; @@ -28,6 +40,13 @@ public static long ClampAxisRange(long value) return value >= Constants.AxisMaxValue ? Constants.AxisMaxValue : value; } + /// + /// Returns either the low or high half of the axis. + /// Stretches the half axis returned to fill the full scale + /// + /// The value of the axis + /// Set to true for the high half, else the low half + /// The new value for the split axis. If axis is negative and high is specified, returns 0. If axis is positive and low is specified, returns 0 public static long SplitAxis(long axis, bool positiveRange) { long value; From bbae508bdd70388a4bcda22b4eb186f72acbc095 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 19:19:42 +0100 Subject: [PATCH 096/105] Throw on invalid percentage --- UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs | 5 ++++- UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 550f222b..98ebe617 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -13,8 +13,11 @@ public int Percentage { get => _percentage; set - //TODO CHECK FOR NEG { + if (Percentage < 0 || Percentage > 100) + { + throw new ArgumentOutOfRangeException(); + } _percentage = value; PrecalculateValues(); } diff --git a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs index ca7e336c..5407b57f 100644 --- a/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/SensitivityHelper.cs @@ -17,6 +17,7 @@ public int Percentage get => _percentage; set { + // Do NOT throw if percentage is not in range 0..100, other values are valid! _percentage = value; PrecalculateValues(); } From 9833d3746a1cd4388ad62925ce9822399174bb0c Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 19:39:41 +0100 Subject: [PATCH 097/105] Test ArgumentOutOfRangeException for DeadZoneHelper --- .../UtilityTests/HelperTests/DeadZoneHelperTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs index 0cbe9f07..63b5fb5a 100644 --- a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs @@ -30,10 +30,19 @@ public long DeadZoneHelperInitTests(long inputValue) [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Half Negative deflection is outside DZ")] [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Positive deflection is inside DZ")] [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Negative deflection is inside DZ")] + [TestCase(-0, 200, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Negative deflection is inside DZ")] public long DeadZoneHelperValueTests(long inputValue, int percentage) { var helper = new DeadZoneHelper { Percentage = percentage }; return helper.ApplyRangeDeadZone(inputValue); } + + [TestCase(101, TestName = "DeadZoneHelper (101): Percentages over 100 should throw an exception")] + [TestCase(-1, TestName = "DeadZoneHelper (-1): Percentages below 0 should throw an exception")] + public void DeadZoneValidationTest(int percentage) + { + var helper = new DeadZoneHelper(); + Assert.Throws(() => helper.Percentage = percentage); + } } } From fded5e0225adb43acdb699f9ad64b6e5ff514906 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 19:39:48 +0100 Subject: [PATCH 098/105] Fix check --- UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs index 98ebe617..6b5ca848 100644 --- a/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs +++ b/UCR.Core/Utilities/AxisHelpers/DeadZoneHelper.cs @@ -14,7 +14,7 @@ public int Percentage get => _percentage; set { - if (Percentage < 0 || Percentage > 100) + if (value < 0 || value > 100) { throw new ArgumentOutOfRangeException(); } From dc79b54ce41cf4ddeda9372aff1dee009d7da9a4 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 20:10:11 +0100 Subject: [PATCH 099/105] Remove unintended test --- UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs index 63b5fb5a..1624632f 100644 --- a/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/DeadZoneHelperTests.cs @@ -30,7 +30,6 @@ public long DeadZoneHelperInitTests(long inputValue) [TestCase(-16384, 50, ExpectedResult = -1, TestName = "DeadZoneHelper (50): Half Negative deflection is outside DZ")] [TestCase(16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Positive deflection is inside DZ")] [TestCase(-16383, 50, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Negative deflection is inside DZ")] - [TestCase(-0, 200, ExpectedResult = 0, TestName = "DeadZoneHelper (50): Below Half Negative deflection is inside DZ")] public long DeadZoneHelperValueTests(long inputValue, int percentage) { var helper = new DeadZoneHelper { Percentage = percentage }; From 509b5602546db969687798d428165632b618b3a8 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 20:10:36 +0100 Subject: [PATCH 100/105] Check Linear Sensitivity 200% --- UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs index e71a8fd5..022b5435 100644 --- a/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs +++ b/UCR.Tests/UtilityTests/HelperTests/SensitivityHelperTests.cs @@ -34,6 +34,8 @@ public long SensitivityHelperValueTests(long inputValue, int percentage) [TestCase(Constants.AxisMinValue, 100, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (100, Linear): Min returns Min")] [TestCase(Constants.AxisMaxValue, 200, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (200, Linear): Min returns Min")] [TestCase(Constants.AxisMinValue, 200, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (200, Linear): Min returns Min")] + [TestCase(16384, 200, ExpectedResult = Constants.AxisMaxValue, TestName = "SensitivityHelper (200, Linear): Half (Positive) Deflection returns Max")] + [TestCase(-16384, 200, ExpectedResult = Constants.AxisMinValue, TestName = "SensitivityHelper (200, Linear): Half (Negative) Deflection returns Min")] public long SensitivityHelperValueLinearTests(long inputValue, int percentage) { var helper = new SensitivityHelper { Percentage = percentage, IsLinear = true}; From 2ce4c6c08fcff1a55ff9525ff6815e76e96a5b4e Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Mon, 3 Sep 2018 22:04:20 +0200 Subject: [PATCH 101/105] InitializeCacheValues added for plugins --- README.md | 2 +- UCR.Core/Managers/SubscriptionsManager.cs | 1 + UCR.Core/Models/Plugin.cs | 8 ++++++++ UCR.Core/Models/PluginProperty.cs | 6 +++++- UCR.Tests/ModelTests/AttributeTests.cs | 12 ++++++------ UCR/Views/AboutWindow.xaml.cs | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 45bbe1e2..082aa3a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Universal Control Remapper -[![GitHub release](https://img.shields.io/badge/release-v0.3.1-blue.svg)](https://github.com/Snoothy/UCR/releases/tag/v0.3.0) [![IOWrapper version](https://img.shields.io/badge/IOWrapper-v0.5.4-blue.svg)](https://github.com/evilC/IOWrapper) [![license](https://img.shields.io/github/license/snoothy/ucr.svg)](https://github.com/Snoothy/UCR/blob/master/LICENSE) [![Github All Releases](https://img.shields.io/github/downloads/snoothy/ucr/total.svg)](https://github.com/Snoothy/UCR/releases) +[![GitHub release](https://img.shields.io/badge/release-v0.4.0-blue.svg)](https://github.com/Snoothy/UCR/releases/tag/v0.4.0) [![IOWrapper version](https://img.shields.io/badge/IOWrapper-v0.5.7-blue.svg)](https://github.com/evilC/IOWrapper) [![license](https://img.shields.io/github/license/snoothy/ucr.svg)](https://github.com/Snoothy/UCR/blob/master/LICENSE) [![Github All Releases](https://img.shields.io/github/downloads/snoothy/ucr/total.svg)](https://github.com/Snoothy/UCR/releases) Universal Control Remapper is a complete rewrite of the original [UCR](https://github.com/evilC/UCR), created in collaboration with [evilC](https://github.com/evilC/). diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index 8e95e2e9..38b4531d 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -67,6 +67,7 @@ private void FinalizeNewState(Profile profile, SubscriptionState subscriptionSta { foreach (var pluginSubscription in mapping.PluginSubscriptions) { + pluginSubscription.Plugin.InitializeCacheValues(); pluginSubscription.Plugin.OnActivate(); } } diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index 732c96a5..50e2063d 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -96,6 +96,14 @@ public virtual void OnPropertyChanged() } + /* + * Called before a plugin OnActivate and OnPropertyChanged to cache run-time values + */ + public virtual void InitializeCacheValues() + { + + } + public virtual void Update(params long[] values) { diff --git a/UCR.Core/Models/PluginProperty.cs b/UCR.Core/Models/PluginProperty.cs index 8c898294..a1d0b6c0 100644 --- a/UCR.Core/Models/PluginProperty.cs +++ b/UCR.Core/Models/PluginProperty.cs @@ -20,7 +20,11 @@ public dynamic Property { if (value.Equals(PropertyInfo.GetValue(Plugin))) return; PropertyInfo.SetValue(Plugin, Convert.ChangeType(value, PropertyInfo.PropertyType, CultureInfo.InvariantCulture)); - Plugin.OnPropertyChanged(); + if (Plugin.Profile.IsActive()) + { + Plugin.InitializeCacheValues(); + Plugin.OnPropertyChanged(); + } Plugin.ContextChanged(); } } diff --git a/UCR.Tests/ModelTests/AttributeTests.cs b/UCR.Tests/ModelTests/AttributeTests.cs index 2af0e25e..1adab77f 100644 --- a/UCR.Tests/ModelTests/AttributeTests.cs +++ b/UCR.Tests/ModelTests/AttributeTests.cs @@ -14,12 +14,12 @@ public void ButtonToButtonIoTest() var inputs = plugin.InputCategories; var outputs = plugin.OutputCategories; - Assert.AreEqual(inputs.Count, 1); - Assert.AreEqual(inputs[0].Category, DeviceBindingCategory.Momentary); - Assert.AreEqual(inputs[0].Name, "Button"); - Assert.AreEqual(outputs.Count, 1); - Assert.AreEqual(outputs[0].Category, DeviceBindingCategory.Momentary); - Assert.AreEqual(outputs[0].Name, "Button"); + Assert.That(inputs.Count, Is.EqualTo(1)); + Assert.That(inputs[0].Category, Is.EqualTo(DeviceBindingCategory.Momentary)); + Assert.That(inputs[0].Name, Is.EqualTo("Button")); + Assert.That(outputs.Count, Is.EqualTo(1)); + Assert.That(outputs[0].Category, Is.EqualTo(DeviceBindingCategory.Momentary)); + Assert.That(outputs[0].Name, Is.EqualTo("Button")); } [Test] diff --git a/UCR/Views/AboutWindow.xaml.cs b/UCR/Views/AboutWindow.xaml.cs index 2c1fce88..a9f2c9df 100644 --- a/UCR/Views/AboutWindow.xaml.cs +++ b/UCR/Views/AboutWindow.xaml.cs @@ -22,7 +22,7 @@ private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation. private string GetVersion() { - return "v0.3.1"; + return "v0.4.0"; // TODO System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); From bfc3adfab438f9c7b9b0b96bd29de4d1d619ed6f Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 21:05:12 +0100 Subject: [PATCH 102/105] Fix split, add regression tests --- UCR.Core/Utilities/Functions.cs | 5 +++-- UCR.Plugins/Remapper/AxisSplitter.cs | 2 +- UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs index 5918e95d..32928369 100644 --- a/UCR.Core/Utilities/Functions.cs +++ b/UCR.Core/Utilities/Functions.cs @@ -50,15 +50,16 @@ public static long ClampAxisRange(long value) public static long SplitAxis(long axis, bool positiveRange) { long value; + if (axis == 0) return Constants.AxisMinValue; if (positiveRange) { - if (axis < 0) return 0; + if (axis < 0) return Constants.AxisMinValue; value = axis; if (value == Constants.AxisMaxValue) value++; } else { - if (axis > 0) return 0; + if (axis > 0) return Constants.AxisMinValue; value = axis * -1; } diff --git a/UCR.Plugins/Remapper/AxisSplitter.cs b/UCR.Plugins/Remapper/AxisSplitter.cs index f47bf038..bde30937 100644 --- a/UCR.Plugins/Remapper/AxisSplitter.cs +++ b/UCR.Plugins/Remapper/AxisSplitter.cs @@ -37,7 +37,7 @@ public override void Update(params long[] values) var high = Functions.SplitAxis(value, true); var low = Functions.SplitAxis(value, false); if (InvertHigh) high = Functions.Invert(high); - if (InvertHigh) low = Functions.Invert(low); + if (InvertLow) low = Functions.Invert(low); WriteOutput(0, high); WriteOutput(1, low); } diff --git a/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs b/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs index 948218c5..0ad46771 100644 --- a/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs +++ b/UCR.Tests/UtilityTests/FunctionTests/FunctionTests.cs @@ -32,6 +32,10 @@ public long ClampTests(long inputValue) [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (High): 0 returns Min")] [TestCase(Constants.AxisMinValue, false, ExpectedResult = Constants.AxisMaxValue, TestName = "SplitAxis (Low): Min returns Max")] [TestCase(0, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (Low): 0 returns Min")] + [TestCase(Constants.AxisMinValue, true, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (High): Negative values return Min")] + [TestCase(Constants.AxisMaxValue, false, ExpectedResult = Constants.AxisMinValue, TestName = "SplitAxis (Low): Positive values return Min")] + [TestCase(1, true, ExpectedResult = -32766, TestName = "SplitAxis (High): 1 returns -32766")] + [TestCase(-1, false, ExpectedResult = -32766, TestName = "SplitAxis (Low): -1 returns -32766")] public long SplitTests(long inputValue, bool positiveRange) { return Functions.SplitAxis(inputValue, positiveRange); From f4c8f8a77ca5055707bae9155a54b612af89e3c6 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 21:19:50 +0100 Subject: [PATCH 103/105] Fix Inverts All inverts now handled by Functions.Invert() Added missing Invert functionality to AxesToAxes --- UCR.Plugins/Remapper/AxesToAxes.cs | 12 +++++++++--- UCR.Plugins/Remapper/AxisMerger.cs | 4 ++-- UCR.Plugins/Remapper/AxisToAxis.cs | 2 +- UCR.Plugins/Remapper/AxisToAxisRelative.cs | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/UCR.Plugins/Remapper/AxesToAxes.cs b/UCR.Plugins/Remapper/AxesToAxes.cs index 869d27a5..34e0cfbf 100644 --- a/UCR.Plugins/Remapper/AxesToAxes.cs +++ b/UCR.Plugins/Remapper/AxesToAxes.cs @@ -19,10 +19,13 @@ public class AxesToAxes : Plugin private readonly SensitivityHelper _sensitivityHelper = new SensitivityHelper(); private double _linearSenstitivityScaleFactor; - [PluginGui("Invert", ColumnOrder = 0)] - public bool Invert { get; set; } + [PluginGui("Invert X", ColumnOrder = 0)] + public bool InvertX { get; set; } - [PluginGui("Sensitivity", ColumnOrder = 1)] + [PluginGui("Invert Y", ColumnOrder = 1)] + public bool InvertY { get; set; } + + [PluginGui("Sensitivity", ColumnOrder = 2)] public int Sensitivity { get; set; } [PluginGui("Linear", RowOrder = 0, ColumnOrder = 2)] @@ -82,6 +85,9 @@ public override void Update(params long[] values) outputValues[0] = Functions.ClampAxisRange(outputValues[0]); outputValues[1] = Functions.ClampAxisRange(outputValues[1]); + if (InvertX) outputValues[0] = Functions.Invert(outputValues[0]); + if (InvertY) outputValues[1] = Functions.Invert(outputValues[1]); + WriteOutput(0, outputValues[0]); WriteOutput(1, outputValues[1]); } diff --git a/UCR.Plugins/Remapper/AxisMerger.cs b/UCR.Plugins/Remapper/AxisMerger.cs index 13f8acbc..0f64744f 100644 --- a/UCR.Plugins/Remapper/AxisMerger.cs +++ b/UCR.Plugins/Remapper/AxisMerger.cs @@ -38,8 +38,8 @@ public override void Update(params long[] values) var valueLow = values[1]; long valueOutput; - if (InvertHigh) valueHigh *= -1; - if (InvertLow) valueLow *= -1; + if (InvertHigh) valueHigh = Functions.Invert(valueHigh); + if (InvertLow) valueLow = Functions.Invert(valueLow); switch (Mode) { diff --git a/UCR.Plugins/Remapper/AxisToAxis.cs b/UCR.Plugins/Remapper/AxisToAxis.cs index 3c1c0749..0e7faf68 100644 --- a/UCR.Plugins/Remapper/AxisToAxis.cs +++ b/UCR.Plugins/Remapper/AxisToAxis.cs @@ -36,7 +36,7 @@ public AxisToAxis() public override void Update(params long[] values) { var value = values[0]; - if (Invert) value *= -1; + if (Invert) Functions.Invert(value); if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); WriteOutput(0, value); diff --git a/UCR.Plugins/Remapper/AxisToAxisRelative.cs b/UCR.Plugins/Remapper/AxisToAxisRelative.cs index 7022b225..df4c1f30 100644 --- a/UCR.Plugins/Remapper/AxisToAxisRelative.cs +++ b/UCR.Plugins/Remapper/AxisToAxisRelative.cs @@ -57,7 +57,7 @@ public override void Update(params long[] values) { var value = values[0]; - if (Invert) value *= -1; + if (Invert) value = Functions.Invert(value); if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); From 1f6e66a37b0e6cf905d6ca04ca7933bd75798514 Mon Sep 17 00:00:00 2001 From: evilC Date: Mon, 3 Sep 2018 21:23:07 +0100 Subject: [PATCH 104/105] Fix missing assign --- UCR.Plugins/Remapper/AxisToAxis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UCR.Plugins/Remapper/AxisToAxis.cs b/UCR.Plugins/Remapper/AxisToAxis.cs index 0e7faf68..e266aa05 100644 --- a/UCR.Plugins/Remapper/AxisToAxis.cs +++ b/UCR.Plugins/Remapper/AxisToAxis.cs @@ -36,7 +36,7 @@ public AxisToAxis() public override void Update(params long[] values) { var value = values[0]; - if (Invert) Functions.Invert(value); + if (Invert) value = Functions.Invert(value); if (DeadZone != 0) value = _deadZoneHelper.ApplyRangeDeadZone(value); if (Sensitivity != 100) value = _sensitivityHelper.ApplyRangeSensitivity(value); WriteOutput(0, value); From d43374456a112a3b53322ad23cd757881a93e769 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Mon, 3 Sep 2018 22:24:35 +0200 Subject: [PATCH 105/105] Renamed AxisToAxisRelative to AxisToAxisCumulative --- .../{AxisToAxisRelative.cs => AxisToAxisCumulative.cs} | 6 +++--- UCR.Plugins/UCR.Plugins.csproj | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename UCR.Plugins/Remapper/{AxisToAxisRelative.cs => AxisToAxisCumulative.cs} (97%) diff --git a/UCR.Plugins/Remapper/AxisToAxisRelative.cs b/UCR.Plugins/Remapper/AxisToAxisCumulative.cs similarity index 97% rename from UCR.Plugins/Remapper/AxisToAxisRelative.cs rename to UCR.Plugins/Remapper/AxisToAxisCumulative.cs index 7022b225..32c50e61 100644 --- a/UCR.Plugins/Remapper/AxisToAxisRelative.cs +++ b/UCR.Plugins/Remapper/AxisToAxisCumulative.cs @@ -9,10 +9,10 @@ namespace HidWizards.UCR.Plugins.Remapper { - [Plugin("Axis to Axis (Relative)")] + [Plugin("Axis to Axis (Cumulative)")] [PluginInput(DeviceBindingCategory.Range, "Axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] - public class AxisToAxisRelative : Plugin + public class AxisToAxisCumulative : Plugin { [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } @@ -44,7 +44,7 @@ public class AxisToAxisRelative : Plugin private Thread _relativeThread; - public AxisToAxisRelative() + public AxisToAxisCumulative() { DeadZone = 0; Sensitivity = 100; diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 31e1c208..f8e91e68 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -49,7 +49,7 @@ - +