16aed176cSClemens Zeidler /* 290169e63SAxel Dörfler * Copyright 2009-2015, Haiku, Inc. All Rights Reserved. 36aed176cSClemens Zeidler * Distributed under the terms of the MIT License. 46aed176cSClemens Zeidler * 56aed176cSClemens Zeidler * Authors: 66aed176cSClemens Zeidler * Clemens Zeidler, haiku@clemens-zeidler.de 76aed176cSClemens Zeidler */ 86aed176cSClemens Zeidler #ifndef ACPI_DRIVER_INTERFACE_H 96aed176cSClemens Zeidler #define ACPI_DRIVER_INTERFACE_H 106aed176cSClemens Zeidler 1195ea1dabSAxel Dörfler 126aed176cSClemens Zeidler #include "DriverInterface.h" 136aed176cSClemens Zeidler 146aed176cSClemens Zeidler #include <Locker.h> 156aed176cSClemens Zeidler #include <ObjectList.h> 166aed176cSClemens Zeidler 17e391ec67SClemens Zeidler 186aed176cSClemens Zeidler const int8 kRateBufferSize = 10; 196aed176cSClemens Zeidler 2095ea1dabSAxel Dörfler class RateBuffer { 216aed176cSClemens Zeidler public: 226aed176cSClemens Zeidler RateBuffer(); 236aed176cSClemens Zeidler void AddRate(int32 rate); 246aed176cSClemens Zeidler int32 GetMeanRate(); 256aed176cSClemens Zeidler 266aed176cSClemens Zeidler private: 276aed176cSClemens Zeidler int32 fRateBuffer[kRateBufferSize]; 286aed176cSClemens Zeidler int8 fPosition; 296aed176cSClemens Zeidler int8 fSize; 306aed176cSClemens Zeidler int8 fCurrentSize; 316aed176cSClemens Zeidler }; 326aed176cSClemens Zeidler 336aed176cSClemens Zeidler 3495ea1dabSAxel Dörfler class Battery { 356aed176cSClemens Zeidler public: 366aed176cSClemens Zeidler Battery(int driverHandler); 376aed176cSClemens Zeidler ~Battery(); 386aed176cSClemens Zeidler 396aed176cSClemens Zeidler status_t InitCheck(); 406aed176cSClemens Zeidler 41e391ec67SClemens Zeidler // Read battery info and update the cache. 42*b19e9d5bSAxel Dörfler status_t UpdateBatteryInfo(); 43e391ec67SClemens Zeidler status_t GetBatteryInfoCached(battery_info* info); 446aed176cSClemens Zeidler status_t GetExtendedBatteryInfo( 456aed176cSClemens Zeidler acpi_extended_battery_info* info); 466aed176cSClemens Zeidler 476aed176cSClemens Zeidler private: 486aed176cSClemens Zeidler void _Init(); 496aed176cSClemens Zeidler 5090169e63SAxel Dörfler private: 516aed176cSClemens Zeidler int fDriverHandler; 526aed176cSClemens Zeidler status_t fInitStatus; 536aed176cSClemens Zeidler 546aed176cSClemens Zeidler acpi_extended_battery_info fExtendedBatteryInfo; 556aed176cSClemens Zeidler 566aed176cSClemens Zeidler RateBuffer fRateBuffer; 57*b19e9d5bSAxel Dörfler acpi_battery_info fCachedInfo; 586aed176cSClemens Zeidler }; 596aed176cSClemens Zeidler 606aed176cSClemens Zeidler 6195ea1dabSAxel Dörfler class ACPIDriverInterface : public PowerStatusDriverInterface { 626aed176cSClemens Zeidler public: 6390169e63SAxel Dörfler ACPIDriverInterface(); 646aed176cSClemens Zeidler virtual ~ACPIDriverInterface(); 656aed176cSClemens Zeidler 666aed176cSClemens Zeidler virtual status_t Connect(); 67*b19e9d5bSAxel Dörfler virtual status_t GetBatteryInfo(int32 index, battery_info* info); 68*b19e9d5bSAxel Dörfler virtual status_t GetExtendedBatteryInfo(int32 index, 69*b19e9d5bSAxel Dörfler acpi_extended_battery_info* info); 706aed176cSClemens Zeidler 716aed176cSClemens Zeidler virtual int32 GetBatteryCount(); 726aed176cSClemens Zeidler 736aed176cSClemens Zeidler protected: 74e391ec67SClemens Zeidler // Read the battery info from the hardware. 75*b19e9d5bSAxel Dörfler virtual status_t _UpdateBatteryInfo(); 76e391ec67SClemens Zeidler 776aed176cSClemens Zeidler virtual void _WatchPowerStatus(); 7843687843SFredrik Holmqvist virtual status_t _FindDrivers(const char* dirpath); 796aed176cSClemens Zeidler 80*b19e9d5bSAxel Dörfler private: 81e391ec67SClemens Zeidler BLocker fInterfaceLocker; 82*b19e9d5bSAxel Dörfler BObjectList<Battery> fDriverList; 836aed176cSClemens Zeidler }; 846aed176cSClemens Zeidler 8595ea1dabSAxel Dörfler #endif // ACPI_DRIVER_INTERFACE_H 86