This commit is contained in:
meelstorm
2025-09-24 16:27:07 +02:00
parent 0ebe629922
commit 87c1145744
11 changed files with 59 additions and 41 deletions

View File

@@ -23,7 +23,7 @@ namespace VisionBuilder.UI.IOCommander.Windows
InitializeCheckboxes();
}
public BitArray PinState { get; set; } = new BitArray(20);
public BitArray PinState { get; set; } = new BitArray(10);
public event Action<int, bool>? 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);

View File

@@ -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<int, string>();
var outputLabelDict = _settings.OutputPinLabels?.ToDictionary(pl => pl.Pin, pl => pl.Label) ?? new Dictionary<int, string>();
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