[arch-commits] Commit in osdbattery/trunk (PKGBUILD sysfs.patch)

Antonio Rojas arojas at archlinux.org
Sat Jun 9 08:40:22 UTC 2018


    Date: Saturday, June 9, 2018 @ 08:40:21
  Author: arojas
Revision: 342145

BUILDINFO rebuild

Added:
  osdbattery/trunk/sysfs.patch
Modified:
  osdbattery/trunk/PKGBUILD

-------------+
 PKGBUILD    |    5 --
 sysfs.patch |  119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 3 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2018-06-09 08:34:45 UTC (rev 342144)
+++ PKGBUILD	2018-06-09 08:40:21 UTC (rev 342145)
@@ -4,7 +4,7 @@
 
 pkgname=osdbattery
 pkgver=1.4
-pkgrel=6
+pkgrel=7
 pkgdesc="Displays battery information in the OSD style"
 arch=('x86_64')
 url="http://osdbattery.sourceforge.net/"
@@ -13,8 +13,7 @@
 makedepends=('patch')
 install=$pkgname.install
 source=(http://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}_${pkgver}.tar.gz
-        sysfs.patch::"http://sourceforge.net/tracker/download.php?group_id=120528&atid=687314&file_id=429967&aid=3450277"
-        showbatt)
+        sysfs.patch showbatt)
 sha256sums=('b1f775c746cd78b6aa7fc9ee75ecf2806ef3da93a42dd806c0414dcae55aed9f'
             'd7a00e918929d36aaf3eb398649ea070ed6c4840e3da2407226fc5d9ae15d776'
             '69969053235642315b49fe6ea5df7f8c391befbf492fd4ff71afbf4d438333b2')

Added: sysfs.patch
===================================================================
--- sysfs.patch	                        (rev 0)
+++ sysfs.patch	2018-06-09 08:40:21 UTC (rev 342145)
@@ -0,0 +1,119 @@
+--- osdbattery.c	2005-08-23 09:31:10.000000000 +0200
++++ osdbattery-1.5.c	2011-12-03 23:41:24.655759085 +0100
+@@ -17,77 +17,55 @@
+ #include <xosd.h>
+ #endif
+ 
++int get_acpi_line(char* file, char* b, int size) {
++        FILE *fp;
++        fp = fopen(file, "r");
++        if (fp == NULL) {
++                printf("Cannot open ACPI info: \"%s\"\n Is ACPI supported by the kernel and is the \"display battery\" configuration correct?\n",file);
++                exit(1);
++        }
++
++        if (fgets(b, size, fp) == NULL) {
++                fclose(fp);
++                return 0;
++        }
++        b[strlen(b)-1] = 0; /* remove trailing newline*/
++
++        fclose(fp);
++        return 1;
++}
++
+ int get_battery_state(battery_state_struct* battery_state, int bnum) {
+-	char present_voltage[64];
+-	char charging_state[64];
+-	char remaining_capacity[64];
+ 	char file[64];
+-	char b[256];
+-	FILE *fp;
++	char b[64];
+ 
+-	sprintf(file, "/proc/acpi/battery/BAT%d/state", bnum );
++        sprintf(file, "/sys/class/power_supply/BAT%d/status", bnum);
++        if ( get_acpi_line(file, b, sizeof(b)) )
++                strcpy(battery_state->charging_state, b);
++
++        sprintf(file, "/sys/class/power_supply/BAT%d/voltage_now", bnum);
++        if ( get_acpi_line(file, b, sizeof(b)) )
++                battery_state->present_voltage = atoi(b);
++
++        sprintf(file, "/sys/class/power_supply/BAT%d/charge_now", bnum);
++        if ( get_acpi_line(file, b, sizeof(b)) )
++                battery_state->remaining_capacity = atoi(b);
+ 
+-	fp = fopen(file, "r");
+-	if (fp == NULL) {
+-		printf("Cannot open ACPI info! Is ACPI supported by the kernel?\n");
+-		exit(1);
+-	}
+-
+-	rewind(fp);
+-	while (!feof(fp)) {
+-
+-		if (fgets(b, 256, fp) == NULL) {
+-			fclose(fp);
+-			return 0;
+-		} 		
+-
+-		if (sscanf(b, "present voltage: %63s", present_voltage ) != errno) {
+-			battery_state->present_voltage = atoi(present_voltage);
+-		}
+-
+-		if (sscanf(b, "charging state: %63s", charging_state ) != errno) {
+-			strcpy(battery_state->charging_state, charging_state);
+-		}
+-
+-		if (sscanf(b, "remaining capacity: %63s", remaining_capacity ) != errno) {
+-			battery_state->remaining_capacity = atoi(remaining_capacity);
+-
+-		}
+-	}	
+-	fclose(fp);
+ 	return 0;
+ }
++
+ int get_battery_info(battery_info_struct* battery_info, int bnum) { 	
+-	char design_voltage[64];
+-	char last_full_capacity[64];
+ 	char file[64];
++	char b[64];
+ 
+-	sprintf(file, "/proc/acpi/battery/BAT%d/info", bnum );
+-
+-	FILE *fp = fopen(file,"r");
+-	if (fp == NULL) {
+-		printf("can not open acpi info, acpi supported by kernel?\n");
+-		exit(1);
+-	}
+-
+-	rewind(fp);
+-	char b[256];
+-
+-	while (!feof(fp)) {
+-
+-		if (fgets(b, 256, fp) == NULL) {
+-			fclose(fp);
+-			return 0;
+-		}
+-
+-		if (sscanf(b, "design voltage: %63s", design_voltage) != errno) {
+-			battery_info->design_voltage = atoi(design_voltage);							   	}
+-
+-		if (sscanf(b, "last full capacity: %63s", last_full_capacity) != errno) {
+-			battery_info->last_full_capacity = atoi(last_full_capacity);	
+-		}
++        sprintf(file, "/sys/class/power_supply/BAT%d/voltage_min_design", bnum);
++        if ( get_acpi_line(file, b, sizeof(b)) )
++                battery_info->design_voltage = atoi(b);
++
++        sprintf(file, "/sys/class/power_supply/BAT%d/charge_full", bnum);
++        if ( get_acpi_line(file, b, sizeof(b)) )
++                battery_info->last_full_capacity = atoi(b);
+ 
+-	}
+ 	return 0;
+ }
+ 



More information about the arch-commits mailing list