Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 2000,2001 Microsoft Corporation
  3. Module Name:
  4. tmpinfo.c
  5. Abstract: SMBus Temperature Sensor Information Property Sheet module.
  6. Environment:
  7. User mode
  8. Author:
  9. Michael Tsang (MikeTs) 25-Jan-2001
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef TMPINFO
  14. char gszUnitDegreeC[] = "\xb0" "C";
  15. PSZ gapszTmpStatusNames[] =
  16. {
  17. "Busy",
  18. "LocalHiAlarm",
  19. "LocalLoAlarm",
  20. "RemoteHiAlarm",
  21. "RemoteLoAlarm",
  22. "RemoteOpen"
  23. };
  24. PSZ gapszTmpCfgNames[] =
  25. {
  26. "Busy",
  27. "LocalHiAlarm",
  28. "LocalLoAlarm",
  29. "RemoteHiAlarm",
  30. "RemoteLoAlarm",
  31. "RemoteOpen"
  32. };
  33. SMBCMD_INFO gTmpCmds[] =
  34. {
  35. TMPCMD_RD_LOCALTMP, SMB_READ_BYTE, BSN, sizeof(BYTE),
  36. " LocalTmp", gszUnitDegreeC, 0, NULL,
  37. TMPCMD_RD_REMOTETMP, SMB_READ_BYTE, BSN, sizeof(BYTE),
  38. " RemoteTmp", gszUnitDegreeC, 0, NULL,
  39. TMPCMD_RD_STATUS, SMB_READ_BYTE, BBT, sizeof(BYTE),
  40. " Status", NULL, 0xfc, gapszTmpStatusNames,
  41. TMPCMD_RD_CONFIG, SMB_READ_BYTE, BBT, sizeof(BYTE),
  42. " Config", NULL, 0xc0, gapszTmpCfgNames,
  43. TMPCMD_RD_CONVERSION_RATE, SMB_READ_BYTE, CNV, sizeof(BYTE),
  44. " ConversionRate", NULL, 0, NULL,
  45. TMPCMD_RD_LOCALTMP_HILIMIT, SMB_READ_BYTE, BSN, sizeof(BYTE),
  46. " LocalTmpHiLimit", gszUnitDegreeC, 0, NULL,
  47. TMPCMD_RD_LOCALTMP_LOLIMIT, SMB_READ_BYTE, BSN, sizeof(BYTE),
  48. " LocalTmpLoLimit", gszUnitDegreeC, 0, NULL,
  49. TMPCMD_RD_REMOTETMP_HILIMIT, SMB_READ_BYTE, BSN, sizeof(BYTE),
  50. "RemoteTmpHiLimit", gszUnitDegreeC, 0, NULL,
  51. TMPCMD_RD_REMOTETMP_LOLIMIT, SMB_READ_BYTE, BSN, sizeof(BYTE),
  52. "RemoteTmpLoLimit", gszUnitDegreeC, 0, NULL,
  53. TMPCMD_RD_MANUFACTURER_ID, SMB_READ_BYTE, BHX, sizeof(BYTE),
  54. " ManufacturerID", NULL, 0, NULL,
  55. TMPCMD_RD_DEVICE_ID, SMB_READ_BYTE, BHX, sizeof(BYTE),
  56. " DeviceID", NULL, 0, NULL,
  57. };
  58. #define NUM_TMP_CMDS (sizeof(gTmpCmds)/sizeof(SMBCMD_INFO))
  59. TMP_INFO gTmpInfo = {0};
  60. /*++
  61. @doc EXTERNAL
  62. @func INT_PTR | TemperatureDlgProc |
  63. Dialog procedure for the temperature page.
  64. @parm IN HWND | hwnd | Window handle.
  65. @parm IN UINT | uMsg | Message.
  66. @parm IN WPARAM | wParam | Word Parameter.
  67. @parm IN LPARAM | lParam | Long Parameter.
  68. @rvalue Return value depends on the message.
  69. --*/
  70. INT_PTR APIENTRY
  71. TemperatureDlgProc(
  72. IN HWND hwnd,
  73. IN UINT uMsg,
  74. IN WPARAM wParam,
  75. IN LPARAM lParam
  76. )
  77. {
  78. TRACEPROC("TemperatureDlgProc", 2)
  79. INT_PTR rc = FALSE;
  80. TRACEENTER(("(hwnd=%p,Msg=%s,wParam=%x,lParam=%x)\n",
  81. hwnd, LookupName(uMsg, WMMsgNames) , wParam, lParam));
  82. switch (uMsg)
  83. {
  84. case WM_INITDIALOG:
  85. rc = InitTemperaturePage(hwnd);
  86. if (!rc)
  87. {
  88. EnableWindow(hwnd, FALSE);
  89. }
  90. break;
  91. case WM_NOTIFY:
  92. {
  93. NMHDR FAR *lpnm = (NMHDR FAR *)lParam;
  94. switch (lpnm->code)
  95. {
  96. case PSN_QUERYINITIALFOCUS:
  97. {
  98. SetWindowLong(hwnd,
  99. DWL_MSGRESULT,
  100. (LONG)GetDlgItem(hwnd, IDC_TMPINFO_REFRESH));
  101. rc = TRUE;
  102. break;
  103. }
  104. }
  105. break;
  106. }
  107. case WM_COMMAND:
  108. switch (LOWORD(wParam))
  109. {
  110. case IDC_TMPINFO_REFRESH:
  111. RefreshTmpInfo(GetDlgItem(hwnd, IDC_TMPINFO_TEXT));
  112. break;
  113. }
  114. break;
  115. }
  116. TRACEEXIT(("=%x\n", rc));
  117. return rc;
  118. } //TemperatureDlgProc
  119. /*++
  120. @doc INTERNAL
  121. @func BOOL | InitTemperaturePage |
  122. Initialize the temperature sensor property page.
  123. @parm IN HWND | hwnd | Window handle.
  124. @rvalue Always returns TRUE.
  125. --*/
  126. BOOL
  127. InitTemperaturePage(
  128. IN HWND hwnd
  129. )
  130. {
  131. TRACEPROC("InitTemperaturePage", 2)
  132. HWND hwndEdit;
  133. TRACEENTER(("(hwnd=%x)\n", hwnd));
  134. hwndEdit = GetDlgItem(hwnd, IDC_TMPINFO_TEXT);
  135. SendMessage(hwndEdit, WM_SETFONT, (WPARAM)ghFont, MAKELONG(FALSE, 0));
  136. RefreshTmpInfo(hwndEdit);
  137. TRACEEXIT(("=1\n"));
  138. return TRUE;
  139. } //InitTemperaturePage
  140. /*++
  141. @doc INTERNAL
  142. @func VOID | RefreshTmpInfo | Refresh termperature information.
  143. @parm IN HWND | hwndEdit | Handle to edit control.
  144. @rvalue None.
  145. --*/
  146. VOID
  147. RefreshTmpInfo(
  148. IN HWND hwndEdit
  149. )
  150. {
  151. TRACEPROC("RefreshTmpInfo", 3)
  152. int i;
  153. PBYTE pbBuff;
  154. TRACEENTER(("(hwndEdit=%x)\n", hwndEdit));
  155. //
  156. // Erase edit control.
  157. //
  158. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  159. SendMessage(hwndEdit, EM_REPLACESEL, 0, (LPARAM)"");
  160. memset(&gTmpInfo, 0, sizeof(gTmpInfo));
  161. for (i = 0, pbBuff = (PBYTE)&gTmpInfo; i < NUM_TMP_CMDS; ++i)
  162. {
  163. if (GetSMBDevInfo(SMB_TMPSENSOR_ADDRESS, &gTmpCmds[i], pbBuff))
  164. {
  165. DisplayTmpInfo(hwndEdit, &gTmpCmds[i], pbBuff);
  166. }
  167. else
  168. {
  169. TRACEWARN(("failed to get temperature info. for %s.\n",
  170. gTmpCmds[i].pszLabel));
  171. }
  172. pbBuff += gTmpCmds[i].iDataSize;
  173. }
  174. //
  175. // Scroll back to the top.
  176. //
  177. SendMessage(hwndEdit, EM_SETSEL, 0, 0);
  178. SendMessage(hwndEdit, EM_SCROLLCARET, 0, 0);
  179. TRACEEXIT(("!\n"));
  180. return;
  181. } //RefreshTmpInfo
  182. /*++
  183. @doc INTERNAL
  184. @func BOOL | DisplayTmpInfo | Display temperature info.
  185. @parm IN HWND | hwndEdit | Edit window handle.
  186. @parm IN PSMBCMD_INFO | TmpCmd | Points to the temperature command.
  187. @parm IN PBYTE | pbBuff | Temperature data to display.
  188. @rvalue SUCCESS | Returns TRUE if it handles it.
  189. @rvalue FAILURE | Returns FALSE if it doesn't handle it.
  190. --*/
  191. BOOL
  192. DisplayTmpInfo(
  193. IN HWND hwndEdit,
  194. IN PSMBCMD_INFO TmpCmd,
  195. IN PBYTE pbBuff
  196. )
  197. {
  198. TRACEPROC("DisplayTmpInfo", 3)
  199. BOOL rc = TRUE;
  200. TRACEENTER(("(hwndEdit=%x,TmpCmd=%p,Cmd=%s,pbBuff=%p)\n",
  201. hwndEdit, TmpCmd, TmpCmd->pszLabel, pbBuff));
  202. EditPrintf(hwndEdit, "%s=", TmpCmd->pszLabel);
  203. switch (TmpCmd->bType)
  204. {
  205. case TYPEF_CONV_RATE:
  206. {
  207. static char *RateTable[] =
  208. {
  209. "0.0625", "0.125", "0.25", "0.5", "1", "2", "4", "8"
  210. };
  211. if (*pbBuff <= 7)
  212. {
  213. EditPrintf(hwndEdit, "%6s Hz\r\n", RateTable[*pbBuff]);
  214. }
  215. else
  216. {
  217. EditPrintf(hwndEdit, " 0x02x\r\n", *pbBuff);
  218. }
  219. break;
  220. }
  221. default:
  222. rc = DisplaySMBDevInfo(hwndEdit, TmpCmd, pbBuff);
  223. }
  224. TRACEEXIT(("=%x\n", rc));
  225. return rc;
  226. } //DisplayTmpInfo
  227. #endif //ifdef TMPINFO