Power supply status, device id and firmware revision queries are now working.
authorsl
Thu, 10 Jul 2014 22:03:29 +0200
changeset 12f37c5ff8af18
parent 11 de55741d90f0
child 13 745d9ee1a2c0
Power supply status, device id and firmware revision queries are now working.
Display.cs
MainForm.Designer.cs
MainForm.cs
     1.1 --- a/Display.cs	Wed Jul 09 11:06:46 2014 +0200
     1.2 +++ b/Display.cs	Thu Jul 10 22:03:29 2014 +0200
     1.3 @@ -85,6 +85,43 @@
     1.4              MiniDisplaySetPixel(iDevice,aX,aY,aValue);
     1.5          }
     1.6  
     1.7 +        public void RequestPowerSupplyStatus()
     1.8 +        {
     1.9 +            MiniDisplayRequestPowerSupplyStatus(iDevice);
    1.10 +        }
    1.11 +
    1.12 +        public void RequestDeviceId()
    1.13 +        {
    1.14 +            MiniDisplayRequestDeviceId(iDevice);
    1.15 +        }
    1.16 +
    1.17 +        public void RequestFirmwareRevision()
    1.18 +        {
    1.19 +            MiniDisplayRequestFirmwareRevision(iDevice);
    1.20 +        }
    1.21 +
    1.22 +        public bool PowerSupplyStatus()
    1.23 +        {
    1.24 +            bool res = MiniDisplayPowerSupplyStatus(iDevice);
    1.25 +            return res;
    1.26 +        }
    1.27 +
    1.28 +        public TMiniDisplayRequest AttemptRequestCompletion()
    1.29 +        {
    1.30 +            return MiniDisplayAttemptRequestCompletion(iDevice);
    1.31 +        }
    1.32 +
    1.33 +        public TMiniDisplayRequest CurrentRequest()
    1.34 +        {
    1.35 +            return MiniDisplayCurrentRequest(iDevice);
    1.36 +        }
    1.37 +
    1.38 +        public bool IsRequestPending()
    1.39 +        {
    1.40 +            return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
    1.41 +        }
    1.42 +
    1.43 +
    1.44          public string Vendor()
    1.45          {
    1.46              IntPtr ptr = MiniDisplayVendor(iDevice);
    1.47 @@ -106,6 +143,20 @@
    1.48              return str;
    1.49          }
    1.50  
    1.51 +        public string DeviceId()
    1.52 +        {
    1.53 +            IntPtr ptr = MiniDisplayDeviceId(iDevice);
    1.54 +            string str = Marshal.PtrToStringAnsi(ptr);
    1.55 +            return str;
    1.56 +        }
    1.57 +
    1.58 +        public string FirmwareRevision()
    1.59 +        {
    1.60 +            IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
    1.61 +            string str = Marshal.PtrToStringAnsi(ptr);
    1.62 +            return str;
    1.63 +        }
    1.64 +
    1.65          //Our display device handle
    1.66          IntPtr iDevice;
    1.67  
    1.68 @@ -166,6 +217,7 @@
    1.69          public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
    1.70  
    1.71          [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.72 +        [return: MarshalAs(UnmanagedType.I1)]
    1.73          public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
    1.74  
    1.75          [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    1.76 @@ -187,9 +239,5 @@
    1.77          public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
    1.78  
    1.79  
    1.80 -        
    1.81 -        
    1.82 -
    1.83 -
    1.84      }
    1.85  }
     2.1 --- a/MainForm.Designer.cs	Wed Jul 09 11:06:46 2014 +0200
     2.2 +++ b/MainForm.Designer.cs	Thu Jul 10 22:03:29 2014 +0200
     2.3 @@ -49,6 +49,7 @@
     2.4              this.toolStripStatusLabelConnect = new System.Windows.Forms.ToolStripStatusLabel();
     2.5              this.toolStripStatusLabelSpring = new System.Windows.Forms.ToolStripStatusLabel();
     2.6              this.toolStripStatusLabelFps = new System.Windows.Forms.ToolStripStatusLabel();
     2.7 +            this.toolStripStatusLabelPower = new System.Windows.Forms.ToolStripStatusLabel();
     2.8              this.tabControl.SuspendLayout();
     2.9              this.tabPageDisplay.SuspendLayout();
    2.10              ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit();
    2.11 @@ -237,7 +238,6 @@
    2.12              this.marqueeLabelBottom.Name = "marqueeLabelBottom";
    2.13              this.marqueeLabelBottom.OwnTimer = false;
    2.14              this.marqueeLabelBottom.PixelsPerSecond = 64;
    2.15 -            this.marqueeLabelBottom.Separator = " | ";
    2.16              this.marqueeLabelBottom.Size = new System.Drawing.Size(254, 31);
    2.17              this.marqueeLabelBottom.TabIndex = 3;
    2.18              this.marqueeLabelBottom.Text = "abcdefghijklmnopqrst-0123456789";
    2.19 @@ -276,6 +276,7 @@
    2.20              this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    2.21              this.toolStripStatusLabelConnect,
    2.22              this.toolStripStatusLabelSpring,
    2.23 +            this.toolStripStatusLabelPower,
    2.24              this.toolStripStatusLabelFps});
    2.25              this.statusStrip.Location = new System.Drawing.Point(0, 420);
    2.26              this.statusStrip.Name = "statusStrip";
    2.27 @@ -293,7 +294,7 @@
    2.28              // toolStripStatusLabelSpring
    2.29              // 
    2.30              this.toolStripStatusLabelSpring.Name = "toolStripStatusLabelSpring";
    2.31 -            this.toolStripStatusLabelSpring.Size = new System.Drawing.Size(497, 17);
    2.32 +            this.toolStripStatusLabelSpring.Size = new System.Drawing.Size(442, 17);
    2.33              this.toolStripStatusLabelSpring.Spring = true;
    2.34              // 
    2.35              // toolStripStatusLabelFps
    2.36 @@ -302,6 +303,12 @@
    2.37              this.toolStripStatusLabelFps.Size = new System.Drawing.Size(26, 17);
    2.38              this.toolStripStatusLabelFps.Text = "FPS";
    2.39              // 
    2.40 +            // toolStripStatusLabelPower
    2.41 +            // 
    2.42 +            this.toolStripStatusLabelPower.Name = "toolStripStatusLabelPower";
    2.43 +            this.toolStripStatusLabelPower.Size = new System.Drawing.Size(24, 17);
    2.44 +            this.toolStripStatusLabelPower.Text = "NA";
    2.45 +            // 
    2.46              // MainForm
    2.47              // 
    2.48              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    2.49 @@ -346,6 +353,7 @@
    2.50          private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelFps;
    2.51          private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpring;
    2.52          private System.Windows.Forms.CheckBox checkBoxShowBorders;
    2.53 +        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelPower;
    2.54      }
    2.55  }
    2.56  
     3.1 --- a/MainForm.cs	Wed Jul 09 11:06:46 2014 +0200
     3.2 +++ b/MainForm.cs	Thu Jul 10 22:03:29 2014 +0200
     3.3 @@ -69,8 +69,41 @@
     3.4              bmp.Save("c:\\capture.png");
     3.5          }
     3.6  
     3.7 +        private void CheckForRequestResults()
     3.8 +        {
     3.9 +            if (iDisplay.IsRequestPending())
    3.10 +            {
    3.11 +                switch (iDisplay.AttemptRequestCompletion())
    3.12 +                {
    3.13 +                    case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus:
    3.14 +                        if (iDisplay.PowerSupplyStatus())
    3.15 +                        {
    3.16 +                            toolStripStatusLabelPower.Text = "ON";
    3.17 +                        }
    3.18 +                        else
    3.19 +                        {
    3.20 +                            toolStripStatusLabelPower.Text = "OFF";
    3.21 +                        }
    3.22 +                        //Issue next request then
    3.23 +                        iDisplay.RequestDeviceId();
    3.24 +                        break;
    3.25 +
    3.26 +                    case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId:
    3.27 +                        toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId();
    3.28 +                        //Issue next request then
    3.29 +                        iDisplay.RequestFirmwareRevision();
    3.30 +                        break;
    3.31 +
    3.32 +                    case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision:
    3.33 +                        toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision();
    3.34 +                        //No more request to issue
    3.35 +                        break;
    3.36 +                }
    3.37 +            }
    3.38 +        }
    3.39 +
    3.40          private void timer_Tick(object sender, EventArgs e)
    3.41 -        {
    3.42 +        {        
    3.43              //Update our animations
    3.44              DateTime NewTickTime = DateTime.Now;
    3.45  
    3.46 @@ -80,6 +113,8 @@
    3.47              //Update our display
    3.48              if (iDisplay.IsOpen())
    3.49              {
    3.50 +                CheckForRequestResults();
    3.51 +
    3.52                  //Draw to bitmap
    3.53                  System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
    3.54                  tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
    3.55 @@ -112,6 +147,7 @@
    3.56              if (iDisplay.Open())
    3.57              {
    3.58                  UpdateStatus();
    3.59 +                iDisplay.RequestPowerSupplyStatus();
    3.60              }
    3.61              else
    3.62              {