Page 1 of 1

Displaying a dynamic battery charge graphic

Posted: Thu Mar 04, 2010 9:14 pm
by talisman
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

Re: Displaying a dynamic battery charge graphic

Posted: Fri Mar 05, 2010 11:46 am
by AshaiRey
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

Re: Displaying a dynamic battery charge graphic

Posted: Fri Mar 05, 2010 7:22 pm
by talisman
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