diff --git a/README.md b/README.md index 0974222..5180a02 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,65 @@ -# sys-oled -Script to display Helios4 system status for i2c OLED screen. +# Description +Application to display Helios4 system status for i2c OLED screen. -![system starting](capture/luma_000001.png) -![system status](capture/luma_000002.png) -![system time](capture/luma_000003.png) +![system status](capture/luma_000001.png) +![system time](capture/luma_000002.png) * Based on [luma.oled](https://github.com/rm-hull/luma.oled) -* Script inspired from [sys_info.py](https://github.com/rm-hull/luma.examples/blob/master/examples/sys_info.py) example +* Inspired from luma.oled [sys_info.py](https://github.com/rm-hull/luma.examples/blob/master/examples/sys_info.py) example -## TO DO -* How to install -* How to tweak/configure -* Add comment to code +## INSTALLATION + +``` +git clone https://github.com/helios-4/sys-oled.git +sudo ./install.sh +``` + +## CONFIGURATION + +### Configure OLED display model + +1. Test which display model is the correct one by launching manually **sys-oled** and trying different display model as parameter. +Example : + +``` +sudo sys-oled --display ssd1306 +sudo sys-oled --display sh1106 + +``` + +Supported values : ssd1306 (default), ssd1322, ssd1325, ssd1327, ssd1331, ssd1351, sh1106. + +2. Once you know which display model is the correct one, edit */etc/sys-oled.conf* and update the **DISPLAY=** line. + + +### Configure storage info + +For now **sys-oled** is a very crude python app that will require you to edit it directly in order to customize what you want to display. + +Edit **sys-oled** script and look for the *status()* function. + +``` +sudo nano /usr/local/bin/sys-oled +``` + +You can edit the following lines to define for which storage devices you want to display info. + +``` +d.text((0, 27), disk_usage('sd', '/'), font=font, fill="white") +d.text((0, 39), disk_usage('md0', '/mnt/md0'), font=font, fill="white") +``` + +In the above example, we are displaying **sd** (SDcard) usage which is the rootfs mounted on *'/'*. We are also displaying **md0** (RAID array) that is mounted on *'/mnt/mnd0'*. +The values *(0, 27)* and *(0, 39)* correspond to the X, Y positions of displayed texts. + +### Start the service + +The install script will automatically setup **sys-oled** to start at every startup. Now you can either restart your Helios4 or you can launch directly the service with the following command: + +``` +systemctl start sys-oled.service +``` + +## Note + +This sys-oled app was developed and tested only with the OLED model SH1106 which has a matrix panel of 132 x 64. If you use a different model that has a smaller resolution, you might need to tweak the coordinate values. diff --git a/sys_oled.py b/bin/sys-oled similarity index 87% rename from sys_oled.py rename to bin/sys-oled index 2746cd7..231c875 100755 --- a/sys_oled.py +++ b/bin/sys-oled @@ -13,7 +13,7 @@ from PIL import Image, ImageDraw, ImageFont interval = 4 font_path = os.path.abspath(os.path.join(os.path.dirname(__file__), - 'font', 'C&C Red Alert [INET].ttf')) + '../share/sys-oled', 'C&C Red Alert [INET].ttf')) font = ImageFont.truetype(font_path, 12) def get_device(actual_args=None): @@ -81,7 +81,7 @@ def status(device): d.line([(0,13),(128,13)]) d.text((0, 15), mem_usage(), font=font, fill="white") d.text((0, 27), disk_usage('sd', '/'), font=font, fill="white") - d.text((0, 39), disk_usage('md0', '/'), font=font, fill="white") + d.text((0, 39), disk_usage('md0', '/mnt/md0'), font=font, fill="white") d.text((0, 51), network('eth0'), font=font, fill="white") device.display(txt.convert(device.mode)) @@ -89,7 +89,7 @@ def status(device): def logo(device, msg): img_path = os.path.abspath(os.path.join(os.path.dirname(__file__), - 'img', 'helios4_logo.png')) + '../share/sys-oled', 'helios4_logo.png')) logo = Image.open(img_path).convert("RGBA") background = Image.new("RGBA", device.size) @@ -109,16 +109,11 @@ signal.signal(signal.SIGTERM, sigterm_handler) def main(): - if 'HELIOS4_STARTING' in os.environ: - logo(device, "System Starting...") - device.persist = True - time.sleep(6) - else: - while True: - status(device) - time.sleep(interval) - logo(device, host_time()) - time.sleep(interval) + while True: + status(device) + time.sleep(interval) + logo(device, host_time()) + time.sleep(interval) if __name__ == "__main__": try: diff --git a/capture/luma_000001.png b/capture/luma_000001.png index aef1e3c..3c3a9b3 100644 Binary files a/capture/luma_000001.png and b/capture/luma_000001.png differ diff --git a/capture/luma_000002.png b/capture/luma_000002.png index 6acc87d..65f600e 100644 Binary files a/capture/luma_000002.png and b/capture/luma_000002.png differ diff --git a/capture/luma_000003.png b/capture/luma_000003.png deleted file mode 100644 index 6e8fdf0..0000000 Binary files a/capture/luma_000003.png and /dev/null differ diff --git a/etc/sys-oled.conf b/etc/sys-oled.conf new file mode 100644 index 0000000..487aec0 --- /dev/null +++ b/etc/sys-oled.conf @@ -0,0 +1,3 @@ +# Define your OLED display model. +# Check luma.oled project to check supported displays. +DISPLAY=sh1106 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1257aaa --- /dev/null +++ b/install.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Install script for sys-oled + +INSTALL_PATH="/usr/local/" +SYSTEMD_PATH="/etc/systemd/" +DEPS="python-dev python-pip python-setuptools python-psutil libfreetype6-dev libjpeg-dev build-essential" + +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root!" + exit 1 +fi + +echo "Installing Dependencies" +apt-get update +apt-get install -y $DEPS + +echo "Installing luma.oled library" +pip install --upgrade luma.oled + +echo "Installing sys-oled files" +cp -frv bin "$INSTALL_PATH" +cp -frv etc "$INSTALL_PATH" +cp -frv share "$INSTALL_PATH" +cp -frv system "$SYSTEMD_PATH" + +echo "Enabling sys-oled at statup" +systemctl daemon-reload +systemctl enable sys-oled.service diff --git a/font/C&C Red Alert [INET].ttf b/share/sys-oled/C&C Red Alert [INET].ttf similarity index 100% rename from font/C&C Red Alert [INET].ttf rename to share/sys-oled/C&C Red Alert [INET].ttf diff --git a/img/helios4_logo.png b/share/sys-oled/helios4_logo.png similarity index 100% rename from img/helios4_logo.png rename to share/sys-oled/helios4_logo.png diff --git a/system/sys-oled.service b/system/sys-oled.service new file mode 100644 index 0000000..eab848d --- /dev/null +++ b/system/sys-oled.service @@ -0,0 +1,9 @@ +[Unit] +Description=System Starting on OLED Display + +[Service] +EnvironmentFile=/etc/sys-oled.conf +ExecStart=/usr/bin/python /usr/local/bin/sys-oled --display ${DISPLAY} + +[Install] +WantedBy=multi-user.target diff --git a/systemd/sys_oled_start.service b/systemd/sys_oled_start.service deleted file mode 100644 index 36f4f60..0000000 --- a/systemd/sys_oled_start.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=System Starting on OLED Display - -[Service] -Environment="SYSTEM_STARTING=1" -ExecStart=/usr/bin/python /usr/local/bin/sys_oled.py --display sh1106 - -[Install] -WantedBy=sysinit.target diff --git a/systemd/sys_oled_status.service b/systemd/sys_oled_status.service deleted file mode 100644 index dcafe3c..0000000 --- a/systemd/sys_oled_status.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=System Status on OLED Display -After=sys_oled_start.service - -[Service] -ExecStart=/usr/bin/python /usr/local/bin/sys_oled.py --display sh1106 - -[Install] -WantedBy=multi-user.target