It is currently March 29th, 2024, 7:47 am

Power Plugin Issue (Status 0 Bug) (Fixed)

Report bugs with the Rainmeter application and suggest features.
User avatar
Floofies
Posts: 22
Joined: February 23rd, 2014, 8:11 pm
Location: Florida, USA

Power Plugin Issue (Status 0 Bug) (Fixed)

Post by Floofies »

I am experiencing a problem exactly like the one posted by viewfindr, here: http://rainmeter.net/forum/viewtopic.php?f=14&t=6601

The Problem, in detail:
When using the "PowerState=Status" measure, the battery status code shows "0" (no battery) when between charge percentages of 33 and 66 percent. Otherwise, status functions normally with no other bugs. This causes no real problems other than tricking Skins into saying "No battery!" (if they support it), and being a pain in the booty if you rely on a skin for information.

I could, just as easily, remove the rendering of that specific code from my skin. (Substitute="0":" ") I figured I'd post here about it first, any ideas about this?

Update: Using the "Status2" Powestate might fix things. I'm testing it now.
Last edited by Floofies on July 17th, 2014, 11:49 pm, edited 3 times in total.
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by FlyingHyrax »

I would like to add that I've experienced a similar issue with the Status values. I can't confirm the range (I never checked that) but my own 'Circuitous Two' battery skin exhibits this problem when my laptop is charging. I'll have to look into it a bit more closely.
Flying Hyrax on DeviantArt
User avatar
Floofies
Posts: 22
Joined: February 23rd, 2014, 8:11 pm
Location: Florida, USA

Power Plugin Issue (Status 0 Bug) (Update 2)

Post by Floofies »

Update: Tested STATUS2, but now a new range of problems has occurred (At least, for me).

BatteryFlag, read from SYSTEM_POWER_STATUS, is STATUS2's source of information. I concede that this may not be a failure of STATUS2 to reliably report data, but rather my (our) failure to interpret the data correctly. In BatteryFlag, you can have the following status codes: 1, 2, 4, 8, 128, and 255. Microsoft does not list any other codes, however there are various numbers that do show up for some reason. For instance, code 9 appears for me randomly.

In how this relates to the first STATUS, I am not 100% sure without having some way to test it. It is entirely possible (and more likely) that the PowerPlugin is not the source of the issue here. If I could check the source of data against what PowerPlugin is reporting, then we could eliminate different possible sources of problems.

At this point, though, I think my best option is to simply omit the errant codes when they show up.
suixin812
Posts: 13
Joined: November 19th, 2012, 5:28 am
Location: China

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by suixin812 »

I checked the source code of Power Plugin. It seems no problem.

Code: Select all

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;
...
		}
	}
	return 0.0;
}
Then I went to MSDN, and I got the answers.

Why the plugin returns 0 when battery is between 33% and 66%?
According to MSDN: "The value (of BatteryFlag) is zero if the battery is not being charged and the battery capacity is between low and high."
When the BatteryFlag is 0, there is no matched condition under the case POWER_STATUS. Thus the plugin returns 0.0 .

Why STATUS2 could returns numbers other than 1, 2, 4, 8, 128, or 255?
Again MSDN: "This member (Battery Flag) can contain one or more of the following flags."
That's to say, when it returns 9, the battery is charging (8) and more than 66% (1).
User avatar
Floofies
Posts: 22
Joined: February 23rd, 2014, 8:11 pm
Location: Florida, USA

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by Floofies »

I see! So, there is no bug in the plugin, and this is just Microsoft Windows being a bit quirky... Thanks!
suixin812
Posts: 13
Joined: November 19th, 2012, 5:28 am
Location: China

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by suixin812 »

Floofies wrote:I see! So, there is no bug in the plugin, and this is just Microsoft Windows being a bit quirky... Thanks!
Well, I need to correct what I said. The problem actually is a bug of the plugin.
Although BatteryFlag is 0 when the battery is 33%~66%,
BatteryFlag equals to 128 instead of 0 when no battery found.
So the plugin should be able to differentiate the two conditions.
If the source code adds a judgement of whether BatteryFlag equlas to 0, then the problem will be solved.
For example:

Code: Select all

         else if (sps.BatteryFlag == 0)
         {
            return 5.0;   // 33%~66%
         }
User avatar
Floofies
Posts: 22
Joined: February 23rd, 2014, 8:11 pm
Location: Florida, USA

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by Floofies »

suixin812 wrote: Well, I need to correct what I said. The problem actually is a bug of the plugin.
Although BatteryFlag is 0 when the battery is 33%~66%,
BatteryFlag equals to 128 instead of 0 when no battery found.
So the plugin should be able to differentiate the two conditions.
If the source code adds a judgement of whether BatteryFlag equlas to 0, then the problem will be solved.
For example:

Code: Select all

         else if (sps.BatteryFlag == 0)
         {
            return 5.0;   // 33%~66%
         }
Oh wow! Do you think there's any chance we can get this fix implemented then?
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Power Plugin Issue (Status 0 Bug) (Update)

Post by poiru »

suixin812 wrote:If the source code adds a judgement of whether BatteryFlag equlas to 0, then the problem will be solved.
For example:

Code: Select all

         else if (sps.BatteryFlag == 0)
         {
            return 5.0;   // 33%~66%
         }
Thanks for investigating this! This will be fixed in the next release of Rainmeter.

For backwards compatibility with existing skins, battery capacity between 33% and 66% will return 4.0 (just like the existing 66%+ case).
User avatar
Floofies
Posts: 22
Joined: February 23rd, 2014, 8:11 pm
Location: Florida, USA

Re: Power Plugin Issue (Status 0 Bug) (Fixed)

Post by Floofies »

Fixed Power plugin: Corrected a STATUS issue when the battery level is higher than "low", but not currently charging.
Wow! Neat how that progressed!