Skip to content

Commit

Permalink
Fixed built issues
Browse files Browse the repository at this point in the history
Added disconnect/reconnect handling and no encoder message
  • Loading branch information
cbrauers committed May 31, 2024
1 parent 0bc5dea commit 29711fb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
12 changes: 0 additions & 12 deletions EncoderVisualizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,18 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="testboi.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="testboi.Designer.cs">
<DependentUpon>testboi.cs</DependentUpon>
</Compile>
<Compile Include="VKBDeviceTab.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="VKB\VKBConnectionHandler.cs" />
<Compile Include="VKB\VKBDevice.cs" />
<Compile Include="VKB\VKBEncoder.cs" />
<Compile Include="VKB\VKBHidReport.cs" />
<EmbeddedResource Include="MainWindow.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="testboi.resx">
<DependentUpon>testboi.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
18 changes: 18 additions & 0 deletions MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;

namespace EncoderVisualizer
{
public class MainWindow: Form
{
delegate VKBDeviceTab AddTabCallback(VKBDevice dev);
delegate void RemoveTabCallback(VKBDevice dev);
public static MainWindow Instance { get { return actualInstance ?? (actualInstance = new MainWindow()); } }
private static MainWindow actualInstance = null;
private readonly TabControl Devices;
Expand All @@ -27,11 +30,26 @@ private MainWindow() {
}
public VKBDeviceTab AddDevice(VKBDevice dev)
{
if (InvokeRequired)
{
AddTabCallback d = new AddTabCallback(AddDevice);
return Invoke(d, new object[] { dev }) as VKBDeviceTab;
}
VKBDeviceTab tab = new VKBDeviceTab(dev);
tab.Text = dev.DeviceName;
Devices.Controls.Add(tab);
return tab;
}
public void RemoveDevice(VKBDevice dev)
{
if (InvokeRequired)
{
RemoveTabCallback d = new RemoveTabCallback(RemoveDevice);
Invoke(d, new object[] { dev });
return;
}
Devices.Controls.Remove(dev.Tab);
}

}
}
21 changes: 21 additions & 0 deletions VKB/VKBConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,31 @@ private VKBConnectionHandler() {
public void Startup(Object sender, EventArgs e)
{
IEnumerable<HidDevice> DevList = DeviceList.Local.GetHidDevices(vendorID: 0x231D);
DeviceList.Local.Changed += DevicesChanged;
foreach (HidDevice dev in DevList)
{
Devices.Add(new VKBDevice(dev));
}
}
public void DevicesChanged(Object sender, EventArgs e)
{
IEnumerable<HidDevice> DevList = DeviceList.Local.GetHidDevices(vendorID: 0x231D);
List<VKBDevice> lostDevices = new List<VKBDevice>();
foreach (VKBDevice dev in Devices)
{
if(!DevList.Contains(dev.HidDev)) lostDevices.Add(dev);
}
foreach (VKBDevice dev in lostDevices) {
MainWindow.Instance.RemoveDevice(dev);
Devices.Remove(dev);
}
foreach (HidDevice dev in DevList)
{
if(Devices.Find(d => d.HidDev == dev) == null)
{
Devices.Add(new VKBDevice(dev));
}
}
}
}
}
2 changes: 1 addition & 1 deletion VKB/VKBDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class VKBDevice
public HidDevice HidDev;
private HidStream Stream;
private HidDeviceInputReceiver Receiver;
private VKBDeviceTab Tab;
public VKBDeviceTab Tab;
private SortedList<byte, VKBEncoder> Encoders = new SortedList<byte, VKBEncoder>();
private byte lastSeqNo;
public VKBDevice(HidDevice dev) {
Expand Down
23 changes: 21 additions & 2 deletions VKBDeviceTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class VKBDeviceTab: TabPage
private readonly TableLayoutPanel TLayout;
private readonly FlowLayoutPanel FLayout;
private readonly Label TBox;
private readonly Label NoEncs;
private int encCount = 0;
public VKBDeviceTab(VKBDevice dev) {
TLayout = new TableLayoutPanel {
Dock = DockStyle.Fill,
Expand All @@ -29,18 +31,35 @@ public VKBDeviceTab(VKBDevice dev) {
Dock = DockStyle.Top,
Text = $"{dev.DeviceName}, PID {dev.HidDev.ProductID:X4}, S/N {dev.SerialNumber}"
};
NoEncs = new Label
{
Dock = DockStyle.Fill,
Text = "No Encoders detected. Make sure that the device:\n" +
"1. is running nJoy32 firmware 2.17.9 or newer\n" +
"2. has \"Virtual BUS over USB\" enabled in VKBDevCfg (and the setting has been Set to the device)\n" +
"3. has encoders configured on the physical button layer",
TextAlign = System.Drawing.ContentAlignment.MiddleLeft,
Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 16, System.Drawing.FontStyle.Bold)
};

Controls.Add(TLayout);
TLayout.Controls.Add(TBox);
TLayout.Controls.Add(FLayout);
TLayout.Controls.Add(NoEncs);

}
public EncoderBox AddEncoderBox(VKBEncoder enc)
{
if (FLayout.InvokeRequired)
if (FLayout.InvokeRequired || TLayout.InvokeRequired)
{
AddEncoderBoxCallback d = new AddEncoderBoxCallback(AddEncoderBox);
return this.Invoke(d, new object[] { enc }) as EncoderBox;
}
if(encCount == 0)
{
TLayout.Controls.Remove(NoEncs);
TLayout.Controls.Add(FLayout);
}
encCount++;
EncoderBox box = new EncoderBox(enc);
FLayout.Controls.Add(box);
return box;
Expand Down

0 comments on commit 29711fb

Please sign in to comment.