Commit a5304cde authored by Yavor Doganov's avatar Yavor Doganov

Import Upstream version 0.9

parent 8ee2582d
/*
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-2014 GNUstep Application Project
Copyright (C) 2005-2016 GNUstep Application Project
Author: Riccardo Mottola
......@@ -51,7 +51,7 @@
- (id)init
{
if ((self = [super init]))
{
{
NSMutableParagraphStyle *style;
NSFont *font;
......@@ -66,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;
}
......@@ -85,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];
}
......@@ -143,7 +145,7 @@
chargePercentToDraw = [batModel chargePercent];
if (chargePercentToDraw > 100)
chargePercentToDraw = 100;
else if (chargePercentToDraw < 0 || chargePercentToDraw == NAN)
else if (chargePercentToDraw < 0 || isnan(chargePercentToDraw))
chargePercentToDraw = 0;
[[NSColor darkGrayColor] set];
......@@ -192,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];
......@@ -220,7 +222,11 @@
[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];
......
/*
Project: batmon
Copyright (C) 2006-2013 GNUstep Application Project
Copyright (C) 2006-2015 GNUstep Application Project
Author: Riccardo Mottola
FreeBSD support by Chris B. Vetter (initial version)
......@@ -23,6 +23,8 @@
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>
......@@ -30,6 +32,9 @@
#include <dev/acpica/acpiio.h>
#define ACPIDEV "/dev/acpi"
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import "BatteryModel.h"
@implementation BatteryModel (PlatformSpecific)
......@@ -111,3 +116,5 @@
}
@end
#endif
/*
Project: batmon
Copyright (C) 2006-2014 GNUstep Application Project
Copyright (C) 2006-2015 GNUstep Application Project
Author: Riccardo Mottola
......@@ -22,10 +22,27 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#if defined(linux)
#import <Foundation/Foundation.h>
#import "BatteryModel.h"
@implementation BatteryModel (PlatformSpecific)
- (void)_readLine :(FILE *)f :(char *)l
{
int ch;
ch = fgetc(f);
while (ch != EOF && ch != '\n')
{
*l = ch;
l++;
ch = fgetc(f);
}
*l = '\0';
}
- (void)initPlatformSpecific
{
NSFileManager *fm;
......@@ -96,7 +113,7 @@
if (dirName != nil)
{
/* scan for the first present battery */
dirName = [[NSString stringWithString:@"/proc/acpi/battery"] stringByAppendingPathComponent:dirName];
dirName = [@"/proc/acpi/battery" stringByAppendingPathComponent:dirName];
[dirName getCString:batteryStatePath0];
strcat(batteryStatePath0, "/state");
NSLog(@"checking: %s", batteryStatePath0);
......@@ -428,7 +445,7 @@
stateFile = fopen(apmPath, "r");
if (stateFile == NULL)
{
NSLog(@"apm state file null");
NSLog(@"apm state file nil");
return;
}
......@@ -437,7 +454,7 @@
// NSLog(@"line: %s", line);
sscanf(line, "%s %s %s %s %s %s %s %s %s", drvVersionStr, apmBiosVersionStr, apmBiosFlagsStr, acLineStatusStr, battStatusStr, battFlagsStr, percentStr, timeRemainingStr, timeUnitStr);
if (percentStr != NULL && strlen(percentStr) > 0)
if (strlen(percentStr) > 0)
{
if (percentStr[strlen(percentStr)-1] == '%')
percentStr[strlen(percentStr)-1] = '\0';
......@@ -454,7 +471,7 @@
// NSLog(@"percent %f", chargePercent);
}
if (battStatusStr != NULL && strlen(battStatusStr) > 0)
if (strlen(battStatusStr) > 0)
{
if (battStatusStr[3] == '0')
battStatusInt = 0;
......@@ -567,3 +584,5 @@
}
@end
#endif
/*
Project: batmon
Copyright (C) 2006-2013 GNUstep Application Project
Copyright (C) 2006-2016 GNUstep Application Project
Author: Riccardo Mottola
......@@ -22,13 +22,15 @@
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)
......@@ -82,13 +84,11 @@
enum1 = [acpibat0 objectEnumerator];
while ((obj1 = [enum1 nextObject]))
{
// NSLog(@"--->%@", obj1);
if ([obj1 isKindOfClass: [NSDictionary class]])
{
NSString *descriptionKey;
descriptionKey = [obj1 objectForKey:@"description"];
// NSLog(@"key-----> %@", descriptionKey);
if (descriptionKey)
[batDict setObject: obj1 forKey: descriptionKey];
}
......@@ -117,7 +117,7 @@
}
desCap = [valueStr floatValue] / 1000000;
}
NSLog(@"design cap: %@ %f", valueStr, desCap);
NSLog(@"design cap: %@ %f, type: %@", valueStr, desCap, [[batDict objectForKey: @"design cap"] objectForKey: @"type"]);
chargeDict = [batDict objectForKey: @"charge"];
valueStr = [chargeDict objectForKey: @"critical-capacity"];
......@@ -131,17 +131,16 @@
{
warnCap = [valueStr floatValue] / 1000000;
}
NSLog(@"warn cap: %@ %f", valueStr, warnCap);
//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);
//NSLog(@"last full cap: %@, %f", valueStr, lastCap);
valueStr = [[batDict objectForKey: @"charge rate"] objectForKey: @"cur-value"];
chargeRate = 0;
if (valueStr)
chargeRate = [valueStr floatValue] / 1000000;
NSLog(@"charge rate: %@ %f", valueStr, chargeRate);
valueStr = [[batDict objectForKey: @"discharge rate"] objectForKey: @"cur-value"];
dischargeRate = 0;
......@@ -156,13 +155,18 @@
valueStr = [[batDict objectForKey: @"charging"] objectForKey: @"cur-value"];
NSLog(@"charging: %@", valueStr);
NSLog(@"currCap %f, lastCap %f, amps %f", currCap, lastCap,amps);
if ([valueStr intValue] == 0)
{
amps = dischargeRate;
if (useWattHours)
amps = dischargeRate / volts;
else
amps = dischargeRate;
NSLog(@"useWattHours %d amps %f", useWattHours, amps);
isCharging = NO;
if (amps > 0)
timeRemaining = currCap / amps;
timeRemaining = currCap / (volts*amps);
else
timeRemaining = -1;
if (lastCap)
......@@ -171,10 +175,16 @@
}
else
{
amps = chargeRate;
if (useWattHours)
amps = chargeRate / volts;
else
amps = chargeRate;
NSLog(@"useWattHours %d amps %f", useWattHours, amps);
isCharging = YES;
if (amps > 0)
timeRemaining = (lastCap-currCap) / amps;
timeRemaining = (lastCap-currCap) / (amps*volts);
else
timeRemaining = -1;
chargePercent = 0;
......@@ -202,3 +212,5 @@
}
@end
#endif
This diff is collapsed.
......@@ -22,6 +22,8 @@
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"
......
/*
Project: batmon
Copyright (C) 2006-2014 GNUstep Application Project
Copyright (C) 2006-2015 GNUstep Application Project
Author: Riccardo Mottola
......@@ -22,7 +22,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
......@@ -34,21 +34,6 @@
@implementation BatteryModel
- (void)_readLine :(FILE *)f :(char *)l
{
int ch;
ch = fgetc(f);
while (ch != EOF && ch != '\n')
{
*l = ch;
l++;
ch = fgetc(f);
}
*l = '\0';
}
- (id)init
{
if ((self = [super init]))
......@@ -250,13 +235,9 @@
@end
#if defined(linux)
#include "BatteryModel-Linux.m"
#elif defined(openbsd) || defined(__OpenBSD__)
#include "BatteryModel-OpenBSD.m"
#elif defined(netbsd) || defined (__NetBSD__)
#include "BatteryModel-NetBSD.m"
#elif defined(freebsd) || defined( __FreeBSD__ )
#include "BatteryModel-FreeBSD.m"
#else
#warning "Unsupported Platform, no specific battery model"
#endif
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
......
......@@ -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.8
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
......
......@@ -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;
};
......
{
APPLICATIONICON = "BatMon_icon.tif";
"APP_DOCUMENT_BASED" = NO;
"APP_TYPE" = GORM;
"BUILDER_TARGETS" = (
all,
install,
uninstall,
clean,
distclean,
dist
);
"CLASS_FILES" = (
"AppController.m",
"BatteryModel.m"
);
COMPILEROPTIONS = "";
CPPOPTIONS = "";
"CREATION_DATE" = "2005-06-25 21:06:19 +0200";
"DOCU_FILES" = (
LICENSE,
README
);
FRAMEWORKS = (
);
"HEADER_FILES" = (
"AppController.h",
"BatteryModel.h"
);
IMAGES = (
"BatMon_icon.tif",
"small_battery.tif",
"small_plug.tif"
);
INSTALLDIR = "$(HOME)/GNUstep";
INTERFACES = (
"batmon.gorm"
);
LANGUAGE = English;
LIBRARIES = (
"gnustep-base",
"gnustep-gui"
);
LINKEROPTIONS = "";
"LOCALIZED_RESOURCES" = (
);
MAININTERFACE = "batmon.gorm";
MAKEFILEDIR = "$(GNUSTEP_MAKEFILES)";
"OBJC_COMPILEROPTIONS" = "";
"OTHER_RESOURCES" = (
);
"OTHER_SOURCES" = (
"main.m"
);
"PRINCIPAL_CLASS" = NSApplication;
"PROJECT_AUTHORS" = (
"Riccardo Mottola (rmottola@users.sf.net)"
);
"PROJECT_COPYRIGHT" = "Copyright (C) 2005-2014";
"PROJECT_COPYRIGHT_DESC" = "Released under GPL";
"PROJECT_CREATOR" = "";
"PROJECT_DESCRIPTION" = "Battery Monitor";
"PROJECT_DOCUMENTTYPES" = (
);
"PROJECT_GROUP" = "No group avaliable!";
"PROJECT_MAINTAINER" = "";
"PROJECT_NAME" = batmon;
"PROJECT_RELEASE" = "0.8";
"PROJECT_SUMMARY" = "No summary avaliable!";
"PROJECT_TYPE" = Application;
"PROJECT_URL" = "http://gap.nongnu.org/batmon/";
"SEARCH_HEADER_DIRS" = (
);
"SEARCH_LIB_DIRS" = (
);
SUBPROJECTS = (
);
"SUPPORTING_FILES" = (
"batmonInfo.plist"
);
"USER_LANGUAGES" = (
English
);
}
\ No newline at end of file
{"LAST_EDITING" = "2014-08-29 03:17:56 +0200"; "PC_WINDOWS" = {ProjectBrowser = "{x = 0; y = 0; width = 544; height = 166}"; ProjectWindow = "107 290 562 501 0 0 1400 1050 "; ShowToolbar = YES; }; }
\ No newline at end of file
......@@ -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-2014";
"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.8";
"PROJECT_RELEASE" = "0.9";
"PROJECT_SUMMARY" = "No summary avaliable!";
"PROJECT_TYPE" = Application;
"PROJECT_URL" = "http://gap.nongnu.org/batmon/";
......
{"LAST_EDITING" = "2014-09-04 00:50:40 +0200"; "PC_WINDOWS" = {ProjectBrowser = "{x = 0; y = 0; width = 544; height = 166}"; ProjectBuild = "0 0 0 0 4 0 3 0 "; ProjectLaunch = "510 109 482 355 0 0 1400 1050 "; ProjectWindow = "107 290 562 501 0 0 1400 1050 "; ShowToolbar = YES; }; }
\ No newline at end of file
......@@ -3,13 +3,14 @@
ApplicationDescription = "Battery Monitor";
ApplicationIcon = "BatMon_icon.tif";
ApplicationName = batmon;
ApplicationRelease = "0.8";
ApplicationRelease = "0.9";
Authors = (
"Riccardo Mottola (rmottola@users.sf.net)"
"Riccardo Mottola (rm@gnu.org)"
);
Copyright = "Copyright (C) 2005-2014";
CFBundleIdentifier = "org.gap.batmon";
Copyright = "Copyright (C) 2005-2016";
CopyrightDescription = "Released under GPL";
FullVersionID = "0.8";
FullVersionID = "0.9";
NSExecutable = batmon;
NSIcon = "BatMon_icon.tif";
NSMainNibFile = "batmon.gorm";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment