* Improved the disabled look (in case there is no battery -- apparently, the
ACPI interface needs some more work, as it currently uses BATTERY_CRITICAL_STATE to report that there is no battery...). * Cleanup of many more of Clemens' coding style violations... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32256 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -5,10 +5,10 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ACPI_DRIVER_INTERFACE_H
|
#ifndef ACPI_DRIVER_INTERFACE_H
|
||||||
#define ACPI_DRIVER_INTERFACE_H
|
#define ACPI_DRIVER_INTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
#include "DriverInterface.h"
|
#include "DriverInterface.h"
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
@@ -17,13 +17,12 @@
|
|||||||
|
|
||||||
const int8 kRateBufferSize = 10;
|
const int8 kRateBufferSize = 10;
|
||||||
|
|
||||||
class RateBuffer
|
class RateBuffer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
RateBuffer();
|
RateBuffer();
|
||||||
void AddRate(int32 rate);
|
void AddRate(int32 rate);
|
||||||
int32 GetMeanRate();
|
int32 GetMeanRate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 fRateBuffer[kRateBufferSize];
|
int32 fRateBuffer[kRateBufferSize];
|
||||||
int8 fPosition;
|
int8 fPosition;
|
||||||
@@ -32,11 +31,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Battery
|
class Battery {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Battery(int driverHandler);
|
Battery(int driverHandler);
|
||||||
~Battery();
|
~Battery();
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
|
|
||||||
@@ -49,19 +47,18 @@ public:
|
|||||||
private:
|
private:
|
||||||
void _Init();
|
void _Init();
|
||||||
|
|
||||||
|
|
||||||
int fDriverHandler;
|
int fDriverHandler;
|
||||||
status_t fInitStatus;
|
status_t fInitStatus;
|
||||||
|
|
||||||
acpi_extended_battery_info fExtendedBatteryInfo;
|
acpi_extended_battery_info fExtendedBatteryInfo;
|
||||||
|
|
||||||
RateBuffer fRateBuffer;
|
RateBuffer fRateBuffer;
|
||||||
acpi_battery_info fCachedAcpiInfo;
|
acpi_battery_info fCachedAcpiInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ACPIDriverInterface : public PowerStatusDriverInterface
|
class ACPIDriverInterface : public PowerStatusDriverInterface {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual ~ACPIDriverInterface();
|
virtual ~ACPIDriverInterface();
|
||||||
|
|
||||||
@@ -75,13 +72,13 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// Read the battery info from the hardware.
|
// Read the battery info from the hardware.
|
||||||
virtual status_t _ReadBatteryInfo();
|
virtual status_t _ReadBatteryInfo();
|
||||||
|
|
||||||
virtual void _WatchPowerStatus();
|
virtual void _WatchPowerStatus();
|
||||||
virtual status_t _FindDrivers(const char* path);
|
virtual status_t _FindDrivers(const char* path);
|
||||||
|
|
||||||
BObjectList<Battery> fDriverList;
|
BObjectList<Battery> fDriverList;
|
||||||
|
|
||||||
BLocker fInterfaceLocker;
|
BLocker fInterfaceLocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // ACPI_DRIVER_INTERFACE_H
|
||||||
|
|||||||
@@ -5,31 +5,30 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef APM_DRIVER_INTERFACE_H
|
#ifndef APM_DRIVER_INTERFACE_H
|
||||||
#define APM_DRIVER_INTERFACE_H
|
#define APM_DRIVER_INTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
#include "DriverInterface.h"
|
#include "DriverInterface.h"
|
||||||
|
|
||||||
|
|
||||||
class APMDriverInterface : public PowerStatusDriverInterface
|
class APMDriverInterface : public PowerStatusDriverInterface {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual ~APMDriverInterface();
|
virtual ~APMDriverInterface();
|
||||||
|
|
||||||
virtual status_t Connect();
|
virtual status_t Connect();
|
||||||
virtual status_t GetBatteryInfo(battery_info* info, int32 index);
|
virtual status_t GetBatteryInfo(battery_info* info, int32 index);
|
||||||
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
||||||
int32 index);
|
int32 index);
|
||||||
virtual int32 GetBatteryCount();
|
virtual int32 GetBatteryCount();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _WatchPowerStatus();
|
virtual void _WatchPowerStatus();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
|
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
|
||||||
int fDevice;
|
int fDevice;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // APM_DRIVER_INTERFACE_H
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DriverInterface.h"
|
#include "DriverInterface.h"
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
|
|
||||||
Monitor::~Monitor()
|
Monitor::~Monitor()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -39,8 +39,7 @@ Monitor::StopWatching(BHandler* target)
|
|||||||
void
|
void
|
||||||
Monitor::Broadcast(uint32 message)
|
Monitor::Broadcast(uint32 message)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < fWatcherList.CountItems(); i++)
|
for (int i = 0; i < fWatcherList.CountItems(); i++) {
|
||||||
{
|
|
||||||
BMessenger messenger(fWatcherList.ItemAt(i));
|
BMessenger messenger(fWatcherList.ItemAt(i));
|
||||||
messenger.SendMessage(message);
|
messenger.SendMessage(message);
|
||||||
}
|
}
|
||||||
@@ -50,9 +49,9 @@ Monitor::Broadcast(uint32 message)
|
|||||||
PowerStatusDriverInterface::PowerStatusDriverInterface()
|
PowerStatusDriverInterface::PowerStatusDriverInterface()
|
||||||
:
|
:
|
||||||
fIsWatching(0),
|
fIsWatching(0),
|
||||||
fThreadId(-1)
|
fThread(-1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,27 +66,25 @@ PowerStatusDriverInterface::StartWatching(BHandler* target)
|
|||||||
{
|
{
|
||||||
BAutolock autolock(fListLocker);
|
BAutolock autolock(fListLocker);
|
||||||
status_t status = Monitor::StartWatching(target);
|
status_t status = Monitor::StartWatching(target);
|
||||||
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (fThreadId > 0)
|
if (fThread > 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
fThreadId = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
|
|
||||||
B_LOW_PRIORITY, this);
|
|
||||||
if (fThreadId >= 0) {
|
|
||||||
atomic_set(&fIsWatching, 1);
|
|
||||||
status = resume_thread(fThreadId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return fThreadId;
|
|
||||||
|
|
||||||
if (status != B_OK && fWatcherList.CountItems() == 0) {
|
fThread = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
|
||||||
|
B_LOW_PRIORITY, this);
|
||||||
|
if (fThread >= 0) {
|
||||||
|
atomic_set(&fIsWatching, 1);
|
||||||
|
status = resume_thread(fThread);
|
||||||
|
} else
|
||||||
|
return fThread;
|
||||||
|
|
||||||
|
if (status != B_OK && fWatcherList.CountItems() == 0)
|
||||||
atomic_set(&fIsWatching, 0);
|
atomic_set(&fIsWatching, 0);
|
||||||
}
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,17 +92,15 @@ status_t
|
|||||||
PowerStatusDriverInterface::StopWatching(BHandler* target)
|
PowerStatusDriverInterface::StopWatching(BHandler* target)
|
||||||
{
|
{
|
||||||
BAutolock autolock(fListLocker);
|
BAutolock autolock(fListLocker);
|
||||||
if (fThreadId < 0)
|
if (fThread < 0)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t status;
|
|
||||||
if (fWatcherList.CountItems() == 1) {
|
if (fWatcherList.CountItems() == 1) {
|
||||||
atomic_set(&fIsWatching, 0);
|
atomic_set(&fIsWatching, 0);
|
||||||
|
wait_for_thread(fThread, NULL);
|
||||||
status = wait_for_thread(fThreadId, &status);
|
fThread = -1;
|
||||||
fThreadId = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Monitor::StopWatching(target);
|
return Monitor::StopWatching(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,9 +117,8 @@ void
|
|||||||
PowerStatusDriverInterface::Disconnect()
|
PowerStatusDriverInterface::Disconnect()
|
||||||
{
|
{
|
||||||
atomic_set(&fIsWatching, 0);
|
atomic_set(&fIsWatching, 0);
|
||||||
status_t status;
|
wait_for_thread(fThread, NULL);
|
||||||
wait_for_thread(fThreadId, &status);
|
fThread = -1;
|
||||||
fThreadId = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Clemens Zeidler, [email protected]
|
* Clemens Zeidler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DRIVER_INTERFACE_H
|
#ifndef DRIVER_INTERFACE_H
|
||||||
#define DRIVER_INTERFACE_H
|
#define DRIVER_INTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
@@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
#include "device/power_managment.h"
|
#include "device/power_managment.h"
|
||||||
|
|
||||||
|
|
||||||
typedef BObjectList<BHandler> WatcherList;
|
typedef BObjectList<BHandler> WatcherList;
|
||||||
|
|
||||||
const uint32 kMsgUpdate = 'updt';
|
const uint32 kMsgUpdate = 'updt';
|
||||||
|
|
||||||
|
|
||||||
struct battery_info
|
struct battery_info {
|
||||||
{
|
|
||||||
int8 state;
|
int8 state;
|
||||||
int32 capacity;
|
int32 capacity;
|
||||||
int32 full_capacity;
|
int32 full_capacity;
|
||||||
@@ -32,11 +32,10 @@ struct battery_info
|
|||||||
|
|
||||||
|
|
||||||
/*! Handle a list of watcher and broadcast a messages to them. */
|
/*! Handle a list of watcher and broadcast a messages to them. */
|
||||||
class Monitor
|
class Monitor {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual ~Monitor();
|
virtual ~Monitor();
|
||||||
|
|
||||||
virtual status_t StartWatching(BHandler* target);
|
virtual status_t StartWatching(BHandler* target);
|
||||||
virtual status_t StopWatching(BHandler* target);
|
virtual status_t StopWatching(BHandler* target);
|
||||||
|
|
||||||
@@ -44,12 +43,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
WatcherList fWatcherList;
|
WatcherList fWatcherList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PowerStatusDriverInterface : public Monitor, public Referenceable
|
class PowerStatusDriverInterface : public Monitor, public Referenceable {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
PowerStatusDriverInterface();
|
PowerStatusDriverInterface();
|
||||||
~PowerStatusDriverInterface();
|
~PowerStatusDriverInterface();
|
||||||
@@ -57,26 +54,27 @@ public:
|
|||||||
virtual status_t StartWatching(BHandler* target);
|
virtual status_t StartWatching(BHandler* target);
|
||||||
virtual status_t StopWatching(BHandler* target);
|
virtual status_t StopWatching(BHandler* target);
|
||||||
virtual void Broadcast(uint32 message);
|
virtual void Broadcast(uint32 message);
|
||||||
|
|
||||||
virtual status_t Connect() = 0;
|
virtual status_t Connect() = 0;
|
||||||
virtual void Disconnect();
|
virtual void Disconnect();
|
||||||
|
|
||||||
virtual status_t GetBatteryInfo(battery_info* status, int32 index) = 0;
|
virtual status_t GetBatteryInfo(battery_info* status, int32 index) = 0;
|
||||||
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
virtual status_t GetExtendedBatteryInfo(acpi_extended_battery_info* info,
|
||||||
int32 index) = 0;
|
int32 index) = 0;
|
||||||
|
|
||||||
virtual int32 GetBatteryCount() = 0;
|
virtual int32 GetBatteryCount() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _WatchPowerStatus() = 0;
|
virtual void _WatchPowerStatus() = 0;
|
||||||
|
|
||||||
vint32 fIsWatching;
|
vint32 fIsWatching;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int32 _ThreadWatchPowerFunction(void* data);
|
static int32 _ThreadWatchPowerFunction(void* data);
|
||||||
|
|
||||||
thread_id fThreadId;
|
thread_id fThread;
|
||||||
BLocker fListLocker;
|
BLocker fListLocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // DRIVER_INTERFACE_H
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ PowerStatus::ReadyToRun()
|
|||||||
isInstalled = deskbar.HasItem(kDeskbarItemName);
|
isInstalled = deskbar.HasItem(kDeskbarItemName);
|
||||||
}
|
}
|
||||||
|
|
||||||
isInstalled = true;
|
|
||||||
if (isDeskbarRunning && !isInstalled) {
|
if (isDeskbarRunning && !isInstalled) {
|
||||||
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
|
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
|
||||||
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||||
|
|||||||
@@ -191,30 +191,27 @@ PowerStatusView::_DrawBattery(BRect rect)
|
|||||||
rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));
|
rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));
|
||||||
|
|
||||||
int32 percent = fPercent;
|
int32 percent = fPercent;
|
||||||
if (percent > 100 || percent < 0)
|
if (percent > 100 || percent < 0 || !fHasBattery)
|
||||||
percent = 100;
|
percent = 100;
|
||||||
|
|
||||||
if (percent > 0) {
|
if (percent > 0) {
|
||||||
rgb_color base;
|
rgb_color base;
|
||||||
if (fOnline) {
|
if (fHasBattery) {
|
||||||
if (percent <= 15)
|
if (percent <= 15)
|
||||||
base.set_to(180, 0, 0);
|
base.set_to(180, 0, 0);
|
||||||
else
|
else
|
||||||
base.set_to(20, 180, 0);
|
base.set_to(20, 180, 0);
|
||||||
} else {
|
} else {
|
||||||
base = HighColor();
|
base = HighColor();
|
||||||
percent = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.InsetBy(gap, gap);
|
rect.InsetBy(gap, gap);
|
||||||
rect.right = rect.left + rect.Width() * percent / 100.0;
|
rect.right = rect.left + rect.Width() * percent / 100.0;
|
||||||
|
|
||||||
if (be_control_look != NULL)
|
if (be_control_look != NULL) {
|
||||||
be_control_look->DrawButtonBackground(this, rect, rect, base,
|
be_control_look->DrawButtonBackground(this, rect, rect, base,
|
||||||
fOnline ? 0 : BControlLook::B_DISABLED);
|
fHasBattery ? 0 : BControlLook::B_DISABLED);
|
||||||
//if (!)
|
} else
|
||||||
|
|
||||||
else
|
|
||||||
FillRect(rect);
|
FillRect(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,11 +340,15 @@ PowerStatusView::Update(bool force)
|
|||||||
|
|
||||||
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
|
||||||
fTimeLeft = fBatteryInfo.time_left;
|
fTimeLeft = fBatteryInfo.time_left;
|
||||||
if (fBatteryInfo.state & BATTERY_CHARGING)
|
if ((fBatteryInfo.state & BATTERY_CHARGING) != 0)
|
||||||
fOnline = true;
|
fOnline = true;
|
||||||
else
|
else
|
||||||
fOnline = false;
|
fOnline = false;
|
||||||
|
|
||||||
|
// TODO: if critical really means that, its name should be changed...
|
||||||
|
fHasBattery = (fBatteryInfo.state & BATTERY_CRITICAL_STATE) == 0
|
||||||
|
&& fPercent >= 0;
|
||||||
|
|
||||||
if (fInDeskbar) {
|
if (fInDeskbar) {
|
||||||
// make sure the tray icon is large enough
|
// make sure the tray icon is large enough
|
||||||
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
|
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
|
||||||
@@ -358,6 +359,15 @@ PowerStatusView::Update(bool force)
|
|||||||
|
|
||||||
if (text[0])
|
if (text[0])
|
||||||
width += ceilf(StringWidth(text)) + 4;
|
width += ceilf(StringWidth(text)) + 4;
|
||||||
|
} else {
|
||||||
|
char text[256];
|
||||||
|
if (fHasBattery) {
|
||||||
|
snprintf(text, sizeof(text), "%ld%%\n%ld:%02ld\n%s",
|
||||||
|
fPercent, fTimeLeft / 3600, (fTimeLeft / 60) % 60,
|
||||||
|
fOnline ? "charging" : "discharging");
|
||||||
|
} else
|
||||||
|
strcpy(text, "no battery");
|
||||||
|
SetToolTip(text);
|
||||||
}
|
}
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
// make sure we're not going away completely
|
// make sure we're not going away completely
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ protected:
|
|||||||
int32 fPercent;
|
int32 fPercent;
|
||||||
time_t fTimeLeft;
|
time_t fTimeLeft;
|
||||||
bool fOnline;
|
bool fOnline;
|
||||||
|
bool fHasBattery;
|
||||||
|
|
||||||
BSize fPreferredSize;
|
BSize fPreferredSize;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user