Add board driver support for the EVK1100 board.
[pub/USBasp.git] / Projects / LEDNotifier / HotmailNotifierApp / MailNotifier.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using Microsoft.Win32;
9
10 namespace TestWinForms
11 {
12 public partial class MailNotifier : Form
13 {
14 private MessengerAPI.Messenger Messenger;
15 private RegistryKey AppRegKey;
16
17 private const int LIGHT_MAX = 0x1F;
18
19 public MailNotifier()
20 {
21 InitializeComponent();
22
23 Messenger = new MessengerAPI.Messenger();
24 AppRegKey = Registry.CurrentUser.CreateSubKey("Software\\MailNotifier");
25
26 for (int i = 1; i < 99; i++)
27 cmbComPort.Items.Add("COM" + i.ToString());
28
29 cmbComPort.SelectedIndex = System.Convert.ToInt32(AppRegKey.GetValue("Port", "1")) - 1;
30 serSerialPort.PortName = cmbComPort.Text;
31
32 nicoNotifyIcon.Icon = this.Icon;
33 nicoNotifyIcon.MouseClick += new MouseEventHandler(TrayIconClick);
34 }
35
36 private void MailNotifier_Load(object sender, EventArgs e)
37 {
38 Messenger.OnUnreadEmailChange += new MessengerAPI.DMessengerEvents_OnUnreadEmailChangeEventHandler(NewEmail);
39
40 bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
41 NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
42
43 Hide();
44 }
45
46 private void TrayIconClick(object sender, MouseEventArgs e)
47 {
48 this.Show();
49 this.WindowState = FormWindowState.Normal;
50 }
51
52 private void NewEmail(MessengerAPI.MUAFOLDER folder, int amount, ref bool enableDefault)
53 {
54 if (folder == MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX)
55 {
56 bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
57 NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
58 }
59 }
60
61 private void NotifyLight(int Red, int Green, int Blue)
62 {
63 byte[] buffer = new byte[3];
64 buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
65 buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
66 buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
67
68 try
69 {
70 serSerialPort.Open();
71 serSerialPort.Write(buffer, 0, buffer.Length);
72 serSerialPort.Close();
73 }
74 catch (Exception e)
75 {
76
77 }
78 }
79
80 private void btnExit_Click(object sender, EventArgs e)
81 {
82 Application.Exit();
83 }
84
85 private void cmbComPort_SelectedIndexChanged(object sender, EventArgs e)
86 {
87 AppRegKey.SetValue("Port", cmbComPort.SelectedIndex + 1);
88 serSerialPort.PortName = cmbComPort.Text;
89
90 for (int i = 1; i < 10; i++)
91 {
92 NotifyLight((LIGHT_MAX / i), (LIGHT_MAX / (i * 10)), 0);
93 System.Threading.Thread.Sleep(10);
94 }
95
96 for (int i = 10; i > 0; i--)
97 {
98 NotifyLight((LIGHT_MAX / i), (LIGHT_MAX / (i * 10)), 0);
99 System.Threading.Thread.Sleep(10);
100 }
101
102 bool UnreadMail = (Messenger.get_UnreadEmailCount(MessengerAPI.MUAFOLDER.MUAFOLDER_INBOX) > 0);
103 NotifyLight((!UnreadMail ? LIGHT_MAX : 0), (UnreadMail ? LIGHT_MAX : 0), 0);
104 }
105
106 private void btnMinimize_Click(object sender, EventArgs e)
107 {
108 this.Hide();
109 }
110 }
111 }