Power supply status, device id and firmware revision queries are now working.
2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using CodeProject.Dialog;
12 namespace SharpDisplayManager
14 public partial class MainForm : Form
16 DateTime LastTickTime;
21 LastTickTime = DateTime.Now;
22 iDisplay = new Display();
24 InitializeComponent();
27 marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
28 marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
29 checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
32 private void buttonFont_Click(object sender, EventArgs e)
34 //fontDialog.ShowColor = true;
35 //fontDialog.ShowApply = true;
36 fontDialog.ShowEffects = true;
37 fontDialog.Font = marqueeLabelTop.Font;
38 //fontDialog.ShowHelp = true;
40 //fontDlg.MaxSize = 40;
41 //fontDlg.MinSize = 22;
43 //fontDialog.Parent = this;
44 //fontDialog.StartPosition = FormStartPosition.CenterParent;
46 //DlgBox.ShowDialog(fontDialog);
48 //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
49 if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
52 //MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
54 //MessageBox.Show("Ok");
55 marqueeLabelTop.Font = fontDialog.Font;
56 marqueeLabelBottom.Font = fontDialog.Font;
57 Properties.Settings.Default.DisplayFont = fontDialog.Font;
58 Properties.Settings.Default.Save();
59 //label1.Font = fontDlg.Font;
60 //textBox1.BackColor = fontDlg.Color;
61 //label1.ForeColor = fontDlg.Color;
65 private void buttonCapture_Click(object sender, EventArgs e)
67 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
68 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
69 bmp.Save("c:\\capture.png");
72 private void CheckForRequestResults()
74 if (iDisplay.IsRequestPending())
76 switch (iDisplay.AttemptRequestCompletion())
78 case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus:
79 if (iDisplay.PowerSupplyStatus())
81 toolStripStatusLabelPower.Text = "ON";
85 toolStripStatusLabelPower.Text = "OFF";
87 //Issue next request then
88 iDisplay.RequestDeviceId();
91 case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId:
92 toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId();
93 //Issue next request then
94 iDisplay.RequestFirmwareRevision();
97 case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision:
98 toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision();
99 //No more request to issue
105 private void timer_Tick(object sender, EventArgs e)
107 //Update our animations
108 DateTime NewTickTime = DateTime.Now;
110 marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
111 marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
114 if (iDisplay.IsOpen())
116 CheckForRequestResults();
119 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
120 tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
121 //Send it to our display
122 for (int i = 0; i < bmp.Width; i++)
124 for (int j = 0; j < bmp.Height; j++)
128 uint color=(uint)bmp.GetPixel(i, j).ToArgb();
129 iDisplay.SetPixel(i, j, Convert.ToInt32((checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000)));
134 iDisplay.SwapBuffers();
138 //Compute instant FPS
139 toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
141 LastTickTime = NewTickTime;
145 private void buttonOpen_Click(object sender, EventArgs e)
150 iDisplay.RequestPowerSupplyStatus();
155 toolStripStatusLabelConnect.Text = "Connection error";
160 private void buttonClose_Click(object sender, EventArgs e)
166 private void buttonClear_Click(object sender, EventArgs e)
169 iDisplay.SwapBuffers();
172 private void buttonFill_Click(object sender, EventArgs e)
175 iDisplay.SwapBuffers();
178 private void trackBarBrightness_Scroll(object sender, EventArgs e)
180 Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value;
181 Properties.Settings.Default.Save();
182 iDisplay.SetBrightness(trackBarBrightness.Value);
186 private void UpdateStatus()
188 if (iDisplay.IsOpen())
190 buttonFill.Enabled = true;
191 buttonClear.Enabled = true;
192 buttonOpen.Enabled = false;
193 buttonClose.Enabled = true;
194 trackBarBrightness.Enabled = true;
195 trackBarBrightness.Minimum = iDisplay.MinBrightness();
196 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
197 trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
198 trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
199 trackBarBrightness.SmallChange = 1;
200 iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness);
202 toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
203 //+ " - " + iDisplay.SerialNumber();
207 buttonFill.Enabled = false;
208 buttonClear.Enabled = false;
209 buttonOpen.Enabled = true;
210 buttonClose.Enabled = false;
211 trackBarBrightness.Enabled = false;
212 toolStripStatusLabelConnect.Text = "Disconnected";
216 private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
218 Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
219 Properties.Settings.Default.Save();