GUI/SoundGraphDisplay.cs
branchMiniDisplay
changeset 434 480652d72031
parent 433 090259cfd699
child 435 9ffcd8ed8537
     1.1 --- a/GUI/SoundGraphDisplay.cs	Sun Feb 03 18:01:50 2013 +0100
     1.2 +++ b/GUI/SoundGraphDisplay.cs	Sun Feb 03 19:06:01 2013 +0100
     1.3 @@ -46,6 +46,127 @@
     1.4      public static extern bool FreeLibrary(IntPtr hModule);
     1.5  }
     1.6  
     1.7 +/**
     1.8 +Definitions taken from public Sound Graph APIs.
     1.9 + */
    1.10 +static class SoundGraph
    1.11 +{
    1.12 +    /**DSPResult
    1.13 +    @brief	These enumeration values represent the returned result for iMON Display API function calls.\n
    1.14 +			    All iMON Display API function calls return one of this result values.\n
    1.15 +			    For meaning of each result, refer the comment of each line below*/
    1.16 +    public enum DSPResult : uint
    1.17 +    {
    1.18 +	    DSP_SUCCEEDED = 0,				//// Function Call Succeeded Without Error
    1.19 +	    DSP_E_FAIL,						//// Unspecified Failure
    1.20 +	    DSP_E_OUTOFMEMORY,				//// Failed to Allocate Necessary Memory
    1.21 +	    DSP_E_INVALIDARG,				//// One or More Arguments Are Not Valid
    1.22 +	    DSP_E_NOT_INITED,				//// API is Not Initialized
    1.23 +	    DSP_E_POINTER,					//// Pointer is Not Valid
    1.24 +
    1.25 +	    DSP_S_INITED = 0x1000,			//// API is Initialized
    1.26 +	    DSP_S_NOT_INITED,				//// API is Not Initialized
    1.27 +	    DSP_S_IN_PLUGIN_MODE,			//// API Can Control iMON Display (Display Plug-in Mode)
    1.28 +	    DSP_S_NOT_IN_PLUGIN_MODE,		//// API Can't Control iMON Display
    1.29 +    };
    1.30 +
    1.31 +
    1.32 +    /**DSPNInitResult
    1.33 +    @brief	These enumeration values represent the result status for requesting Display Plug-in Mode to iMON.\n
    1.34 +			    iMON Display API notifies one of this result values to the caller application after requesting Display Plug-in Mode to iMON.\n
    1.35 +			    For more information, refer the comment of each line below*/
    1.36 +    public enum DSPNInitResult : uint
    1.37 +    {
    1.38 +	    DSPN_SUCCEEDED = 0,				//// Display Plug-in Mode is Initialized Successfully
    1.39 +	    DSPN_ERR_IN_USED = 0x0100,		//// Display Plug-in is Already Used by Other Application
    1.40 +	    DSPN_ERR_HW_DISCONNECTED,		//// iMON HW is Not Connected
    1.41 +	    DSPN_ERR_NOT_SUPPORTED_HW,		//// The Connected iMON HW doesn't Support Display Plug-in
    1.42 +	    DSPN_ERR_PLUGIN_DISABLED,		//// Display Plug-in Mode Option is Disabled
    1.43 +	    DSPN_ERR_IMON_NO_REPLY,			//// The Latest iMON is Not Installed or iMON Not Running
    1.44 +	    DSPN_ERR_UNKNOWN = 0x0200,		//// Unknown Failure
    1.45 +    };
    1.46 +
    1.47 +
    1.48 +    /**DSPType
    1.49 +    @brief	These enumeration values represent display type.\n
    1.50 +			    Currently iMON Display API supports VFD and LCD products.*/
    1.51 +    public enum DSPType : uint
    1.52 +    {
    1.53 +	    DSPN_DSP_NONE	= 0,
    1.54 +	    DSPN_DSP_VFD	= 0x01,			//// VFD products
    1.55 +	    DSPN_DSP_LCD	= 0x02,			//// LCD products
    1.56 +    };
    1.57 +
    1.58 +
    1.59 +    /**DSPNotifyCode
    1.60 +    @brief	These enumeration values represent the notification codes.\n
    1.61 +			    iMON Display API will send or post message to the caller application.\n
    1.62 +			    The caller application should assign the message and the winodw handle to receivce message with IMON_Display_Init fucntion.\n
    1.63 +			    These enumeration values are used with WPARAM parameter of the message.\n 
    1.64 +			    For more information, see the explanation of each notification code below*/
    1.65 +    public enum DSPNotifyCode : uint
    1.66 +    {
    1.67 +	    /**DSPNM_PLUGIN_SUCCEED
    1.68 +	    @brief	When API succeeds to get the control for the display, API will post caller-specified message with DSPNM_PLUGIN_SUCCEED as WPARAM parameter.\n
    1.69 +				    LPARAM represents DSPType. This value can be 0x01 (VFD), 0x02 (LCD) or 0x03 (VFD+LCD).*/
    1.70 +	    DSPNM_PLUGIN_SUCCEED = 0,
    1.71 +
    1.72 +	    /**DSPNM_PLUGIN_FAILED
    1.73 +	    @brief	When API fails to get the control for the display, API will post caller-specified message with DSPNM_PLUGIN_FAILED as WPARAM parameter.\n
    1.74 +				    LPARAM represents error code with DSPNResult.*/
    1.75 +	    DSPNM_PLUGIN_FAILED,
    1.76 +
    1.77 +	    /**DSPNM_IMON_RESTARTED
    1.78 +	    @brief	When iMON starts, API will post caller-specified message with DSPNM_IMON_RESTARTED as WPARAM parameter.\n
    1.79 +				    LPARAM represents DSPType. This value can be 0 (No Display), 0x01 (VFD), 0x02 (LCD) or 0x03 (VFD+LCD).*/
    1.80 +	    DSPNM_IMON_RESTARTED,
    1.81 +
    1.82 +	    /**DSPNM_IMON_CLOSED
    1.83 +	    @brief	When iMON closed, API will post caller-specified message with DSPNM_IMON_CLOSED as WPARAM parameter.\n
    1.84 +				    LPARAM is not used.*/
    1.85 +	    DSPNM_IMON_CLOSED,
    1.86 +
    1.87 +	    /**DSPNM_HW_CONNECTED
    1.88 +	    @brief	When iMON HW newly connected, API will post caller-specified message with DSPNM_HW_CONNECTED as WPARAM parameter.\n
    1.89 +				    LPARAM represents DSPType. This value can be 0 (No Display), 0x01 (VFD), 0x02 (LCD) or 0x03 (VFD+LCD).*/
    1.90 +	    DSPNM_HW_CONNECTED,
    1.91 +
    1.92 +	    /**DSPNM_HW_DISCONNECTED
    1.93 +	    @brief	When iMON HW disconnected, API will post caller-specified message with DSPNM_HW_DISCONNECTED as WPARAM parameter.\n
    1.94 +				    LPARAM is DSPNResult value, DSPN_ERR_HW_DISCONNECTED.*/
    1.95 +	    DSPNM_HW_DISCONNECTED,
    1.96 +
    1.97 +
    1.98 +	    /**DSPNM_LCD_TEXT_SCROLL_DONE
    1.99 +	    @brief	When iMON LCD finishes scrolling Text, API will post caller-specified message with DSPNM_LCD_TEXT_SCROLL_DONE as WPARAM parameter.\n
   1.100 +				    The caller application may need to know when text scroll is finished, for sending next text.\n
   1.101 +				    LPARAM is not used.*/
   1.102 +	    DSPNM_LCD_TEXT_SCROLL_DONE = 0x1000,
   1.103 +    };
   1.104 +
   1.105 +    /// Functions
   1.106 +    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   1.107 +    public delegate DSPResult IMON_Display_Uninit();
   1.108 +
   1.109 +    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   1.110 +    public delegate DSPResult IMON_Display_Init(IntPtr hwndNoti, uint uMsgNotification);
   1.111 +
   1.112 +    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   1.113 +    public delegate DSPResult IMON_Display_IsInited();
   1.114 +
   1.115 +    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   1.116 +    public delegate DSPResult IMON_Display_IsPluginModeEnabled();
   1.117 +
   1.118 +    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   1.119 +    public delegate DSPResult IMON_Display_SetVfdText(
   1.120 +        [MarshalAs(UnmanagedType.LPWStr)] string lpsz1stLine,
   1.121 +        [MarshalAs(UnmanagedType.LPWStr)] string lpsz2ndLine);
   1.122 +
   1.123 +    //IMONDSPAPI DSPResult IMON_Display_SetVfdText(LPCTSTR lpsz1stLine, LPCTSTR lpsz2ndLine);
   1.124 +
   1.125 +}
   1.126 +
   1.127 +
   1.128  
   1.129  namespace OpenHardwareMonitor.GUI
   1.130  {
   1.131 @@ -58,6 +179,11 @@
   1.132          //private bool mainIconEnabled = false;
   1.133          //private NotifyIconAdv mainIcon;
   1.134          IntPtr iSoundGraphDll;
   1.135 +        SoundGraph.IMON_Display_Uninit iIMON_Display_Uninit;
   1.136 +        SoundGraph.IMON_Display_Init iIMON_Display_Init;
   1.137 +        SoundGraph.IMON_Display_IsInited iIMON_Display_IsInited;
   1.138 +        SoundGraph.IMON_Display_IsPluginModeEnabled iIMON_Display_IsPluginModeEnabled;
   1.139 +        SoundGraph.IMON_Display_SetVfdText iIMON_Display_SetVfdText;
   1.140  
   1.141          public SoundGraphDisplay(IComputer computer, PersistentSettings settings,
   1.142            UnitManager unitManager)
   1.143 @@ -82,9 +208,24 @@
   1.144              else
   1.145              {
   1.146                  Console.Write(@"iMON: DLL loaded.");
   1.147 +                //Gather our function pointers
   1.148 +                //TODO: Check returned pointers for validity
   1.149 +                IntPtr functionPointer = NativeMethods.GetProcAddress(iSoundGraphDll, "IMON_Display_Uninit");
   1.150 +                iIMON_Display_Uninit = (SoundGraph.IMON_Display_Uninit)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(SoundGraph.IMON_Display_Uninit));
   1.151 +                
   1.152 +                functionPointer = NativeMethods.GetProcAddress(iSoundGraphDll, "IMON_Display_Init");
   1.153 +                iIMON_Display_Init = (SoundGraph.IMON_Display_Init)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(SoundGraph.IMON_Display_Init));
   1.154 +                
   1.155 +                functionPointer = NativeMethods.GetProcAddress(iSoundGraphDll, "IMON_Display_IsInited");
   1.156 +                iIMON_Display_IsInited = (SoundGraph.IMON_Display_IsInited)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(SoundGraph.IMON_Display_IsInited));
   1.157 +                
   1.158 +                functionPointer = NativeMethods.GetProcAddress(iSoundGraphDll, "IMON_Display_IsPluginModeEnabled");
   1.159 +                iIMON_Display_IsPluginModeEnabled = (SoundGraph.IMON_Display_IsPluginModeEnabled)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(SoundGraph.IMON_Display_IsPluginModeEnabled));
   1.160 +
   1.161 +                functionPointer = NativeMethods.GetProcAddress(iSoundGraphDll, "IMON_Display_SetVfdText");
   1.162 +                iIMON_Display_SetVfdText = (SoundGraph.IMON_Display_SetVfdText)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(SoundGraph.IMON_Display_SetVfdText));
   1.163 +
   1.164              }
   1.165 -
   1.166 -
   1.167          }
   1.168  
   1.169          private void HardwareRemoved(IHardware hardware)
   1.170 @@ -204,6 +345,21 @@
   1.171               */
   1.172          }
   1.173  
   1.174 +        private void Init(IntPtr aHWND)
   1.175 +        {
   1.176 +            //iIMON_Display_Init
   1.177 +        }
   1.178 +
   1.179 +        private void Uninit()
   1.180 +        {
   1.181 +            iIMON_Display_Uninit();
   1.182 +        }
   1.183 +
   1.184 +        private void SetText(string aUpperLine, string aLowerLine)
   1.185 +        {
   1.186 +
   1.187 +        }
   1.188 +
   1.189          /*
   1.190          public bool IsMainIconEnabled
   1.191          {
   1.192 @@ -217,5 +373,11 @@
   1.193                  }
   1.194              }
   1.195          }*/
   1.196 +
   1.197 +
   1.198 +        public bool IsDllLoaded
   1.199 +        {
   1.200 +            get { return iSoundGraphDll!=IntPtr.Zero; }
   1.201 +        }
   1.202      }
   1.203  }