Ludo - visual error display for your Raspberry Pi

This is an old driver based LedBorg script
We recommend using the new driver free based scripts for LedBorg.
The new driver free examples can be found here, the installation can be found here.

When executing scripts, one or more commands may return an error which you don't notice due to large amounts of text scrolling down the screen. If the error handling is poor (which it usually is for quick scripts), you may get to the end and think everything is all good and well. Then later on, something related doesn't work, and you can't figure out why!

So we thought a visual indicator might help out some people. And having the LedBorg display this would be fantastic!

Imagine the following three commands in a script file:

mkdir ~/test
cp ./missingfile ~/test/
ps –A

You could miss the error the missing file generates cp: cannot stat './missing': No such file or directory

So if we precede the commands with ludo (after installing LedBorg and ludo)

ludo mkdir ~/test
ludo cp ./missingfile ~/test/
ludo ps –A

Whilst executing, the LedBorg goes to Blue to indicate it is busy

Then the first command (mkdir) lights the LedBorg Green to indicate OK.

The second command with the missing file returns an error and lights the LedBorg Red to indicate a failed return code

The third command executes OK, but as there was a previous error, it now lights Orange

Purple (Red and Blue) means it has had an error and is currently busy.
White (Red, Green and Blue) means it did have an error, the last instruction was OK, and it is currently busy.

Red Channel = ERROR
Green Channel = OK
Blue Channel on = BUSY

To clear the Led again, simply type ludo without any arguments

  • To make script executable
    chmod +x ludo.sh
  • To clear (reset)
    ./ludo.sh
  • To copy to programs (use without ./)
    sudo cp ludo.sh /usr/local/bin/ludo
  • To run normally
    ./ludo.sh command goes here
  • To run as root / superuser
    ./ludo.sh s command goes here

Here's the code, you can download ludo script file as text here
Save the text file on your pi as ludo.sh

#!/bin/bash

if [ $# -eq 0 ]; then
    # No arguments provided, reset colours to off
    echo "000" > /dev/ledborg                       # Write the colour string for off to the LedBorg device
else
    # Arguments provided, user wants to run a command
 
    # Read the current colour from the LedBorg device
    oldColour=`cat /dev/ledborg`                    # Read the entire contents of the LedBorg file (should only be 3 characters long)
    red=`echo "$oldColour" | cut -b 1`              # Get the red setting from the colour string
    green=`echo "$oldColour" | cut -b 2`            # Get the red setting from the colour string
    blue=`echo "$oldColour" | cut -b 3`             # Get the red setting from the colour string

    # Set running state
    blue="2"                                        # Change blue indicator to say we are running
    echo "${red}${green}${blue}" > /dev/ledborg     # Write the colour string to the LedBorg device

    # Perform command
    if [ "$1" = "s" ]; then
        # Superuser command, run via sudo
        shift                                           # Throw away the first argument (currently $1)
        sudo $*                                         # Run whatever command we were passed ($* is shorthand for all arguments)
    else
        # Normal command
        $*                                              # Run whatever command we were passed ($* is shorthand for all arguments)
    fi

    # Check the return code for the command and pick red/green levels ($? holds the last returned error code)
    result=$?
    if [ $result -eq 0 ]; then
        # No error this time
        if [ $red -eq 0 ]; then
            # No errors since the last reset, set green
            green="2"
            red="0"
        else
            # We have had both a success this time and an error previously, set orange
            green="1"
            red="2"
        fi
    else
        # We have had an error, set red
        green="0"
        red="2"
    fi

    # Set final state
    blue="0"                                        # Change blue indicator to say we are finished
    echo "${red}${green}${blue}" > /dev/ledborg     # Write the colour string to the LedBorg device
fi

exit $result                                        # Return the same error code we received to whoever called us
Subscribe to Comments for "Ludo - visual error display for your Raspberry Pi"