static void check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac) { const char *base = proc_acpi_ac_adapter_path; char state[256]; char *ptr = NULL; char *key = NULL; char *val = NULL; if (!read_power_file(base, node, "state", state, sizeof (state))) { return; } ptr = &state[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (strcmp(key, "state") == 0) { if (strcmp(val, "on-line") == 0) { *have_ac = SDL_TRUE; } } } }
void PowerX11::check_proc_acpi_ac_adapter(const char *node, bool *have_ac) { const char *base = proc_acpi_ac_adapter_path; char state[256]; char *ptr = NULL; char *key = NULL; char *val = NULL; if (!read_power_file(base, node, "state", state, sizeof(state))) { return; } ptr = &state[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { String skey = key; if (skey == "state") { String sval = val; if (sval == "on-line") { *have_ac = true; } } } }
static void check_proc_acpi_battery(const char * node, SDL_bool * have_battery, SDL_bool * charging, int *seconds, int *percent) { const char *base = proc_acpi_battery_path; char info[1024]; char state[1024]; char *ptr = NULL; char *key = NULL; char *val = NULL; SDL_bool charge = SDL_FALSE; SDL_bool choose = SDL_FALSE; int maximum = -1; int remaining = -1; int secs = -1; int pct = -1; if (!read_power_file(base, node, "state", state, sizeof (state))) { return; } else if (!read_power_file(base, node, "info", info, sizeof (info))) { return; } ptr = &state[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (strcmp(key, "present") == 0) { if (strcmp(val, "yes") == 0) { *have_battery = SDL_TRUE; } } else if (strcmp(key, "charging state") == 0) { /* !!! FIXME: what exactly _does_ charging/discharging mean? */ if (strcmp(val, "charging/discharging") == 0) { charge = SDL_TRUE; } else if (strcmp(val, "charging") == 0) { charge = SDL_TRUE; } } else if (strcmp(key, "remaining capacity") == 0) { char *endptr = NULL; const int cvt = (int) strtol(val, &endptr, 10); if (*endptr == ' ') { remaining = cvt; } } } ptr = &info[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (strcmp(key, "design capacity") == 0) { char *endptr = NULL; const int cvt = (int) strtol(val, &endptr, 10); if (*endptr == ' ') { maximum = cvt; } } } if ((maximum >= 0) && (remaining >= 0)) { pct = (int) ((((float) remaining) / ((float) maximum)) * 100.0f); if (pct < 0) { pct = 0; } else if (pct > 100) { pct = 100; } } /* !!! FIXME: calculate (secs). */ /* * We pick the battery that claims to have the most minutes left. * (failing a report of minutes, we'll take the highest percent.) */ if ((secs < 0) && (*seconds < 0)) { if ((pct < 0) && (*percent < 0)) { choose = SDL_TRUE; /* at least we know there's a battery. */ } if (pct > *percent) { choose = SDL_TRUE; } } else if (secs > *seconds) { choose = SDL_TRUE; } if (choose) { *seconds = secs; *percent = pct; *charging = charge; } }
void PowerX11::check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging) { const char *base = proc_acpi_battery_path; char info[1024]; char state[1024]; char *ptr = NULL; char *key = NULL; char *val = NULL; bool charge = false; bool choose = false; int maximum = -1; int remaining = -1; int secs = -1; int pct = -1; if (!read_power_file(base, node, "state", state, sizeof(state))) { return; } else { if (!read_power_file(base, node, "info", info, sizeof(info))) return; } ptr = &state[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (String(key) == "present") { if (String(val) == "yes") { *have_battery = true; } } else if (String(key) == "charging state") { /* !!! FIXME: what exactly _does_ charging/discharging mean? */ if (String(val) == "charging/discharging") { charge = true; } else if (String(val) == "charging") { charge = true; } } else if (String(key) == "remaining capacity") { String sval = val; const int cvt = sval.to_int(); remaining = cvt; } } ptr = &info[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (String(key) == "design capacity") { String sval = val; const int cvt = sval.to_int(); maximum = cvt; } } if ((maximum >= 0) && (remaining >= 0)) { pct = (int)((((float)remaining) / ((float)maximum)) * 100.0f); if (pct < 0) { pct = 0; } else if (pct > 100) { pct = 100; } } /* !!! FIXME: calculate (secs). */ /* * We pick the battery that claims to have the most minutes left. * (failing a report of minutes, we'll take the highest percent.) */ if ((secs < 0) && (this->nsecs_left < 0)) { if ((pct < 0) && (this->percent_left < 0)) { choose = true; /* at least we know there's a battery. */ } if (pct > this->percent_left) { choose = true; } } else if (secs > this->nsecs_left) { choose = true; } if (choose) { this->nsecs_left = secs; this->percent_left = pct; *charging = charge; } }