Skip to content

Commit

Permalink
Merge pull request #31 from Snoothy/develop
Browse files Browse the repository at this point in the history
UCR v0.4.0
  • Loading branch information
Snoothy authored Sep 3, 2018
2 parents c220c8a + 57c3c52 commit 96e3d90
Show file tree
Hide file tree
Showing 56 changed files with 2,732 additions and 230 deletions.
Binary file modified .nuke
Binary file not shown.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<img src="icon.png" align="right" />

# 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/).

Expand Down Expand Up @@ -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 ##

Expand Down
31 changes: 21 additions & 10 deletions UCR.Core/Managers/SubscriptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -49,17 +49,33 @@ 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.InitializeCacheValues();
pluginSubscription.Plugin.OnActivate();
}
}

foreach (var action in _context.ActiveProfileCallbacks)
{
action();
}

return true;
}

public bool DeactivateProfile()
Expand Down Expand Up @@ -161,11 +177,6 @@ private bool ActivateSubscriptionState(SubscriptionState state)
{
success &= SubscribeDeviceBindingInput(state, deviceBindingSubscription);
}

foreach (var pluginSubscription in mappingSubscription.PluginSubscriptions)
{
pluginSubscription.Plugin.OnActivate();
}
}

state.IsActive = true;
Expand Down
45 changes: 43 additions & 2 deletions UCR.Core/Models/Binding/DeviceBinding.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -12,7 +15,7 @@ public enum DeviceBindingCategory
Delta
}

public class DeviceBinding
public class DeviceBinding : INotifyPropertyChanged
{
/* Persistence */
public bool IsBound { get; set; }
Expand All @@ -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();
Expand Down Expand Up @@ -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));
}
}
}
1 change: 1 addition & 0 deletions UCR.Core/Models/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
18 changes: 18 additions & 0 deletions UCR.Core/Models/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public virtual void OnActivate()

}

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)
{

Expand Down Expand Up @@ -120,6 +133,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)
Expand Down
9 changes: 8 additions & 1 deletion UCR.Core/Models/PluginProperty.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.CodeDom;
using System.Globalization;
using System.Reflection;

namespace HidWizards.UCR.Core.Models
Expand All @@ -17,7 +19,12 @@ 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));
if (Plugin.Profile.IsActive())
{
Plugin.InitializeCacheValues();
Plugin.OnPropertyChanged();
}
Plugin.ContextChanged();
}
}
Expand Down
Loading

0 comments on commit 96e3d90

Please sign in to comment.