1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.Core/Services/DeviceService.cs
Robert a06ad8f011 Marked all service implementations as internal
Core - Enabled XML docs
Modules - Added DI to module VMs
2020-08-19 19:45:22 +02:00

57 lines
1.7 KiB
C#

using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services.Interfaces;
using SkiaSharp;
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);
}
private void BlinkDevice(ArtemisDevice device, int blinkCount)
{
// Draw a white overlay over the device
void DrawOverlay(object sender, FrameRenderingEventArgs args)
{
args.Canvas.DrawPath(device.RenderPath, new SKPaint {Color = new SKColor(255, 255, 255)});
}
_coreService.FrameRendering += DrawOverlay;
// After 200ms, stop drawing the overlay
Task.Run(async () =>
{
await Task.Delay(200);
_coreService.FrameRendering -= DrawOverlay;
if (blinkCount < 5)
{
// After another 200ms, draw the overlay again, 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);
}
}