-rw-r--r-- | library/power.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/library/power.cpp b/library/power.cpp index 990ff62..12b52ed 100644 --- a/library/power.cpp +++ b/library/power.cpp @@ -57,96 +57,98 @@ const PowerStatus &PowerStatusManager::readStatus() powerManager->getStatus(); return *ps; } // Standard /proc/apm reader bool PowerStatusManager::getProcApmStatus( int &ac, int &bs, int &bf, int &pc, int &sec ) { bool ok = false; ac = 0xff; bs = 0xff; bf = 0xff; pc = -1; sec = -1; FILE *f = fopen("/proc/apm", "r"); if ( f ) { //I 1.13 1.2 0x02 0x00 0xff 0xff 49% 147 sec char u; fscanf(f, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%x 0x%x %d%% %i %c", &ac, &bs, &bf, &pc, &sec, &u); fclose(f); switch ( u ) { case 'm': sec *= 60; case 's': break; // ok default: sec = -1; // unknown } // extract data switch ( bs ) { case 0x00: ps->bs = PowerStatus::High; break; case 0x01: ps->bs = PowerStatus::Low; break; case 0x7f: ps->bs = PowerStatus::VeryLow; break; case 0x02: ps->bs = PowerStatus::Critical; break; case 0x03: ps->bs = PowerStatus::Charging; break; case 0x04: + case 0xff: // 0xff is Unknown but we map to NotPresent + default: ps->bs = PowerStatus::NotPresent; break; } switch ( ac ) { case 0x00: ps->ac = PowerStatus::Offline; break; case 0x01: ps->ac = PowerStatus::Online; break; case 0x02: ps->ac = PowerStatus::Backup; break; } if ( pc > 100 ) pc = -1; ps->percentRemain = pc; ps->secsRemain = sec; ok = true; } return ok; } #ifdef QT_QWS_CUSTOM void PowerStatusManager::getStatus() { int ac, bs, bf, pc, sec; ps->percentAccurate = TRUE; // not for long... if ( haveProcApm && getProcApmStatus( ac, bs, bf, pc, sec ) ) { // special case if ( bs == 0x7f ) ps->bs = PowerStatus::VeryLow; pc = -1; // fake percentage if ( pc < 0 ) { switch ( bs ) { case 0x00: ps->percentRemain = 100; break; // High case 0x01: ps->percentRemain = 30; break; // Low case 0x7f: ps->percentRemain = 10; break; // Very Low case 0x02: ps->percentRemain = 5; break; // Critical case 0x03: ps->percentRemain = -1; break; // Charging } |