- continue;
- char n[sizeof(dir) + 1 + strlen(e->d_name) + 6];
- const char * const names[] = { "state", "info" };
- int present = 0;
- int rate = 0;
- int charging = 0;
- int remains = 0;
- int last_full = 0;
- int batt_id = -1;
- for (int i=0; i<2; i++)
- {
- sprintf(n, "%s/%s/%s", dir, e->d_name, names[i]);
- FILE *f = fopen(n, "r");
- if (!f)
- continue;
- char line[1024];
- while (fgets(line, sizeof(line)-1, f))
- {
- char *val = parse_line(line);
- if (!val)
- continue;
- // printf("<%s> <%s>\n", line, val);
- if (!strcmp(line, "present"))
- present = !strcmp(val, "yes");
- else if (!strcmp(line, "charging state"))
- charging = !strcmp(val, "charging");
- else if (!strcmp(line, "present rate"))
- rate = atol(val);
- else if (!strcmp(line, "remaining capacity"))
- remains = atol(val);
- else if (!strcmp(line, "last full capacity"))
- last_full = atol(val);
- else if (!strcmp(line, "serial number"))
- batt_id = atol(val);
- }
- fclose(f);
- }
- if (present)
- {
- if (batt_id < 0 || batt_id > 31)
- batt_id = 0;
- present_mask |= 1 << batt_id;
- total_full += remains;
- total_capa += last_full;
- if (charging)
- {
- charge_mask |= 1 << batt_id;
- int ch = (last_full - remains)*3600 / rate;
- if (ch > charge_time)
- charge_time = ch;
- }
- else if (rate > 0)
- {
- discharge_mask |= 1 << batt_id;
- discharge_rate += rate;
- }
- }
+ continue;
+ snprintf(sys_dir, sizeof(sys_dir), "%s/%s", dir, e->d_name);
+ DBG("%s\n", sys_dir);
+
+ char type[BUFSIZE];
+ if (!sys_read(type, "type"))
+ continue;
+
+ if (!strcmp(type, "Mains"))
+ parse_ac();
+ else if (!strcmp(type, "Battery"))
+ parse_batt(e->d_name);