BatMon - Battery Status on emulators

BatMon is a Clockwork Pi app that creates an overlay with the battery percentage on top of emulators or games, because you can only see that information in the main menu, this is my attempt on solving that issue.

splash

Changelog:

2020-01-16T23:00:00Z

  • Ported to Qt5.
  • Even less steps to install.
  • Optimization and improvements (Less CPU Cycles).
  • Code cleaning and refactoring.

Apr 23, '19 3:59 PM

  • Now supports OS v0.3.
  • Now it only runs once and stays alive, previosly a script called and killed the process which was unefficient.
  • User can set a custom update interval from the caller script, previosly you had to recompile.
  • Can be toggled on and off from menu, previosly once you ran it it stayed until reboot.
  • Now includes a clock feature :smiley:
  • Easier to install.
  • Removed the pseudo transparency and replaced it with black background.

How to install?

You need to go to Releases · Mihaylov93/BatMon · GitHub and get the latest release. (currently its the 0.5)

You can download BatMon.tar.gz to your computer and copy it to your gameshell or download it from the gameshell.

Once you have BatMon.tar.gz on your gameshell, you need to execute the following commands:

tar -zxvf BatMon-0.5.tar.gz -C /home/cpi/apps/Menu/

Then you need to reload the launcher and it will appear there :slight_smile: thats all.

How to use?

There are 3 modes, battery only, battery and clock in horizontal layout and battery and clock in vertical layout. The default mode is battery only with 30 seconds interval, if you want to customize that you need to change the launcher script located in /home/cpi/apps/Menu/BatMon
image

The content of the script looks like this:

#!/bin/bash
APP_ID=$(ps -C BatMon --no-header --format 'pid')
if [ -n "${APP_ID}" ]; then
  echo "Stopping instance $APP_ID"
  kill "${APP_ID}"
else
# You can change the refresh time in seconds and/or the mode
./BatMon 30 &
fi
exit

The line you need to change is this: ./BatMon 30 &

Examples:

  • Default mode (Mode 0):
    default_mode

There are 4 ways that the app will enter in default mode:

  1. You call it without arguments, for example: ./BatMon &
  2. You call it with 1 argument setting up the refresh seconds, for exampe: ./BatMon 30 &
  3. You call it with 2 arguments, setting the seconds and the mode 0 (Default) ./BatMon 30 0 &
  4. You enter wrong arguments and the app entered default mode with 30 seconds. For example ./BatMon bla bla &
  • Battery and clock in horizontal (Mode 1):
    screen
    To enter this mode you need to set the second argument to 1, for example: ./BatMon 30 1 &

  • Battery and clock in vertical (Mode 2):
    screen2
    To enter this mode you need to set the second argument to 1, for example: ./BatMon 30 2 &

But I want to compile it myself!

Fair enough, if you want to compile it yourself clone the repository with git clone https://github.com/Mihaylov93/BatMon.git

This was made with Qt5, check your version of Qt with qmake --version

qmake BatmMon.pro
make

If make ran succesfully you don’t need to do anything else, BatMon will be installed in your launcher.

Links:
Source code: GitHub - Mihaylov93/BatMon: Battery monitoring widget for Clockwork Pi
Releases: Releases · Mihaylov93/BatMon · GitHub

9 Likes

Is there a way to get this to auto-run when starting up something else (game/emulator/different app) without having to initially start it by itself??

You can set it to run on boot. As you have to run it once for the process to be running then it works forever until your reboot.

And how would I do that?? Definitely something I would like to do

With crontab

crontab -e

@reboot /path/to_script/BatMon.sh &

More info: https://www.raspberrypi-spy.co.uk/2013/07/running-a-python-script-at-boot-using-cron/

1 Like

Hmmm I can’t seem to get it to work.

I’ve moved BatMon to ~/apps/ (just so it’s not on my homescreen).

I added @reboot /home/cpi/apps/Batmon/Batmon.sh & to the bottom of the crontab screen, then tried sudo reboot but it doesn’t seem to start up after reboot? Am I doing something wrong? Does BatMon have to be in ~/launcher/ or ~/apps/Menu/ to actually run?

EDIT: just realised that I mistyped the location, but still doesn’t work

Try the actual binary instead BatMon because the script is made for being able to start and stop and maybe cron doesnt like it

so

@reboot /home/cpi/apps/Batmon/BatMon 30 &

Note, dont forget the arguments, if you modified them from your Batmon.sh

#!/bin/bash
APP_ID=$(ps -C BatMon --no-header --format 'pid')
if [ -n "${APP_ID}" ]; then
  echo "Stopping instance $APP_ID"
  kill "${APP_ID}"
else
# You can change the refresh time in seconds 
./BatMon 30 &
fi
exit
1 Like

Sweet I’ll give that a try. I had a look into other options to run on boot. Is putting something in rc.local an alternative? I only ask because that’s how the global brightness mod works

Basically anything that lets you run a binary would work.

I’m still not having any luck getting this to run after reboot… Might have to put it in the “too hard” basket for now until someone else figures it out

I could check after work.

Don’t go out of your way or anything. Definitely not urgent. I think I can deal with running BatMon before starting to play anything :sweat_smile:

upower -i /org/freedesktop/UPower/devices/battery_axp20x_battery

This looks more accurate.

It should be about the same.

So did anyone get the chance to try getting BatMon to run from start-up/reboot??

add ~/apps/Menu/BatMon/BatMon & to your .bashrc file

Of course, add the arguments that you use normally with BatMon and the path you moved it in

~/path/BatMon X Y &

2 Likes

I get an error on boot saying “BatMon: cannot connect to X server”?

Damn! That was my theory of why it doesn’t work with the crontab, because it tries to run before everything is initialized, and the X server started.

I find it weird that in the bashrc for you it still starts faster than the X server, in my gameshell works.

In that case the startup of BatMon should be delayed, like for example, wait 20 seconds after startup and then start BatMon

EDIT:

OH! Right! try to put it in

~/.xinitrc

instead

Uuhhh… How do I do that?? :sweat_smile:

I’ve tried looking into it myself, with no luck. No idea where to look/start