1 /* 2 * Copyright 2009, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Clemens Zeidler, haiku@clemens-zeidler.de 7 */ 8 #ifndef ACPI_DRIVER_INTERFACE_H 9 #define ACPI_DRIVER_INTERFACE_H 10 11 12 #include "DriverInterface.h" 13 14 #include <Locker.h> 15 #include <ObjectList.h> 16 17 18 const int8 kRateBufferSize = 10; 19 20 class RateBuffer { 21 public: 22 RateBuffer(); 23 void AddRate(int32 rate); 24 int32 GetMeanRate(); 25 26 private: 27 int32 fRateBuffer[kRateBufferSize]; 28 int8 fPosition; 29 int8 fSize; 30 int8 fCurrentSize; 31 }; 32 33 34 class Battery { 35 public: 36 Battery(int driverHandler); 37 ~Battery(); 38 39 status_t InitCheck(); 40 41 // Read battery info and update the cache. 42 status_t ReadBatteryInfo(); 43 status_t GetBatteryInfoCached(battery_info* info); 44 status_t GetExtendedBatteryInfo( 45 acpi_extended_battery_info* info); 46 47 private: 48 void _Init(); 49 50 51 int fDriverHandler; 52 status_t fInitStatus; 53 54 acpi_extended_battery_info fExtendedBatteryInfo; 55 56 RateBuffer fRateBuffer; 57 acpi_battery_info fCachedAcpiInfo; 58 }; 59 60 61 class ACPIDriverInterface : public PowerStatusDriverInterface { 62 public: 63 virtual ~ACPIDriverInterface(); 64 65 virtual status_t Connect(); 66 virtual status_t GetBatteryInfo(battery_info* info, int32 index); 67 virtual status_t GetExtendedBatteryInfo( 68 acpi_extended_battery_info* info, int32 index); 69 70 virtual int32 GetBatteryCount(); 71 72 protected: 73 // Read the battery info from the hardware. 74 virtual status_t _ReadBatteryInfo(); 75 76 virtual void _WatchPowerStatus(); 77 virtual status_t _FindDrivers(const char* dirpath); 78 79 BObjectList<Battery> fDriverList; 80 81 BLocker fInterfaceLocker; 82 }; 83 84 #endif // ACPI_DRIVER_INTERFACE_H 85