コード例 #1
0
ファイル: system.c プロジェクト: dns/CLove
system_PowerState system_getPowerInfo() {
    int seconds, percent;
    int power = SDL_GetPowerInfo(&seconds, &percent);

	const char* state;
	if (power == SDL_POWERSTATE_UNKNOWN)
		state = "power_state_unknown";
	else if (power == SDL_POWERSTATE_CHARGED)
		state = "battery_charged";
	else if (power == SDL_POWERSTATE_CHARGING)
		state = "battery_charging";
	else if (power == SDL_POWERSTATE_ON_BATTERY)
		state = "not_plugged_running_on_battery";
	else if (power == SDL_POWERSTATE_NO_BATTERY)
		state = "plugged_in_no_battery";
	else
		state = "unknown";

   	system_PowerState powerState = {
        state,
        seconds,
        percent
    };
    return powerState;
}
コード例 #2
0
ファイル: Battery.cpp プロジェクト: CnZoom/XcSoarPull
void
UpdateBatteryInfo()
{
  int remaining_percent;
  SDL_PowerState power_state = SDL_GetPowerInfo(NULL, &remaining_percent);
  if (remaining_percent >= 0) {
    Power::Battery::RemainingPercent = remaining_percent;
    Power::Battery::RemainingPercentValid = true;
  } else {
    Power::Battery::RemainingPercentValid = false;
  }

  switch (power_state) {
  case SDL_POWERSTATE_CHARGING:
  case SDL_POWERSTATE_CHARGED:
    Power::External::Status = Power::External::ON;
    Power::Battery::Status = Power::Battery::CHARGING;
  case SDL_POWERSTATE_ON_BATTERY:
    Power::External::Status = Power::External::OFF;
    if (remaining_percent >= 0) {
      if (remaining_percent > 30) {
        Power::Battery::Status = Power::Battery::HIGH;
      } else if (remaining_percent > 30) {
        Power::Battery::Status = Power::Battery::LOW;
      } else {
        Power::Battery::Status = Power::Battery::CRITICAL;
      }
    } else {
      Power::Battery::Status = Power::Battery::UNKNOWN;
    }
  default:
    Power::External::Status = Power::External::UNKNOWN;
  }
}
コード例 #3
0
ファイル: sys_sdl2.c プロジェクト: imanex/ezquake-source
static void Sys_BatteryInfo_f(void)
{
	SDL_PowerState res;
	int secs, percent;

	if ((res = SDL_GetPowerInfo(&secs, &percent)) == SDL_POWERSTATE_UNKNOWN) {
		Com_Printf("Failed to retrieve power state info\n");
		return;
	}

	switch (res) {
		case SDL_POWERSTATE_ON_BATTERY:
			Com_Printf("%d%% left (%d:%02dh)\n", percent, secs/3600, (secs%3600)/60);
			break;
		case SDL_POWERSTATE_NO_BATTERY:
			Com_Printf("No battery available\n");
			break;
		case SDL_POWERSTATE_CHARGING:
			Com_Printf("Plugged in, charging battery (%d%%)\n", percent);
			break;
		case SDL_POWERSTATE_CHARGED:
			Com_Printf("Plugged in, battery is fully charged\n");
			break;
		default:
			break;
	}
}
コード例 #4
0
ファイル: System.cpp プロジェクト: AntonioModer/LoveMore
love::system::System::PowerState System::getPowerInfo(int &seconds, int &percent) const
{
	SDL_PowerState sdlstate = SDL_GetPowerInfo(&seconds, &percent);

	PowerState state = POWER_UNKNOWN;
	powerStates.find(sdlstate, state);

	return state;
}
コード例 #5
0
ファイル: sdlpower_stub.c プロジェクト: codename68/OCamlSDL2
CAMLprim value
caml_SDL_GetPowerInfo(value unit)
{
    CAMLparam0();
    CAMLlocal1(ret);

    int secs, pct;
    SDL_PowerState state = SDL_GetPowerInfo(&secs, &pct);

    ret = caml_alloc(3, 0);
    Store_field(ret, 0, Val_int(state));
    Store_field(ret, 1, Val_int(secs));
    Store_field(ret, 2, Val_int(pct));
    CAMLreturn(ret);
}
コード例 #6
0
ファイル: Battery.cpp プロジェクト: PhilColbert/LK8000
bool GetBatteryInfo(BATTERYINFO* pBatteryInfo) {
    int remaining_percent = 0;

    // check incoming pointer
    if (NULL == pBatteryInfo) {
        return false;
    }

    // assume failure at entry
    pBatteryInfo->BatteryLifePercent = BATTERY_UNKNOWN;
    pBatteryInfo->acStatus = Battery::UNKNOWN;
    pBatteryInfo->chargeStatus = Battery::CHARGE_UNKNOWN;


    SDL_PowerState power_state = SDL_GetPowerInfo(NULL, &remaining_percent);
    if (remaining_percent >= 0) {
        pBatteryInfo->BatteryLifePercent = remaining_percent;
    }

    switch (power_state) {
        case SDL_POWERSTATE_CHARGING:
        case SDL_POWERSTATE_CHARGED:
            pBatteryInfo->acStatus = Battery::ONLINE;
            pBatteryInfo->chargeStatus = Battery::CHARGING;
            break;
        case SDL_POWERSTATE_ON_BATTERY:
            pBatteryInfo->acStatus = Battery::OFFLINE;
            if (remaining_percent >= 0) {
                if (remaining_percent > 30) {
                    pBatteryInfo->chargeStatus = Battery::HIGH;
                } else if (remaining_percent > 30) {
                    pBatteryInfo->chargeStatus = Battery::LOW;
                } else {
                    pBatteryInfo->chargeStatus = Battery::CRITICAL;
                }
            } else {
                pBatteryInfo->chargeStatus = Battery::CHARGE_UNKNOWN;
            }
            break;
        default:
            pBatteryInfo->chargeStatus = Battery::CHARGE_UNKNOWN;
            break;
    }
    
    return true;
}
コード例 #7
0
ファイル: Battery.cpp プロジェクト: Dgame/Flatlands-ESOE
    Battery RemainingBattery() {
        int secs, pct;
        SDL_PowerState state = SDL_GetPowerInfo(&secs, &pct);

        return Battery{secs, static_cast<int8>(pct), static_cast<Battery::State>(state)};
    }
