It is currently March 28th, 2024, 10:15 pm

CoreTemp temperature scale

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

jsmorley wrote:I don't use CoreTemp or know too much about it, but if there is a "portable" version or a 32bit version of it, you might have to offer a way in your [Variables] section to set the "installed location" for the application. Probably reasonably safe to assume the default location, but you might want to offer a way to change it if needed.
Yep, maybe I should and probably I even will. I have installed the CoreTemp, so will have to take a look at the portable version of it. Thanks...
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: CoreTemp temperature scale

Post by jsmorley »

balala wrote:Thanks again jsmorley, just two more questions I have about this code, which definitely works.
  • What I can't understand is why does it work, because if I'm not mistaken, the [ is a reserved character, so should be it escaped (something like this: RegExp=(?siU).*[color=#FF0000]\[/color][Core Temp settings].*Fahr=(.*);. But it definitely works, even not escaped, so, what the explanation?
  • There is any disadvantage if I set an UpdateRate=1 option to the WebParser measure. I know what disadvantage has if the measure parses a website, however what if it does a local file? Can this setting create any trouble, in long term usage?
Thanks again.
Well, you are right on the use of [ in a regular expression. The reason it works without the escape in this case is that what [Core Temp settings] means in regular expression is "a character set consisting of Core Temp settings", which still gets us the correct result in this case. It really should be escaped to be technically correct though.

I don't see any big reason not to "read a file" once a second. Windows is going to do a lot of caching and it won't be physically read from the disk unless it changes anyway. However, It will "write" to a file in your TEMP folder, since that is how WebParser works, it "downloads" the resource and uses that, so there will be some small amount of writing going on, but if you need the values once a second for some reason, I think it would probably be fine.

Personally I would be tempted to read the file with Lua instead, so there is zero "writing", but I'm not sure it's a big deal.

EDIT: I did some double-checking, and I was wrong on this. WebParser does not "write" to the TEMP folder when it is parsing resources it goes and gets from the URL option, only when it is downloading an image with the Download=1 option.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

jsmorley wrote:Well, you are right on the use of [ in a regular expression. The reason it works without the escape in this case is that what [Core Temp settings] means in regular expression is "a character set consisting of Core Temp settings", which still gets us the correct result in this case. It really should be escaped to be technically correct though.
Thanks for these details. Now it's clearer why does it work...
jsmorley wrote:I don't see any big reason not to "read a file" once a second. Windows is going to do a lot of caching and it won't be physically read from the disk unless it changes anyway. However, It will "write" to a file in your TEMP folder, since that is how WebParser works, it "downloads" the resource and uses that, so there will be some small amount of writing going on, but if you need the values once a second for some reason, I think it would probably be fine.

Personally I would be tempted to read the file with Lua instead, so there is zero "writing", but I'm not sure it's a big deal.
If so (it continuously writes a file to the TEMP folder), that's not a good idea, because I'm using a SSD, not a hard disk.
However I think in the meantime I figured out another solution, which doesn't use a lua script. Just in case, I describe my idea. I've created a Calc measure, which has the same value as the CoreTemp plugin measure, which returns the temperature. This Calc measure has set an UpdateDivider=10 option. This UpdateDivider makes the Calc measure to keep the previous value of the CoreTemp plugin measure, when this last one changes.
Another Calc measure, which calculates the difference between the CoreTemp plugin measure and the previous Calc measure is used to update the WebParser measure: when the value of the difference goes above 10 (this happens when I change the temperature scale in CoreTemp main app), the WebParser measure is updated. This solution seems to working well.

Thanks for all your help.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: CoreTemp temperature scale

Post by jsmorley »

Up to you, but the Lua is pretty easy...

Skin:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
AppPath=C:\Program Files\Core Temp\Coretemp.ini

[Lua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1

[MeasureFahr]
Measure=String
String=[&Lua:GetScale()]
DynamicVariables=1
Substitute="1":"Fahrenheit","0":"Celsius"

[MeterScale]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Number:[MeasureFahr:] | String: [MeasureFahr]
Lua:

Code: Select all

function GetScale()

   filePath = SKIN:GetVariable('AppPath')
   local file = io.open(filePath, 'r')
   
   allText = file:read('*all')
   io.close(file)
   
   if allText:match('Fahr=1;') then
      return 1
   else
      return 0
   end
   
end
1.png
The number value of [MeasureFahr:] will be 1 or 0 and the string value of [MeasureFahr] will be "Fahrenheit" or "Celsius". Use it as you need.

Seems a tad less convoluted, and it never writes...
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

jsmorley wrote:Seems a tad less convoluted, and it never writes...
Indeed very interesting code. I probably will use and many thanks for it, but right now I have something I can't understand. If the [Lua] Script measure is never updated (due to its UpdateDivider=-1 option) and nowhere is an !UpdateMeasure (or !Update) bang to update it, how can it immediately show the appropriate value? :o
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: CoreTemp temperature scale

Post by jsmorley »

balala wrote:Indeed very interesting code. I probably will use and many thanks for it, but right now I have something I can't understand. If the [Lua] Script measure is never updated (due to its UpdateDivider=-1 option) and nowhere is an !UpdateMeasure (or !Update) bang to update it, how can it immediately show the appropriate value? :o
In this case, the Lua script itself is never "updated". The function in it is directly executed by the inline Lua I used in the String measure on the first update of the skin. It could just as well have been:

Code: Select all

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1
And it wold function exactly the same. There is no Update() function in the .lua file. The Script measure will only execute any Initialize() function when the skin is loaded, and then just sit there. It has no "work" that it is expected to do itself.

The GetScale() function in the .lua file will be directly executed by the linline Lua call, and the return value will replace the inline Lua where it it used, just like a #Variable# is replaced where it is used.

https://docs.rainmeter.net/manual/lua-scripting/inline-lua/

Inline Lua is new starting in 4.1 of Rainmeter, and I have to tell you, it is one of the best features we have added in a long time. It's really a game-changer.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

jsmorley wrote:Inline Lua is new starting in 4.1 of Rainmeter, and I have to tell you, it is one of the best features we have added in a long time. It's really a game-changer.
Thanks jsmorley for these explanations. The Inline Lua seems indeed to be a very useful new feature. I read about it a while ago, but never used it. Now it came the time to study it a bit deeper, I think.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

jsmorley wrote:EDIT: I did some double-checking, and I was wrong on this. WebParser does not "write" to the TEMP folder when it is parsing resources it goes and gets from the URL option, only when it is downloading an image with the Download=1 option.
Also good to be known, because as I said, I'm using now an SSD, the less writing, the better.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: CoreTemp temperature scale

Post by jsmorley »

To expand on this a bit, I would point out that this can be even "shorter". There is really no need for the String measure I used to call the function. It is really there for one reason, to do the Substitute that provides a string value that matches the number value.

That can be done without the String measure, by having the Lua set a string variable, and having an Inline Lua call that just goes and gets it.

Skin:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
AppPath=C:\Program Files\Core Temp\Coretemp.ini

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[MeterScale]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Number: [&Lua:GetScale()] | String: [&Lua:scaleString]
Lua:

Code: Select all

function GetScale()

	filePath = SKIN:GetVariable('AppPath')
	local file = io.open(filePath, 'r')
   
	allText = file:read('*all')
	io.close(file)
   
	if allText:match('Fahr=1;') then
		scaleString = 'Fahrenheit'  
		return 1
	else
		scaleString = 'Celsius'
		return 0
	end
   
end
1.png
So we are doing two things in the skin:

1) Calling a function that returns a number value.
Number: [&Lua:GetScale()]
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/#CallingAFunction

Then the clever bit..

2) Having that same function also set a string variable that we go get.
String: [&Lua:scaleString]
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/#RetrievingAVariable

Note that the order is of some importance. We want to call the function first, so the string variable is created, and when we go get it, it already exists, and we get the value that is set during that meter "update" and not the previous one.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: CoreTemp temperature scale

Post by balala »

Interesting approach. I think will have to study it a bit deeper.
Thanks for the details.