Added Corsair support as a plugin

This commit is contained in:
SpoinkyNL committed 2019-08-11 16:58:43 +02:00
1 parent 1146de1fc5
commit 090c726880
25 files changed
+302 -131

No files matched your search

+2 -6
View File
@@ -82,9 +82,6 @@
<Reference Include="RGB.NET.Decorators, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Decorators.0.1.25\lib\net45\RGB.NET.Decorators.dll</HintPath>
</Reference>
<Reference Include="RGB.NET.Devices.Corsair, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Devices.Corsair.0.1.25\lib\net45\RGB.NET.Devices.Corsair.dll</HintPath>
</Reference>
<Reference Include="RGB.NET.Groups, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Groups.0.1.25\lib\net45\RGB.NET.Groups.dll</HintPath>
</Reference>
@@ -99,8 +96,8 @@
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data" />
@@ -145,7 +142,6 @@
<Compile Include="Events\PluginEventArgs.cs" />
<Compile Include="Services\PluginService.cs" />
<Compile Include="Services\StorageService.cs" />
<Compile Include="UtilitiesRemoveMe.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@@ -1,4 +1,5 @@
using System.Drawing;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Groups;
using Color = RGB.NET.Core.Color;
@@ -12,11 +13,10 @@ namespace Artemis.Core.RGB.NET
public GraphicsDecorator(ListLedGroup ledGroup)
{
// var width = ledGroup.GetLeds().Max(l => l.LedRectangle.X + l.LedRectangle.Width);
// var height = ledGroup.GetLeds().Max(l => l.LedRectangle.Y + l.LedRectangle.Height);
var width = 500;
var height = 500;
_bitmap = new DirectBitmap(width, height);
var width = ledGroup.GetLeds().Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width);
var height = ledGroup.GetLeds().Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height);
_bitmap = new DirectBitmap((int) width, (int) height);
}
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
+1 -2
View File
@@ -40,7 +40,6 @@ namespace Artemis.Core.Services
// Initialize the services
await Task.Run(() => _pluginService.LoadPlugins());
await _rgbService.LoadDevices();
OnInitialized();
}
@@ -61,7 +60,7 @@ namespace Artemis.Core.Services
// Render all active modules
using (var g = _rgbService.GraphicsDecorator.GetGraphics())
{
g.Clear(Color.Red);
g.Clear(Color.Black);
foreach (var module in modules)
module.Render(args.DeltaTime, _rgbService.Surface, g);
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.RGB.NET;
using RGB.NET.Core;
@@ -8,10 +7,9 @@ namespace Artemis.Core.Services.Interfaces
{
public interface IRgbService : IArtemisService
{
bool LoadingDevices { get; }
RGBSurface Surface { get; set; }
GraphicsDecorator GraphicsDecorator { get; }
Task LoadDevices();
void AddDeviceProvider(IRGBDeviceProvider deviceProvider);
void Dispose();
/// <summary>
@@ -23,15 +21,5 @@ namespace Artemis.Core.Services.Interfaces
/// Occurs when a single device has reloaded
/// </summary>
event EventHandler<DeviceEventArgs> DeviceReloaded;
/// <summary>
/// Occurs when loading all devices has started
/// </summary>
event EventHandler StartingLoadingDevices;
/// <summary>
/// Occurs when loading all devices has finished
/// </summary>
event EventHandler FinishedLoadedDevices;
}
}
+22 -56
View File
@@ -6,7 +6,6 @@ using Artemis.Core.RGB.NET;
using Artemis.Core.Services.Interfaces;
using RGB.NET.Brushes;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair;
using RGB.NET.Groups;
namespace Artemis.Core.Services
@@ -39,49 +38,30 @@ namespace Artemis.Core.Services
public RGBSurface Surface { get; set; }
public GraphicsDecorator GraphicsDecorator { get; private set; }
/// <inheritdoc />
public async Task LoadDevices()
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
{
OnStartedLoadingDevices();
Surface.LoadDevices(deviceProvider);
Surface.AlignDevices();
await Task.Run(() =>
{
// TODO SpoinkyNL 8-1-18: Keep settings into account
// This one doesn't work well without ASUS devices installed
// Surface.LoadDevices(AsusDeviceProvider.Instance);
// Surface.LoadDevices(CoolerMasterDeviceProvider.Instance);
Surface.LoadDevices(CorsairDeviceProvider.Instance);
// Surface.LoadDevices(DMXDeviceProvider.Instance);
// Surface.LoadDevices(LogitechDeviceProvider.Instance);
// Surface.LoadDevices(MsiDeviceProvider.Instance);
// Surface.LoadDevices(NovationDeviceProvider.Instance);
// Surface.LoadDevices(RazerDeviceProvider.Instance);
lock (_loadedDevices)
{
foreach (var surfaceDevice in deviceProvider.Devices)
{
if (!_loadedDevices.Contains(surfaceDevice))
{
_loadedDevices.Add(surfaceDevice);
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
}
else
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
}
}
// TODO SpoinkyNL 8-1-18: Load alignment
Surface.AlignDevices();
lock (_loadedDevices)
{
foreach (var surfaceDevice in Surface.Devices)
{
if (!_loadedDevices.Contains(surfaceDevice))
{
_loadedDevices.Add(surfaceDevice);
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
}
else
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
}
}
});
// Apply the application wide brush and decorator
var background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))};
GraphicsDecorator = new GraphicsDecorator(background);
background.Brush.AddDecorator(GraphicsDecorator);
OnFinishedLoadedDevices();
// Apply the application wide brush and decorator
var background = new ListLedGroup(Surface.Leds) { Brush = new SolidColorBrush(new Color(255, 255, 255, 255)) };
GraphicsDecorator = new GraphicsDecorator(background);
background.Brush.AddDecorator(GraphicsDecorator);
}
public void Dispose()
@@ -101,8 +81,6 @@ namespace Artemis.Core.Services
public event EventHandler<DeviceEventArgs> DeviceLoaded;
public event EventHandler<DeviceEventArgs> DeviceReloaded;
public event EventHandler StartingLoadingDevices;
public event EventHandler FinishedLoadedDevices;
private void OnDeviceLoaded(DeviceEventArgs e)
{
@@ -113,19 +91,7 @@ namespace Artemis.Core.Services
{
DeviceReloaded?.Invoke(this, e);
}
private void OnStartedLoadingDevices()
{
LoadingDevices = true;
StartingLoadingDevices?.Invoke(this, EventArgs.Empty);
}
private void OnFinishedLoadedDevices()
{
LoadingDevices = false;
FinishedLoadedDevices?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
-90
View File
@@ -1,90 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace Artemis.Core
{
public static class ColorHelpers
{
private static readonly Random _rand = new Random();
/// <summary>
/// Comes up with a 'pure' psuedo-random color
/// </summary>
/// <returns>The color</returns>
public static Color GetRandomRainbowColor()
{
var colors = new List<int>();
for (var i = 0; i < 3; i++)
colors.Add(_rand.Next(0, 256));
var highest = colors.Max();
var lowest = colors.Min();
colors[colors.FindIndex(c => c == highest)] = 255;
colors[colors.FindIndex(c => c == lowest)] = 0;
var returnColor = Color.FromArgb(255, colors[0], colors[1], colors[2]);
return returnColor;
}
public static Color GetRandomRainbowMediaColor()
{
var colors = new List<byte>();
for (var i = 0; i < 3; i++)
colors.Add((byte) _rand.Next(0, 256));
var highest = colors.Max();
var lowest = colors.Min();
colors[colors.FindIndex(c => c == highest)] = 255;
colors[colors.FindIndex(c => c == lowest)] = 0;
var returnColor = Color.FromArgb(255, colors[0], colors[1], colors[2]);
return returnColor;
}
public static Color ShiftColor(Color c, int shiftAmount)
{
int newRed = c.R;
int newGreen = c.G;
int newBlue = c.B;
// Red to purple
if (c.R == 255 && c.B < 255 && c.G == 0)
newBlue = newBlue + shiftAmount;
// Purple to blue
else if (c.B == 255 && c.R > 0)
newRed = newRed - shiftAmount;
// Blue to light-blue
else if (c.B == 255 && c.G < 255)
newGreen = newGreen + shiftAmount;
// Light-blue to green
else if (c.G == 255 && c.B > 0)
newBlue = newBlue - shiftAmount;
// Green to yellow
else if (c.G == 255 && c.R < 255)
newRed = newRed + shiftAmount;
// Yellow to red
else if (c.R == 255 && c.G > 0)
newGreen = newGreen - shiftAmount;
newRed = BringIntInColorRange(newRed);
newGreen = BringIntInColorRange(newGreen);
newBlue = BringIntInColorRange(newBlue);
return Color.FromArgb(c.A, newRed, newGreen, newBlue);
}
private static int BringIntInColorRange(int i)
{
if (i < 0)
return 0;
if (i > 255)
return 255;
return i;
}
}
}
+1 -2
View File
@@ -10,9 +10,8 @@
<package id="RGB.NET.Brushes" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Decorators" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Devices.Corsair" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Groups" version="0.1.25" targetFramework="net472" />
<package id="Stylet" version="1.1.22" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net472" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>