Nokia5110-LCD/Danielle_LCD.py

154 lines
3.2 KiB
Python

import time
import datetime
import spidev
import requests
import RPi.GPIO as GPIO
import commands
import glyph
from lcdlib import *
#functions
def position(x, y):
# maths the line number + other binary
GPIO.output(DC, False)
x = (x+128)
y = (y+64)
spi.writebytes([x, y])
GPIO.output(DC, True)
# display commands
def writeword(word):
GPIO.output(DC, True)
for x in word:
if x == " ":
spi.writebytes(glyph.SPACE)
else:
spi.writebytes(getattr(glyph, x))
def writedelay(word):
for x in word:
if x == " ":
spi.writebytes(glyph.SPACE)
else:
spi.writebytes(getattr(glyph, x))
time.sleep(0.3)
def clearscreen():
GPIO.output(DC, True)
x = 0
while x < (48*84):
spi.writebytes([0x00])
x+=1
def splash():
position(0,0)
spi.writebytes(glyph.SCREEN)
time.sleep(1.0)
#setup hw
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=400000
#gpio pin definitions
DC = 23
RST = 24
DIN = 19
SPI_PORT = 0
SPI_DEVICE = 0
#gpio setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(RST, GPIO.OUT)
GPIO.setup(DC, GPIO.OUT)
#LEDs
led1 = 12
led2 = 20
led3 = 16
led4 = 21
led5 = 26
button1 = 5 #green
button2 = 6 #red
button3 = 13 #up
button4 = 19 #down
screen = 18
GPIO.setup(led1, GPIO.OUT)
GPIO.setup(led2, GPIO.OUT)
GPIO.setup(led3, GPIO.OUT)
GPIO.setup(led4, GPIO.OUT)
GPIO.setup(led5, GPIO.OUT)
GPIO.setup(button1, GPIO.IN)
GPIO.setup(button2, GPIO.IN)
GPIO.setup(button3, GPIO.IN)
GPIO.setup(button4, GPIO.IN)
GPIO.setup(screen, GPIO.OUT)
GPIO.output(screen, False)
#pulse reset
GPIO.output(RST, False)
time.sleep(0.4)
GPIO.output(RST, True)
#DC low for commands
GPIO.output(DC, False)
spi.writebytes([0x21, 0xB8, 0x04, 0x14, 0x20, 0x09, 0x0C])
#transmit data
GPIO.output(DC, True)
splash()
clearscreen()
while True:
process_list = commands.getoutput('ps -A')
if 'nginx' in process_list:
GPIO.output(led1, True)
else:
GPIO.output(led1, False)
if 'smbd' in process_list:
GPIO.output(led2, True)
else:
GPIO.output(led2, False)
if 'murmurd' in process_list:
GPIO.output(led3, True)
else:
GPIO.output(led3, False)
if 'deluged' in process_list:
GPIO.output(led4, True)
else:
GPIO.output(led4, False)
position(5,0)
writeword("ironserver")
position(10,1)
writeword("nginx")
position(10,2)
writeword("samba")
position(10,3)
writeword("murmur")
position(10,4)
writeword("deluge")
position(10,5)
writeword("ipstv")
# check http
position(60,1)
if 'nginx' in process_list:
writeword("on")
spi.writebytes(glyph.SPACE)
else:
writeword("off")
# check nas
position(60,2)
if 'smbd' in process_list:
writeword("on")
spi.writebytes(glyph.SPACE)
else:
writeword("off")
#check VOIP
position(60,3)
if 'murmurd' in process_list:
writeword("on")
spi.writebytes(glyph.SPACE)
else:
writeword("off")
#check torrents
position(60,4)
if 'deluged' in process_list:
writeword("on")
spi.writebytes(glyph.SPACE)
else:
writeword("off")
spi.close()