1/* 2 * Copyright 2009-2015, 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 18const int8 kRateBufferSize = 10; 19 20class RateBuffer { 21public: 22 RateBuffer(); 23 void AddRate(int32 rate); 24 int32 GetMeanRate(); 25 26private: 27 int32 fRateBuffer[kRateBufferSize]; 28 int8 fPosition; 29 int8 fSize; 30 int8 fCurrentSize; 31}; 32 33 34class Battery { 35public: 36 Battery(int driverHandler); 37 ~Battery(); 38 39 status_t InitCheck(); 40 41 // Read battery info and update the cache. 42 status_t UpdateBatteryInfo(); 43 status_t GetBatteryInfoCached(battery_info* info); 44 status_t GetExtendedBatteryInfo( 45 acpi_extended_battery_info* info); 46 47private: 48 void _Init(); 49 50private: 51 int fDriverHandler; 52 status_t fInitStatus; 53 54 acpi_extended_battery_info fExtendedBatteryInfo; 55 56 RateBuffer fRateBuffer; 57 acpi_battery_info fCachedInfo; 58}; 59 60 61class ACPIDriverInterface : public PowerStatusDriverInterface { 62public: 63 ACPIDriverInterface(); 64 virtual ~ACPIDriverInterface(); 65 66 virtual status_t Connect(); 67 virtual status_t GetBatteryInfo(int32 index, battery_info* info); 68 virtual status_t GetExtendedBatteryInfo(int32 index, 69 acpi_extended_battery_info* info); 70 71 virtual int32 GetBatteryCount(); 72 73protected: 74 // Read the battery info from the hardware. 75 virtual status_t _UpdateBatteryInfo(); 76 77 virtual void _WatchPowerStatus(); 78 virtual status_t _FindDrivers(const char* dirpath); 79 80private: 81 BLocker fInterfaceLocker; 82 BObjectList<Battery> fDriverList; 83}; 84 85#endif // ACPI_DRIVER_INTERFACE_H 86