-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugForm.cs
82 lines (73 loc) · 2.52 KB
/
DebugForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
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 ArchonLightingSystem.Models;
using ArchonLightingSystem.Interfaces;
using ArchonLightingSystem.Components;
using ArchonLightingSystem.UsbApplication;
namespace ArchonLightingSystem
{
public partial class DebugForm : Form
{
private UsbApp usbApp;
private DragWindowSupport dragSupport = new DragWindowSupport();
private int selectedAddressIdx = -1;
public DebugForm()
{
InitializeComponent();
cbo_DeviceAddress.DisplayMember = "Text";
cbo_DeviceAddress.ValueMember = "Value";
dragSupport.Initialize(this);
}
public void InitializeForm(UsbApp usbApplication)
{
usbApp = usbApplication;
var activeDevices = usbApp.UsbDevices
.Where(dev => dev.IsAttached && dev.AppIsInitialized && dev.AppData.DeviceControllerData?.IsInitialized == true)
.Select((dev) => new ComboBoxItem { Text = dev.AppData.DeviceControllerData.DeviceAddress.ToString(), Value = usbApp.UsbDevices.IndexOf(dev) })
.ToList();
activeDevices.ForEach(dev =>
{
cbo_DeviceAddress.Items.Add(dev);
});
if (cbo_DeviceAddress.Items.Count > 0)
{
cbo_DeviceAddress.SelectedIndex = 0;
}
}
public void UpdateFormData()
{
}
private void btn_ReadDebug_Click(object sender, EventArgs e)
{
if(selectedAddressIdx >= 0)
{
usbApp.GetDevice(selectedAddressIdx).AppData.ReadDebugPending = true;
updateFormTimer.Enabled = true;
}
}
private void updateFormTimer_Tick(object sender, EventArgs e)
{
txt_Debug.Text += usbApp.GetDevice(selectedAddressIdx).AppData.Debug;
updateFormTimer.Enabled = false;
}
private void btn_ClearScreen_Click(object sender, EventArgs e)
{
txt_Debug.Text = "";
}
private void cbo_DeviceAddress_SelectedIndexChanged(object sender, EventArgs e)
{
selectedAddressIdx = ((ComboBoxItem)((ComboBox)sender).SelectedItem).Value;
}
private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}
}
}