I'm starting to make one of my first skins, and I can't find out how to do something that I feel should be fairly simple with If statements and the !SetOption bang. I've made a Roundline meter for my laptop's battery status, but I want it to change color based on the PowerState=Status measure of the Power plugin.
If Status returns 1, then my computer is plugged in, and I want the Roundline meter to be blue. If it's 2, then the battery is critical and it should be red, and similarly it should be yellow for 3/low and green for 4/high.
But I can only put one instance of IfEqualValue in the BatteryStatus measure, so I can only do one of the four color swaps. Is there a way I can get this to work without having to use .Lua scripting?
It is currently May 4th, 2024, 2:23 am
Basic IfEqualValue question
-
- Posts: 2
- Joined: April 3rd, 2013, 12:27 am
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Basic IfEqualValue question
I don't have a laptop handy, but I faked up a calc measure to replicate the return value:
So on your measure getting the battery status, add that Substitute option. It will first change 1/2/3/4 to -1/-2/-3/-4 (so we don't have conflicts with color code numbers later) then change each of the -1/-2/-3/-4 values to the appropriate color code.
Then just use the value of the measure on any option (ImageTint, FontColor, SolidColor, etc) as the string value by using [MeasureName] in square brackets and set DynamicVariables=1.
In this example the value will rotate through 1/2/3/4 every 5 seconds.
Code: Select all
[Rainmeter]
Update=1000
[MeasureFakeBatteryStatus]
Measure=Calc
Formula=(MeasureFakeBatteryStatus % 4) + 1
UpdateDivider=5
Substitute="1":"-1","2":"-2","3":"-3","4":"-4","-1":"82,175,204,255","-2":"212,114,114,255","-3":"247,247,181,255","-4":"189,247,181,255"
[MeterOne]
Meter=String
FontSize=20
FontColor=[MeasureFakeBatteryStatus]
AntiAlias=1
Text=Battery Status
DynamicVariables=1
Then just use the value of the measure on any option (ImageTint, FontColor, SolidColor, etc) as the string value by using [MeasureName] in square brackets and set DynamicVariables=1.
In this example the value will rotate through 1/2/3/4 every 5 seconds.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Basic IfEqualValue question
Another approach is:
Don't need any FontColor on our example meter, as the !SetOption sets it for us. Also don't need DynamicVariables=1 on the measure or meter as !SetOption is by its nature always dynamic.
Code: Select all
[Rainmeter]
Update=1000
[Variables]
1=82,175,204,255
2=212,114,114,255
3=247,247,181,255
4=189,247,181,255
[MeasureFakeBatteryStatus]
Measure=Calc
Formula=(MeasureFakeBatteryStatus % 4) + 1
UpdateDivider=5
OnUpdateAction=[!SetOption MeterOne FontColor #[MeasureFakeBatteryStatus]#][!UpdateMeter MeterOne][!Redraw]
[MeterOne]
Meter=String
FontSize=20
AntiAlias=1
Text=Battery Status
-
- Posts: 2
- Joined: April 3rd, 2013, 12:27 am
Re: Basic IfEqualValue question
Okay, I see what you're saying. I tried your first solution, and it didn't work quite right. When this runs, with my computer plugged in at 100% battery, the Roundline turns green instead of blue like I wanted. I figured out why; PowerState=Status only returns 1 if the battery is actively being charged, but I want it to be blue any time that the computer has an AC line, even when the battery is fully charged.
So what I need to do instead is use PowerState=ACLine with PowerState=Status and do a calculation. This is what I came up with:
After all that, it finally works! Blue when charging, Green when full and not charging, Yellow when low battery, Red when critically low. Thanks for your help!
So what I need to do instead is use PowerState=ACLine with PowerState=Status and do a calculation. This is what I came up with:
Code: Select all
[MeasureACLine]
Measure=Plugin
Plugin=PowerPlugin
PowerState=ACLine
[MeasureBatteryState]
Measure=Plugin
Plugin=PowerPlugin
PowerState=Status
[MeasureBatteryCalc]
Measure=Calc
Formula=(MeasureACLine = 1) ? 1 : MeasureBatteryState
Substitute="1":"-1", "2":"-2", "3":"-3", "4":"-4", "-1":"#Blue#", "-2":"#Red#", "-3":"#Yellow#", "-4":"#Green#"
[MeterBattery]
Meter=Roundline
MeasureName=MeasureBatteryPercent
X=700
Y=80
LineStart=55
LineLength=75
StartAngle=(Rad(270))
RotationAngle=(-Rad(360))
Solid=1
LineColor=[MeasureBatteryCalc]
DynamicVariables=1
AntiAlias=1
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Basic IfEqualValue question
My pleasure.