Archived
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
#! /usr/bin/python3
|
|
# -*- coding: utf8 -*-
|
|
|
|
# load needed modules from luma
|
|
from luma.core.interface.serial import i2c, spi
|
|
from luma.core.render import canvas
|
|
from luma.oled.device import sh1106
|
|
from luma.core import lib
|
|
from luma.core.virtual import terminal
|
|
|
|
# load needed modules from RPi.GPIO
|
|
import RPi.GPIO as GPIO
|
|
|
|
# load needed modules from PIL
|
|
from PIL import ImageFont, ImageDraw, Image
|
|
|
|
# load more needed modules
|
|
import time
|
|
import sys
|
|
|
|
# load randommodules
|
|
#from random import randint, gauss
|
|
from pathlib import Path
|
|
import pyudev
|
|
|
|
|
|
#GPIO define pins
|
|
RST_PIN = 25 #Reset
|
|
CS_PIN = 8
|
|
DC_PIN = 24
|
|
|
|
serial = spi(device=0, port=0, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC_PIN, gpio_RST = RST_PIN)
|
|
device_used = sh1106(serial, rotate=2) #sh1106
|
|
|
|
context = pyudev.Context()
|
|
|
|
def main():
|
|
while True:
|
|
|
|
term = terminal(device_used, ImageFont.truetype(None, None))
|
|
monitor = pyudev.Monitor.from_netlink(context)
|
|
monitor.filter_by('block')
|
|
for device in iter(monitor.poll, None):
|
|
if 'ID_FS_TYPE' in device:
|
|
term.println('{0} partition {1}'.format(device.action, device.get('ID_FS_LABEL')))
|
|
time.sleep(5)
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
GPIO.cleanup() |