import epd2in7b

import Image

import ImageFont

import ImageDraw

import time

import RPi.GPIO as GPIO

import subprocess

 

epd = epd2in7b.EPD()

epd.init()

 

COLORED = 1

UNCOLORED = 0

 

GPIO.setmode(GPIO.BCM)

 

knop1 = 5

knop2 = 6

knop3 = 13

knop4 = 19

 

knoppen = [knop1, knop2, knop3, knop4]

 

GPIO.setup(knoppen, GPIO.IN, pull_up_down=GPIO.PUD_UP)

 

def knop1_ingedrukt(pin):

    toonTekstZwart(subprocess.check_output([“date”, “+%H:%M:%S”]))

    print(‘knop 1’)

 

def knop2_ingedrukt(pin):

    toonTekstZwart(subprocess.check_output([“hostname”, “-I”]))

    print(‘knop 2’)

 

def knop3_ingedrukt(pin):

    toonTekstZwart(subprocess.check_output([“curl”, “ipinfo.io/ip”]))

    print(‘knop 3’)

 

def knop4_ingedrukt(pin):

    toonTekstZwart(subprocess.check_output([“uptime”, “-p”]))

    print(‘knop 4’)

 

GPIO.add_event_detect(knop1, GPIO.FALLING, callback=knop1_ingedrukt, bouncetime=200)

GPIO.add_event_detect(knop2, GPIO.FALLING, callback=knop2_ingedrukt, bouncetime=200)

GPIO.add_event_detect(knop3, GPIO.FALLING, callback=knop3_ingedrukt, bouncetime=200)

GPIO.add_event_detect(knop4, GPIO.FALLING, callback=knop4_ingedrukt, bouncetime=200)

 

def toonTekstZwart(tekst):

    frame_black = [0] * (epd.width * epd.height / 8)

    frame_red = [0] * (epd.width * epd.height / 8)

 

    font = ImageFont.truetype(‘/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf’, 18)

    epd.draw_string_at(frame_black, 4, 80, tekst, font, COLORED)

    epd.display_frame(frame_black, frame_red)

 

def toonTekstRood(tekst):

    frame_black = [0] * (epd.width * epd.height / 8)

    frame_red = [0] * (epd.width * epd.height / 8)

 

    font = ImageFont.truetype(‘/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf’, 18)

    epd.draw_string_at(frame_red, 4, 80, tekst, font, COLORED)

    epd.display_frame(frame_black, frame_red)

 

def main():

    epd.set_rotate(epd2in7b.ROTATE_270)

    toonTekstRood(‘Info’)

    while True:

        time.sleep(0.01)

 

if __name__ == ‘__main__’:

    main()