This commit is contained in:
EugeneTes
2026-02-17 10:11:33 +01:00
parent e133942594
commit 2bac7140a4
11 changed files with 82 additions and 27 deletions

View File

@@ -30,23 +30,42 @@ public class IOCommanderModule:IVisionBuilderModule
{
_ioCommander = _factory.Create();
_ioCommander.OnPinChanged += OnPinChanged;
BroadcastInitialPinStates();
}
catch (Exception e)
{
Log.Warning("IOCommander did non load: {e}",e);
_ioCommander= null;
}
if (_settings.ShowDebugView)_debugViewService.ShowDebugView();
}
private void BroadcastInitialPinStates()
{
if (_ioCommander == null) return;
Task.Run(async () =>
{
// Wait for the first poll cycle to populate PinState
for (int attempt = 0; attempt < 10 && _ioCommander?.PinState == null; attempt++)
{
await Task.Delay(200);
}
if (_ioCommander?.PinState == null) return;
for (int i = 0; i < _ioCommander.PinState.Length; i++)
{
OnPinChanged(i + 1, _ioCommander.PinState[i]);
}
});
}
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
public event Action<int, bool>? OnPinChangedEvent = delegate { };
private void OnPinChanged(int arg1, bool arg2)
{
_pinStates.TryAdd(arg1, arg2);
_pinStates[arg1] = arg2;
_debugViewService.SetInputPinStatus(arg1, arg2);
OnPinChangedEvent?.Invoke(arg1, arg2);
}