-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
499 lines (428 loc) · 16.1 KB
/
Form1.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
using System;
using System.Windows.Forms;
using System.IO.Ports;
using System.Drawing;
using System.Windows.Input;
namespace SerialKiller3000
{
public partial class Form1 : Form
{
public static Form1 form1 = new Form1();
PreferencesWindow preferencesWindow = new PreferencesWindow();
bool preferencesOpen = false;
//borderless form move stuff
private bool _dragging = false;
private Point _start_point = new Point(0, 0);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
form1 = this; //holy shit, it took me some time to find out why nothing was working properly
tempControl1.TempControl_Load(null, null);
soundControl1.SoundControl_Load(null, null); //preload forms for devices to become available
EnableForms(false);
initMinimizeToTrayStuff();
baudBox.Text = "19200";
stuff.Serial.GetPorts();
foreach (var port in stuff.Serial.portlist)
{
portBox.Items.Add(port);
}
portBox.SelectedIndex = 0;
if (Properties.Settings.Default.Preferences_startMinimized) //start minimized or not
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
if (Properties.Settings.Default.Preferences_autoconnect) //connect automatically on load to the board or not
{
openport.Checked = true;
}
normalControl1.LoadSettingsNormalControl();
if (stuff.Serial.connected && Properties.Settings.Default.Preferences_autostart) //if already connected the selected mode will start
{
//System.Threading.Thread.Sleep(100);
//stuff.SettingsMisc.AutoLoad();
}
}
private void openport_CheckedChanged(object sender, EventArgs e)
{
if (openport.Checked)
{
stuff.Serial.Connect();
}
else
{
stuff.Serial.Disconnect();
}
}
public void EnableForms(bool b)
{
btnNormal.Enabled = b;
btnNormalPrefs.Enabled = b;
btnRainbow.Enabled = b;
//btnRainbowPrefs.Enabled = b;
btnBreathing.Enabled = b;
btnBreathingPrefs.Enabled = b;
btnDualBreathing.Enabled = b;
btnDualBreathingPrefs.Enabled = b;
btnSound.Enabled = b;
btnSoundPrefs.Enabled = b;
btnStrobe.Enabled = b;
btnStrobePrefs.Enabled = b;
btnTemp.Enabled = b;
btnTempPrefs.Enabled = b;
}
public void EnableCustomControls(bool b)
{
normalControl1.Enabled = b;
breathingControl1.Enabled = b;
strobeControl1.Enabled = b;
soundControl1.Enabled = b;
tempControl1.Enabled = b;
}
public void CustomControlsAreVisible(bool b)
{
normalControl1.Visible = b;
breathingControl1.Visible = b;
strobeControl1.Visible = b;
soundControl1.Visible = b;
tempControl1.Visible = b;
}
public void UncheckButtons()
{
foreach (Control c in Controls)
{
if (c is CheckBox && ((CheckBox)c).Checked == true)
{
((CheckBox)c).Checked = false;
}
}
}
#region Mode buttons
private void btnNormal_CheckedChanged(object sender, EventArgs e) //normal
{
if (btnNormal.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.normalModeActive;
EnableForms(false);
btnNormal.Enabled = true;
btnNormalPrefs.Enabled = true;
stuff.Serial.uart.Write("rgb " + normalControl1.r + "," + normalControl1.g + "," + normalControl1.b + ";");
}
else
{
stuff.Serial.RgbledOFF();
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
}
}
private void btnNormalPrefs_Click(object sender, EventArgs e) //normal prefs
{
SlidePanel(normalControl1);
}
private void btnRainbow_CheckedChanged(object sender, EventArgs e) //rainbow
{
int r = 255, g = 0, b = 0;
if (btnRainbow.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.RainbowActive;
EnableForms(false);
EnableCustomControls(false);
btnRainbow.Enabled = true;
btnRainbowPrefs.Enabled = true;
stuff.Serial.uart.Write("rgb " + 255 + "," + 0 + "," + 0 + ";"); //r max
while (btnRainbow.Enabled)
{
for (g = 0; g < 255 && btnRainbow.Enabled; g++) //g to max
{
stuff.Serial.uart.Write("rgb " + r + "," + stuff.Gamma.correction[g] + "," + b + ";");
Application.DoEvents();
}
for (r = 255; r >= 1 && btnRainbow.Enabled; r--) //r to 0
{
stuff.Serial.uart.Write("rgb " + stuff.Gamma.correction[r] + "," + g + "," + b + ";");
Application.DoEvents();
}
for (b = 0; b < 255 && btnRainbow.Enabled; b++) //b to max
{
stuff.Serial.uart.Write("rgb " + r + "," + g + "," + stuff.Gamma.correction[b] + ";");
Application.DoEvents();
}
for (g = 255; g >= 1 && btnRainbow.Enabled; g--) //g to 0
{
stuff.Serial.uart.Write("rgb " + r + "," + stuff.Gamma.correction[g] + "," + b + ";");
Application.DoEvents();
}
for (r = 0; r < 255 && btnRainbow.Enabled; r++) //r to max
{
stuff.Serial.uart.Write("rgb " + stuff.Gamma.correction[r] + "," + g + "," + b + ";");
Application.DoEvents();
}
for (b = 255; b >= 1 && btnRainbow.Enabled; b--) //b to 0
{
stuff.Serial.uart.Write("rgb " + r + "," + g + "," + stuff.Gamma.correction[b] + ";");
Application.DoEvents();
}
}
}
else
{
stuff.Serial.RgbledOFF();
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
EnableCustomControls(true);
}
}
private void btnRainbowPrefs_Click(object sender, EventArgs e) //rainbow prefs
{
}
private void btnBreathing_CheckedChanged(object sender, EventArgs e)
{
if (btnBreathing.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.breathingModeActive;
EnableForms(false);
EnableCustomControls(false);
btnBreathing.Enabled = true;
btnBreathingPrefs.Enabled = true;
breathingControl1.Enabled = true;
breathingControl1.BreathingStart(this, null);
}
else
{
breathingControl1.BreathingStop();
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
EnableCustomControls(true);
}
} //breathing
private void btnBreathingPrefs_Click(object sender, EventArgs e) //breathing prefs
{
SlidePanel(breathingControl1);
}
private void btnDualBreathing_CheckedChanged(object sender, EventArgs e) //dual breathing
{
}
private void btnDualBreathingPrefs_Click(object sender, EventArgs e) //dual breathing prefs
{
}
private void btnSound_CheckedChanged(object sender, EventArgs e) //sound
{
if (btnSound.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.SoundModeActive;
EnableForms(false);
EnableCustomControls(false);
btnSound.Enabled = true;
btnSoundPrefs.Enabled = true;
soundControl1.Enabled = true;
soundControl1.soundModeStart(null, null);
}
else
{
soundControl1.soundModeStop(null, null);
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
EnableCustomControls(true);
}
}
private void btnSoundPrefs_Click(object sender, EventArgs e) //sound prefs
{
SlidePanel(soundControl1);
}
private void btnStrobe_CheckedChanged(object sender, EventArgs e) //strobe
{
if (btnStrobe.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.strobeModeActive;
EnableForms(false);
EnableCustomControls(false);
btnStrobe.Enabled = true;
btnStrobePrefs.Enabled = true;
strobeControl1.Enabled = true;
strobeControl1.strobeModeStart(null, null);
}
else
{
strobeControl1.strobeModeStop(null, null);
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
EnableCustomControls(true);
}
}
private void btnStrobePrefs_Click(object sender, EventArgs e) //strobe prefs
{
SlidePanel(strobeControl1);
}
private void btnTemp_CheckedChanged(object sender, EventArgs e) //temp
{
if (btnTemp.Checked)
{
stuff.Mode = (int)stuff.ModeStatus.TempModeActive;
EnableForms(false);
EnableCustomControls(false);
btnTemp.Enabled = true;
btnTempPrefs.Enabled = true;
tempControl1.Enabled = true;
tempControl1.TempModeInit();
}
else
{
tempControl1.TempModeStop();
stuff.Mode = (int)stuff.ModeStatus.off;
EnableForms(true);
EnableCustomControls(true);
}
}
private void btnTempPrefs_Click(object sender, EventArgs e) //temp prefs
{
SlidePanel(tempControl1);
}
#endregion
#region minimize to tray
void initMinimizeToTrayStuff()
{
MenuItem open = new MenuItem("Open");
MenuItem Leds = new MenuItem("Leds");
MenuItem exit = new MenuItem("Exit");
ContextMenu cm = new ContextMenu();
Leds.MenuItems.Add(new MenuItem("On"));
Leds.MenuItems.Add(new MenuItem("Off"));
cm.MenuItems.Add(open);
cm.MenuItems.Add(Leds);
cm.MenuItems.Add(exit);
open.Click += new System.EventHandler(this.open_Click);
Leds.Click += new System.EventHandler(this.LedsOn_Click);
Leds.Click += new System.EventHandler(this.LedsOff_Click);
exit.Click += new System.EventHandler(this.exit_Click);
taskbarIcon.Visible = false;
taskbarIcon.ContextMenu = cm;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
this.Hide();
taskbarIcon.Visible = true;
}
else if (FormWindowState.Normal == this.WindowState)
{
taskbarIcon.Visible = false;
}
}
private void open_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void LedsOn_Click(object sender, EventArgs e)
{
MessageBox.Show("derp");
}
private void LedsOff_Click(object sender, EventArgs e)
{
MessageBox.Show("derp");
}
#endregion
#region X button
private void buttonClose_MouseEnter(object sender, EventArgs e)
{
buttonClose.BackgroundImage = SerialKiller3000.Properties.Resources.xMouse;
}
private void buttonClose_MouseLeave(object sender, EventArgs e)
{
buttonClose.BackgroundImage = SerialKiller3000.Properties.Resources.x;
}
private void buttonClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion
#region Minimize button
private void buttonMinimize_MouseEnter(object sender, EventArgs e)
{
buttonMinimize.BackgroundImage = SerialKiller3000.Properties.Resources._Mouse;
}
private void buttonMinimize_MouseLeave(object sender, EventArgs e)
{
buttonMinimize.BackgroundImage = SerialKiller3000.Properties.Resources._;
}
private void buttonMinimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
#endregion
#region Borderless window move
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
_dragging = true; // _dragging is your variable flag
_start_point = new Point(e.X, e.Y);
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
_dragging = false;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (_dragging)
{
Point p = PointToScreen(e.Location);
Location = new Point(p.X - this._start_point.X, p.Y - this._start_point.Y);
}
}
#endregion
private void SlidePanel(Control userControl)
{
if (!preferencesOpen)
{
this.Width += 265;
this.CenterToScreen();
preferencesOpen = true;
userControl.Visible = true;
}
else if (preferencesOpen && !userControl.Visible)
{
CustomControlsAreVisible(false);
userControl.Visible = true;
}
else
{
this.Width -= 265;
this.CenterToScreen();
preferencesOpen = false;
CustomControlsAreVisible(false);
}
}
private void btnPreferences_Click(object sender, EventArgs e)
{
preferencesWindow.ShowDialog();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (stuff.Serial.connected)
{
stuff.Serial.RgbledOFF();
stuff.Serial.uart.Close();
}
}
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
pictureBox1.Image = SerialKiller3000.Properties.Resources.logoMouse;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.Image = SerialKiller3000.Properties.Resources.logo;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/espilioto/SerialKiller3000");
}
}
}