1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Small fixes

No longer taking exclusive CUE access, seems to work well with latest CUE this way
Removed LUA stack trace logging, just refers to MoonSharp code anyway
Artemis disables and re-enables itself after system wake for #204
This commit is contained in:
SpoinkyNL 2016-12-27 10:35:39 +01:00
parent ef69c39cf5
commit 97281e24df
7 changed files with 86 additions and 58 deletions

View File

@ -22,7 +22,7 @@ namespace Artemis.DeviceProviders.Corsair
{
CanUse = CanInitializeSdk();
if (CanUse && !CueSDK.IsInitialized)
CueSDK.Initialize(true);
CueSDK.Initialize();
Logger.Debug("Attempted to enable Corsair headset. CanUse: {0}", CanUse);

View File

@ -10,6 +10,7 @@ using CUE.NET;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Exceptions;
using CUE.NET.Helper;
using Ninject.Extensions.Logging;
using Point = System.Drawing.Point;
@ -44,7 +45,7 @@ namespace Artemis.DeviceProviders.Corsair
public override void Enable()
{
if (!CueSDK.IsInitialized)
CueSDK.Initialize(true);
CueSDK.Initialize();
CueSDK.UpdateMode = UpdateMode.Manual;
_keyboard = CueSDK.KeyboardSDK;
@ -87,8 +88,17 @@ namespace Artemis.DeviceProviders.Corsair
public override void Disable()
{
if (CueSDK.IsInitialized)
CueSDK.Reinitialize();
try
{
if (CueSDK.IsInitialized)
CueSDK.Reinitialize();
}
catch (WrapperException e)
{
// This occurs when releasing the SDK after sleep, ignore it
if (e.Message != "The previously loaded Keyboard got disconnected.")
throw;
}
}
/// <summary>

View File

@ -22,7 +22,7 @@ namespace Artemis.DeviceProviders.Corsair
{
CanUse = CanInitializeSdk();
if (CanUse && !CueSDK.IsInitialized)
CueSDK.Initialize(true);
CueSDK.Initialize();
Logger.Debug("Attempted to enable Corsair mice. CanUse: {0}", CanUse);

View File

@ -22,7 +22,7 @@ namespace Artemis.DeviceProviders.Corsair
{
CanUse = CanInitializeSdk();
if (CanUse && !CueSDK.IsInitialized)
CueSDK.Initialize(true);
CueSDK.Initialize();
Logger.Debug("Attempted to enable Corsair mousemat. CanUse: {0}", CanUse);

View File

@ -80,15 +80,15 @@ namespace Artemis.Managers
}
catch (InternalErrorException e)
{
_logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
_logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
}
catch (SyntaxErrorException e)
{
_logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
_logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
}
catch (ScriptRuntimeException e)
{
_logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
_logger.Error("[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
@ -10,6 +9,7 @@ using Artemis.Utilities;
using Artemis.Utilities.DataReaders;
using Artemis.Utilities.GameState;
using Artemis.ViewModels;
using Microsoft.Win32;
using Ninject;
using Ninject.Extensions.Logging;
@ -51,6 +51,9 @@ namespace Artemis.Managers
var updateTask = new Task(Updater.UpdateApp);
updateTask.Start();
// Listen for power mode changes
SystemEvents.PowerModeChanged += OnPowerChange;
Logger.Info("Intialized MainManager");
Logger.Info($"Artemis version {Assembly.GetExecutingAssembly().GetName().Version} is ready!");
}
@ -83,6 +86,23 @@ namespace Artemis.Managers
public event EventHandler<EnabledChangedEventArgs> OnEnabledChangedEvent;
/// <summary>
/// Restarts the loop manager when the system resumes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void OnPowerChange(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode != PowerModes.Resume)
return;
Logger.Debug("Restarting for OnPowerChange");
DisableProgram();
// Wait an extra while for device providers to be fully ready
await Task.Delay(2000);
EnableProgram();
}
/// <summary>
/// Loads the last active effect and starts the program
/// </summary>
@ -124,13 +144,11 @@ namespace Artemis.Managers
// If the currently active effect is a no longer running game, get rid of it.
var activeGame = EffectManager.ActiveEffect as GameModel;
if (activeGame != null)
{
if (!runningProcesses.Any(p => p.ProcessName == activeGame.ProcessName && p.HasExited == false))
{
Logger.Info("Disabling game: {0}", activeGame.Name);
EffectManager.DisableGame(activeGame);
}
}
// Look for running games, stopping on the first one that's found.
var newGame = EffectManager.EnabledGames

View File

@ -1,49 +1,49 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Artemis.DeviceProviders;
using Artemis.Managers;
using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua.Modules
{
[MoonSharpUserData]
public class LuaKeyboardModule : LuaModule
{
private readonly KeyboardProvider _keyboardProvider;
public LuaKeyboardModule(LuaManager luaManager) : base(luaManager)
{
_keyboardProvider = luaManager.KeyboardProvider;
// Register the KeyMatch type for usage in GetKeyPosition
UserData.RegisterType(typeof(KeyMatch));
}
public override string ModuleName => "Keyboard";
public string Name => _keyboardProvider.Name;
public string Slug => _keyboardProvider.Slug;
public int Width => _keyboardProvider.Width;
public int Height => _keyboardProvider.Height;
public void PressKeys(string keys)
{
SendKeys.SendWait(keys);
}
public KeyMatch? GetKeyPosition(string key)
{
// Convert string to Keys enum, I'm not sure if built-in enums can be converted automatically
try
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Artemis.DeviceProviders;
using Artemis.Managers;
using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua.Modules
{
[MoonSharpUserData]
public class LuaKeyboardModule : LuaModule
{
private readonly KeyboardProvider _keyboardProvider;
public LuaKeyboardModule(LuaManager luaManager) : base(luaManager)
{
_keyboardProvider = luaManager.KeyboardProvider;
// Register the KeyMatch type for usage in GetKeyPosition
UserData.RegisterType(typeof(KeyMatch));
}
public override string ModuleName => "Keyboard";
public string Name => _keyboardProvider.Name;
public string Slug => _keyboardProvider.Slug;
public int Width => _keyboardProvider.Width;
public int Height => _keyboardProvider.Height;
public void PressKeys(string keys)
{
SendKeys.SendWait(keys);
}
public KeyMatch? GetKeyPosition(string key)
{
// Convert string to Keys enum, I'm not sure if built-in enums can be converted automatically
try
{
var keyEnum = (Keys)Enum.Parse(typeof(Keys), key);
return _keyboardProvider.GetKeyPosition(keyEnum);
}
catch (ArgumentException)
{
throw new ScriptRuntimeException($"Key '{key}' not found");
}
}
}
return _keyboardProvider.GetKeyPosition(keyEnum);
}
catch (ArgumentException)
{
throw new ScriptRuntimeException($"Key '{key}' not found");
}
}
}
}