Skip to content

Commit 29711fb

Browse files
committed
Fixed built issues
Added disconnect/reconnect handling and no encoder message
1 parent 0bc5dea commit 29711fb

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

EncoderVisualizer.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,18 @@
6565
<DesignTime>True</DesignTime>
6666
<DependentUpon>Resources.resx</DependentUpon>
6767
</Compile>
68-
<Compile Include="testboi.cs">
69-
<SubType>Form</SubType>
70-
</Compile>
71-
<Compile Include="testboi.Designer.cs">
72-
<DependentUpon>testboi.cs</DependentUpon>
73-
</Compile>
7468
<Compile Include="VKBDeviceTab.cs">
7569
<SubType>Component</SubType>
7670
</Compile>
7771
<Compile Include="VKB\VKBConnectionHandler.cs" />
7872
<Compile Include="VKB\VKBDevice.cs" />
7973
<Compile Include="VKB\VKBEncoder.cs" />
8074
<Compile Include="VKB\VKBHidReport.cs" />
81-
<EmbeddedResource Include="MainWindow.resx">
82-
<DependentUpon>MainWindow.cs</DependentUpon>
83-
</EmbeddedResource>
8475
<EmbeddedResource Include="Properties\Resources.resx">
8576
<Generator>ResXFileCodeGenerator</Generator>
8677
<SubType>Designer</SubType>
8778
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
8879
</EmbeddedResource>
89-
<EmbeddedResource Include="testboi.resx">
90-
<DependentUpon>testboi.cs</DependentUpon>
91-
</EmbeddedResource>
9280
<None Include="packages.config" />
9381
<None Include="Properties\Settings.settings">
9482
<Generator>SettingsSingleFileGenerator</Generator>

MainWindow.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Windows.Forms;
8+
using static System.Net.Mime.MediaTypeNames;
89

910
namespace EncoderVisualizer
1011
{
1112
public class MainWindow: Form
1213
{
14+
delegate VKBDeviceTab AddTabCallback(VKBDevice dev);
15+
delegate void RemoveTabCallback(VKBDevice dev);
1316
public static MainWindow Instance { get { return actualInstance ?? (actualInstance = new MainWindow()); } }
1417
private static MainWindow actualInstance = null;
1518
private readonly TabControl Devices;
@@ -27,11 +30,26 @@ private MainWindow() {
2730
}
2831
public VKBDeviceTab AddDevice(VKBDevice dev)
2932
{
33+
if (InvokeRequired)
34+
{
35+
AddTabCallback d = new AddTabCallback(AddDevice);
36+
return Invoke(d, new object[] { dev }) as VKBDeviceTab;
37+
}
3038
VKBDeviceTab tab = new VKBDeviceTab(dev);
3139
tab.Text = dev.DeviceName;
3240
Devices.Controls.Add(tab);
3341
return tab;
3442
}
43+
public void RemoveDevice(VKBDevice dev)
44+
{
45+
if (InvokeRequired)
46+
{
47+
RemoveTabCallback d = new RemoveTabCallback(RemoveDevice);
48+
Invoke(d, new object[] { dev });
49+
return;
50+
}
51+
Devices.Controls.Remove(dev.Tab);
52+
}
3553

3654
}
3755
}

VKB/VKBConnectionHandler.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,31 @@ private VKBConnectionHandler() {
1616
public void Startup(Object sender, EventArgs e)
1717
{
1818
IEnumerable<HidDevice> DevList = DeviceList.Local.GetHidDevices(vendorID: 0x231D);
19+
DeviceList.Local.Changed += DevicesChanged;
1920
foreach (HidDevice dev in DevList)
2021
{
2122
Devices.Add(new VKBDevice(dev));
2223
}
2324
}
25+
public void DevicesChanged(Object sender, EventArgs e)
26+
{
27+
IEnumerable<HidDevice> DevList = DeviceList.Local.GetHidDevices(vendorID: 0x231D);
28+
List<VKBDevice> lostDevices = new List<VKBDevice>();
29+
foreach (VKBDevice dev in Devices)
30+
{
31+
if(!DevList.Contains(dev.HidDev)) lostDevices.Add(dev);
32+
}
33+
foreach (VKBDevice dev in lostDevices) {
34+
MainWindow.Instance.RemoveDevice(dev);
35+
Devices.Remove(dev);
36+
}
37+
foreach (HidDevice dev in DevList)
38+
{
39+
if(Devices.Find(d => d.HidDev == dev) == null)
40+
{
41+
Devices.Add(new VKBDevice(dev));
42+
}
43+
}
44+
}
2445
}
2546
}

VKB/VKBDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class VKBDevice
1919
public HidDevice HidDev;
2020
private HidStream Stream;
2121
private HidDeviceInputReceiver Receiver;
22-
private VKBDeviceTab Tab;
22+
public VKBDeviceTab Tab;
2323
private SortedList<byte, VKBEncoder> Encoders = new SortedList<byte, VKBEncoder>();
2424
private byte lastSeqNo;
2525
public VKBDevice(HidDevice dev) {

VKBDeviceTab.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class VKBDeviceTab: TabPage
1414
private readonly TableLayoutPanel TLayout;
1515
private readonly FlowLayoutPanel FLayout;
1616
private readonly Label TBox;
17+
private readonly Label NoEncs;
18+
private int encCount = 0;
1719
public VKBDeviceTab(VKBDevice dev) {
1820
TLayout = new TableLayoutPanel {
1921
Dock = DockStyle.Fill,
@@ -29,18 +31,35 @@ public VKBDeviceTab(VKBDevice dev) {
2931
Dock = DockStyle.Top,
3032
Text = $"{dev.DeviceName}, PID {dev.HidDev.ProductID:X4}, S/N {dev.SerialNumber}"
3133
};
34+
NoEncs = new Label
35+
{
36+
Dock = DockStyle.Fill,
37+
Text = "No Encoders detected. Make sure that the device:\n" +
38+
"1. is running nJoy32 firmware 2.17.9 or newer\n" +
39+
"2. has \"Virtual BUS over USB\" enabled in VKBDevCfg (and the setting has been Set to the device)\n" +
40+
"3. has encoders configured on the physical button layer",
41+
TextAlign = System.Drawing.ContentAlignment.MiddleLeft,
42+
Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 16, System.Drawing.FontStyle.Bold)
43+
};
44+
3245
Controls.Add(TLayout);
3346
TLayout.Controls.Add(TBox);
34-
TLayout.Controls.Add(FLayout);
47+
TLayout.Controls.Add(NoEncs);
3548

3649
}
3750
public EncoderBox AddEncoderBox(VKBEncoder enc)
3851
{
39-
if (FLayout.InvokeRequired)
52+
if (FLayout.InvokeRequired || TLayout.InvokeRequired)
4053
{
4154
AddEncoderBoxCallback d = new AddEncoderBoxCallback(AddEncoderBox);
4255
return this.Invoke(d, new object[] { enc }) as EncoderBox;
4356
}
57+
if(encCount == 0)
58+
{
59+
TLayout.Controls.Remove(NoEncs);
60+
TLayout.Controls.Add(FLayout);
61+
}
62+
encCount++;
4463
EncoderBox box = new EncoderBox(enc);
4564
FLayout.Controls.Add(box);
4665
return box;

0 commit comments

Comments
 (0)