- } else if (acpi_bat_fp[idx] != NULL) {//skipped on n900
- /* ACPI */
- int present_rate = -1;
- int remaining_capacity = -1;
- char charging_state[64];
- char present[4];
-
- /* read last full capacity if it's zero */
- if (acpi_last_full[idx] == 0) {
- static int rep3 = 0;
- char path[128];
- FILE *fp;
-
- snprintf(path, 127, ACPI_BATTERY_BASE_PATH "/%s/info", bat);
- fp = open_file(path, &rep3);
- if (fp != NULL) {
- while (!feof(fp)) {
- char b[256];
-
- if (fgets(b, 256, fp) == NULL) {
- break;
- }
- if (sscanf(b, "last full capacity: %d",
- &acpi_last_full[idx]) != 0) {
- break;
- }
- }
-
- fclose(fp);
- }
- }
-
- fseek(acpi_bat_fp[idx], 0, SEEK_SET);
-
- strcpy(charging_state, "unknown");
-
- while (!feof(acpi_bat_fp[idx])) {
- char buf[256];
-
- if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL) {
- break;
- }
-
- /* let's just hope units are ok */
- if (strncmp(buf, "present:", 8) == 0) {
- sscanf(buf, "present: %4s", present);
- } else if (strncmp(buf, "charging state:", 15) == 0) {
- sscanf(buf, "charging state: %63s", charging_state);
- } else if (strncmp(buf, "present rate:", 13) == 0) {
- sscanf(buf, "present rate: %d", &present_rate);
- } else if (strncmp(buf, "remaining capacity:", 19) == 0) {
- sscanf(buf, "remaining capacity: %d", &remaining_capacity);
- }
- }
- /* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
- if (remaining_capacity > acpi_last_full[idx]) {
- /* normalize to 100% */
- acpi_last_full[idx] = remaining_capacity;
- }
-
- /* not present */
- if (strcmp(present, "no") == 0) {
- strncpy(last_battery_str[idx], "not present", 64);
- /* charging */
- } else if (strcmp(charging_state, "charging") == 0) {
- if (acpi_last_full[idx] != 0 && present_rate > 0) {
- /* e.g. charging 75% */
- snprintf(last_battery_str[idx],
- sizeof(last_battery_str[idx]) - 1, "charging %i%%",
- (int) ((remaining_capacity * 100) / acpi_last_full[idx]));
- /* e.g. 2h 37m */
- format_seconds(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1,
- (long) (((acpi_last_full[idx] - remaining_capacity) *
- 3600) / present_rate));
- } else if (acpi_last_full[idx] != 0 && present_rate <= 0) {
- snprintf(last_battery_str[idx],
- sizeof(last_battery_str[idx]) - 1, "charging %d%%",
- (int) ((remaining_capacity * 100) / acpi_last_full[idx]));
- snprintf(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1, "unknown");
- } else {
- strncpy(last_battery_str[idx], "charging",
- sizeof(last_battery_str[idx]) - 1);
- snprintf(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1, "unknown");
- }
- /* discharging */
- } else if (strncmp(charging_state, "discharging", 64) == 0) {
- if (present_rate > 0) {
- /* e.g. discharging 35% */
- snprintf(last_battery_str[idx],
- sizeof(last_battery_str[idx]) - 1, "discharging %i%%",
- (int) ((remaining_capacity * 100) / acpi_last_full[idx]));
- /* e.g. 1h 12m */
- format_seconds(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1,
- (long) ((remaining_capacity * 3600) / present_rate));
- } else if (present_rate == 0) { /* Thanks to Nexox for this one */
- snprintf(last_battery_str[idx],
- sizeof(last_battery_str[idx]) - 1, "full");
- snprintf(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1, "unknown");
- } else {
- snprintf(last_battery_str[idx],
- sizeof(last_battery_str[idx]) - 1, "discharging %d%%",
- (int) ((remaining_capacity * 100) / acpi_last_full[idx]));
- snprintf(last_battery_time_str[idx],
- sizeof(last_battery_time_str[idx]) - 1, "unknown");
- }
- /* charged */
- } else if (strncmp(charging_state, "charged", 64) == 0) {
- /* thanks to Lukas Zapletal <lzap@seznam.cz> */
- /* Below happens with the second battery on my X40,
- * when the second one is empty and the first one being charged. */
- if (remaining_capacity == 0) {
- strcpy(last_battery_str[idx], "empty");
- } else {
- strcpy(last_battery_str[idx], "charged");
- }
- /* unknown, probably full / AC */
- } else {
- if (strncmp(charging_state, "Full", 64) == 0) {
- strncpy(last_battery_str[idx], "full", 64);
- } else if (acpi_last_full[idx] != 0
- && remaining_capacity != acpi_last_full[idx]) {
- snprintf(last_battery_str[idx], 64, "unknown %d%%",
- (int) ((remaining_capacity * 100) / acpi_last_full[idx]));
- } else {
- strncpy(last_battery_str[idx], "AC", 64);
- }
- }
- fclose(acpi_bat_fp[idx]);
- acpi_bat_fp[idx] = NULL;
- } else {//also skipped on n900
- /* APM */
- if (apm_bat_fp[idx] == NULL) {
- apm_bat_fp[idx] = open_file(APM_PATH, &rep2);
- }
-
- if (apm_bat_fp[idx] != NULL) {
- unsigned int ac, status, flag;
- int life;
-
- fscanf(apm_bat_fp[idx], "%*s %*s %*x %x %x %x %d%%",
- &ac, &status, &flag, &life);
+ } else {
+ //if don't have power kernel, use HAL / dbus
+ //int present_rate = 50; //not available via dbus
+ int remaining_capacity = -1; //in %
+ //char charging_state[64];//can't get this without hal bme
+ //int voltage = 6666;//might as well set the default to something with 4 digits so as to not screw up a config layout
+ int temp = -1;
+ remaining_capacity = get_battery_perct(bat);
+ // fprintf(stderr,"got remaining cap %i",remaining_capacity);
+ get_dbus_stuff(buffer,n,DBUS_HAL_BATTERY_VOLTS_CURRENT);
+ //last_battery_volts[idx] = voltage;
+
+ get_dbus_stuff(buffer,n,DBUS_HAL_BATTERY_CHRG_STATUS);
+ if (strncmp(buffer, "on", 2) == 0) {
+ snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %i%%", remaining_capacity);
+ //strcpy(charging_state, "charging");
+ }
+ else if (strncmp(buffer, "off", 3) == 0) {
+ snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "discharging %i%%", remaining_capacity);
+ //strcpy(charging_state, "discharging");
+ }
+ else if (strncmp(buffer, "full", 4) == 0) {//no, it won't always be 100%. stupid dbus.
+ snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charged %i%%", remaining_capacity);
+ }
+ //strcpy(last_battery_str[idx], charging_state);