433
void YApm::SysStr(char *s, bool Tool) {
434
char buf[80], bat_info[250];
436
//name of the battery
438
//battery is present or absent
440
//battery status charging/discharging/unknown
442
//maximal battery capacity (mWh)
443
int BATcapacity_full;
444
//design capacity (mAh)
445
int BATcapacity_design;
446
//current battery capacity (mWh)
447
int BATcapacity_remain;
448
//how much energy is used atm (mW)
450
//time until the battery is discharged (min)
452
//status of ac-adapter online/offline
458
//assign some default values, in case
459
//the file in /sys/class/power_supply will contain unexpected values
461
if (acpiACName && acpiACName[0] != 0) {
462
strcat3(buf, "/sys/class/power_supply/", acpiACName, "/online", sizeof(buf));
463
fd = fopen(buf, "r");
465
while (fgets(buf, sizeof(buf), fd)) {
466
if (strncmp(buf, "1", 1) == 0) {
467
ACstatus = AC_ONLINE;
469
else if (strncmp(buf, "0", 1) == 0) {
470
ACstatus = AC_OFFLINE;
473
ACstatus = AC_UNKNOWN;
481
for (i = 0; i < batteryNum; i++) {
482
BATname = acpiBatteries[i]->name;
483
//assign some default values, in case
484
//the files in /sys/class/power_supply will contain unexpected values
487
BATcapacity_full = -1;
488
BATcapacity_design = -1;
489
BATcapacity_remain = -1;
493
strcat3(buf, "/sys/class/power_supply/", BATname, "/status", sizeof(buf));
494
fd = fopen(buf, "r");
495
if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
496
if (strncasecmp(buf, "charging", 8) == 0) {
497
BATstatus = BAT_CHARGING;
499
else if (strncasecmp(buf, "discharging", 11) == 0) {
500
BATstatus = BAT_DISCHARGING;
502
else if (strncasecmp(buf, "full", 4) == 0) {
503
BATstatus = BAT_FULL;
506
BATstatus = BAT_UNKNOWN;
510
strcat3(buf, "/sys/class/power_supply/", BATname, "/current_now", sizeof(buf));
511
fd = fopen(buf, "r");
512
if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
513
//In case it contains non-numeric value
514
if (sscanf(buf,"%d", &BATrate) <= 0) {
519
strcat3(buf, "/sys/class/power_supply/", BATname, "/energy_now", sizeof(buf));
520
fd = fopen(buf, "r");
522
strcat3(buf, "/sys/class/power_supply/", BATname, "/charge_now", sizeof(buf));
523
fd = fopen(buf, "r");
525
if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
526
//In case it contains non-numeric value
527
if (sscanf(buf,"%d", &BATcapacity_remain) <= 0) {
528
BATcapacity_remain = -1;
532
strcat3(buf, "/sys/class/power_supply/", BATname, "/present", sizeof(buf));
533
fd = fopen(buf, "r");
534
if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
535
if (strncmp(buf, "1", 1) == 0) {
536
BATpresent = BAT_PRESENT;
539
BATpresent = BAT_ABSENT;
544
if (BATpresent == BAT_PRESENT) { //battery is present now
545
if (acpiBatteries[i]->present == BAT_ABSENT) { //and previously was absent
546
//read full-capacity value
547
strcat3(buf, "/sys/class/power_supply/", BATname, "/energy_full_design", sizeof(buf));
548
fd = fopen(buf, "r");
550
strcat3(buf, "/sys/class/power_supply/", BATname, "/charge_full_design", sizeof(buf));
551
fd = fopen(buf, "r");
554
if (fgets(buf, sizeof(buf), fd)) {
555
//in case it contains non-numeric value
556
if (sscanf(buf, "%d", &BATcapacity_design)<=0) {
557
BATcapacity_design = -1;
562
strcat3(buf, "/sys/class/power_supply/", BATname, "/energy_full", sizeof(buf));
563
fd = fopen(buf, "r");
565
strcat3(buf, "/sys/class/power_supply/", BATname, "/charge_full", sizeof(buf));
566
fd = fopen(buf, "r");
569
if (fgets(buf, sizeof(buf), fd)) {
570
//in case it contains non-numeric value
571
if (sscanf(buf, "%d", &BATcapacity_full)<=0) {
572
BATcapacity_full = -1;
577
if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0)
578
BATcapacity_full = BATcapacity_design;
579
acpiBatteries[i]->capacity_full = BATcapacity_full;
582
BATcapacity_full = acpiBatteries[i]->capacity_full;
585
acpiBatteries[i]->present = BATpresent;
588
taskBarShowApmTime &&
589
BATpresent == BAT_PRESENT &&
590
//bios calculates remaining time, only while discharging
591
BATstatus == BAT_DISCHARGING &&
592
//did we parse the needed values successfully?
593
BATcapacity_full >= 0 && BATcapacity_remain >= 0 && BATrate > 0) {
594
BATtime_remain = (int) (60 * (double)(BATcapacity_remain) / BATrate);
595
sprintf(bat_info, "%d:%02d", BATtime_remain / 60, BATtime_remain % 60);
597
else if (BATpresent == BAT_PRESENT &&
598
//did we parse the needed values successfully?
599
BATcapacity_remain >= 0 && BATcapacity_full >= 0)
601
sprintf(bat_info, "%3.0f%%",
602
100 * (double)BATcapacity_remain / BATcapacity_full);
605
//battery is absent or we didn't parse some needed values
609
if (BATstatus == BAT_CHARGING) {
611
strcat(bat_info, _(" - Charging"));
613
strcat(bat_info, _("C"));
616
if ((n > 0) && (*bat_info)) {
626
if (ACstatus == AC_ONLINE) {
628
strcat(s,_(" - Power"));
630
/// if (!prettyClock) strcat(s, " ");
421
637
void YApm::PmuStr(char *s, const bool tool_tip)
423
639
#warning Why the string s is " "?
558
791
//scan for first ac_adapter
559
n = scandir("/proc/acpi/ac_adapter", &de, 0, alphasort);
793
n = scandir("/proc/acpi/ac_adapter", &de, 0, alphasort);
794
else if (mode == SYSFS)
795
n = scandir("/sys/class/power_supply", &de, 0, alphasort);
563
if (!ignore_directory_entry(de[i])) {
564
//found an ac_adapter
565
acpiACName = (char*)calloc(strlen(de[i]->d_name) + 1, sizeof(char));
566
strcpy(acpiACName, de[i]->d_name);
801
strcat3(buf, "/sys/class/power_supply/", de[i]->d_name, "/online", sizeof(buf));
802
fd = fopen(buf, "r");
804
acpiACName = (char*)calloc(strlen(de[i]->d_name) + 1, sizeof(char));
805
strcpy(acpiACName, de[i]->d_name);
810
if (!ignore_directory_ac_entry(de[i])) {
811
//found an ac_adapter
812
acpiACName = (char*)calloc(strlen(de[i]->d_name) + 1, sizeof(char));
813
strcpy(acpiACName, de[i]->d_name);