1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile apmh.h:
|
---|
4 | * header file for apmh.c.
|
---|
5 | *
|
---|
6 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
7 | * numbering.
|
---|
8 | *
|
---|
9 | *@@include #include <os2.h>
|
---|
10 | *@@include #include "helpers\apmh.h"
|
---|
11 | */
|
---|
12 |
|
---|
13 | /* Copyright (C) 1998-2001 Ulrich Mller.
|
---|
14 | * This file is part of the "XWorkplace helpers" source package.
|
---|
15 | * This is free software; you can redistribute it and/or modify
|
---|
16 | * it under the terms of the GNU General Public License as published
|
---|
17 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
18 | * "COPYING" file of the XWorkplace main distribution.
|
---|
19 | * This program is distributed in the hope that it will be useful,
|
---|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
22 | * GNU General Public License for more details.
|
---|
23 | */
|
---|
24 |
|
---|
25 | #if __cplusplus
|
---|
26 | extern "C" {
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #ifndef APMH_HEADER_INCLUDED
|
---|
30 | #define APMH_HEADER_INCLUDED
|
---|
31 |
|
---|
32 | /* ******************************************************************
|
---|
33 | *
|
---|
34 | * APM definitions (from DDK)
|
---|
35 | *
|
---|
36 | ********************************************************************/
|
---|
37 |
|
---|
38 | /*---------------------------------------------------------------------------*
|
---|
39 | * Category 12 (Power Management) IOCtl Function Codes *
|
---|
40 | *---------------------------------------------------------------------------*/
|
---|
41 |
|
---|
42 | #define APMGIO_Category 12 // Generic IOCtl Category for APM.
|
---|
43 |
|
---|
44 | #define APMGIO_SendEvent 0x40 // Function Codes.
|
---|
45 | #define APMGIO_SetEventSem 0x41
|
---|
46 | #define APMGIO_ConfirmEvent 0x42 // 0x42 is UNDOCUMENTED.
|
---|
47 | #define APMGIO_BroadcastEvent 0x43 // 0x43 is UNDOCUMENTED.
|
---|
48 | #define APMGIO_RegDaemonThread 0x44 // 0x44 is UNDOCUMENTED.
|
---|
49 | #define APMGIO_OEMFunction 0x45
|
---|
50 | #define APMGIO_QueryStatus 0x60
|
---|
51 | #define APMGIO_QueryEvent 0x61
|
---|
52 | #define APMGIO_QueryInfo 0x62
|
---|
53 | #define APMGIO_QueryState 0x63
|
---|
54 |
|
---|
55 | #pragma pack(1)
|
---|
56 |
|
---|
57 | /*---------------------------------------------------------------------------*
|
---|
58 | * Function 0x60, Query Power Status *
|
---|
59 | * Reference MS/Intel APM specification for interpretation of status codes. *
|
---|
60 | *---------------------------------------------------------------------------*/
|
---|
61 |
|
---|
62 | typedef struct _APMGIO_QSTATUS_PPKT // Parameter Packet.
|
---|
63 | {
|
---|
64 | USHORT ParmLength; // Length, in bytes, of the Parm Packet.
|
---|
65 | USHORT Flags; // Output: Flags.
|
---|
66 | UCHAR ACStatus;
|
---|
67 | // Output: 0x00 if not on AC,
|
---|
68 | // 0x01 if AC,
|
---|
69 | // 0x02 if on backup power,
|
---|
70 | // 0xFF if unknown
|
---|
71 | UCHAR BatteryStatus;
|
---|
72 | // Output: 0x00 if battery high,
|
---|
73 | // 0x01 if battery low,
|
---|
74 | // 0x02 if battery critically low,
|
---|
75 | // 0x03 if battery charging
|
---|
76 | // 0xFF if unknown
|
---|
77 | UCHAR BatteryLife;
|
---|
78 | // Output: Battery power life (as percentage)
|
---|
79 | UCHAR BatteryTimeForm;
|
---|
80 | // Output:
|
---|
81 | // 0x00 if format is seconds,
|
---|
82 | // 0x01 if format is minutes,
|
---|
83 | // 0xFF if unknown
|
---|
84 | USHORT BatteryTime; // Output: Remaining battery time.
|
---|
85 | UCHAR BatteryFlags; // Output: Battery status flags
|
---|
86 |
|
---|
87 | } APMGIO_QSTATUS_PPKT, *NPAPMGIO_QSTATUS_PPKT, FAR *PAPMGIO_QSTATUS_PPKT;
|
---|
88 |
|
---|
89 | typedef struct _APMGIO_10_QSTATUS_PPKT { // Parameter Packet for
|
---|
90 | // APM 1.0 interface
|
---|
91 | USHORT ParmLength; // Length, in bytes, of the Parm Packet.
|
---|
92 | USHORT Flags; // Output: Flags.
|
---|
93 | UCHAR ACStatus; // Output: AC line power status.
|
---|
94 | UCHAR BatteryStatus; // Output: Battery power status
|
---|
95 | UCHAR BatteryLife; // Output: Battery power status
|
---|
96 |
|
---|
97 | } APMGIO_10_QSTATUS_PPKT;
|
---|
98 |
|
---|
99 | // Error return codes.
|
---|
100 | #define GIOERR_PowerNoError 0
|
---|
101 | #define GIOERR_PowerBadSubId 1
|
---|
102 | #define GIOERR_PowerBadReserved 2
|
---|
103 | #define GIOERR_PowerBadDevId 3
|
---|
104 | #define GIOERR_PowerBadPwrState 4
|
---|
105 | #define GIOERR_PowerSemAlreadySetup 5
|
---|
106 | #define GIOERR_PowerBadFlags 6
|
---|
107 | #define GIOERR_PowerBadSemHandle 7
|
---|
108 | #define GIOERR_PowerBadLength 8
|
---|
109 | #define GIOERR_PowerDisabled 9
|
---|
110 | #define GIOERR_PowerNoEventQueue 10
|
---|
111 | #define GIOERR_PowerTooManyQueues 11
|
---|
112 | #define GIOERR_PowerBiosError 12
|
---|
113 | #define GIOERR_PowerBadSemaphore 13
|
---|
114 | #define GIOERR_PowerQueueOverflow 14
|
---|
115 | #define GIOERR_PowerStateChangeReject 15
|
---|
116 | #define GIOERR_PowerNotSupported 16
|
---|
117 | #define GIOERR_PowerDisengaged 17
|
---|
118 | #define GIOERR_PowerHighestErrCode 17
|
---|
119 |
|
---|
120 | typedef struct _APMGIO_DPKT {
|
---|
121 |
|
---|
122 | USHORT ReturnCode;
|
---|
123 |
|
---|
124 | } APMGIO_DPKT, *NPAPMGIO_DPKT, FAR *PAPMGIO_DPKT;
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * define constants and type for APM function
|
---|
128 | */
|
---|
129 |
|
---|
130 | #define POWER_SUBID_ENABLE_APM 0x0003
|
---|
131 | #define POWER_SUBID_SET_POWER_STATE 0x0006
|
---|
132 |
|
---|
133 | #define POWER_DEVID_ALL_DEVICES 0x0001
|
---|
134 |
|
---|
135 | #define POWER_STATE_OFF 0x0003
|
---|
136 |
|
---|
137 | #define BIOSFLAG_APMSUPPORTED 0x0008
|
---|
138 |
|
---|
139 | typedef struct
|
---|
140 | {
|
---|
141 | USHORT usSubID;
|
---|
142 | USHORT usReserved;
|
---|
143 | USHORT usData1;
|
---|
144 | USHORT usData2;
|
---|
145 | } SENDPOWEREVENT;
|
---|
146 |
|
---|
147 | typedef struct
|
---|
148 | {
|
---|
149 | USHORT usParmLength;
|
---|
150 | USHORT usBIOSFlags;
|
---|
151 | USHORT usBIOSVersion;
|
---|
152 | USHORT usDriverVersion;
|
---|
153 | } GETPOWERINFO;
|
---|
154 |
|
---|
155 | #pragma pack()
|
---|
156 |
|
---|
157 | /* ******************************************************************
|
---|
158 | *
|
---|
159 | * APM helper APIs
|
---|
160 | *
|
---|
161 | ********************************************************************/
|
---|
162 |
|
---|
163 | #pragma pack(1)
|
---|
164 |
|
---|
165 | /*
|
---|
166 | *@@ APM:
|
---|
167 | * APM monitor data returned from apmhOpen.
|
---|
168 | *
|
---|
169 | *@@added V0.9.14 (2001-08-01) [umoeller]
|
---|
170 | *@@changed V0.9.19 (2002-05-28) [umoeller]: added fUsingAC
|
---|
171 | */
|
---|
172 |
|
---|
173 | typedef struct _APM
|
---|
174 | {
|
---|
175 | HFILE hfAPMSys;
|
---|
176 |
|
---|
177 | USHORT usBIOSVersion,
|
---|
178 | usDriverVersion,
|
---|
179 | usLowestAPMVersion;
|
---|
180 |
|
---|
181 | BYTE fAlreadyRead;
|
---|
182 | // TRUE after the first call to aphReadStatus
|
---|
183 |
|
---|
184 | // the following are valid after a call to apmhReadStatus
|
---|
185 |
|
---|
186 | // Note: According to Eirik, his laptop did not return
|
---|
187 | // bBatteryStatus == 0x03 after the battery had finished
|
---|
188 | // charging. So bBatteryStatus cannot be used to determine
|
---|
189 | // whether the system is running on AC or not. Hence the
|
---|
190 | // addition of fUsingAC.
|
---|
191 | // V0.9.19 (2002-05-28) [umoeller]
|
---|
192 | BYTE fUsingAC;
|
---|
193 | // 0x00 if not on AC,
|
---|
194 | // 0x01 if AC,
|
---|
195 | // 0x02 if on backup power,
|
---|
196 | // 0xFF if unknown
|
---|
197 |
|
---|
198 | BYTE bBatteryStatus;
|
---|
199 | // copy of APM battery status, that is:
|
---|
200 | // Output: 0x00 if battery high,
|
---|
201 | // 0x01 if battery low,
|
---|
202 | // 0x02 if battery critically low,
|
---|
203 | // 0x03 if battery charging
|
---|
204 | // 0xFF if unknown
|
---|
205 | BYTE bBatteryLife;
|
---|
206 | // current battery life as percentage (0-100)
|
---|
207 |
|
---|
208 | } APM, *PAPM;
|
---|
209 |
|
---|
210 | #pragma pack()
|
---|
211 |
|
---|
212 | APIRET APIENTRY apmhIOCtl(HFILE hfAPMSys, ULONG ulFunction, PVOID pvParamPck, ULONG cbParamPck);
|
---|
213 | typedef APIRET APIENTRY APMHIOCTL(HFILE hfAPMSys, ULONG ulFunction, PVOID pvParamPck, ULONG cbParamPck);
|
---|
214 | typedef APMHIOCTL *PAPMHIOCTL;
|
---|
215 |
|
---|
216 | APIRET APIENTRY apmhOpen(PAPM *ppApm);
|
---|
217 | typedef APIRET APIENTRY APMHOPEN(PAPM *ppApm);
|
---|
218 | typedef APMHOPEN *PAPMHOPEN;
|
---|
219 |
|
---|
220 | APIRET APIENTRY apmhReadStatus(PAPM pApm, PBOOL pfChanged);
|
---|
221 | typedef APIRET APIENTRY APMHREADSTATUS(PAPM pApm, PBOOL pfChanged);
|
---|
222 | typedef APMHREADSTATUS *PAPMHREADSTATUS;
|
---|
223 |
|
---|
224 | VOID APIENTRY apmhClose(PAPM *ppApm);
|
---|
225 | typedef VOID APIENTRY APMHCLOSE(PAPM *ppApm);
|
---|
226 | typedef APMHCLOSE *PAPMHCLOSE;
|
---|
227 |
|
---|
228 | BOOL apmhHasBattery(VOID);
|
---|
229 |
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | #if __cplusplus
|
---|
233 | }
|
---|
234 | #endif
|
---|
235 |
|
---|