Пример #1
0
enum frontend_powerstate frontend_win32_get_powerstate(int *seconds, int *percent)
{
   SYSTEM_POWER_STATUS status;
	enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE;

	if (!GetSystemPowerStatus(&status))
		return ret;

	if (status.BatteryFlag == 0xFF)
		ret = FRONTEND_POWERSTATE_NONE;
	if (status.BatteryFlag & (1 << 7))
		ret = FRONTEND_POWERSTATE_NO_SOURCE;
	else if (status.BatteryFlag & (1 << 3))
		ret = FRONTEND_POWERSTATE_CHARGING;
	else if (status.ACLineStatus == 1)
		ret = FRONTEND_POWERSTATE_CHARGED;
	else
		ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;

	*percent  = (int)status.BatteryLifePercent;
	*seconds  = (int)status.BatteryLifeTime;

#ifdef _WIN32
      if (*percent == 255)
         *percent = 0;
#endif
	return ret;
}
Пример #2
0
PLUGIN_EXPORT double Update(void* data)
{
	MeasureData* measure = (MeasureData*)data;

	SYSTEM_POWER_STATUS sps;
	if (GetSystemPowerStatus(&sps))
	{
		switch (measure->type)
		{
		case POWER_ACLINE:
			return sps.ACLineStatus == 1 ? 1.0 : 0.0;

		case POWER_STATUS:
			if (sps.BatteryFlag & 128)
			{
				return 0.0;	// No battery
			}
			else if (sps.BatteryFlag & 8)
			{
				return 1.0;	// Charging
			}
			else if (sps.BatteryFlag & 4)
			{
				return 2.0;	// Critical
			}
			else if (sps.BatteryFlag & 2)
			{
				return 3.0;	// Low
			}
			else if (sps.BatteryFlag & 1)
			{
				return 4.0;	// High
			}
			break;

		case POWER_STATUS2:
			return sps.BatteryFlag;

		case POWER_LIFETIME:
			return sps.BatteryLifeTime;

		case POWER_PERCENT:
			return sps.BatteryLifePercent == 255 ? 100.0 : sps.BatteryLifePercent;

		case POWER_MHZ:
		case POWER_HZ:
			if (g_NumOfProcessors > 0)
			{
				PROCESSOR_POWER_INFORMATION* ppi = new PROCESSOR_POWER_INFORMATION[g_NumOfProcessors];
				memset(ppi, 0, sizeof(PROCESSOR_POWER_INFORMATION) * g_NumOfProcessors);
				CallNtPowerInformation(ProcessorInformation, nullptr, 0, ppi, sizeof(PROCESSOR_POWER_INFORMATION) * g_NumOfProcessors);
				double value = (measure->type == POWER_MHZ) ? ppi[0].CurrentMhz : ppi[0].CurrentMhz * 1000000.0;
				delete [] ppi;
				return value;
			}
		}
	}

	return 0.0;
}
Пример #3
0
int CWin32PowerSyscall::BatteryLevel()
{
  SYSTEM_POWER_STATUS SystemPowerStatus;
  if (GetSystemPowerStatus(&SystemPowerStatus) && SystemPowerStatus.BatteryLifePercent != 255)
      return SystemPowerStatus.BatteryLifePercent;
  return 0;
}
Пример #4
0
void
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
{
  SYSTEM_POWER_STATUS status;
  if (!GetSystemPowerStatus(&status)) {
    aBatteryInfo->level() = kDefaultLevel;
    aBatteryInfo->charging() = kDefaultCharging;
    aBatteryInfo->remainingTime() = kDefaultRemainingTime;
    return;
  }

  aBatteryInfo->level() =
    status.BatteryLifePercent == 255 ? kDefaultLevel
                                     : ((double)status.BatteryLifePercent) / 100.0;
  aBatteryInfo->charging() = (status.ACLineStatus != 0);
  if (status.ACLineStatus != 0) {
    if (aBatteryInfo->level() == 1.0) {
      // GetSystemPowerStatus API may returns -1 for BatteryFullLifeTime.
      // So, if battery is 100%, set kDefaultRemainingTime at force.
      aBatteryInfo->remainingTime() = kDefaultRemainingTime;
    } else {
      aBatteryInfo->remainingTime() =
        status.BatteryFullLifeTime == (DWORD)-1 ? kUnknownRemainingTime
                                                : status.BatteryFullLifeTime;
    }
  } else {
    aBatteryInfo->remainingTime() =
      status.BatteryLifeTime == (DWORD)-1 ? kUnknownRemainingTime
                                          : status.BatteryLifeTime;
  }
}
Пример #5
0
/// <summary>
/// Poll power source status.
/// </summary>
VOID PowerSchemes::Poll()
{
	if (!GetSystemPowerStatus(&pwrStat))
	{
		isPsValid = FALSE;
	}
	isPsValid = TRUE;
}
bool windows_battery_info::does_device_have_battery()
{
	SYSTEM_POWER_STATUS power_status;
	BOOL success = GetSystemPowerStatus(&power_status);
	if(success) {
		return !(power_status.BatteryFlag & 128);
	} else {
		return false;
	}
}
double windows_battery_info::get_battery_percentage()
{
	SYSTEM_POWER_STATUS power_status;
	BOOL success = GetSystemPowerStatus(&power_status);
	if(success) {
		return power_status.BatteryLifePercent;
	} else {
		return 0.0;
	}
}
Пример #8
0
DWORD WINAPI PowerMonitorThread(LPVOID lpParams)
{
    SYSTEM_POWER_STATUS PowerStatus;
    PMONITOR_THREAD_PARAMS pMonitorThreadParams = (PMONITOR_THREAD_PARAMS)lpParams;
    
    WriteLineToLog("PowerMonitorThread: Started");

    if(!GetSystemPowerStatus(&PowerStatus)) {
        WriteLineToLog("PowerMonitorThread: Error detecting initial power state.");
        goto cleanexit;
    }
    if(!PowerStatus.ACLineStatus) {
        WriteLineToLog("PowerMonitorThread: Machine was not connected to AC power at lock time.");
        goto cleanexit;
    }

    while(1) {
        if(!GetSystemPowerStatus(&PowerStatus)) {
            continue;
        }
        if(!PowerStatus.ACLineStatus) {
            WriteLineToLog("PowerMonitorThread: Firing monitor event");
            SetEvent(pMonitorThreadParams->hMonitorEvent);
            goto cleanexit;
        }
        else {
            ResetEvent(pMonitorThreadParams->hMonitorEvent);
        }
        switch (WaitForSingleObject(pMonitorThreadParams->hMonitorStopEvent, DEFAULT_SLEEP_TIME)) {
        case WAIT_OBJECT_0:
            goto cleanexit;
        case WAIT_TIMEOUT:
            continue;
        }
    }

cleanexit:
    WriteLineToLog("PowerMonitorThread: Exiting");
    HB_SAFE_FREE(pMonitorThreadParams);

    return 0;
}
Пример #9
0
int Battery::currentLevel()
{
#if defined Q_OS_WIN
    GetSystemPowerStatus (&power);
    return static_cast<int> (power.BatteryLifePercent);
#endif

#if defined Q_OS_MAC
    QByteArray data;
    QProcess process;

    process.start ("pmset -g batt");

    while (process.waitForReadyRead())
        data.append (process.readAll());

    /* Parse the digits of the percentage */
    int h = data.at (data.indexOf ("%") - 3) - '0'; // Hundreds
    int t = data.at (data.indexOf ("%") - 2) - '0'; // Tens
    int u = data.at (data.indexOf ("%") - 1) - '0'; // Units

    /* Process data is invalid or we do not know how to read */
    if (h < 0) h = 0;
    if (t < 0) t = 0;
    if (u < 0) u = 0;

    return (h * 100) + (t * 10) + u;
#endif

#if defined Q_OS_LINUX
    QByteArray data;
    QProcess process;

    process.start ("bash -c \"upower -i $(upower -e | grep 'BAT') | "
                   "grep -E 'state|to\\ full|percentage'\"");

    while (process.waitForReadyRead())
        data.append (process.readAll());

    /* Parse the digits of the percentage */
    int h = data.at (data.indexOf ("%") - 3) - '0'; // Hundreds
    int t = data.at (data.indexOf ("%") - 2) - '0'; // Tens
    int u = data.at (data.indexOf ("%") - 1) - '0'; // Units

    /* Process data is invalid or we do not know how to read */
    if (h < 0) h = 0;
    if (t < 0) t = 0;
    if (u < 0) u = 0;

    return (h * 100) + (t * 10) + u;
#endif
}
Пример #10
0
std::string pcType()
{
#ifdef _WIN32
    SYSTEM_POWER_STATUS powerStatus = {};
    GetSystemPowerStatus(&powerStatus);
    if (powerStatus.BatteryFlag == 128)
        return "desktop";
    else
        return "laptop";
#else
    return "unknown";
#endif
}
Пример #11
0
/**
 * Return remaining battery time in seconds.
 * @return Battery time in seconds or 0 if no battery (or connected to power)
 */
