Hi,
I am trying to get a graphic showing the battery charge of a device.
I tried this directly:
Image_[$SCRIPT=Math.Round(&hs.DeviceValue("V1")/25)*25].png
But this does not work, so I used $hs.regex to run a little script which does this indirectly, I am just having problems returning a (correct) result. How does this work?
The script is simple and currently looks like this:
Sub Main (parm as object)
Dim Charge as Integer = parm
Charge = Math.Round(Charge / 25)*25
hs.writelog("Battery", "Rounded Batterylife comes to: " & Charge)
End Sub
Where the log returns the expected value, but in HSTouch I get 0?
Any ideas?
Cheers,
Elco
Displaying a dynamic battery charge graphic
Re: Displaying a dynamic battery charge graphic
I don't know what values you get but here's my grain of salt.
If the variable is an integer then every value below 1 will be zero. Try to multiply the value by 100.
e.g. 0.89 will become 0 but 0.89 * 100 will give a value of 89
If the variable is an integer then every value below 1 will be zero. Try to multiply the value by 100.
e.g. 0.89 will become 0 but 0.89 * 100 will give a value of 89
Bram
Re: Displaying a dynamic battery charge graphic
The values are in the range of 0 - 100 like any other device - The problem was that I do not want to make an image for every charge value (1, 2, 3, 4, etc), but only for empty and every 25% up to full.
I did find the solution - it needed to be a function (my VB isn't great) :
Function Main (parm as object)
Dim Charge as Integer = parm
Charge = Math.Round(Charge / 25)*25
hs.writelog("Battery", "Rounded Batterylife comes to: " & Charge)
Main = Charge
End Function
Cheers,
Elco
I did find the solution - it needed to be a function (my VB isn't great) :
Function Main (parm as object)
Dim Charge as Integer = parm
Charge = Math.Round(Charge / 25)*25
hs.writelog("Battery", "Rounded Batterylife comes to: " & Charge)
Main = Charge
End Function
Cheers,
Elco