mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Device service - Use an RGB.NET brush for device identify
This commit is contained in:
parent
ea98c6114a
commit
2708e190cb
@ -14,6 +14,9 @@ apiRules:
|
|||||||
- exclude:
|
- exclude:
|
||||||
uidRegex: ^Artemis\.Core\.Properties
|
uidRegex: ^Artemis\.Core\.Properties
|
||||||
type: Type
|
type: Type
|
||||||
|
- exclude:
|
||||||
|
uidRegex: ^Artemis\.Core\.Services\.IArtemisService
|
||||||
|
type: Type
|
||||||
- exclude:
|
- exclude:
|
||||||
uidRegex: ^Artemis\.UI\.Shared\.Properties
|
uidRegex: ^Artemis\.UI\.Shared\.Properties
|
||||||
type: Type
|
type: Type
|
||||||
@ -59,6 +59,9 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="RGB.NET.Brushes">
|
||||||
|
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Brushes.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="RGB.NET.Core">
|
<Reference Include="RGB.NET.Core">
|
||||||
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Core.dll</HintPath>
|
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@ -1,17 +1,13 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Linq;
|
||||||
using SkiaSharp;
|
using System.Threading.Tasks;
|
||||||
|
using RGB.NET.Brushes;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
using RGB.NET.Groups;
|
||||||
|
|
||||||
namespace Artemis.Core.Services
|
namespace Artemis.Core.Services
|
||||||
{
|
{
|
||||||
internal class DeviceService : IDeviceService
|
internal class DeviceService : IDeviceService
|
||||||
{
|
{
|
||||||
private readonly ICoreService _coreService;
|
|
||||||
|
|
||||||
public DeviceService(ICoreService coreService)
|
|
||||||
{
|
|
||||||
_coreService = coreService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void IdentifyDevice(ArtemisDevice device)
|
public void IdentifyDevice(ArtemisDevice device)
|
||||||
{
|
{
|
||||||
BlinkDevice(device, 0);
|
BlinkDevice(device, 0);
|
||||||
@ -19,36 +15,26 @@ namespace Artemis.Core.Services
|
|||||||
|
|
||||||
private void BlinkDevice(ArtemisDevice device, int blinkCount)
|
private void BlinkDevice(ArtemisDevice device, int blinkCount)
|
||||||
{
|
{
|
||||||
// Draw a white overlay over the device
|
// Create a LED group way at the top
|
||||||
void DrawOverlay(object sender, FrameRenderingEventArgs args)
|
var ledGroup = new ListLedGroup(device.Leds.Select(l => l.RgbLed))
|
||||||
{
|
{
|
||||||
args.Canvas.DrawPath(device.RenderPath, new SKPaint {Color = new SKColor(255, 255, 255)});
|
Brush = new SolidColorBrush(new Color(255, 255, 255)),
|
||||||
}
|
ZIndex = 999
|
||||||
|
};
|
||||||
|
|
||||||
_coreService.FrameRendering += DrawOverlay;
|
// After 200ms, detach the LED group
|
||||||
|
|
||||||
// After 200ms, stop drawing the overlay
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);
|
||||||
_coreService.FrameRendering -= DrawOverlay;
|
ledGroup.Detach();
|
||||||
|
|
||||||
if (blinkCount < 5)
|
if (blinkCount < 5)
|
||||||
{
|
{
|
||||||
// After another 200ms, draw the overlay again, repeat six times
|
// After another 200ms, start over, repeat six times
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);
|
||||||
BlinkDevice(device, blinkCount + 1);
|
BlinkDevice(device, blinkCount + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IDeviceService : IArtemisService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Identifies the device by making it blink white 5 times
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="device"></param>
|
|
||||||
void IdentifyDevice(ArtemisDevice device);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
11
src/Artemis.Core/Services/Interfaces/IDeviceService.cs
Normal file
11
src/Artemis.Core/Services/Interfaces/IDeviceService.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
public interface IDeviceService : IArtemisService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Identifies the device by making it blink white 5 times
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
void IdentifyDevice(ArtemisDevice device);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Artemis.Core.Services
|
namespace Artemis.Core.Services
|
||||||
{
|
{
|
||||||
public class SurfaceService : ISurfaceService
|
internal class SurfaceService : ISurfaceService
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IPluginService _pluginService;
|
private readonly IPluginService _pluginService;
|
||||||
@ -17,7 +17,7 @@ namespace Artemis.Core.Services
|
|||||||
private readonly List<ArtemisSurface> _surfaceConfigurations;
|
private readonly List<ArtemisSurface> _surfaceConfigurations;
|
||||||
private readonly ISurfaceRepository _surfaceRepository;
|
private readonly ISurfaceRepository _surfaceRepository;
|
||||||
|
|
||||||
internal SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, IPluginService pluginService, ISettingsService settingsService)
|
public SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, IPluginService pluginService, ISettingsService settingsService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_surfaceRepository = surfaceRepository;
|
_surfaceRepository = surfaceRepository;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user