io commander
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using System.Runtime;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
using VisionBuilder.UI.Common.ViewModel;
|
||||
using VisionBuilder.UI.IOCommander.Settings;
|
||||
|
||||
namespace VisionBuilder.UI.IOCommander.Modules;
|
||||
|
||||
public class IOCommanderCameraModule: IVisionBuilderModule
|
||||
{
|
||||
private readonly IOCommanderModule _mainModule;
|
||||
private readonly IOCommanderSettings _settings;
|
||||
private readonly IOCommanderCameraSettings _cameraSettings;
|
||||
private readonly IRecognitionControl _recognitionControl;
|
||||
private readonly MainWindowVM _mainWindowVm;
|
||||
|
||||
public IOCommanderCameraModule(IOCommanderModule mainModule, IOCommanderSettings settings, IOCommanderCameraSettings cameraSettings, IRecognitionControl recognitionControl, MainWindowVM mainWindowVm)
|
||||
{
|
||||
_mainModule = mainModule;
|
||||
_settings = settings;
|
||||
_cameraSettings = cameraSettings;
|
||||
_recognitionControl = recognitionControl;
|
||||
_mainWindowVm = mainWindowVm;
|
||||
|
||||
_recognitionControl.ImageProcessed += _recognitionControl_ImageProcessed;
|
||||
_recognitionControl.SessionStarted += _recognitionControl_SessionStarted;
|
||||
_recognitionControl.SessionEnded += _recognitionControl_SessionEnded;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void EmitEvent(EProcessingEvent @event)
|
||||
{
|
||||
|
||||
var @eventActions = _cameraSettings.ProcessingEvents.First(x => x.Event == @event);
|
||||
var actions = @eventActions.Actions;
|
||||
if (_mainWindowVm.TestMode)
|
||||
{
|
||||
var testModeActions = _cameraSettings.TestModeOverride;
|
||||
var testModePins = testModeActions.Select(x => x.Pin).ToList();
|
||||
actions = actions.Where(x => !testModePins.Contains(x.Pin)).ToList();
|
||||
actions.AddRange(testModeActions);
|
||||
}
|
||||
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
_mainModule.SetOutput(action.Pin, !action.Low);
|
||||
if (action.Pulse)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(_settings.PulseLength);
|
||||
_mainModule.SetOutput(action.Pin, action.Low);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void _recognitionControl_SessionEnded(SessionEndedEvent obj)
|
||||
{
|
||||
EmitEvent(EProcessingEvent.SessionEnded);
|
||||
|
||||
}
|
||||
|
||||
private void _recognitionControl_SessionStarted(SessionStartedEvent obj)
|
||||
{
|
||||
EmitEvent(EProcessingEvent.SessionStarted);
|
||||
}
|
||||
|
||||
private void _recognitionControl_ImageProcessed(Common.Commands.ImageProcessedEvent obj)
|
||||
{
|
||||
|
||||
if (obj.HasError)
|
||||
{
|
||||
EmitEvent(EProcessingEvent.ErrorOccurred);
|
||||
}
|
||||
else
|
||||
{
|
||||
EmitEvent(EProcessingEvent.GoodOccured);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user