# HG changeset patch # User sl # Date 1404761522 -7200 # Node ID 71b55cfd8c05f2890429b01980dcc4993567d3e6 # Parent f516c3f656bf021666bb80571aa2577bb04202a0 Adding basic display functions: open, close, clear, fill, brightness control. diff -r f516c3f656bf -r 71b55cfd8c05 Display.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Display.cs Mon Jul 07 21:32:02 2014 +0200 @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +// +using System.Runtime.InteropServices; +using System.Text; + +namespace SharpDisplayManager +{ + class Display + { + + //Constructor + public Display() + { + iDevice = IntPtr.Zero; + } + + // + public bool Open() + { + if (iDevice == IntPtr.Zero) + { + iDevice = MiniDisplayOpen(); + } + return iDevice != IntPtr.Zero; + } + + public void Close() + { + MiniDisplayClose(iDevice); + iDevice = IntPtr.Zero; + } + + public bool IsOpen() + { + return iDevice != IntPtr.Zero; + } + + public void Clear() + { + MiniDisplayClear(iDevice); + } + + public void Fill() + { + MiniDisplayFill(iDevice); + } + + public void SwapBuffers() + { + MiniDisplaySwapBuffers(iDevice); + } + + public int MaxBrightness() + { + return MiniDisplayMaxBrightness(iDevice); + } + + public int MinBrightness() + { + return MiniDisplayMinBrightness(iDevice); + } + + public void SetBrightness(int aBrightness) + { + if (!IsOpen()) return; + + MiniDisplaySetBrightness(iDevice, aBrightness); + } + + //Our display device handle + IntPtr iDevice; + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr MiniDisplayOpen(); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern void MiniDisplayClose(IntPtr aDevice); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern void MiniDisplayClear(IntPtr aDevice); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern void MiniDisplayFill(IntPtr aDevice); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern void MiniDisplaySwapBuffers(IntPtr aDevice); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern int MiniDisplayMinBrightness(IntPtr aDevice); + + [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] + public static extern int MiniDisplayMaxBrightness(IntPtr aDevice); + + + } +} diff -r f516c3f656bf -r 71b55cfd8c05 MainForm.Designer.cs --- a/MainForm.Designer.cs Mon Jun 16 12:18:46 2014 +0200 +++ b/MainForm.Designer.cs Mon Jul 07 21:32:02 2014 +0200 @@ -37,11 +37,17 @@ this.tabPageTests = new System.Windows.Forms.TabPage(); this.fontDialog = new System.Windows.Forms.FontDialog(); this.timer = new System.Windows.Forms.Timer(this.components); + this.buttonOpen = new System.Windows.Forms.Button(); + this.buttonClose = new System.Windows.Forms.Button(); + this.buttonClear = new System.Windows.Forms.Button(); + this.buttonFill = new System.Windows.Forms.Button(); + this.trackBarBrightness = new System.Windows.Forms.TrackBar(); this.marqueeLabelTop = new SharpDisplayManager.MarqueeLabel(); this.marqueeLabelBottom = new SharpDisplayManager.MarqueeLabel(); this.tabControl.SuspendLayout(); this.tabPageDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit(); this.SuspendLayout(); // // tabControl @@ -59,6 +65,11 @@ // // tabPageDisplay // + this.tabPageDisplay.Controls.Add(this.trackBarBrightness); + this.tabPageDisplay.Controls.Add(this.buttonFill); + this.tabPageDisplay.Controls.Add(this.buttonClear); + this.tabPageDisplay.Controls.Add(this.buttonClose); + this.tabPageDisplay.Controls.Add(this.buttonOpen); this.tabPageDisplay.Controls.Add(this.buttonCapture); this.tabPageDisplay.Controls.Add(this.tableLayoutPanel); this.tabPageDisplay.Controls.Add(this.buttonFont); @@ -87,7 +98,7 @@ this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel.Controls.Add(this.marqueeLabelTop, 0, 0); this.tableLayoutPanel.Controls.Add(this.marqueeLabelBottom, 0, 1); - this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165); + this.tableLayoutPanel.Location = new System.Drawing.Point(180, 161); this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel.Name = "tableLayoutPanel"; this.tableLayoutPanel.RowCount = 2; @@ -105,6 +116,14 @@ this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); this.tableLayoutPanel.TabIndex = 4; // @@ -134,11 +153,62 @@ this.timer.Interval = 50; this.timer.Tick += new System.EventHandler(this.timer_Tick); // + // buttonOpen + // + this.buttonOpen.Location = new System.Drawing.Point(6, 6); + this.buttonOpen.Name = "buttonOpen"; + this.buttonOpen.Size = new System.Drawing.Size(75, 23); + this.buttonOpen.TabIndex = 6; + this.buttonOpen.Text = "Open"; + this.buttonOpen.UseVisualStyleBackColor = true; + this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click); + // + // buttonClose + // + this.buttonClose.Location = new System.Drawing.Point(6, 35); + this.buttonClose.Name = "buttonClose"; + this.buttonClose.Size = new System.Drawing.Size(75, 23); + this.buttonClose.TabIndex = 7; + this.buttonClose.Text = "Close"; + this.buttonClose.UseVisualStyleBackColor = true; + this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click); + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(6, 64); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(75, 23); + this.buttonClear.TabIndex = 8; + this.buttonClear.Text = "Clear"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click); + // + // buttonFill + // + this.buttonFill.Location = new System.Drawing.Point(6, 93); + this.buttonFill.Name = "buttonFill"; + this.buttonFill.Size = new System.Drawing.Size(75, 23); + this.buttonFill.TabIndex = 9; + this.buttonFill.Text = "Fill"; + this.buttonFill.UseVisualStyleBackColor = true; + this.buttonFill.Click += new System.EventHandler(this.buttonFill_Click); + // + // trackBarBrightness + // + this.trackBarBrightness.BackColor = System.Drawing.SystemColors.Window; + this.trackBarBrightness.Location = new System.Drawing.Point(470, 6); + this.trackBarBrightness.Name = "trackBarBrightness"; + this.trackBarBrightness.Orientation = System.Windows.Forms.Orientation.Vertical; + this.trackBarBrightness.Size = new System.Drawing.Size(45, 324); + this.trackBarBrightness.TabIndex = 10; + this.trackBarBrightness.TickStyle = System.Windows.Forms.TickStyle.Both; + this.trackBarBrightness.Scroll += new System.EventHandler(this.trackBarBrightness_Scroll); + // // marqueeLabelTop // this.marqueeLabelTop.BackColor = System.Drawing.Color.Transparent; this.marqueeLabelTop.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelTop.Location = new System.Drawing.Point(1, -187); + this.marqueeLabelTop.Location = new System.Drawing.Point(1, -313); this.marqueeLabelTop.Margin = new System.Windows.Forms.Padding(0); this.marqueeLabelTop.Name = "marqueeLabelTop"; this.marqueeLabelTop.OwnTimer = false; @@ -152,7 +222,7 @@ // marqueeLabelBottom // this.marqueeLabelBottom.Dock = System.Windows.Forms.DockStyle.Fill; - this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -61); + this.marqueeLabelBottom.Location = new System.Drawing.Point(1, -166); this.marqueeLabelBottom.Margin = new System.Windows.Forms.Padding(0); this.marqueeLabelBottom.Name = "marqueeLabelBottom"; this.marqueeLabelBottom.OwnTimer = false; @@ -173,7 +243,9 @@ this.Text = "Sharp Display Manager"; this.tabControl.ResumeLayout(false); this.tabPageDisplay.ResumeLayout(false); + this.tabPageDisplay.PerformLayout(); this.tableLayoutPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).EndInit(); this.ResumeLayout(false); } @@ -190,6 +262,11 @@ private MarqueeLabel marqueeLabelBottom; private System.Windows.Forms.Button buttonCapture; private System.Windows.Forms.Timer timer; + private System.Windows.Forms.Button buttonFill; + private System.Windows.Forms.Button buttonClear; + private System.Windows.Forms.Button buttonClose; + private System.Windows.Forms.Button buttonOpen; + private System.Windows.Forms.TrackBar trackBarBrightness; } } diff -r f516c3f656bf -r 71b55cfd8c05 MainForm.cs --- a/MainForm.cs Mon Jun 16 12:18:46 2014 +0200 +++ b/MainForm.cs Mon Jul 07 21:32:02 2014 +0200 @@ -14,10 +14,12 @@ public partial class MainForm : Form { DateTime LastTickTime; + Display iDisplay; public MainForm() { LastTickTime = DateTime.Now; + iDisplay = new Display(); InitializeComponent(); } @@ -68,5 +70,37 @@ LastTickTime = NewTickTime; } + + private void buttonOpen_Click(object sender, EventArgs e) + { + if (iDisplay.Open()) + { + trackBarBrightness.Minimum = iDisplay.MinBrightness(); + trackBarBrightness.Maximum = iDisplay.MaxBrightness(); + } + + } + + private void buttonClose_Click(object sender, EventArgs e) + { + iDisplay.Close(); + } + + private void buttonClear_Click(object sender, EventArgs e) + { + iDisplay.Clear(); + iDisplay.SwapBuffers(); + } + + private void buttonFill_Click(object sender, EventArgs e) + { + iDisplay.Fill(); + iDisplay.SwapBuffers(); + } + + private void trackBarBrightness_Scroll(object sender, EventArgs e) + { + iDisplay.SetBrightness(trackBarBrightness.Value); + } } } diff -r f516c3f656bf -r 71b55cfd8c05 SharpDisplayManager.csproj --- a/SharpDisplayManager.csproj Mon Jun 16 12:18:46 2014 +0200 +++ b/SharpDisplayManager.csproj Mon Jul 07 21:32:02 2014 +0200 @@ -48,6 +48,7 @@ + Form