io commander

This commit is contained in:
meelstorm
2025-07-19 15:57:59 +02:00
parent 40d74d6da6
commit cd70088d9a
46 changed files with 2198 additions and 28 deletions

View File

@@ -0,0 +1,62 @@
using System.Collections.Concurrent;
using VisionBuilder.UI.Common;
using VisionBuilder.UI.Common.Commands;
using VisionBuilder.UI.Common.RecipeProcessing;
using VisionBuilder.UI.Common.ViewModel;
using VisionBuilder.UI.IOCommander.Interfaces;
using VisionBuilder.UI.IOCommander.Settings;
namespace VisionBuilder.UI.IOCommander.Modules;
public class IOCommanderModule:IVisionBuilderModule
{
private readonly IOCommanderSettings _settings;
private readonly IIOCommanderDebugViewService _debugViewService;
private IOCommander? _ioCommander;
public IOCommanderModule(IOCommanderSettings settings, IIOCommanderDebugViewService debugViewService)
{
_settings = settings;
_debugViewService = debugViewService;
}
public void InitializeModule()
{
if (!_settings.EmulationMode)
{
_ioCommander = new IOCommander(_settings.Port);
_ioCommander.OnPinChanged += OnPinChanged;
}
if(_settings.ShowDebugView)_debugViewService.ShowDebugView();
}
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
private void OnPinChanged(int arg1, bool arg2)
{
_pinStates.TryAdd(arg1, arg2);
_debugViewService.SetInputPinStatus(arg1, arg2);
}
public void SetOutput(int pin, bool value)
{
if (_ioCommander != null)
{
_ioCommander.SetPins(pin, value);
}
_debugViewService.SetOutputPinStatus(pin,value);
}
public bool GetInput(int pin)
{
if (_ioCommander == null) return false;
var found=_pinStates.TryGetValue(pin, out var value);
if (found)
{
return value;
}
return false;
}
}