2 * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler, haiku@clemens-zeidler.de
10 #include "APMDriverInterface.h"
12 #include <arch/x86/apm_defs.h>
13 #include <generic_syscall_defs.h>
17 const bigtime_t kUpdateInterval
= 2000000;
21 APMDriverInterface::~APMDriverInterface()
27 APMDriverInterface::Connect()
30 status_t status
= _kern_generic_syscall(APM_SYSCALLS
, B_SYSCALL_INFO
,
31 &version
, sizeof(version
));
34 status
= _kern_generic_syscall(APM_SYSCALLS
, APM_GET_BATTERY_INFO
,
35 &info
, sizeof(battery_info
));
43 APMDriverInterface::GetBatteryInfo(int32 index
, battery_info
* info
)
48 info
->current_rate
= -1;
50 apm_battery_info apmInfo
;
51 status_t status
= _kern_generic_syscall(APM_SYSCALLS
, APM_GET_BATTERY_INFO
,
52 &apmInfo
, sizeof(apm_battery_info
));
54 info
->state
= apmInfo
.online
? BATTERY_CHARGING
: BATTERY_DISCHARGING
;
55 info
->capacity
= apmInfo
.percent
;
56 info
->full_capacity
= 100;
57 info
->time_left
= apmInfo
.time_left
;
65 APMDriverInterface::GetExtendedBatteryInfo(int32 index
,
66 acpi_extended_battery_info
* info
)
68 return B_NOT_SUPPORTED
;
73 APMDriverInterface::GetBatteryCount()
80 APMDriverInterface::_WatchPowerStatus()
82 while (atomic_get(&fIsWatching
) > 0) {
83 Broadcast(kMsgUpdate
);
84 acquire_sem_etc(fWaitSem
, 1, B_RELATIVE_TIMEOUT
, kUpdateInterval
);