Merge pull request #2 from helios-4/dev
Rework, clean-up + install script
@@ -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.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
* 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.
|
||||
|
||||
@@ -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:
|
||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,3 @@
|
||||
# Define your OLED display model.
|
||||
# Check luma.oled project to check supported displays.
|
||||
DISPLAY=sh1106
|
||||
@@ -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
|
||||
|
Before Width: | Height: | Size: 716 B After Width: | Height: | Size: 716 B |
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||