Updated the software USART code in the XPLAIN Bridge application so that the incommin...
[pub/USBasp.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 for (int i = 1; i <= 99; i++)
24 cbPort.Items.Add("COM" + i.ToString());
25
26 cbPort.SelectedIndex = 0;
27
28 tbRed.Maximum = LIGHT_MAX;
29 tbGreen.Maximum = LIGHT_MAX;
30 tbBlue.Maximum = LIGHT_MAX;
31 }
32
33 private void tbRed_Scroll(object sender, EventArgs e)
34 {
35 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
36 }
37
38 private void tbGreen_Scroll(object sender, EventArgs e)
39 {
40 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
41 }
42
43 private void tbBlue_Scroll(object sender, EventArgs e)
44 {
45 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
46 }
47
48 private void NotifyLight(int Red, int Green, int Blue)
49 {
50 byte[] buffer = new byte[3];
51 buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
52 buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
53 buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
54
55 try
56 {
57 serSerialPort.PortName = cbPort.Text;
58 serSerialPort.Open();
59 serSerialPort.Write(buffer, 0, buffer.Length);
60 serSerialPort.Close();
61 }
62 catch (Exception e)
63 {
64
65 }
66 }
67
68 private void cbPort_SelectedIndexChanged(object sender, EventArgs e)
69 {
70 NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
71 }
72 }
73 }