EXPORT int get_battery_state(void)
{
	SYSTEM_POWER_STATUS powerStatus;
	int batteryTime = 0;

	if (GetSystemPowerStatus(&powerStatus) == TRUE)
	{

		if (powerStatus.ACLineStatus == 0)
			batteryTime = (int) powerStatus.BatteryLifeTime;
	}
	return batteryTime;
}
Пример #12
0
SDL_bool
SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent)
{
#ifdef _WIN32_WCE
    SYSTEM_POWER_STATUS_EX status;
#else
    SYSTEM_POWER_STATUS status;
#endif
    SDL_bool need_details = SDL_FALSE;

    /* This API should exist back to Win95 and Windows CE. */
#ifdef _WIN32_WCE
    if (!GetSystemPowerStatusEx(&status, FALSE))
#else
    if (!GetSystemPowerStatus(&status))
#endif
    {
        /* !!! FIXME: push GetLastError() into SDL_GetError() */
        *state = SDL_POWERSTATE_UNKNOWN;
    } else if (status.BatteryFlag == 0xFF) {    /* unknown state */
        *state = SDL_POWERSTATE_UNKNOWN;
    } else if (status.BatteryFlag & (1 << 7)) { /* no battery */
        *state = SDL_POWERSTATE_NO_BATTERY;
    } else if (status.BatteryFlag & (1 << 3)) { /* charging */
        *state = SDL_POWERSTATE_CHARGING;
        need_details = SDL_TRUE;
    } else if (status.ACLineStatus == 1) {
        *state = SDL_POWERSTATE_CHARGED;        /* on AC, not charging. */
        need_details = SDL_TRUE;
    } else {
        *state = SDL_POWERSTATE_ON_BATTERY;     /* not on AC. */
        need_details = SDL_TRUE;
    }

    *percent = -1;
    *seconds = -1;
    if (need_details) {
        const int pct = (int) status.BatteryLifePercent;
        const int secs = (int) status.BatteryLifeTime;

        if (pct != 255) {       /* 255 == unknown */
            *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
        }
        if (secs != 0xFFFFFFFF) {       /* ((DWORD)-1) == unknown */
            *seconds = secs;
        }
    }

    return SDL_TRUE;            /* always the definitive answer on Windows. */
}
Пример #13
0
/*
 * This function is called every time the random pool needs
 * stirring, and will acquire the system time in all available
 * forms and the battery status.
 */
