...
 
Commits (2)
/*
Project: batmon
Copyright (C) 2005-2010 GNUstep Application Project
Copyright (C) 2005-2015 GNUstep Application Project
Author: Riccardo Mottola
......@@ -30,23 +30,30 @@
@interface AppController : NSObject
{
IBOutlet NSWindow *monitorWin;
IBOutlet NSTextField *voltage;
IBOutlet NSTextField *amperage;
IBOutlet NSTextField *presentCap;
IBOutlet NSTextField *rate;
IBOutlet NSTextField *rateLabel;
IBOutlet NSTextField *percent;
IBOutlet NSTextField *timeLeft;
IBOutlet NSTextField *chState;
IBOutlet NSProgressIndicator *level;
IBOutlet NSButton *cellInfoButton;
IBOutlet NSBox *lifeBox;
IBOutlet NSBox *cellDataBox;
IBOutlet NSWindow *monitorWin;
IBOutlet NSWindow *infoWin;
IBOutlet NSProgressIndicator *lifeGauge;
IBOutlet NSTextField *lifeGaugePercent;
IBOutlet NSTextField *designCap;
IBOutlet NSTextField *battType;
IBOutlet NSTextField *battTypeLabel;
IBOutlet NSTextField *manufacturer;
IBOutlet NSTextField *manufacturerLabel;
IBOutlet NSTextField *lastFullCharge;
IBOutlet NSBox *cellHealthBox;
NSDictionary *stateStrAttributes;
......
/*
Project: batmon
Copyright (C) 2005-2010 GNUstep Application Project
Copyright (C) 2005-2016 GNUstep Application Project
Author: Riccardo Mottola
FreeBSD support by Chris B. Vetter
Created: 2005-06-25 21:06:19 +0200 by multix
......@@ -47,14 +46,12 @@
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (id)init
{
if ((self = [super init]))
{
{
NSMutableParagraphStyle *style;
NSFont *font;
......@@ -69,7 +66,10 @@
style, NSParagraphStyleAttributeName, nil] retain];
iconPlug = [[NSImage imageNamed:@"small_plug.tif"] retain];
iconBattery = [[NSImage imageNamed:@"small_battery.tif"] retain];
}
/* localization */
[rateLabel setStringValue:_(@"Discharge Rate")];
}
return self;
}
......@@ -88,7 +88,6 @@
if (YES)
{
NSLog(@"app initialized, setting timer");
timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(updateInfo:) userInfo:nil repeats:YES];
[timer fire];
}
......@@ -146,6 +145,8 @@
chargePercentToDraw = [batModel chargePercent];
if (chargePercentToDraw > 100)
chargePercentToDraw = 100;
else if (chargePercentToDraw < 0 || isnan(chargePercentToDraw))
chargePercentToDraw = 0;
[[NSColor darkGrayColor] set];
/* main body */
......@@ -160,7 +161,9 @@
[NSBezierPath fillRect: NSMakeRect((WIDTH/2)-2, HEIGHT+1+1, 4, 2)];
/* draw the charge status */
if ([batModel isCritical] == YES)
if ([batModel isWarning] == YES)
[[NSColor orangeColor] set];
else if ([batModel isCritical] == YES)
[[NSColor redColor] set];
else
[[NSColor greenColor] set];
......@@ -191,7 +194,7 @@
{
float lifeVal;
float timeRem;
float chargePercentToDraw; /* we need this beause chargePercent can go beyond 100% */
float chargePercentToDraw; /* we need this because chargePercent can go beyond 100% */
[batModel update];
......@@ -219,12 +222,16 @@
[presentCap setStringValue:[NSString stringWithFormat:@"%3.2f Wh", [batModel remainingCapacity]]];
else
[presentCap setStringValue:[NSString stringWithFormat:@"%3.2f Ah", [batModel remainingCapacity]]];
if ([batModel isCharging])
[rateLabel setStringValue:_(@"Charge Rate")];
else
[rateLabel setStringValue:_(@"Discharge Rate")];
/* info window */
lifeVal = [batModel lastCapacity]/[batModel designCapacity];
[lifeGauge setDoubleValue:lifeVal*100];
[lifeGaugePercent setStringValue:[NSString stringWithFormat:@"%3.1f%", lifeVal*100]];
[lifeGaugePercent setStringValue:[NSString stringWithFormat:@"%3.1f%%", lifeVal*100]];
[battType setStringValue:[batModel batteryType]];
[manufacturer setStringValue:[batModel manufacturer]];
......
/*
Project: batmon
Copyright (C) 2006-2015 GNUstep Application Project
Author: Riccardo Mottola
FreeBSD support by Chris B. Vetter (initial version)
Created: 2013-07-23 Riccardo Mottola
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#if defined(freebsd) || defined( __FreeBSD__ )
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/acpica/acpiio.h>
#define ACPIDEV "/dev/acpi"
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import "BatteryModel.h"
@implementation BatteryModel (PlatformSpecific)
- (void)initPlatformSpecific
{
}
- (void)updatePlatformSpecific
{
union acpi_battery_ioctl_arg battio;
int acpifd;
battio.unit = 0;
acpifd = open(ACPIDEV, O_RDWR);
if (acpifd == -1) acpifd = open(ACPIDEV, O_RDONLY);
if (acpifd == -1) return;
if( -1 == ioctl(acpifd, ACPIIO_CMBAT_GET_BIF, &battio) ) return;
desCap = (float)battio.bif.dcap / 1000; // design capacity
lastCap = (float)battio.bif.lfcap / 1000; // last full capacity
if( -1 == ioctl(acpifd, ACPIIO_CMBAT_GET_BST, &battio) ) return;
close(acpifd);
currCap = (float)battio.bst.cap / 1000; // remaining capacity
volts = (float)battio.bst.volt / 1000; // present voltage
watts = (float)battio.bst.rate / 1000; // present rate
amps = 0;
if (volts)
amps = watts / volts;
batteryType = @"";
if( ACPI_BATT_STAT_NOT_PRESENT != battio.bst.state )
{
isCritical = NO;
if( battio.bst.state & ACPI_BATT_STAT_CRITICAL )
isCritical = YES;
if( battio.bst.state == 0 )
batteryState = BMBStateHigh;
else if( battio.bst.state & ACPI_BATT_STAT_CHARGING )
batteryState = BMBStateCharging;
else if( battio.bst.state & ACPI_BATT_STAT_DISCHARG )
batteryState = BMBStateDischarging;
else if (battio.bst.state & ACPI_BATT_STAT_INVALID )
batteryState = BMBStateUnknown;
else
batteryState = BMBStateUnknown;
batteryType = [NSString stringWithFormat: @"%s", battio.bif.type];
}
else
{
batteryState = BMBStateMissing;
batteryType = @"Missing";
}
if( batteryState == BMBStateHigh )
{
timeRemaining = 0;
chargePercent = currCap/lastCap*100;
isCharging = YES;
}
else if( batteryState == BMBStateCharging )
{
timeRemaining = (lastCap-currCap) / watts;
chargePercent = currCap/lastCap*100;
isCharging = YES;
}
else if( batteryState == BMBStateDischarging )
{
timeRemaining = currCap / watts;
chargePercent = currCap/lastCap*100;
isCharging = NO;
}
}
@end
#endif
This diff is collapsed.
/*
Project: batmon
Copyright (C) 2006-2016 GNUstep Application Project
Author: Riccardo Mottola
Created: 2013-07-23 Riccardo Mottola
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#if defined(netbsd) || defined (__NetBSD__)
#include <paths.h> /* path for the system devices */
#include <fcntl.h> /* open */
#include <unistd.h>
#include <sys/envsys.h>
#include <prop/proplib.h> /* psd property dictionaries */
#import <Foundation/Foundation.h>
#import "BatteryModel.h"
@implementation BatteryModel (PlatformSpecific)
- (void)initPlatformSpecific
{
}
- (void)updatePlatformSpecific
{
int sysmonfd; /* fd of /dev/sysmon */
int rval;
prop_dictionary_t bsd_dict;
NSString *string;
NSDictionary *dict;
char *cStr;
NSEnumerator *enum1;
id obj1;
NSDictionary *acpibat0;
NSMutableDictionary *batDict;
NSDictionary *chargeDict;
NSString *valueStr;
float chargeRate;
float dischargeRate;
/* Open the device in ro mode */
if ((sysmonfd = open(_PATH_SYSMON, O_RDONLY)) == -1)
NSLog(@"Error opening device: %s", _PATH_SYSMON);
rval = prop_dictionary_recv_ioctl(sysmonfd,
ENVSYS_GETDICTIONARY,
&bsd_dict);
if (rval)
{
NSLog(@"Error: %s", strerror(rval));
return;
}
cStr = prop_dictionary_externalize(bsd_dict);
string = [NSString stringWithCString: cStr];
dict = [string propertyList];
if (dict == nil)
{
NSLog(@"Could not parse dictionary");
return;
}
acpibat0 = [dict objectForKey: @"acpibat0"];
//NSLog(@"acpibat0: %@", acpibat0);
batDict = [NSMutableDictionary dictionaryWithCapacity: 3];
enum1 = [acpibat0 objectEnumerator];
while ((obj1 = [enum1 nextObject]))
{
if ([obj1 isKindOfClass: [NSDictionary class]])
{
NSString *descriptionKey;
descriptionKey = [obj1 objectForKey:@"description"];
if (descriptionKey)
[batDict setObject: obj1 forKey: descriptionKey];
}
else
NSLog(@"not a dict");
}
//NSLog(@"battery dictionary: %@", batDict);
(void)close(sysmonfd);
valueStr = [[batDict objectForKey: @"voltage"] objectForKey: @"cur-value"];
if (valueStr)
volts = [valueStr floatValue] / 1000000;
NSLog(@"voltage: %@ %f", valueStr, volts);
valueStr = [[batDict objectForKey: @"design cap"] objectForKey: @"cur-value"];
if (valueStr)
{
if ([[[batDict objectForKey: @"design cap"] objectForKey: @"type"] isEqualToString: @"Ampere hour"])
{
useWattHours = NO;
}
else if ([[[batDict objectForKey: @"design cap"] objectForKey: @"type"] isEqualToString: @"Watt hour"])
{
useWattHours = YES;
}
desCap = [valueStr floatValue] / 1000000;
}
NSLog(@"design cap: %@ %f, type: %@", valueStr, desCap, [[batDict objectForKey: @"design cap"] objectForKey: @"type"]);
chargeDict = [batDict objectForKey: @"charge"];
valueStr = [chargeDict objectForKey: @"critical-capacity"];
if (valueStr)
{
critCap = [valueStr floatValue] / 1000000;
}
NSLog(@"crit cap: %@ %f", valueStr, critCap);
valueStr = [chargeDict objectForKey: @"warning-capacity"];
if (valueStr)
{
warnCap = [valueStr floatValue] / 1000000;
}
//NSLog(@"warn cap: %@ %f", valueStr, warnCap);
valueStr = [[batDict objectForKey: @"last full cap"] objectForKey: @"cur-value"];
if (valueStr)
lastCap = [valueStr floatValue] / 1000000;
//NSLog(@"last full cap: %@, %f", valueStr, lastCap);
valueStr = [[batDict objectForKey: @"charge rate"] objectForKey: @"cur-value"];
chargeRate = 0;
if (valueStr)
chargeRate = [valueStr floatValue] / 1000000;
valueStr = [[batDict objectForKey: @"discharge rate"] objectForKey: @"cur-value"];
dischargeRate = 0;
if (valueStr)
dischargeRate = [valueStr floatValue] / 1000000;
NSLog(@"discharge rate: %@ %f", valueStr, dischargeRate);
valueStr = [[batDict objectForKey: @"charge"] objectForKey: @"cur-value"];
if (valueStr)
currCap = [valueStr floatValue] / 1000000;
NSLog(@"charge: %@, %f", valueStr, currCap);
valueStr = [[batDict objectForKey: @"charging"] objectForKey: @"cur-value"];
NSLog(@"charging: %@", valueStr);
if ([valueStr intValue] == 0)
{
if (useWattHours)
amps = dischargeRate / volts;
else
amps = dischargeRate;
NSLog(@"useWattHours %d amps %f", useWattHours, amps);
isCharging = NO;
if (amps > 0)
timeRemaining = currCap / (volts*amps);
else
timeRemaining = -1;
if (lastCap)
chargePercent = currCap/lastCap*100;
batteryState = BMBStateDischarging;
}
else
{
if (useWattHours)
amps = chargeRate / volts;
else
amps = chargeRate;
NSLog(@"useWattHours %d amps %f", useWattHours, amps);
isCharging = YES;
if (amps > 0)
timeRemaining = (lastCap-currCap) / (amps*volts);
else
timeRemaining = -1;
chargePercent = 0;
if (lastCap)
chargePercent = currCap/lastCap*100;
batteryState = BMBStateCharging;
}
watts = amps * volts;
/* sanitize */
if (critCap > warnCap)
critCap = warnCap;
if (critCap == 0)
{
if (warnCap > 0)
critCap = warnCap;
else
critCap = desCap / 100;
}
isCritical = NO;
if (currCap <= critCap)
isCritical = YES;
}
@end
#endif
This diff is collapsed.
/*
Project: batmon
Copyright (C) 2006-2013 GNUstep Application Project
Copyright (C) 2006-2014 GNUstep Application Project
Author: Riccardo Mottola
......@@ -22,6 +22,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <Foundation/NSObject.h>
#if defined (linux)
#define DEV_SYS_POWERSUPPLY @"/sys/class/power_supply"
#define DEV_PROC_PMU @"/proc/pmu"
#endif
typedef enum
{
BMBStateUnknown = 0,
......@@ -70,6 +79,8 @@ typedef enum
@private float timeRemaining;
@private BOOL isCharging;
@private BOOL isCritical;
@private float critPercent;
@private float warnPercent;
@private BMBatteryStates batteryState;
@private NSString *batteryType;
......@@ -89,6 +100,7 @@ typedef enum
- (float)chargePercent;
- (BOOL)isCritical;
- (BOOL)isWarning;
- (BOOL)isCharging;
- (BOOL)isUsingWattHours;
......@@ -100,3 +112,9 @@ typedef enum
@end
@interface BatteryModel (PlatformSpecific)
- (void)initPlatformSpecific;
- (void)updatePlatformSpecific;
@end
This diff is collapsed.
2016-01-27 Riccardo Mottola <rm@gnu.org>
* AppController.h
* AppController.m
* Resources/batmon.gorm
Change label to Discharge and Charge according to state, connect Boxes IBOutlets to be able to set title.
2016-01-27 Riccardo Mottola <rm@gnu.org>
* BatteryModel-NetBSD.m
Fix time if charge is expressed in Watts, improved attempt.
2015-09-11 Riccardo Mottola <rm@gnu.org>
* BatteryModel-NetBSD.m
Fix Amps if charge is expressed in Watts
2015-01-18 Riccardo Mottola <rm@gnu.org>
* AppController.h
Add some label outlets.
* Resources/batmon.gorm
Captialize some terms, connect outlets.
2015-01-16 Riccardo Mottola <rm@gnu.org>
* BatteryModel.m
* BatteryModel-Linux.m
_readLine is Linux specific
2015-01-15 Riccardo Mottola <rm@gnu.org>
* BatteryModel-OpenBSD.m
Support AmperHour and not only WattHour, support full and idle states better.
2015-01-14 Riccardo Mottola <rm@gnu.org>
* BatteryModel.h
Import NSObject.h
* BatteryModel-Linux.m
* BatteryModel-NetBSD.m
* BatteryModel-FreeBSD.m
Guard appropriately for OS.
* BatteryModel-OpenBSD.m
Implement ACPI sensor parsing
2014-10-09 Riccardo Mottola <rm@gnu.org>
* AppController.m
Use isnan() instead of NAN
2014-05-25 Riccardo Mottola <rm@gnu.org>
* AppController.m
* BatteryModel.h
* BatteryModel.m
Calculate warning capacity and draw orange bar in case.
2014-05-25 Riccardo Mottola <rm@gnu.org>
* BatteryModel.m
Calculate critical status on capacity if !isCritical.
2014-05-04 Riccardo Mottola <rm@gnu.org>
* BatteryModel-Linux.m
* BatteryModel-OpenBSD.m
Init isCritical, so that once condition reverts it returns to NO.
2014-01-19 Riccardo Mottola <rm@gnu.org>
* BatteryModel.h
* BatteryModel.m
Fix ACPI/APM/PMU detection fallback on Linux.
2013-10-15 Riccardo Mottola <rm@gnu.org>
* AppController.m
Fix formatting string.
2013-07-24 Riccardo Mottola <rm@gnu.org>
* BatteryModel-NetBSD.m
* BatteryModel-FreeBSD.m
* BatteryModel.m
FreeBSD and NetBSD refactor.
2013-07-24 Riccardo Mottola <rm@gnu.org>
* BatteryModel-Linux.m
* BatteryModel-OpenBSD.m
* BatteryModel.h
* BatteryModel.m
Provide initPlatformSpecific initialization code (used only for linux)
2013-07-24 Riccardo Mottola <rm@gnu.org>
* BatteryModel.m
* BatteryModel-Linux.m
Separate update method into OpenBSD Platform Specific file.
2013-07-24 Riccardo Mottola <rm@gnu.org>
* BatteryModel.h
* BatteryModel.m
* BatteryModel-Linux.m
Separate update method into linux Platform Specific file.
2013-04-12 Riccardo Mottola <rm@gnu.org>
* BatteryModel.m (update)
Fix leak of file descriptor on linux.
......@@ -3,6 +3,15 @@
#
ifeq ($(GNUSTEP_MAKEFILES),)
GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null)
ifeq ($(GNUSTEP_MAKEFILES),)
$(warning )
$(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!)
$(warning Perhaps gnustep-make is not properly installed,)
$(warning so gnustep-config is not in your PATH.)
$(warning )
$(warning Your PATH is currently $(PATH))
$(warning )
endif
endif
ifeq ($(GNUSTEP_MAKEFILES),)
$(error You need to set GNUSTEP_MAKEFILES before compiling!)
......@@ -13,7 +22,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
#
# Application
#
VERSION = 0.7
VERSION = 0.9
PACKAGE_NAME = batmon
APP_NAME = batmon
batmon_APPLICATION_ICON = BatMon_icon.tif
......@@ -39,11 +48,15 @@ AppController.h \
BatteryModel.h
#
# Class files
# Objective-C Class files
#
batmon_OBJC_FILES = \
AppController.m \
BatteryModel.m
BatteryModel.m \
BatteryModel-FreeBSD.m \
BatteryModel-Linux.m \
BatteryModel-NetBSD.m \
BatteryModel-OpenBSD.m
#
# Other sources
......
......@@ -21,7 +21,9 @@ ADDITIONAL_INCLUDE_DIRS +=
ADDITIONAL_LIB_DIRS +=
# Additional GUI libraries to link
ifeq ($(findstring netbsd, $(GNUSTEP_TARGET_OS)), netbsd)
ADDITIONAL_GUI_LIBS += -lprop
ADDITIONAL_GUI_LIBS +=
ifeq ($(findstring netbsd, $(GNUSTEP_TARGET_OS)), netbsd)
ADDITIONAL_GUI_LIBS += -lprop
endif
......@@ -8,22 +8,29 @@
"showBattInfo:"
);
Outlets = (
monitorWin,
voltage,
amperage,
presentCap,
rate,
rateLabel,
percent,
timeLeft,
chState,
level,
monitorWin,
cellInfoButton,
lifeBox,
cellDataBox,
infoWin,
lifeGauge,
lifeGaugePercent,
designCap,
battType,
battTypeLabel,
manufacturer,
lastFullCharge
manufacturerLabel,
lastFullCharge,
cellHealthBox
);
Super = NSObject;
};
......
......@@ -10,9 +10,14 @@
distclean,
dist
);
"BUNDLE_IDENTIFIER" = "org.gap.batmon";
"CLASS_FILES" = (
"AppController.m",
"BatteryModel.m"
"BatteryModel.m",
"BatteryModel-FreeBSD.m",
"BatteryModel-Linux.m",
"BatteryModel-NetBSD.m",
"BatteryModel-OpenBSD.m"
);
COMPILEROPTIONS = "";
CPPOPTIONS = "";
......@@ -54,9 +59,9 @@
);
"PRINCIPAL_CLASS" = NSApplication;
"PROJECT_AUTHORS" = (
"Riccardo Mottola (rmottola@users.sf.net)"
"Riccardo Mottola (rm@gnu.org)"
);
"PROJECT_COPYRIGHT" = "Copyright (C) 2005-2013";
"PROJECT_COPYRIGHT" = "Copyright (C) 2005-2016";
"PROJECT_COPYRIGHT_DESC" = "Released under GPL";
"PROJECT_CREATOR" = "";
"PROJECT_DESCRIPTION" = "Battery Monitor";
......@@ -65,7 +70,7 @@
"PROJECT_GROUP" = "No group avaliable!";
"PROJECT_MAINTAINER" = "";
"PROJECT_NAME" = batmon;
"PROJECT_RELEASE" = "0.6";
"PROJECT_RELEASE" = "0.9";
"PROJECT_SUMMARY" = "No summary avaliable!";
"PROJECT_TYPE" = Application;
"PROJECT_URL" = "http://gap.nongnu.org/batmon/";
......@@ -81,4 +86,4 @@
"USER_LANGUAGES" = (
English
);
}
}
\ No newline at end of file
......@@ -3,17 +3,18 @@
ApplicationDescription = "Battery Monitor";
ApplicationIcon = "BatMon_icon.tif";
ApplicationName = batmon;
ApplicationRelease = "0.7";
ApplicationRelease = "0.9";
Authors = (
"Riccardo Mottola (rmottola@users.sf.net)"
"Riccardo Mottola (rm@gnu.org)"
);
Copyright = "Copyright (C) 2005-2013";
CFBundleIdentifier = "org.gap.batmon";
Copyright = "Copyright (C) 2005-2016";
CopyrightDescription = "Released under GPL";
FullVersionID = "0.7";
FullVersionID = "0.9";
NSExecutable = batmon;
NSIcon = "BatMon_icon.tif";
NSMainNibFile = "batmon.gorm";
NSPrincipalClass = NSApplication;
NSRole = Application;
URL = "http://gap.nongnu.org/batmon/";
}
}
\ No newline at end of file