Added device identification to surface editor

Fixed dialog rendering
Cleaned up XAML
This commit is contained in:
SpoinkyNL committed 2019-11-22 20:46:34 +01:00
1 parent 733c9bf1a5
commit 25f8f1e72f
24 files changed
+165 -79

No files matched your search

+1
View File
@@ -188,6 +188,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RGB.NET\DirectBitmap.cs" />
<Compile Include="RGB.NET\GraphicsDecorator.cs" />
<Compile Include="Services\DeviceService.cs" />
<Compile Include="Services\Interfaces\IProtectedArtemisService.cs" />
<Compile Include="Services\Interfaces\IMainDataModelService.cs" />
<Compile Include="Services\CoreService.cs" />
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services.Interfaces;
namespace Artemis.Core.Services
{
public class DeviceService : IDeviceService
{
private readonly ICoreService _coreService;
public DeviceService(ICoreService coreService)
{
_coreService = coreService;
}
public void IdentifyDevice(Device device)
{
BlinkDevice(device, 0);
}
private void BlinkDevice(Device device, int blinkCount)
{
// Draw a white overlay over the device
void DrawOverlay(object sender, FrameRenderingEventArgs args)
{
using (var g = Graphics.FromImage(args.Bitmap))
{
g.FillPath(new SolidBrush(Color.White), device.RenderPath);
}
}
_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(Device device);
}
}