forked from computergeek1507/ColorlightPlugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStatusForm.cs
152 lines (127 loc) · 3.5 KB
/
StatusForm.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using Newtonsoft.Json;
using PcapDotNet.Core;
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;
namespace ColorlightPlugin
{
public partial class StatusForm : Form
{
private ColorlightPlugin _plugin;
public event EventHandler ReloadSettings;
int testCount = 0;
public StatusForm(ColorlightPlugin plugin)
{
_plugin = plugin;
InitializeComponent();
}
void OnReloadSettings() => ReloadSettings.Invoke(this, null);
private void StatusForm_Load(object sender, EventArgs e)
{
}
public void StatusFormMeasage(object sender, string e)
{
listBox1.Items.Add(e);
}
public void ReloadStatusBox(object sender, EventArgs e)
{
SetStatusBox();
}
private void buttonSave_Click(object sender, EventArgs e)
{
PluginSettings settings = new PluginSettings(_plugin._showDir);
if (outputComboBox.SelectedIndex != -1 && outputComboBox.SelectedIndex < _plugin._allDevices.Count)
settings.EthernetOutput = _plugin._allDevices[outputComboBox.SelectedIndex].Name;
settings.MatrixName = matrixComboBox.SelectedItem.ToString();
settings.Brightness = decimal.ToInt32(brightnessNumericUpDown.Value);
settings.Save();
OnReloadSettings();
}
private void StatusForm_Shown(object sender, EventArgs e)
{
LoadSettings();
}
private void LoadSettings()
{
matrixComboBox.Items.Clear();
outputComboBox.Items.Clear();
brightnessNumericUpDown.Value = _plugin._brightness;
string result;
_plugin.xSchedule_Action("GetMatrices", "", "", out result);
var product = new { Name = "", Price = 0 };
MatricesData matrices = JsonConvert.DeserializeObject<MatricesData>(result);
if (matrices.Matrices.Length == 0)
{
listBox1.Items.Add("No Matrices Defined in xSchedule.");
}
foreach (var m in matrices.Matrices)
{
matrixComboBox.Items.Add(m);
}
int indexM = matrixComboBox.FindString(_plugin._selectedMatrix);
if (indexM != -1)
{
matrixComboBox.SelectedIndex = indexM;
}
int index = -1;
if (_plugin._allDevices.Count == 0)
{
listBox1.Items.Add("No interfaces found! Make sure WinPcap is installed.");
}
else
{
for (int i = 0; i != _plugin._allDevices.Count; ++i)
{
LivePacketDevice device = _plugin._allDevices[i];
string fullName = device.Name;
if (device.Description != null)
fullName += (" (" + device.Description + ")");
outputComboBox.Items.Add(fullName);
if(device.Name == _plugin._selectedOutput)
{
index = i;
}
}
}
if (index != -1)
{
outputComboBox.SelectedIndex = index;
}
SetStatusBox();
}
private void SetStatusBox()
{
textBoxStatus.Text = string.Format("Height:{0} Width:{1} Start Channel:{2} Channels:{3}",
_plugin._panelHeight, _plugin._panelWidth, _plugin._startChannel,
(_plugin._panelHeight * _plugin._panelWidth * 3));
}
private void timer1_Tick(object sender, EventArgs e)
{
if (checkBoxTest.Checked)
{
if (testCount > 2) testCount = 0;
_plugin.TestPanel(0xFF, testCount);
++testCount;
}
else
{
string result;
_plugin.xSchedule_Action("GetPlayingStatus", "", "", out result);
//listBox1.Items.Add(result.ToString());
if (result.Contains("\"status\":\"idle\""))
{
_plugin.TestPanel(0x00, 0);
}
}
}
private void checkBoxTest_CheckedChanged(object sender, EventArgs e)
{
}
}
}