コード例 #8
0
ファイル: debug_utils.c プロジェクト: AntonioND/giibiiadvance
static void _sys_info_reset(void)
{
    memset(sys_info_buffer,0,sizeof(sys_info_buffer));

    _sys_info_printf("SDL information:\n"
                     "----------------\n"
                     "\n"
                     "SDL_GetPlatform(): %s\n\n"
                     "SDL_GetCPUCount(): %d (Number of logical CPU cores)\n"
#if SDL_VERSION_ATLEAST(2,0,1)
                     "SDL_GetSystemRAM(): %d MB\n"
#endif
                     "SDL_GetCPUCacheLineSize(): %d kB (Cache L1)\n\n",
                     SDL_GetPlatform(), SDL_GetCPUCount(),
#if SDL_VERSION_ATLEAST(2,0,1)
                     SDL_GetSystemRAM(),
#endif
                     SDL_GetCPUCacheLineSize() );

    int total_secs, pct;
    SDL_PowerState st = SDL_GetPowerInfo(&total_secs,&pct);
    char * st_string;
    switch(st)
    {
        default:
        case SDL_POWERSTATE_UNKNOWN:
            st_string = "SDL_POWERSTATE_UNKNOWN (cannot determine power status)";
            break;
        case SDL_POWERSTATE_ON_BATTERY:
            st_string = "SDL_POWERSTATE_ON_BATTERY (not plugged in, running on battery)";
            break;
        case SDL_POWERSTATE_NO_BATTERY:
            st_string = "SDL_POWERSTATE_NO_BATTERY (plugged in, no battery available)";
            break;
        case SDL_POWERSTATE_CHARGING:
            st_string = "SDL_POWERSTATE_CHARGING (plugged in, charging battery)";
            break;
        case SDL_POWERSTATE_CHARGED:
            st_string = "SDL_POWERSTATE_CHARGED (plugged in, battery charged)";
            break;
    }

    unsigned int hours = ((unsigned int)total_secs)/3600;
    unsigned int min = (((unsigned int)total_secs)-(hours*3600))/60;
    unsigned int secs = (((unsigned int)total_secs)-(hours*3600)-(min*60));

    _sys_info_printf("SDL_GetPowerInfo():\n  %s\n  Time left: %d:%02d:%02d\n  Percentage: %3d%%\n\n",
                     st_string,hours,min,secs,pct);
#ifdef ENABLE_OPENGL
    _sys_info_printf("OpenGL information:\n"
                     "-------------------\n"
                     "\n"
                     "GL_RENDERER   = %s\n"
                     "GL_VERSION    = %s\n"
                     "GL_VENDOR     = %s\n"
                     "GL_EXTENSIONS = ",
                     (char*)glGetString(GL_RENDERER),(char*)glGetString(GL_VERSION),
                     (char*)glGetString(GL_VENDOR));
    _sys_info_print((char*)glGetString(GL_EXTENSIONS));
#endif
    _sys_info_printf("\n\nEND LOG\n");
}