It is currently May 1st, 2024, 2:02 am

Dynamically change Update frequency?

Get help with creating, editing & fixing problems with skins
mistawac
Posts: 14
Joined: August 19th, 2012, 8:05 pm

Dynamically change Update frequency?

Post by mistawac »

If you've been on the forums at all today you've noticed me asking a few questions. This should be the final question based on this project. Is there a way to dynamically change the update frequency of a skin?

Context:
I've got a rotating image that now changes color based on core temperature (thanks to devs). What I'd like to do with it now is have it change update frequency based on CPU usage, therefore forcing the image to rotate faster and faster depending on how much of the CPU is being used.

Is this possible?
mistawac
Posts: 14
Joined: August 19th, 2012, 8:05 pm

Re: Dynamically change Update frequency?

Post by mistawac »

For reference, here's what I have so far:

Code: Select all

;===========================================
;  Variables
;===========================================

[MeasureSpeedTemp5]
Measure=Plugin
Plugin=SpeedFanPlugin
SpeedFanType=TEMPERATURE
SpeedFanNumber=5

[MeasureCPU]
Measure=CPU

;===========================================
;  Image Speed Settings
;===========================================

[CPUCalc]
Measure=Calc
Forumla=(MeasureCPU > 15) ? 3 : ((MeasureCPU > 5) ? 2: 1)
Substitute="3":".2857","2":".5714","1":"1"

;===========================================
;  Image Color Settings
;===========================================

[ImageColorCalc]
Measure=Calc
Formula=(MeasureSpeedTemp5 > 38) ? 3 : ((MeasureSpeedTemp5 > 28) ? 2 : 1)
Substitute="3":"Red","2":"Yellow","1":"Blue"

[ImageNumberCalc]
Measure=Calc
Formula=Counter % 81

[ImageMeter]
Meter=Image
ImageName=ImagesFrames[ImageColorCalc]\[ImageNumberCalc].png
DynamicVariables=1
X=1865
Y=160
UpdateDivider=[CPUCalc]
DynamicVariables=1
[MeasureCPU] in the Variables section does just that, measures the CPU. [CPUCalc] in the Image Speed Settings section was taken from the color section. It's basically saying that if MeasureCPU is greater than 15, then 3, ElseIf MeasureCPU is greater than 5, then 2, else 1, where 3 = .2857, 2 = .5714, and 1 = 1. Then I read in the manual that if you add DynamicVariables=1 to any meter, you can use the name of a measure in brackets as a value. So in the [ImageMeter] meter under Image Color Settings, I added UpdateDivider=[CPUCalc] and DynamicVariables=1. When I save and refresh, nothing changes. Ideas?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Dynamically change Update frequency?

Post by Kaelri »

You can read a fuller explanation of how Update/UpdateDivider works here. But the upshot is this: what UpdateDivider really does is tell a meter/measure to "skip" a number of updates. So the Update speed is the fastest that any part of the skin can update, and UpdateDivider makes a meter or measure update slower than that. This also means that UpdateDivider must be an integer (a whole number).

Also, you don't need to use a Substitute on a Calc measure when you're only using numbers. ;) You can put them right in the formula.

As an example, this version of the [CPUCalc] measure would come out as "2" (between 0%-5% CPU), "4" (between 6%-15%) or "8" (16%-100%). With Update=1000, whatever uses [CPUCalc] for its UpdateDivider will update once every 2 seconds, 4 seconds or 8 seconds, respectively. Changing the Update speed will make all of these faster or slower.

Code: Select all

[CPUCalc]
Measure=Calc
Forumla=(MeasureCPU > 15) ? 8 : ((MeasureCPU > 5) ? 4: 2)
(Note: remember that the skin's Update speed affects all meters and measures. So it's important to make sure that nothing is updating faster than it needs to. Otherwise, you'll probably experience some high CPU usage from Rainmeter, or even more serious problems, depending on what kind of actions your skin is doing. This is especially important for plugins like WebParser, which can get you blocked by some websites if it's hitting them for updates too frequently.)

Finally, there's one other thing you'll need to do differently. Updating [ImageMeter] faster won't make the animation go faster or slower, because the frame number depends on [ImageNumberCalc], which keeps on going regardless of what the meter is doing. So you'll need the new UpdateDivider to affect [ImageNumberCalc], as well.

This also means that you can't use "Counter," which is always tied to the skin's Update speed. So you need to make the calc formula increment itself:

Code: Select all

[ImageNumberCalc]
Measure=Calc
Formula=(ImageNumberCalc + 1) % 81
UpdateDivider=[CPUCalc]
DynamicVariables=1
mistawac
Posts: 14
Joined: August 19th, 2012, 8:05 pm

Re: Dynamically change Update frequency?

Post by mistawac »

I've read through the Update section in the manual and wasn't thinking straight while working on this (Breaking Bad distracted me). I made the changes you suggested and it still doesn't want to work, at least with Update=5. The reason it needs to be so fast is because it's a group of images that it needs to rotate through faster. If I set it to 1000, it looks like trash.

