diff --git a/Hawkeye.VisionBuilder/Hawkeye.VisionBuilder.csproj b/Hawkeye.VisionBuilder/Hawkeye.VisionBuilder.csproj index 9891cd5..8cc3630 100644 --- a/Hawkeye.VisionBuilder/Hawkeye.VisionBuilder.csproj +++ b/Hawkeye.VisionBuilder/Hawkeye.VisionBuilder.csproj @@ -16,7 +16,6 @@ - diff --git a/VisionBuilder.UI.Common/Processing/BaseRecognitionControl.cs b/VisionBuilder.UI.Common/Processing/BaseRecognitionControl.cs index 0e7d743..97b4138 100644 --- a/VisionBuilder.UI.Common/Processing/BaseRecognitionControl.cs +++ b/VisionBuilder.UI.Common/Processing/BaseRecognitionControl.cs @@ -40,6 +40,8 @@ public abstract class BaseRecognitionControl: IRecognitionControl public RecipeData CurrentRecipe => _currentRecipe; + public ILoadingService LoadingService => _loadingService; + private DateTime _startTime; public void Start() @@ -141,7 +143,7 @@ public abstract class BaseRecognitionControl: IRecognitionControl private async Task Loop(CancellationToken token) { - // Start the recognition process using the Hawkeye library + while (!token.IsCancellationRequested) { diff --git a/VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs b/VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs index b6a4986..e9703d8 100644 --- a/VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs +++ b/VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs @@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input; using OpenCvSharp; using VisionBuilder.UI.Common.Commands; using VisionBuilder.UI.Common.Commands.Interfaces; +using VisionBuilder.UI.Common.Services; using VisionBuilder.UI.Common.ViewModel.Classes; using VisionBuilder.UI.Common.ViewModel.Interfaces.UI; using static System.Runtime.InteropServices.JavaScript.JSType; @@ -16,12 +17,14 @@ public partial class ErrorPreviewVM:ObservableObject private ErrorData _errorData; private readonly ILearningTool _learningTool; + private readonly IPasswordInputService _passwordInputService; - [ObservableProperty] private string _recipeName; + private readonly UIConfiguration _uiConfiguration; + [ObservableProperty] private bool _learnButtonVisible; @@ -37,13 +40,15 @@ public partial class ErrorPreviewVM:ObservableObject [ObservableProperty] private Mat _imageAnalysis; - public ErrorPreviewVM(ErrorsVM errorsVm, ErrorData errorData, string recipeName, UIConfiguration uiConfiguration, ILearningTool learningTool) + public ErrorPreviewVM(ErrorsVM errorsVm, ErrorData errorData, string recipeName, UIConfiguration uiConfiguration, ILearningTool learningTool, IPasswordInputService passwordInputService) { _errorsVm = errorsVm; _errorData = errorData; _recipeName = recipeName; + _uiConfiguration = uiConfiguration; _learningTool = learningTool; - + _passwordInputService = passwordInputService; + UpdateData(); } @@ -95,6 +100,11 @@ public partial class ErrorPreviewVM:ObservableObject [RelayCommand(CanExecute = nameof(LearnButtonVisible))] public void Learn() { + if (string.IsNullOrEmpty(_uiConfiguration.AdminPassword)) + { + var passwordOk= _passwordInputService.GetPassword()==_uiConfiguration.AdminPassword; + if (!passwordOk) return; + } _learningTool.Learn(_errorData.RecipeName, _errorData.ImageOriginal); } diff --git a/VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs b/VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs index c3de511..377a919 100644 --- a/VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs +++ b/VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using VisionBuilder.UI.Common.Commands; using VisionBuilder.UI.Common.Commands.Interfaces; +using VisionBuilder.UI.Common.Services; using VisionBuilder.UI.Common.ViewModel.Classes; using VisionBuilder.UI.Common.ViewModel.Interfaces.UI; @@ -11,12 +12,14 @@ public class ErrorsVM:IEventHandler, IEventHandler, IEventHandler? OnPinChanged = delegate { }; public void SetPins(int pin, bool state) @@ -35,7 +35,7 @@ namespace VisionBuilder.UI.IOCommander.Windows { // Set form properties this.Text = "IO Commander Virtual Input"; - this.ClientSize = new Size(200, 500); + this.ClientSize = new Size(200, 280); this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.StartPosition = FormStartPosition.Manual; @@ -50,11 +50,11 @@ namespace VisionBuilder.UI.IOCommander.Windows this.Controls.Add(panel); // Initialize checkboxes - _checkBoxes = new CheckBox[20]; + _checkBoxes = new CheckBox[10]; - for (int i = 0; i < 20; i++) + for (int i = 0; i < 10; i++) { - int pinNumber = i; // Pins are 1-indexed + int pinNumber = i + 1; // Pins are 1-indexed (1-10) _checkBoxes[i] = new CheckBox { Text = pinNumber.ToString(), @@ -77,8 +77,8 @@ namespace VisionBuilder.UI.IOCommander.Windows int pin = (int)checkBox.Tag; bool state = checkBox.Checked; - // Update the BitArray - PinState.Set(pin, state); // Adjust for 0-based indexing in BitArray + // Update the BitArray (convert 1-based pin to 0-based index) + PinState.Set(pin - 1, state); // Trigger the event OnPinChanged?.Invoke(pin, state); diff --git a/VisionBuilder.UI.IOCommander.Windows/WindowsIOCommanderDebugViewService.cs b/VisionBuilder.UI.IOCommander.Windows/WindowsIOCommanderDebugViewService.cs index 40a7d7e..3d42999 100644 --- a/VisionBuilder.UI.IOCommander.Windows/WindowsIOCommanderDebugViewService.cs +++ b/VisionBuilder.UI.IOCommander.Windows/WindowsIOCommanderDebugViewService.cs @@ -38,25 +38,25 @@ namespace VisionBuilder.UI.IOCommander.Windows this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(50, 50); - this.Size = new Size(280, 450); // Made wider to accommodate labels + this.Size = new Size(400, 350); // Made wider and adjusted height for 10 rows this.BackColor = Color.FromArgb(64, 64, 64); this.MinimizeBox = false; this.MaximizeBox = false; - // Create pin indicators for input pins 0-19 and output pins 0-19 (20 rows, 2 columns) - int pinSize = 18; - int spacing = 2; - int centerX = 140; // Center the graphics in the wider form - int startY = 10; + // Create pin indicators for input pins 1-10 and output pins 1-10 (10 rows, 2 columns) + int pinSize = 24; // Increased from 18 + int spacing = 4; // Increased from 2 + int centerX = 200; // Center the graphics in the wider form + int startY = 15; // Slightly more margin // Get label dictionaries for quick lookup var inputLabelDict = _settings.InputPinLabels?.ToDictionary(pl => pl.Pin, pl => pl.Label) ?? new Dictionary(); var outputLabelDict = _settings.OutputPinLabels?.ToDictionary(pl => pl.Pin, pl => pl.Label) ?? new Dictionary(); - for (int row = 0; row < 20; row++) + for (int row = 0; row < 10; row++) // Changed from 20 to 10 { - int inputPin = row; // Input pins numbered 0-19 - int outputPin = row; // Output pins numbered 0-19 + int inputPin = row + 1; // Input pins numbered 1-10 + int outputPin = row + 1; // Output pins numbered 1-10 // Left column (input pins) var leftIndicator = new PinIndicator(inputPin, true) @@ -81,9 +81,9 @@ namespace VisionBuilder.UI.IOCommander.Windows var leftLabel = new Label { Text = inputLabelText, - Location = new Point(5, startY + (row * (pinSize + spacing)) + 2), - Size = new Size(centerX - pinSize - spacing * 3 - 5, 14), - Font = new Font("Arial", 6, FontStyle.Bold), + Location = new Point(5, startY + (row * (pinSize + spacing)) + 4), // Adjusted vertical alignment + Size = new Size(centerX - pinSize - spacing * 3 - 5, 16), // Increased height from 14 + Font = new Font("Arial", 8, FontStyle.Bold), // Increased from 6 ForeColor = Color.White, BackColor = Color.Transparent, TextAlign = ContentAlignment.MiddleRight @@ -95,9 +95,9 @@ namespace VisionBuilder.UI.IOCommander.Windows var rightLabel = new Label { Text = outputLabelText, - Location = new Point(centerX + pinSize + spacing * 3, startY + (row * (pinSize + spacing)) + 2), - Size = new Size(this.Width - (centerX + pinSize + spacing * 3) - 10, 14), - Font = new Font("Arial", 6, FontStyle.Bold), + Location = new Point(centerX + pinSize + spacing * 3, startY + (row * (pinSize + spacing)) + 4), // Adjusted vertical alignment + Size = new Size(this.Width - (centerX + pinSize + spacing * 3) - 10, 16), // Increased height from 14 + Font = new Font("Arial", 8, FontStyle.Bold), // Increased from 6 ForeColor = Color.White, BackColor = Color.Transparent, TextAlign = ContentAlignment.MiddleLeft diff --git a/VisionBuilder.UI.IOCommander/IOCommander.cs b/VisionBuilder.UI.IOCommander/IOCommander.cs index 7c90ede..2894f1e 100644 --- a/VisionBuilder.UI.IOCommander/IOCommander.cs +++ b/VisionBuilder.UI.IOCommander/IOCommander.cs @@ -51,7 +51,7 @@ public class IOCommander : IIOCommander for (int i = 0; i < 8; i++) { if (arrcurrentPinsState[i] != arrreadState[i]) - OnPinChanged(i, arrreadState[i]); + OnPinChanged(i+1, arrreadState[i]); } } @@ -80,6 +80,7 @@ public class IOCommander : IIOCommander public void SetPins(int pin, bool state) { + pin -= 1; lock (this) { //Log.Logger.ForContext().Verbose("Setting pin {pin} to {state}", pin, state); diff --git a/VisionBuilder.UI.IOCommander/Settings/IOCommanderSettings.cs b/VisionBuilder.UI.IOCommander/Settings/IOCommanderSettings.cs index 84636be..34f5d08 100644 --- a/VisionBuilder.UI.IOCommander/Settings/IOCommanderSettings.cs +++ b/VisionBuilder.UI.IOCommander/Settings/IOCommanderSettings.cs @@ -4,12 +4,12 @@ using VisionBuilder.UI.Common; namespace VisionBuilder.UI.IOCommander.Settings; -public class IOCommanderSettings: ISettings +public class IOCommanderSettings : ISettings { public IOCommanderCameraSettings[] Cameras { get; } public int PulseLength { get; set; } = 100; public bool ShowDebugView { get; set; } = false; - public string Port { get; set; }="COM3"; + public string Port { get; set; } = "COM3"; public bool Enabled { get; set; } public List GlobalEvents { get; set; } = @@ -28,10 +28,12 @@ public class IOCommanderSettings: ISettings settings.RegisterSimple(this, () => Port, "IOCommander", nameof(Port)); settings.RegisterSimple(this, () => PulseLength, "IOCommander", nameof(PulseLength)); settings.RegisterSimple(this, () => ShowDebugView, "IOCommander", nameof(ShowDebugView)); - + settings.RegisterSimple(this, () => Enabled, "IOCommander", nameof(Enabled)); + foreach (IOCommanderProcessingEvent @event in GlobalEvents) { - settings.RegisterSimple(@event, () => @event.Actions, "IOCommander/Global outputs/" + @event.Event.ToString(), nameof(@event.Actions)); + settings.RegisterSimple(@event, () => @event.Actions, + "IOCommander/Global outputs/" + @event.Event.ToString(), nameof(@event.Actions)); } } } \ No newline at end of file diff --git a/VisionBuilder.UI.Recipes.HawkeyeRecipe/HawkeyeRecognitionControl.cs b/VisionBuilder.UI.Recipes.HawkeyeRecipe/HawkeyeRecognitionControl.cs index 03a4db7..090ebd2 100644 --- a/VisionBuilder.UI.Recipes.HawkeyeRecipe/HawkeyeRecognitionControl.cs +++ b/VisionBuilder.UI.Recipes.HawkeyeRecipe/HawkeyeRecognitionControl.cs @@ -17,7 +17,7 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe { private readonly IImageSource _imageSource; private readonly HawkeyeRecognitionSettings _recognitionConfiguration; - private readonly ILoadingService _loadingService; + private CancellationTokenSource _cts; private Task _loopTask; @@ -31,7 +31,7 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe public override List GetRecipesData() { - _loadingService.StartLoading($"Loading recipes for {_recognitionConfiguration.CameraName}..."); + LoadingService.StartLoading($"Loading recipes for {_recognitionConfiguration.CameraName}..."); try { var files = WorkflowRecipeHelper.ListRecipeFiles(_recognitionConfiguration.RecipeNameFilter); @@ -52,7 +52,7 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe } finally { - _loadingService.StopLoading($"Loading recipes for {_recognitionConfiguration.CameraName}..."); + LoadingService.StopLoading($"Loading recipes for {_recognitionConfiguration.CameraName}..."); } } @@ -95,7 +95,7 @@ namespace VisionBuilder.UI.Recipes.HawkeyeRecipe _workflow.Context.GraphicsElements.ForEach(x => x.Draw(canvas)); var originalImage = _workflow.Context.LastCameraImage.ImageData; - var analysisImage = _workflow.Context.ActiveImage.ImageData; + var analysisImage = annotated; var cameraOperation = _workflow.Operations.FirstOrDefault(x => x is GetImageOperation); TimeSpan cameraTime = TimeSpan.FromMilliseconds(0); diff --git a/VisionBuilder.UI.Windows.Test/VisionBuilder.UI.Windows.Uno.csproj b/VisionBuilder.UI.Windows.Test/VisionBuilder.UI.Windows.Uno.csproj index 7590cae..747a63d 100644 --- a/VisionBuilder.UI.Windows.Test/VisionBuilder.UI.Windows.Uno.csproj +++ b/VisionBuilder.UI.Windows.Test/VisionBuilder.UI.Windows.Uno.csproj @@ -8,7 +8,7 @@ enable Inspectron icon-512.ico false - 1.0.3 + 1.0.4