By the look of it, they run a small program in the background (a daemon) to handle the power low condition and all its code can be found
here on Github
You could use that to shut down the Pi when the battery runs out or you could do the work in your program.
A quick read of the script (and I am weak in this area) it seems that the pin config is set up by line 62 with
raspi-gpio set $trigger_pin ip pu and this toolkit is installed with:
and the help text gives a neat version of:
raspi-gpio help
WARNING! raspi-gpio set writes directly to the GPIO control registers
ignoring whatever else may be using them (such as Linux drivers) -
it is designed as a debug tool, only use it if you know what you
are doing and at your own risk!
The raspi-gpio tool is designed to help hack / debug BCM283x GPIO.
Running raspi-gpio with the help argument prints this help.
raspi-gpio can get and print the state of a GPIO (or all GPIOs)
and can be used to set the function, pulls and value of a GPIO.
raspi-gpio must be run as root.
Use:
raspi-gpio get [GPIO]
OR
raspi-gpio set <GPIO> [options]
OR
raspi-gpio funcs [GPIO]
OR
raspi-gpio raw
GPIO is a comma-separated list of pin numbers or ranges (without spaces),
e.g. 4 or 18-21 or 7,9-11
Note that omitting [GPIO] from raspi-gpio get prints all GPIOs.
raspi-gpio funcs will dump all the possible GPIO alt funcions in CSV format
or if [GPIO] is specified the alternate funcs just for that specific GPIO.
Valid [options] for raspi-gpio set are:
ip set GPIO as input
op set GPIO as output
a0-a5 set GPIO to alternate function alt0-alt5
pu set GPIO in-pad pull up
pd set GPIO pin-pad pull down
pn set GPIO pull none (no pull)
dh set GPIO to drive to high (1) level (only valid if set to be an output)
dl set GPIO to drive low (0) level (only valid if set to be an output)
Examples:
raspi-gpio get Prints state of all GPIOs one per line
raspi-gpio get 20 Prints state of GPIO20
raspi-gpio get 20,21 Prints state of GPIO20 and GPIO21
raspi-gpio set 20 a5 Set GPIO20 to ALT5 function (GPCLK0)
raspi-gpio set 20 pu Enable GPIO20 ~50k in-pad pull up
raspi-gpio set 20 pd Enable GPIO20 ~50k in-pad pull down
raspi-gpio set 20 op Set GPIO20 to be an output
raspi-gpio set 20 dl Set GPIO20 to output low/zero (must already be set as an output)
raspi-gpio set 20 ip pd Set GPIO20 to input with pull down
raspi-gpio set 35 a0 pu Set GPIO35 to ALT0 function (SPI_CE1_N) with pull up
raspi-gpio set 20 op pn dh Set GPIO20 to ouput with no pull and driving high
so the command (
raspi-gpio set $trigger_pin ip pu) is:
raspi-gpio set Call the program from the command line to set the state of a pin
$trigger_pin This is pin 4 in this case (defined on line 44 of the script)
ip GPIO as input
pu GPIO internal pull up set on
You could emulate that in your program set-up and trigger a routine if this is pulled down by the shim (I think - still learning).
Please remember a little knowledge is dangerous - therefore I am a danger to your Pi

At worst case you could need the £35 fix
