radxa / rockpi-penta

Penta SATA HAT
MIT License
5 stars 5 forks source link

Suggestion: Use Terminus TTF font by default #8

Open boltronics opened 1 week ago

boltronics commented 1 week ago

Terminus TTF can easily be dropped into the project. It is very clean at size 12, and can be fetched here. It looks much nicer to my eyes over the ones that are included.

20241114_013524-cropped

boltronics commented 1 week ago

The above was done by editing oled.py as follows:

# ...

font = {
    # ...
    '12': ImageFont.truetype('fonts/TerminusMono-Bold.ttf', 12),
    # ...
}

# ...

def gen_pages(pages):
    if pages == None:
        pages = [0, 1, 2]
    result = {}
    if 0 in pages:
        result[0] = [
            {'xy': (0, -2), 'text': misc.get_info('cpu'), 'fill': 255, 'font': font['12']},
            {'xy': (0, 10), 'text': misc.get_info('men'), 'fill': 255, 'font': font['12']},
            {'xy': (0, 21), 'text': misc.get_info('ip'), 'fill': 255, 'font': font['12']},
        ]
    # ...

# ...

using my branch from here.

I also made minor adjustments to the commands in misc.py to get the text nicely aligned and consistent:

# ...

cmds = {
    'blk': "lsblk | awk '{print $1}'",
    'up': "echo Uptime: `uptime | sed 's/.*up \\([^,]*\\), .*/\\1/'`",
    'temp': "cat /sys/class/thermal/thermal_zone0/temp",
    'ip': "hostname -I | awk '{printf \"IP:  %s\", $1}'",
    'cpu': "uptime | awk '{printf \"CPU: %.2f\", $(NF-2)}'",
    'men': "free -m | awk 'NR==2{printf \"RAM: %s/%sMB\", $3,$2}'",
    'disk': "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'"
}

# ...