void noise_get_light(void (*func) (void *, int)) {
    SYSTEMTIME systime;
    DWORD adjust[2];
    BOOL rubbish;
    SYSTEM_POWER_STATUS pwrstat;

    GetSystemTime(&systime);
    func(&systime, sizeof(systime));

    GetSystemTimeAdjustment(&adjust[0], &adjust[1], &rubbish);
    func(&adjust, sizeof(adjust));

    if (GetSystemPowerStatus(&pwrstat))
	func(&pwrstat, sizeof(pwrstat));
}
Пример #14
0
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
	MeasureData* measure = (MeasureData*)data;

	LPCWSTR value = RmReadString(rm, L"PowerState", L"");
	if (_wcsicmp(L"ACLINE", value) == 0)
	{
		measure->type = POWER_ACLINE;
		*maxValue = 1.0;
	}
	else if (_wcsicmp(L"STATUS", value) == 0)
	{
		measure->type = POWER_STATUS;
		*maxValue = 4.0;
	}
	else if (_wcsicmp(L"STATUS2", value) == 0)
	{
		measure->type = POWER_STATUS2;
		*maxValue = 255.0;
	}
	else if (_wcsicmp(L"LIFETIME", value) == 0)
	{
		measure->type= POWER_LIFETIME;

		value = RmReadString(rm, L"Format", L"%H:%M");
		measure->format = value;

		SYSTEM_POWER_STATUS sps;
		if (GetSystemPowerStatus(&sps))
		{
			*maxValue = sps.BatteryFullLifeTime;
		}
	}
	else if (_wcsicmp(L"MHZ", value) == 0)
	{
		measure->type = POWER_MHZ;
	}
	else if (_wcsicmp(L"HZ", value) == 0)
	{
		measure->type = POWER_HZ;
	}
	else if (_wcsicmp(L"PERCENT", value) == 0)
	{
		measure->type = POWER_PERCENT;
		*maxValue = 100.0;
	}
}
Пример #15
0
int main() {
    SYSTEM_POWER_STATUS test;
    GetSystemPowerStatus(&test);
    int percent  = test.BatteryLifePercent;
    if (percent > 100) percent = 100;
    std::string out;
    if (test.BatteryFlag & 8) {
        out = "charging";
    } else if (test.ACLineStatus == 1) {
        out = "AC";
    } else {
        out = "discharging";
    }
    out += " " + std::to_string(percent);
    std::cout << out << std::endl;
    return 0;
}
Пример #16
0
void BatteryWindows::read() {
    m_iMinutesLeft = 0;
    m_dPercentage = 0.0;
    m_chargingState = Battery::UNKNOWN;

    // SYSTEM_POWER_STATUS doc
    // http://msdn.microsoft.com/en-us/library/windows/desktop/aa373232(v=vs.85).aspx
    SYSTEM_POWER_STATUS spsPwr;
    if (GetSystemPowerStatus(&spsPwr)) {
        // get rest power of battery
        m_dPercentage = static_cast<double>(spsPwr.BatteryLifePercent);
        // check for unkown flag and reset to default
        if (m_dPercentage == 255) {
            m_dPercentage = 0;
        }
        int batStat = static_cast<int>(spsPwr.BatteryFlag);
        if (batStat == 1 || batStat == 2 || batStat == 4) {
            m_chargingState = Battery::DISCHARGING;
        } else if (batStat == 8) {
            m_chargingState = Battery::CHARGING;
        }
        // I get this directly from the API
        if (m_dPercentage > 99) {
            m_chargingState = Battery::CHARGED;
        }
        // windows tells us the remainging time in seconds
        m_iMinutesLeft = static_cast<int>(spsPwr.BatteryLifeTime) / 60;
    }

    // QString bat = "unkown";
    // switch (m_chargingState) {
    // case Battery::CHARGING:
    //     bat = "charging";
    //     break;
    // case Battery::DISCHARGING:
    //     bat = "discharging";
    //     break;
    // case Battery::CHARGED:
    //     bat = "charged";
    // }
    // qDebug() << "BatteryWindows::read()"
    //          << "capacity " << m_dPercentage
    //          << "minutes_left " << m_iMinutesLeft
    //          << "battery_status " << bat;
}
Пример #17
0
//---------------------------------------------------------------------
// WM_POWERBROADCASTメッセージ処理
//---------------------------------------------------------------------
LRESULT OnPowerBroadcast(HWND hwnd, WPARAM wParam, LPARAM lParam) {
	DWORD dwPowerEvent = (DWORD)wParam;
	DWORD dwData = (DWORD)lParam;

	// 電源状態変数の更新
	//
	// はじめは、描画時に取得してなるべく新しい状態を表示するようにしていたが、
	// GetSystemPowerStatus 関数の所要時間が、250ms 程度かかることが多く、
	// 画面がちらつくため、このタイミングで情報を更新するように修正。

	GetSystemPowerStatus(&g_sps);

	SaveSystemPowerStatus(dwPowerEvent, dwData);

	// ウィンドウの再描画を促す
	InvalidateRect(hwnd, NULL, TRUE);
	return TRUE;
}
Пример #18
0
	void PlatformWinAPI::handleBatteryStateChanged (int newPercentage)
	{
		//TODO(DZhon): Rewrite using Win32_Battery WMI Class.

		qDebug() << tr ("New battery state detected") << ": [" << newPercentage << "]";

		SYSTEM_POWER_STATUS powerStatus;
		BOOL retCode = GetSystemPowerStatus (&powerStatus);

		Q_ASSERT (retCode);

		BatteryInfo info;		

		info.TimeToEmpty_ = powerStatus.BatteryLifeTime;
		info.Percentage_ = newPercentage;

		emit batteryInfoUpdated (info);
	}
