epd_2in13g_test.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. import os
  5. picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
  6. libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
  7. if os.path.exists(libdir):
  8. sys.path.append(libdir)
  9. import logging
  10. from waveshare_epd import epd2in13g
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd2in13g Demo")
  17. epd = epd2in13g.EPD()
  18. logging.info("init and Clear")
  19. epd.init()
  20. epd.Clear()
  21. font15 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15)
  22. font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
  23. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  24. font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
  25. # Drawing on the image
  26. logging.info("1.Drawing on the image...")
  27. Himage = Image.new('RGB', (epd.height, epd.width), epd.WHITE)
  28. draw = ImageDraw.Draw(Himage)
  29. draw.rectangle([(0,0),(50,50)],outline = epd.BLACK)
  30. draw.rectangle([(55,0),(100,50)],fill = epd.RED)
  31. draw.line([(0,0),(50,50)], fill = epd.YELLOW,width = 1)
  32. draw.line([(0,50),(50,0)], fill = epd.YELLOW,width = 1)
  33. draw.pieslice((55, 60, 95, 100), 90, 180, outline = epd.RED)
  34. draw.pieslice((55, 60, 95, 100), 270, 360, fill = epd.BLACK)
  35. draw.chord((10, 60, 50, 100), 0, 360, fill = epd.YELLOW)
  36. draw.ellipse((55, 60, 95, 100), outline = epd.RED)
  37. draw.polygon([(110,0),(110,50),(150,25)],outline = epd.BLACK)
  38. draw.polygon([(190,0),(190,50),(150,25)],fill = epd.BLACK)
  39. draw.text((120, 60), 'e-Paper demo', font = font15, fill = epd.YELLOW)
  40. draw.text((110, 90), u'微雪电子', font = font24, fill = epd.RED)
  41. epd.display(epd.getbuffer(Himage))
  42. time.sleep(3)
  43. # read bmp file
  44. logging.info("2.read bmp file")
  45. Himage = Image.open(os.path.join(picdir, '2in13g.bmp'))
  46. epd.display(epd.getbuffer(Himage))
  47. time.sleep(3)
  48. logging.info("Clear...")
  49. epd.Clear()
  50. logging.info("Goto Sleep...")
  51. epd.sleep()
  52. except IOError as e:
  53. logging.info(e)
  54. except KeyboardInterrupt:
  55. logging.info("ctrl + c:")
  56. epd2in13g.epdconfig.module_exit(cleanup=True)
  57. exit()