Extension for getting Battery/Powerstate. *Windows Only*

One of several possible nightmares: During a performance, someone accidentally unplugs the AC from your laptop. After some time your battery is depleted and Windows shuts down. Total mayhem :rage:

It would be nice if you had a way to make GP scream at you it is running on battery. Then you could correct the issue before it becomes a problem.

To make this possible Iā€™ve written a small extension (Windows only!): battery-ext-4.5.8.dll. When you drop that in the 'extensions-folder` of GP and activate it in GP (options->extensions) then you get several extra functions in gpscript available to retrieve things like the state of the AC powerline, the battery percentage, etc. To make GP scream at you is up to you :smiley:

** To take advantage of these extension you must write a rack-script **. Below an example. Iā€™ve also attached a sample gigfile, which you can check out.

Example of how to use it:

//$<AutoDeclare>
//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   Display : Widget
   ReqBatt : Widget
   DisplayLifetime : Widget
//$</AutoDeclare>

// Called when a single widget value has changed
On WidgetValueChanged(newValue : double) from ReqBatt
var Bpct : int = 0
    BChg : boolean = false
    BDchg : boolean  = false
    BPrsnt : boolean  = false
    BStat : int = 0
    BLife : int = 0
    disp : string = ""
    
    if newValue != 0
    then
        Bpct = BatteryInfo_GetBatteryPercent()
        BChg = BatteryInfo_GetBatteryCharging()
        BDchg = BatteryInfo_GetBatteryDischarging()
        BPrsnt = BatteryInfo_GetBatteryPresent()
        BStat = BatteryInfo_GetACLineStatus()
        BLife = BatteryInfo_GetBatteryLifeTime()

        disp = "Percent " + Bpct + " Charging " + BChg + " Discharging " + BDchg + " Present " + BPrsnt + " State " + BStat

        Display.SetWidgetLabel(disp )
        DisplayLifetime.SetWidgetLabel("Remaining seconds " + BLife )
    end
End

All functions start with BatteryInfo_, so using the functions explorer in the gpscript editor you should be able to find them easily.

SHA256: 2580A691C14E83FDD6C2FC7651AE467073876684E5DE068E482DB5A0D8A521D0

BatteryInfo-Ext-4.5.8.zip (12.1 KB)

The Gigfile (same one as I attached a little further in this topic):

BatteryInfo Demo.gig (37.6 KB)

For those interested in the source code (and maybe do it better), here is where you can find it:

10 Likes

Thanks for this extension.

Iā€™ve created a sample gig file demoing how it should work:

BatteryInfo Demo.gig (37.6 KB)

5 Likes

Excellent! Tested under Win10 22H2, works fine here!
In the past decades it happened a few times to me that the laptop was not on AC during a gig ā€¦

With a few cut&paste actions I have tested it in a global rackspace and panel, as this warning and info should be there for all songs, all rackspace, globally:

BatteryInfo Demo Global.gig (38.1 KB)

4 Likes

This Extention seems not to work anymore in Gig performer 4.7. At importing the Extention you get an info that the extention ist too old for this verion and the Demo Gig-File doesnā€™t work also, compiling the Rachspace script causes Rackspace (Rackspace) - Semantic error in ā€œMainā€: Line 20, Col 18: Unknown identifier: BatteryInfo_GetBatteryPercent

I can recompile it. Shouldnā€™t be a big deal. Iā€™ll check within a few hours.

1 Like

This would be very nice :slight_smile:

This works in 4.7 (at least at my place :slight_smile:)

Name: BatteryInfo-Ext-4.7.zip
Size: 12794 bytes (12 KiB)
SHA256: 1D80DC31137D62DAC37A28563CD10F3955E94C5274CBD43570FC64574648EFEA
SHA1: AE4E0ABD41912E0F76C812056395962E1C3E9B5F

BatteryInfo-Ext-4.7.zip (12.5 KB)

4 Likes

Frank,

Does anyone know if that one also works in 4.5.8.

Unlike my Dell, my new computer does not light up when its connected to power.

Jeff

An extension compiled for 4.7 will not work under older versions as it will be expecting GP to be exposing functions that did not exist in earlier versions

1 Like

Thereā€™s this version that works with 4.5.8

2 Likes

I installed the current version of the extension to match GP 4.7 and compiled the script in my prototype rackspace. Everything now worked as expected in this rack space. Now I wanted to add this to the rest of the rack spaces I had already created. But every time I want to compile the current Rackspace script, GP just crashes. I work on Windows 11. Does anyone have an idea?

To narrow it down and rule out other causes: can you create a gig file with just three empty rackspaces and only add the widgets and script for the power? (Save it after the first rackspace got its compiled script) Let me know whether that also crashes. If it crashes, upload your gig file please

Thanks