What I would like is this:

If CPU = 0%-15% then Update=35
If CPU = 16%-30% then Update=30
If CPU = 30%-45% then Update=25
If CPU = 46%-60% then Update=20
If CPU = 61%-75% then Update=15
If CPU = 76%-90% then Update=10
If CPU = 91%-100% then Update=5

Here is what I coded out to attempt that based on what you mentioned:

Code: Select all

;===========================================
;  Variables
;===========================================

[MeasureSpeedTemp5]
Measure=Plugin
Plugin=SpeedFanPlugin
SpeedFanType=TEMPERATURE
SpeedFanNumber=5

[MeasureCPU]
Measure=CPU

;===========================================
;  Image Speed Settings
;===========================================

[CPUCalc]
Measure=Calc
Forumla=(MeasureCPU > 90) ? 1 : (MeasureCPU > 75) ? 2: (MeasureCPU > 60) ? 3: (MeasureCPU > 45) ? 4: (MeasureCPU > 30) ? 5: ((MeasureCPU > 15) ? 6: 7)

;===========================================
;  Image Color Settings
;===========================================

[ImageColorCalc]
Measure=Calc
Formula=(MeasureSpeedTemp5 > 38) ? 3 : ((MeasureSpeedTemp5 > 28) ? 2 : 1)
Substitute="3":"Red","2":"Yellow","1":"Blue"

[ImageNumberCalc]
Measure=Calc
Formula=(ImageNumberCalc +1) % 81
UpdateDivider=[CPUCalc]
DynamicVariables=1

[ImageMeter]
Meter=Image
ImageName=ImagesFrames[ImageColorCalc]\[ImageNumberCalc].png
DynamicVariables=1
X=1865
Y=160
Focus on the [CPUCalc] measure specifically, that's what I changed (obviously) and let me know what you think. It seems to constantly be running at Update=5 rather than changing based on my CPU usage. I've also been monitoring the CPU usage and temperature and it seems to be alright. With Update=5 the CPU usage doesn't go above 8% and the temperature sits at around 29 Celsius, which is alright because I'm in a warm room to begin with.
mistawac
Posts: 14
Joined: August 19th, 2012, 8:05 pm

Re: Dynamically change Update frequency?

Post by mistawac »

I think I'm going to scrap this part of the project until I can find something else to do for the CPU Usage. I took a deeper look into the CPU through the resource monitor and while it's usage was at only 7%, it was actually doing quite a bit of work by updating this thing every 5 milliseconds.

I truly appreciate the help though. Not often are Dev's readily available to support their project so thoroughly.

I'll repost if I find an alternative way to do this that's much less CPU intensive.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Dynamically change Update frequency?

Post by Kaelri »

You might get better performance if you only update the meters/measures involved in the animation, and let the rest update at the normal 1/second.

5 ms is also a bit much. ;) I find something in the range of 20-50 is good for making most transitions feel "smooth" enough.

Try this.

Code: Select all

[Rainmeter]
Update=#UpdateSpeed#

;===========================================
;  Variables
;===========================================

[Variables]
UpdateSpeed=20

[MeasureSpeedTemp5]
Measure=Plugin
Plugin=SpeedFanPlugin
SpeedFanType=TEMPERATURE
SpeedFanNumber=5
UpdateDivider=(1000/#UpdateSpeed#)

[MeasureCPU]
Measure=CPU
UpdateDivider=(1000/#UpdateSpeed#)

;===========================================
;  Image Speed Settings
;===========================================

[CPUCalc]
Measure=Calc
Forumla=(MeasureCPU > 90) ? 1 : ((MeasureCPU > 75) ? 2 : ((MeasureCPU > 60) ? 3 : ((MeasureCPU > 45) ? 4 : ((MeasureCPU > 30) ? 5 : ((MeasureCPU > 15) ? 6 : 7)))))
UpdateDivider=(1000/#UpdateSpeed#)

;===========================================
;  Image Color Settings
;===========================================

[ImageColorCalc]
Measure=Calc
Formula=(MeasureSpeedTemp5 > 38) ? 3 : ((MeasureSpeedTemp5 > 28) ? 2 : 1)
Substitute="3":"Red","2":"Yellow","1":"Blue"
UpdateDivider=(1000/#UpdateSpeed#)

[ImageNumberCalc]
Measure=Calc
Formula=(ImageNumberCalc +1) % 81
UpdateDivider=[CPUCalc]
DynamicVariables=1

[ImageMeter]
Meter=Image
ImageName=ImagesFrames[ImageColorCalc]\[ImageNumberCalc].png
DynamicVariables=1
X=1865
Y=160
mistawac
Posts: 14
Joined: August 19th, 2012, 8:05 pm

Re: Dynamically change Update frequency?

Post by mistawac »

That's lookin' much better. Thank you greatly for the help! Think I'm going to zip this up and post it for people to use now. For those (like myself) who like knowing exactly what's going on at all times, this gives a real pretty way to see that.