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.

276 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 2000,2001 Microsoft Corporation
  3. Module Name:
  4. chgrinfo.c
  5. Abstract: SMBus Battery Charger Information Property Sheet module.
  6. Environment:
  7. User mode
  8. Author:
  9. Michael Tsang (MikeTs) 26-Jan-2001
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef CHGRINFO
  14. PSZ gapszChgrStatus1Names[] =
  15. {
  16. "ACPresent",
  17. "BattPresent",
  18. "PwrFail",
  19. "AlarmDisabled",
  20. "ThermUR",
  21. "ThermHot",
  22. "ThermCold",
  23. "ThermOR",
  24. "InvalidVoltage",
  25. "InvalidCurrent"
  26. };
  27. PSZ gapszChgrStatus2Names[] =
  28. {
  29. "CurrentNotInReg",
  30. "VoltageNotInReg",
  31. "MasterMode",
  32. "Disabled"
  33. };
  34. SMBCMD_INFO gChgrCmds[] =
  35. {
  36. CHGRCMD_SPECINFO, SMB_READ_WORD, CSI, sizeof(WORD),
  37. "ChargerSpecInfo", NULL, 0, NULL,
  38. CHGRCMD_STATUS, SMB_READ_WORD, CST, sizeof(WORD),
  39. " ChargerStatus", NULL, 0xffc0, gapszChgrStatus1Names,
  40. CHGRCMD_LTC_VERSION, SMB_READ_WORD, WHX, sizeof(WORD),
  41. " LTCVersion", NULL, 0, NULL,
  42. };
  43. #define NUM_CHGR_CMDS (sizeof(gChgrCmds)/sizeof(SMBCMD_INFO))
  44. CHGR_INFO gChgrInfo = {0};
  45. /*++
  46. @doc EXTERNAL
  47. @func INT_PTR | ChargerDlgProc |
  48. Dialog procedure for the battery charger page.
  49. @parm IN HWND | hwnd | Window handle.
  50. @parm IN UINT | uMsg | Message.
  51. @parm IN WPARAM | wParam | Word Parameter.
  52. @parm IN LPARAM | lParam | Long Parameter.
  53. @rvalue Return value depends on the message.
  54. --*/
  55. INT_PTR APIENTRY
  56. ChargerDlgProc(
  57. IN HWND hwnd,
  58. IN UINT uMsg,
  59. IN WPARAM wParam,
  60. IN LPARAM lParam
  61. )
  62. {
  63. TRACEPROC("ChargerDlgProc", 2)
  64. INT_PTR rc = FALSE;
  65. TRACEENTER(("(hwnd=%p,Msg=%s,wParam=%x,lParam=%x)\n",
  66. hwnd, LookupName(uMsg, WMMsgNames) , wParam, lParam));
  67. switch (uMsg)
  68. {
  69. case WM_INITDIALOG:
  70. rc = InitChargerPage(hwnd);
  71. if (!rc)
  72. {
  73. EnableWindow(hwnd, FALSE);
  74. }
  75. break;
  76. case WM_NOTIFY:
  77. {
  78. NMHDR FAR *lpnm = (NMHDR FAR *)lParam;
  79. switch (lpnm->code)
  80. {
  81. case PSN_QUERYINITIALFOCUS:
  82. {
  83. SetWindowLong(hwnd,
  84. DWL_MSGRESULT,
  85. (LONG)GetDlgItem(hwnd, IDC_CHGRINFO_REFRESH));
  86. rc = TRUE;
  87. break;
  88. }
  89. }
  90. break;
  91. }
  92. case WM_COMMAND:
  93. switch (LOWORD(wParam))
  94. {
  95. case IDC_CHGRINFO_REFRESH:
  96. RefreshChgrInfo(GetDlgItem(hwnd, IDC_CHGRINFO_TEXT));
  97. break;
  98. }
  99. break;
  100. }
  101. TRACEEXIT(("=%x\n", rc));
  102. return rc;
  103. } //ChargerDlgProc
  104. /*++
  105. @doc INTERNAL
  106. @func BOOL | InitChargerPage |
  107. Initialize the battery charger property page.
  108. @parm IN HWND | hwnd | Window handle.
  109. @rvalue Always returns TRUE.
  110. --*/
  111. BOOL
  112. InitChargerPage(
  113. IN HWND hwnd
  114. )
  115. {
  116. TRACEPROC("InitChargerPage", 2)
  117. HWND hwndEdit;
  118. TRACEENTER(("(hwnd=%x)\n", hwnd));
  119. hwndEdit = GetDlgItem(hwnd, IDC_CHGRINFO_TEXT);
  120. SendMessage(hwndEdit, WM_SETFONT, (WPARAM)ghFont, MAKELONG(FALSE, 0));
  121. RefreshChgrInfo(hwndEdit);
  122. TRACEEXIT(("=1\n"));
  123. return TRUE;
  124. } //InitChargerPage
  125. /*++
  126. @doc INTERNAL
  127. @func VOID | RefreshChgrInfo | Refresh charger information.
  128. @parm IN HWND | hwndEdit | Handle to edit control.
  129. @rvalue None.
  130. --*/
  131. VOID
  132. RefreshChgrInfo(
  133. IN HWND hwndEdit
  134. )
  135. {
  136. TRACEPROC("RefreshChgrInfo", 3)
  137. int i;
  138. PBYTE pbBuff;
  139. TRACEENTER(("(hwndEdit=%x)\n", hwndEdit));
  140. //
  141. // Erase edit control.
  142. //
  143. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  144. SendMessage(hwndEdit, EM_REPLACESEL, 0, (LPARAM)"");
  145. memset(&gChgrInfo, 0, sizeof(gChgrInfo));
  146. for (i = 0, pbBuff = (PBYTE)&gChgrInfo; i < NUM_CHGR_CMDS; ++i)
  147. {
  148. if (GetSMBDevInfo(SMB_CHARGER_ADDRESS, &gChgrCmds[i], pbBuff))
  149. {
  150. DisplayChgrInfo(hwndEdit, &gChgrCmds[i], pbBuff);
  151. }
  152. else
  153. {
  154. TRACEWARN(("failed to get charger info. for %s.\n",
  155. gChgrCmds[i].pszLabel));
  156. }
  157. pbBuff += gChgrCmds[i].iDataSize;
  158. }
  159. //
  160. // Scroll back to the top.
  161. //
  162. SendMessage(hwndEdit, EM_SETSEL, 0, 0);
  163. SendMessage(hwndEdit, EM_SCROLLCARET, 0, 0);
  164. TRACEEXIT(("!\n"));
  165. return;
  166. } //RefreshChgrInfo
  167. /*++
  168. @doc INTERNAL
  169. @func BOOL | DisplayChgrInfo | Display charger info.
  170. @parm IN HWND | hwndEdit | Edit window handle.
  171. @parm IN PSMBCMD_INFO | ChgrCmd | Points to the charger command.
  172. @parm IN PBYTE | pbBuff | Charger data to display.
  173. @rvalue SUCCESS | Returns TRUE if it handles it.
  174. @rvalue FAILURE | Returns FALSE if it doesn't handle it.
  175. --*/
  176. BOOL
  177. DisplayChgrInfo(
  178. IN HWND hwndEdit,
  179. IN PSMBCMD_INFO ChgrCmd,
  180. IN PBYTE pbBuff
  181. )
  182. {
  183. TRACEPROC("DisplayChgrInfo", 3)
  184. BOOL rc = TRUE;
  185. WORD wData = *((PWORD)pbBuff);
  186. TRACEENTER(("(hwndEdit=%x,ChgrCmd=%p,Cmd=%s,pbBuff=%p)\n",
  187. hwndEdit, ChgrCmd, ChgrCmd->pszLabel, pbBuff));
  188. EditPrintf(hwndEdit, "%s=", ChgrCmd->pszLabel);
  189. switch (ChgrCmd->bType)
  190. {
  191. case TYPEF_CHGR_SPECINFO:
  192. EditPrintf(hwndEdit, "0x%04x", wData);
  193. if (wData & CHGRSI_SELECTOR_SUPPORT)
  194. {
  195. EditPrintf(hwndEdit, ",SelectorSupport");
  196. }
  197. EditPrintf(hwndEdit, ",Spec:%x\r\n", wData & CHGRSI_SPEC_MASK);
  198. break;
  199. case TYPEF_CHGR_STATUS:
  200. EditPrintf(hwndEdit, "0x%04x", wData);
  201. DisplayDevBits(hwndEdit,
  202. ChgrCmd->dwData,
  203. (PSZ *)ChgrCmd->pvData,
  204. (DWORD)wData);
  205. if ((wData & CHGRSTATUS_CTRL_MASK) == CHGRSTATUS_CTRL_BATT)
  206. {
  207. EditPrintf(hwndEdit, ",BattCtrl'd");
  208. }
  209. else if ((wData & CHGRSTATUS_CTRL_MASK) == CHGRSTATUS_CTRL_HOST)
  210. {
  211. EditPrintf(hwndEdit, ",HostCtrl'd");
  212. }
  213. DisplayDevBits(hwndEdit,
  214. 0xf,
  215. gapszChgrStatus2Names,
  216. (DWORD)wData);
  217. EditPrintf(hwndEdit, "\r\n");
  218. break;
  219. default:
  220. rc = DisplaySMBDevInfo(hwndEdit, ChgrCmd, pbBuff);
  221. }
  222. TRACEEXIT(("=%x\n", rc));
  223. return rc;
  224. } //DisplayChgrInfo
  225. #endif //ifdef CHGRINFO