Пример #19
0
bool_t CC_CALL sys_get_power_info(CC_POWER_STATE_ENUM *state, dword_t *seconds, byte_t *percent)
{
    SYSTEM_POWER_STATUS status;
    bool_t need_details = FALSE;

    /* This API should exist back to Win95. */
    if (!GetSystemPowerStatus(&status)) {
        /* !!! FIXME: push GetLastError() */
        *state = CC_POWERSTATE_UNKNOWN;
    } else if (status.BatteryFlag == 0xFF) {/* unknown state */
        *state = CC_POWERSTATE_UNKNOWN;
    } else if (status.BatteryFlag & (1 << 7)) {/* no battery */
        *state = CC_POWERSTATE_NO_BATTERY;
    } else if (status.BatteryFlag & (1 << 3)) {/* charging */
        *state = CC_POWERSTATE_CHARGING;
        need_details = TRUE;
    } else if (status.ACLineStatus == 1) {/* on AC, not charging. */
        *state = CC_POWERSTATE_CHARGED;
        need_details = TRUE;
    } else {
        *state = CC_POWERSTATE_ON_BATTERY;/* not on AC. */
        need_details = TRUE;
    }

    *percent = -1;
    *seconds = -1;

    if (need_details) {
        const byte_t pct = (byte_t)status.BatteryLifePercent;
        const dword_t secs = (dword_t)status.BatteryLifeTime;
        /* 255 == unknown */
        if (pct != 0xFF) {
            /* clamp between 0%, 100% */
            *percent = (pct > 100) ? 100 : pct; 
        }
        /* ((DWORD)-1) == unknown */
        if (secs != 0xFFFFFFFF) {
            *seconds = secs;
        }
    }
    /* always the definitive answer on Windows. */
    return TRUE;
}
Пример #20
0
VOID GetBatteryState(BOOL *pbLBI, BOOL *pbVLBI)
{
#if defined BAT_SIMULATION
	switch (GetPrivateProfileInt(_T("LowBat"),_T("Level"),2,_T(".\\Lowbat.ini")))
	{
	case 0: // empty
		*pbLBI = TRUE;
		*pbVLBI = TRUE;
		break;
	case 1: // low
		*pbLBI = TRUE;
		*pbVLBI = FALSE;
		break;
	default: // full
		*pbLBI = FALSE;
		*pbVLBI = FALSE;
		break;
	}
#else
	SYSTEM_POWER_STATUS sSps;

	*pbLBI = FALSE;							// no battery warning
	*pbVLBI = FALSE;

	VERIFY(GetSystemPowerStatus(&sSps));

	// low bat emulation enabled and battery powered
	if (!bLowBatDisable && sSps.ACLineStatus == AC_LINE_OFFLINE)
	{
		// on critical battery state make sure that lowbat flag is also set
		if ((sSps.BatteryFlag & BATTERY_FLAG_CRITICAL) != 0)
			sSps.BatteryFlag |= BATTERY_FLAG_LOW;

		// low bat detection
		*pbLBI = ((sSps.BatteryFlag & BATTERY_FLAG_LOW) != 0);

		// very low bat detection
		*pbVLBI = ((sSps.BatteryFlag & BATTERY_FLAG_CRITICAL) != 0);
	}
#endif
	return;
}
Пример #21
0
KLF_EXPORT KLFSysInfo::BatteryInfo _klf_win_battery_info()
{
  KLFSysInfo::BatteryInfo info;

  SYSTEM_POWER_STATUS batterystatus;

  if (GetSystemPowerStatus(&batterystatus) == 0) {
    klfWarning("Could not get battery status.") ;
    info.islaptop = false;
    info.onbatterypower = false;
    return info;
  }

  info.islaptop = (batterystatus.ACLineStatus != 255);
  info.onbatterypower = false;
  if (batterystatus.ACLineStatus == 0)
    info.onbatterypower = true;

  return info;
}
Пример #22
0
Файл: apm.c Проект: OLSR/olsrd
int
apm_read(struct olsr_apm_info *ApmInfo)
{
#if !defined WINCE
  SYSTEM_POWER_STATUS PowerStat;

  memset(ApmInfo, 0, sizeof(struct olsr_apm_info));

  if (!GetSystemPowerStatus(&PowerStat))
    return 0;

  ApmInfo->ac_line_status = (PowerStat.ACLineStatus == 1) ? OLSR_AC_POWERED : OLSR_BATTERY_POWERED;

  ApmInfo->battery_percentage = (PowerStat.BatteryLifePercent <= 100) ? PowerStat.BatteryLifePercent : 0;

  return 1;
#else /* !defined WINCE */
  return 0;
#endif /* !defined WINCE */
}
Пример #23
0
PLUGIN_EXPORT LPCWSTR GetString(void* data)
{
	static WCHAR buffer[128];
	MeasureData* measure = (MeasureData*)data;

	if (measure->type == POWER_LIFETIME)
	{
		SYSTEM_POWER_STATUS sps;
		if (GetSystemPowerStatus(&sps))
		{
			// Change it to time string
			if (sps.BatteryLifeTime == -1)
			{
				return L"Unknown";
			}
			else
			{
				tm time = {0};
				time.tm_sec = sps.BatteryLifeTime % 60;
				time.tm_min = (sps.BatteryLifeTime / 60) % 60;
				time.tm_hour = sps.BatteryLifeTime / 60 / 60;

				_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(NullCRTInvalidParameterHandler);
				_CrtSetReportMode(_CRT_ASSERT, 0);

				errno = 0;
				wcsftime(buffer, 128, measure->format.c_str(), &time);
				if (errno == EINVAL)
				{
					buffer[0] = L'\0';
				}

				_set_invalid_parameter_handler(oldHandler);

				return buffer;
			}
		}
	}

	return nullptr;
}
Пример #24
0
int BLBS_GetBatteryStat()
{
	wchar_t* msg_ac = NULL;
	wchar_t* msg_charge = NULL;
	wchar_t fullmsg[BS_STRING_BUF_SIZE];

	if (GetSystemPowerStatus(&stat) == 0)
		JV_ErrorHandle(JVERR_GetSystemPowerStatus, TRUE);

// DEBUG Information Start
	switch (stat.ACLineStatus)
	{
	case 0: // AC Off
		msg_ac = L"Battery";
		break;
	case 1: // AC OnS
		msg_ac = L"AC";
		break;
	case 255: // Unknown
		msg_ac = L"Unknown";
		break;
	}

	if (stat.BatteryFlag & 0x08)
		msg_charge = L"Charging";
	else if (stat.ACLineStatus == 1)
		msg_charge = L"Full";
	else if (stat.ACLineStatus == 0)
		msg_charge = L"Using Battery";

	StringCchPrintfW(fullmsg, BS_STRING_BUF_SIZE,
					L"Power Source : %ws\n"
					L"Battery Status : %ws\n"
					L"Battery Percent : %d%%\n",
					msg_ac, msg_charge, stat.BatteryLifePercent);
	MessageBoxW(NULL, fullmsg, L"Power Info", MB_ICONINFORMATION | MB_OK);
// DEBUG Information End

    return 0;
}
Пример #25
0
bool Battery::isConenctedToPowerSupply()
{
#if defined Q_OS_WIN
    GetSystemPowerStatus (&power);
    return power.ACLineStatus != 0;
#endif

#if defined Q_OS_MAC
    QByteArray data;
    QProcess process;

    process.start ("pmset -g batt");

    while (process.waitForReadyRead())
        data.append (process.readAll());

    if (data.contains ("discharging"))
        return false;

    return true;
#endif

#if defined Q_OS_LINUX
    QByteArray data;
    QProcess process;

    process.start ("bash -c \"upower -i $(upower -e | grep 'BAT') | "
                   "grep -E 'state|to\\ full|percentage'\"");

    while (process.waitForReadyRead())
        data.append (process.readAll());

    if (data.contains ("discharging"))
        return false;

    return true;
#endif
}
Пример #26
0
HRESULT WindowsPowerLW::GetCurrentPowerScheme()
{
    DEBUG_XCOVER_MARK_LINE;
    memset(&pwrPolicy,0,sizeof(POWER_POLICY));
    //得到当前正在使用的Power Scheme的索引 
    if (!GetActivePwrScheme(&nIndex))
    {
        return HRESULT_FROM_WIN32(::GetLastError());
    }
    DEBUG_XCOVER_MARK_LINE;
    if (!ReadPwrScheme(nIndex,&pwrPolicy))
    {
        return HRESULT_FROM_WIN32(::GetLastError());
    }
    //得到电源情况
    DEBUG_XCOVER_MARK_LINE;
    if (!GetSystemPowerStatus(&SystemPowerStatus))
    {
        return HRESULT_FROM_WIN32(GetLastError());
    }
    DEBUG_XCOVER_MARK_LINE;
    return S_OK;
}
Пример #27
0
/*++
* @name DynamicLoadIcon
*
* Returns the respective icon as per the current battery capacity.
* It also does the work of setting global parameters of battery capacity and tooltips.
*
* @param hinst
*        A handle to a instance of the module.
*
* @return The handle to respective battery icon.
*
*--*/
static HICON DynamicLoadIcon(HINSTANCE hinst)
{
    SYSTEM_POWER_STATUS PowerStatus;
    HICON hBatIcon;
    UINT index = -1;

    if (!GetSystemPowerStatus(&PowerStatus) ||
        PowerStatus.ACLineStatus == AC_LINE_UNKNOWN ||
        PowerStatus.BatteryFlag == BATTERY_FLAG_UNKNOWN)
    {
        hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_BATTCAP_ERR));
        g_strTooltip.LoadStringW(IDS_PWR_UNKNOWN_REMAINING);
        return hBatIcon;
    }

    if (((PowerStatus.BatteryFlag & BATTERY_FLAG_NO_BATTERY) == 0) &&
        ((PowerStatus.BatteryFlag & BATTERY_FLAG_CHARGING) == BATTERY_FLAG_CHARGING))
    {
        index = Quantize(PowerStatus.BatteryLifePercent);
        hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(bc_icons[index])); 
        g_strTooltip.Format(IDS_PWR_CHARGING, PowerStatus.BatteryLifePercent);
    }
    else if (((PowerStatus.BatteryFlag & BATTERY_FLAG_NO_BATTERY) == 0) &&
             ((PowerStatus.BatteryFlag & BATTERY_FLAG_CHARGING) == 0))
    {
        index = Quantize(PowerStatus.BatteryLifePercent);
        hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(br_icons[index]));
        g_strTooltip.Format(IDS_PWR_PERCENT_REMAINING, PowerStatus.BatteryLifePercent);
    }
    else
    {
        hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_POWER_AC));
        g_strTooltip.LoadStringW(IDS_PWR_AC);
    }

    return hBatIcon;
}
Пример #28
0
//---------------------------------------------------------------------
// SYSTEM_POWER_STATUSの保存
//---------------------------------------------------------------------
void SaveSystemPowerStatus(DWORD dwPowerEvent, DWORD dwData) {
#if 0
	FILE* fp = _tfopen(_T("SystemPowerStatus.csv"), _T("a+"));
	if (fp) {
		SYSTEM_POWER_STATUS sps;
		GetSystemPowerStatus(&sps);

		SYSTEMTIME stNow;
		GetLocalTime(&stNow);
		_ftprintf(fp, _T("%d/%d/%d %d:%02d:%02d,%d,%d,%d,%d,%d,%d,%d\n"),
			stNow.wYear, stNow.wMonth, stNow.wDay,
			stNow.wHour, stNow.wMinute, stNow.wSecond,
			dwPowerEvent, dwData,
			sps.ACLineStatus,
			sps.BatteryFlag,
			sps.BatteryLifePercent,
			sps.BatteryLifeTime,
			sps.BatteryFullLifeTime
		);

		fclose(fp);
	}
#endif
}
Пример #29
0
//---------------------------------------------------------------------
// WM_CREATEメッセージ処理
//---------------------------------------------------------------------
LRESULT OnCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {

	// 電源状態変数を初期化
	GetSystemPowerStatus(&g_sps);

	// 起動時の電源状態を記録
	SaveSystemPowerStatus(0, 0);

	RECT rcWork;
	SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);

	RECT rc;
	GetWindowRect(hwnd, &rc);

	SetWindowPos(
		hwnd,
		NULL,
		rcWork.right - (rc.right - rc.left),
		rcWork.bottom - (rc.bottom - rc.top),
		0, 0,
		SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER);

	return 0;
}
Пример #30
0
void CPlayerToolBar::SetStatusTimer(REFERENCE_TIME rtNow, REFERENCE_TIME rtDur, bool fHighPrecision, const GUID* pTimeFormat, double playRate)
{
  ASSERT(pTimeFormat);

  CString str;
  CString posstr, durstr;

  if(*pTimeFormat == TIME_FORMAT_MEDIA_TIME)
  {
    DVD_HMSF_TIMECODE tcNow = RT2HMSF(rtNow);
    DVD_HMSF_TIMECODE tcDur = RT2HMSF(rtDur);

    if(tcDur.bHours > 0 || (rtNow >= rtDur && tcNow.bHours > 0)) 
      posstr.Format(_T("%02d:%02d:%02d"), tcNow.bHours, tcNow.bMinutes, tcNow.bSeconds);
    else 
      posstr.Format(_T("%02d:%02d"), tcNow.bMinutes, tcNow.bSeconds);

    if(tcDur.bHours > 0)
      durstr.Format(_T("%02d:%02d:%02d"), tcDur.bHours, tcDur.bMinutes, tcDur.bSeconds);
    else
      durstr.Format(_T("%02d:%02d"), tcDur.bMinutes, tcDur.bSeconds);

    if(fHighPrecision)
    {
      str.Format(_T("%s.%03d"), posstr, (rtNow/10000)%1000);
      posstr = str;
      str.Format(_T("%s.%03d"), durstr, (rtDur/10000)%1000);
      durstr = str;
      str.Empty();
    }
  }
  else if(*pTimeFormat == TIME_FORMAT_FRAME)
  {
    posstr.Format(_T("%I64d"), rtNow);
    durstr.Format(_T("%I64d"), rtDur);
  }

  str = (/*start <= 0 &&*/ rtDur <= 0) ? posstr : posstr + _T(" / ") + durstr;

  SYSTEM_POWER_STATUS status;
  GetSystemPowerStatus(&status);
  CString szPower ;
  if ( status.BatteryFlag != 128 && status.BatteryFlag != 255 && status.BatteryLifePercent < 91 ){
    szPower.Format(ResStr(IDS_STATUS_BAR_LABEL_BATTRAY_WITH_PADDING), status.BatteryLifePercent);
  }else{
    //szPower = ResStr(IDS_STATUS_BAR_LABEL_BATTRAY_UNLIMIT);
  }
  CString szPlayrate;
  if(fabs(playRate - 1.0) > 0.02 && playRate > 0.01)	{
    szPlayrate.Format(ResStr(IDS_STATUS_BAR_LABEL_PLAY_SPEED_WITH_PADDING), playRate);
  }

  CMainFrame* pFrame = ((CMainFrame*)AfxGetMainWnd());
  CString szPlayingFileName = pFrame->GetCurPlayingFileName();
  if(!szPlayingFileName.IsEmpty()){
    //szPlayingFileName.Append(_T("  "));
  }

  //szPlayingFileName
  SetStatusTimer( str + szPlayrate + szPower + m_buffering );
}