]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Projects/LEDNotifier/LEDMixerApp/LEDMixer.cs
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Projects / LEDNotifier / LEDMixerApp / LEDMixer.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace LEDMixer
11 {
12 public partial class LEDMixer : Form
13 {
14 private const int LIGHT_MAX = 0x1F;
15
16 public LEDMixer()
17 {
18 InitializeComponent();
19 }
20
21 private void LEDMixer_Load(object sender, EventArgs e)
22 {
23 String[] PortNames = System.IO.Ports.SerialPort.GetPortNames();
24 Array.Sort<String>(PortNames, delegate(string strA, string strB) { return int.Parse(strA.Substring(3)).CompareTo(int.Parse(strB.Substring(3))); });
25 cbPort.Items.Clear();
26 cbPort.Items.AddRange(PortNames);
27
28 cbPort.SelectedIndex = 0;
29
30 tbRed.Maximum = LIGHT_MAX;
31 tbGreen.Maximum = LIGHT_MAX;
32 tbBlue.Maximum = LIGHT_MAX;
33 }
34
35 private void tbRed_Scroll(object sender, EventArgs e)
36 {
37 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
38 }
39
40 private void tbGreen_Scroll(object sender, EventArgs e)
41 {
42 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
43 }
44
45 private void tbBlue_Scroll(object sender, EventArgs e)
46 {
47 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
48 }
49
50 private void NotifyLight(int Red, int Green, int Blue)
51 {
52 byte[] buffer = new byte[3];
53 buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
54 buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
55 buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
56
57 try
58 {
59 serSerialPort.PortName = cbPort.Text;
60 serSerialPort.Open();
61 serSerialPort.Write(buffer, 0, buffer.Length);
62 serSerialPort.Close();
63 }
64 catch (Exception e)
65 {
66
67 }
68 }
69
70 private void cbPort_SelectedIndexChanged(object sender, EventArgs e)
71 {
72 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
73 }
74 }
75 }
Imprint / Impressum