iocommander input and virtual input
This commit is contained in:
@@ -14,22 +14,54 @@ public class IOCommanderCameraModule: IVisionBuilderModule
|
||||
private readonly IOCommanderCameraSettings _cameraSettings;
|
||||
private readonly IRecognitionControl _recognitionControl;
|
||||
private readonly MainWindowVM _mainWindowVm;
|
||||
private readonly SingleCameraVM _cameraVm;
|
||||
|
||||
public IOCommanderCameraModule(IOCommanderModule mainModule, IOCommanderSettings settings, IOCommanderCameraSettings cameraSettings, IRecognitionControl recognitionControl, MainWindowVM mainWindowVm)
|
||||
public IOCommanderCameraModule(IOCommanderModule mainModule, IOCommanderSettings settings, IOCommanderCameraSettings cameraSettings, IRecognitionControl recognitionControl, MainWindowVM mainWindowVm, SingleCameraVM cameraVm)
|
||||
{
|
||||
_mainModule = mainModule;
|
||||
_settings = settings;
|
||||
_cameraSettings = cameraSettings;
|
||||
_recognitionControl = recognitionControl;
|
||||
_mainWindowVm = mainWindowVm;
|
||||
_cameraVm = cameraVm;
|
||||
|
||||
_recognitionControl.ImageProcessed += _recognitionControl_ImageProcessed;
|
||||
_recognitionControl.SessionStarted += _recognitionControl_SessionStarted;
|
||||
_recognitionControl.SessionEnded += _recognitionControl_SessionEnded;
|
||||
mainModule.OnPinChangedEvent += MainModule_OnPinChangedEvent;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ProcessCommand(EGPIOCommand command)
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case EGPIOCommand.Start:
|
||||
if(_cameraVm.StartCommand.CanExecute(null))
|
||||
{
|
||||
_cameraVm.StartCommand.Execute(null);
|
||||
}
|
||||
break;
|
||||
case EGPIOCommand.Stop:
|
||||
if(_cameraVm.StopCommand.CanExecute(null))
|
||||
{
|
||||
_cameraVm.StopCommand.Execute(null);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(command), command, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void MainModule_OnPinChangedEvent(int arg1, bool arg2)
|
||||
{
|
||||
var @event = _cameraSettings.GPIOCommands.FirstOrDefault(x => x.Pin == arg1 && x.OnHigh == arg2);
|
||||
if (@event != null)
|
||||
{
|
||||
ProcessCommand(@event.Command);
|
||||
}
|
||||
}
|
||||
|
||||
private void EmitEvent(EProcessingEvent @event)
|
||||
{
|
||||
|
||||
@@ -12,28 +12,32 @@ namespace VisionBuilder.UI.IOCommander.Modules;
|
||||
public class IOCommanderModule:IVisionBuilderModule
|
||||
{
|
||||
private readonly IOCommanderSettings _settings;
|
||||
private readonly IIOCommanderFactory _factory;
|
||||
private readonly IIOCommanderDebugViewService _debugViewService;
|
||||
|
||||
private IOCommander? _ioCommander;
|
||||
public IOCommanderModule(IOCommanderSettings settings, IIOCommanderDebugViewService debugViewService)
|
||||
private IIOCommander? _ioCommander;
|
||||
public IOCommanderModule(IOCommanderSettings settings, IIOCommanderFactory factory, IIOCommanderDebugViewService debugViewService)
|
||||
{
|
||||
_settings = settings;
|
||||
_factory = factory;
|
||||
_debugViewService = debugViewService;
|
||||
}
|
||||
|
||||
public void InitializeModule()
|
||||
{
|
||||
if (!_settings.EmulationMode)
|
||||
{
|
||||
_ioCommander = new IOCommander(_settings.Port);
|
||||
_ioCommander.OnPinChanged += OnPinChanged;
|
||||
}
|
||||
_ioCommander = _factory.Create();
|
||||
_ioCommander.OnPinChanged += OnPinChanged;
|
||||
|
||||
if(_settings.ShowDebugView)_debugViewService.ShowDebugView();
|
||||
if (_settings.ShowDebugView)_debugViewService.ShowDebugView();
|
||||
|
||||
|
||||
}
|
||||
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
|
||||
public event Action<int, bool>? OnPinChangedEvent
|
||||
{
|
||||
add => _ioCommander!.OnPinChanged += value;
|
||||
remove => _ioCommander!.OnPinChanged -= value;
|
||||
}
|
||||
private void OnPinChanged(int arg1, bool arg2)
|
||||
{
|
||||
_pinStates.TryAdd(arg1, arg2);
|
||||
|
||||
Reference in New Issue
Block a user