Tobias Simetsreiter преди 4 години
родител
ревизия
14453a8182
променени са 9 файла, в които са добавени 103 реда и са изтрити 81 реда
  1. 0 1
      .gitignore
  2. 3 0
      .gitmodules
  3. 22 23
      Makefile
  4. 0 57
      bin/nametag.py
  5. 19 0
      bin/simpi.py
  6. 2 0
      config.mk.j2
  7. 14 0
      simpilib/__init__.py
  8. 42 0
      simpilib/cli.py
  9. 1 0
      sub/wavesharelib

+ 0 - 1
.gitignore

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

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "sub/wavesharelib"]
+	path = sub/wavesharelib
+	url = http://git.tsimnet.eu/upstreams/wavesharelib.git

+ 22 - 23
Makefile

@@ -1,25 +1,27 @@
 
 include config.mk
 
-test:
-	python3 test.py
+RASPI_REMOTE?=${RASPI_USER}@${RASPI_IP}
 
-deply: bcmlib wiringpi pythonlib
+run:
+	ssh pi@${RASPI_IP} "cd ${DEPLOY_DIR};./bin/simpi.py ${ARGS}"
 
-update: wavesharelib
-	rsync -ai Makefile bin/ pi@${RASPI_IP}:raspi-zero-waveshare/Makefile
-	rsync -ai --delete bin/ pi@${RASPI_IP}:raspi-zero-waveshare/bin/
-	rsync -ai --delete simpilib/ pi@${RASPI_IP}:raspi-zero-waveshare/simpilib/
-	rsync -ai --delete wavesharelib/RaspberryPi\&JetsonNano/python/ pi@${RASPI_IP}:raspi-zero-waveshare/wavesharelib/
+rerun: update run
 
-run/%:
-	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;./bin/${*}.py ${ARGS}"
+deploy: bcmlib wiringpi pythonlib
+
+update:
+	ssh ${RASPI_REMOTE} mkdir -p ${DEPLOY_DIR}/sub/
+	rsync -ai Makefile config.mk simpilib bin ${RASPI_REMOTE}:${DEPLOY_DIR}/
+	rsync -ai --delete sub/wavesharelib/RaspberryPi\&JetsonNano/python/ ${RASPI_REMOTE}:${DEPLOY_DIR}/wavesharelib/
+
+install_ssh: update remote/deploy
 
 ssh/%:
-	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;${*}"
+	ssh ${RASPI_REMOTE} "cd raspi-zero-waveshare;${*}"
 
 remote/%:
-	ssh pi@${RASPI_IP} "cd raspi-zero-waveshare;$(MAKE) ${*}"
+	ssh ${RASPI_REMOTE} "cd raspi-zero-waveshare;$(MAKE) ${*}"
 
 bcmlib:
 	wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
@@ -46,14 +48,11 @@ pythonlib:
 	sudo apt-get install python3-pip python3-pil python3-numpy
 	sudo pip3 install RPi.GPIO spidev
 
-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
-
+# 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
+# 

+ 0 - 57
bin/nametag.py

@@ -1,57 +0,0 @@
-#!/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__))))
-picdir = os.path.join(pydir, "wavesharelib",'pic')
-libdirs = [
-    os.path.join(pydir),
-    os.path.join(pydir, 'wavesharelib','lib'),
-]
-for d in libdirs:
-    if os.path.exists(d):
-        sys.path.append(d)
-
-import logging
-from waveshare_epd import epd2in13_V2
-import time
-from PIL import Image,ImageDraw
-from simpilib import wrapText,loadFontSize
-
-
-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)
-
-try:
-    import requests
-    import json
-    import random
-    r = requests.get('https://type.fit/api/quotes')
-    r = r.json()
-    r = random.choices(r)[0]
-    text = r["text"] + " - " + r["author"]
-except Exception as ex:
-    text = str(ex)
-
-fontpath = os.path.join(picdir, 'Font.ttc')
-
-text, longline = wrapText(text)
-font = loadFontSize(text, draw, image, fontpath)
-
-w, h = draw.textsize(text, font=font)
-center = (
-    int((epd.height-w)/2),
-    int((epd.width-h)/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.display(epd.getbuffer(image))
-epd.sleep()
-epd.Dev_exit()

+ 19 - 0
bin/simpi.py

@@ -0,0 +1,19 @@
+#!/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__))))
+
+libdirs = [
+    os.path.join(pydir),
+    os.path.join(pydir,'wavesharelib','lib'),
+]
+
+for d in libdirs:
+    if os.path.exists(d):
+        sys.path.append(d)
+
+from simpilib.cli import main
+
+if __name__ == "__main__":
+    main()

+ 2 - 0
config.mk.j2

@@ -1,2 +1,4 @@
 
 RASPI_IP?={{ RASPI_IP }}
+RASPI_USER?={{ RASPI_USER }}
+DEPLOY_DIR?={{ DEPLOY_DIR }}

+ 14 - 0
simpilib/__init__.py

@@ -42,3 +42,17 @@ def getLongLine(split):
         if len(l) > len(longline):
             longline = l
     return longline
+
+
+def getQuote():
+    try:
+        import requests
+        # r = requests.get('https://type.fit/api/quotes')
+        r = requests.get('http://api.quotable.io/random?maxLength=200')
+        r = r.json()
+        text = r["content"] + " - " + r["author"]
+
+    except Exception as ex:
+        text = str(ex)
+
+    return text

+ 42 - 0
simpilib/cli.py

@@ -0,0 +1,42 @@
+
+def main():
+    import logging
+    from waveshare_epd import epd2in13_V2
+    import time
+    from PIL import Image,ImageDraw
+
+    import os
+    fontpath = os.path.realpath(os.path.join(__file__,"..","..","wavesharelib","pic", 'Font.ttc'))
+
+    import simpilib
+
+    text = simpilib.getQuote()
+
+    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, longline = simpilib.wrapText(text)
+    font = simpilib.loadFontSize(text, draw, image, fontpath)
+
+    w, h = draw.textsize(text, font=font)
+    center = (
+        int((epd.height-w)/2),
+        int((epd.width-h)/2)
+    )
+
+    print("Drawing:", (w, h), (epd.height, epd.width))
+    draw.text(center, text, align="center", font = font, fill = 0)
+
+    # epd.display(epd.getbuffer(image.rotate(180)))
+    epd.display(epd.getbuffer(image))
+    epd.sleep()
+    epd.Dev_exit()
+
+def parser():
+    from argparse import ArgumentParser
+    p = ArgumentParser()
+    return p

+ 1 - 0
sub/wavesharelib

@@ -0,0 +1 @@
+Subproject commit 2fe12e1a175fc9f183e888fac09dc753d21c924f