BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / powerstatus / APMDriverInterface.cpp
blob4a050506d33b67481e48cf132ea68dac130f3631
1 /*
2 * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler, haiku@clemens-zeidler.de
7 */
10 #include "APMDriverInterface.h"
12 #include <arch/x86/apm_defs.h>
13 #include <generic_syscall_defs.h>
14 #include <syscalls.h>
17 const bigtime_t kUpdateInterval = 2000000;
18 // every two seconds
21 APMDriverInterface::~APMDriverInterface()
26 status_t
27 APMDriverInterface::Connect()
29 uint32 version = 0;
30 status_t status = _kern_generic_syscall(APM_SYSCALLS, B_SYSCALL_INFO,
31 &version, sizeof(version));
32 if (status == B_OK) {
33 battery_info info;
34 status = _kern_generic_syscall(APM_SYSCALLS, APM_GET_BATTERY_INFO,
35 &info, sizeof(battery_info));
38 return status;
42 status_t
43 APMDriverInterface::GetBatteryInfo(int32 index, battery_info* info)
45 if (index != 0)
46 return B_BAD_VALUE;
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));
53 if (status == B_OK) {
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;
60 return status;
64 status_t
65 APMDriverInterface::GetExtendedBatteryInfo(int32 index,
66 acpi_extended_battery_info* info)
68 return B_NOT_SUPPORTED;
72 int32
73 APMDriverInterface::GetBatteryCount()
75 return 1;
79 void
80 APMDriverInterface::_WatchPowerStatus()
82 while (atomic_get(&fIsWatching) > 0) {
83 Broadcast(kMsgUpdate);
84 acquire_sem_etc(fWaitSem, 1, B_RELATIVE_TIMEOUT, kUpdateInterval);