mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +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:
|
||||
uidRegex: ^Artemis\.Core\.Properties
|
||||
type: Type
|
||||
- exclude:
|
||||
uidRegex: ^Artemis\.Core\.Services\.IArtemisService
|
||||
type: Type
|
||||
- exclude:
|
||||
uidRegex: ^Artemis\.UI\.Shared\.Properties
|
||||
type: Type
|
||||
@ -59,6 +59,9 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="RGB.NET.Brushes">
|
||||
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Brushes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RGB.NET.Core">
|
||||
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Core.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using SkiaSharp;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using RGB.NET.Brushes;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal class DeviceService : IDeviceService
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
|
||||
public DeviceService(ICoreService coreService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
}
|
||||
|
||||
public void IdentifyDevice(ArtemisDevice device)
|
||||
{
|
||||
BlinkDevice(device, 0);
|
||||
@ -19,36 +15,26 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void BlinkDevice(ArtemisDevice device, int blinkCount)
|
||||
{
|
||||
// Draw a white overlay over the device
|
||||
void DrawOverlay(object sender, FrameRenderingEventArgs args)
|
||||
// Create a LED group way at the top
|
||||
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, stop drawing the overlay
|
||||
// After 200ms, detach the LED group
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(200);
|
||||
_coreService.FrameRendering -= DrawOverlay;
|
||||
ledGroup.Detach();
|
||||
|
||||
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);
|
||||
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
|
||||
{
|
||||
public class SurfaceService : ISurfaceService
|
||||
internal class SurfaceService : ISurfaceService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPluginService _pluginService;
|
||||
@ -17,7 +17,7 @@ namespace Artemis.Core.Services
|
||||
private readonly List<ArtemisSurface> _surfaceConfigurations;
|
||||
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;
|
||||
_surfaceRepository = surfaceRepository;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user