Tobias Simetsreiter 4 vuotta sitten
vanhempi
sitoutus
6973a7846e
4 muutettua tiedostoa jossa 129 lisäystä ja 5 poistoa
  1. 1 0
      .gitignore
  2. 20 5
      Makefile
  3. 41 0
      bin/nametag.py
  4. 67 0
      bin/test.py

+ 1 - 0
.gitignore

@@ -58,3 +58,4 @@ docs/_build/
 # PyBuilder
 target/
 config.mk
+wavesharelib

+ 20 - 5
Makefile

@@ -1,10 +1,20 @@
 
 include config.mk
 
-all: bcmlib wiringpi pythonlib
+test:
+	python3 test.py
 
-update:
-	rsync -ai ./ pi@${RASPI_IP}:raspi-zero-waveshare/
+deply: bcmlib wiringpi pythonlib
+
+update: wavesharelib
+	rsync -ai bin Makefile pi@${RASPI_IP}:raspi-zero-waveshare/
+	rsync -ai wavesharelib/RaspberryPi\&JetsonNano/python/ pi@${RASPI_IP}:raspi-zero-waveshare/lib/
+
+run/%:
+	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;./bin/${*}.py ${ARGS}"
+
+ssh/%:
+	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;${*}"
 
 remote/%:
 	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;$(MAKE) ${*}"
@@ -34,8 +44,13 @@ pythonlib:
 	sudo apt-get install python3-pip python3-pil python3-numpy
 	sudo pip3 install RPi.GPIO spidev
 
-demo:
-	sudo git clone https://github.com/waveshare/e-Paper
+wavesharelib:
+	git clone https://github.com/waveshare/e-Paper wavesharelib
+
+demo-py/%:
+	cd e-Paper/RaspberryPi\&JetsonNano/python/examples && sudo python3 ${*}
+
+demo-c:
 	$(MAKE) -C e-Paper/RaspberryPi\&JetsonNano/c/ clean
 	$(MAKE) -C e-Paper/RaspberryPi\&JetsonNano/c/
 	cd e-Paper/RaspberryPi\&JetsonNano/c/ && ./epd

+ 41 - 0
bin/nametag.py

@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+import sys
+import os
+pydir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
+picdir = os.path.join(pydir, 'pic')
+libdir = os.path.join(pydir, 'lib')
+print(picdir)
+print(libdir)
+if os.path.exists(libdir):
+    sys.path.append(libdir)
+
+import logging
+from waveshare_epd import epd2in13_V2
+import time
+from PIL import Image,ImageDraw,ImageFont
+from PIL.ImageOps import invert
+
+font = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), int(sys.argv[1]))
+
+epd = epd2in13_V2.EPD()
+logging.info("init and Clear")
+epd.init(epd.FULL_UPDATE)
+epd.Clear(0xFF)
+image = Image.new('1', (epd.height, epd.width), 255)
+draw = ImageDraw.Draw(image)
+
+text = "\n".join(sys.argv[2:])
+
+h, w = draw.textsize(text, font=font)
+center = (
+    int((epd.height-h)/2),
+    int((epd.width-w)/2)
+)
+
+print(center, (w, h), (epd.width, epd.height))
+draw.text(center, text, align="center", font = font, fill = 0)
+
+epd.display(epd.getbuffer(image.rotate(180)))
+epd.sleep()
+epd.Dev_exit()

+ 67 - 0
bin/test.py

@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+import sys
+import os
+pydir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
+picdir = os.path.join(pydir, 'pic')
+libdir = os.path.join(pydir, 'lib')
+if os.path.exists(libdir):
+    sys.path.append(libdir)
+
+import logging
+from waveshare_epd import epd2in13_V2
+import time
+from PIL import Image,ImageDraw,ImageFont 
+from PIL.ImageOps import invert
+
+import traceback
+
+logging.basicConfig(level=logging.DEBUG)
+
+try:
+    logging.info("epd2in13_V2 Demo")
+
+    font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
+
+    epd = epd2in13_V2.EPD()
+    logging.info("init and Clear")
+    epd.init(epd.FULL_UPDATE)
+    epd.Clear(0xFF)
+
+    # read bmp file 
+    logging.info("2.read bmp file...")
+    image = Image.open(os.path.join(picdir, '2in13.bmp'))
+    draw = ImageDraw.Draw(image)
+    epd.displayPartBaseImage(epd.getbuffer(image))
+
+    time.sleep(2)
+    logging.info("4.show time...")
+    image = Image.new('1', (epd.height, epd.width), 255)
+    draw = ImageDraw.Draw(image)
+
+    epd.init(epd.FULL_UPDATE)
+    epd.displayPartBaseImage(epd.getbuffer(image))
+
+    epd.init(epd.PART_UPDATE)
+    draw.text((120, 60), " ".join(sys.argv[1:]), font = font24, fill = 0)
+    num = 0
+    while (True):
+        draw.rectangle((120, 80, 220, 105), fill = 255)
+        draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
+        epd.displayPartial(epd.getbuffer(image.rotate(180)))
+        num = num + 1
+        if(num == 10):
+            break
+
+    time.sleep(2)
+    logging.info("Goto Sleep...")
+    epd.sleep()
+    epd.Dev_exit()
+
+except IOError as e:
+    logging.info(e)
+
+except KeyboardInterrupt:
+    logging.info("ctrl + c:")
+    epd2in13_V2.epdconfig.module_exit()
+    exit()