iocommander input and virtual input
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using VisionBuilder.UI.Common;
|
||||
using VisionBuilder.UI.IOCommander.Interfaces;
|
||||
|
||||
namespace VisionBuilder.UI.IOCommander.Windows
|
||||
{
|
||||
public partial class IOCommanderVirtualInput : Form, IIOCommander
|
||||
{
|
||||
private CheckBox[] _checkBoxes;
|
||||
|
||||
public IOCommanderVirtualInput()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeCheckboxes();
|
||||
}
|
||||
|
||||
public BitArray PinState { get; set; } = new BitArray(20);
|
||||
public event Action<int, bool>? OnPinChanged = delegate { };
|
||||
|
||||
public void SetPins(int pin, bool state)
|
||||
{
|
||||
// This is a dummy function as per requirement
|
||||
}
|
||||
|
||||
private void InitializeCheckboxes()
|
||||
{
|
||||
// Set form properties
|
||||
this.Text = "IO Commander Virtual Input";
|
||||
this.ClientSize = new Size(200, 500);
|
||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.StartPosition = FormStartPosition.Manual;
|
||||
this.Location = new Point(350, 50); // Set a fixed position for the form
|
||||
|
||||
// Create a panel to contain checkboxes with scrolling if needed
|
||||
Panel panel = new Panel
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
AutoScroll = true
|
||||
};
|
||||
this.Controls.Add(panel);
|
||||
|
||||
// Initialize checkboxes
|
||||
_checkBoxes = new CheckBox[20];
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
int pinNumber = i + 1; // Pins are 1-indexed
|
||||
_checkBoxes[i] = new CheckBox
|
||||
{
|
||||
Text = pinNumber.ToString(),
|
||||
Location = new Point(20, 20 + (i * 22)),
|
||||
Size = new Size(150, 20),
|
||||
Tag = pinNumber, // Store the pin number in Tag for easy reference
|
||||
};
|
||||
|
||||
// Add event handler
|
||||
_checkBoxes[i].CheckedChanged += CheckBox_CheckedChanged;
|
||||
|
||||
panel.Controls.Add(_checkBoxes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckBox_CheckedChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is CheckBox checkBox)
|
||||
{
|
||||
int pin = (int)checkBox.Tag;
|
||||
bool state = checkBox.Checked;
|
||||
|
||||
// Update the BitArray
|
||||
PinState.Set(pin - 1, state); // Adjust for 0-based indexing in BitArray
|
||||
|
||||
// Trigger the event
|
||||
OnPinChanged?.Invoke(pin, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void OnShown(EventArgs e)
|
||||
{
|
||||
TopMost= true;
|
||||
Focus();
|
||||
TopMost = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user