epd_7in3e_test.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 epd7in3e
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd7in3f Demo")
  17. epd = epd7in3e.EPD()
  18. logging.info("init and Clear")
  19. epd.init()
  20. epd.Clear()
  21. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  22. font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
  23. font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
  24. # Drawing on the image
  25. logging.info("1.Drawing on the image...")
  26. Himage = Image.new('RGB', (epd.width, epd.height), epd.WHITE) # 255: clear the frame
  27. draw = ImageDraw.Draw(Himage)
  28. draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
  29. draw.text((5, 20), '7.3inch e-Paper (e)', font = font24, fill = epd.YELLOW)
  30. draw.text((5, 45), u'微雪电子', font = font40, fill = epd.GREEN)
  31. draw.text((5, 85), u'微雪电子', font = font40, fill = epd.BLUE)
  32. draw.text((5, 125), u'微雪电子', font = font40, fill = epd.BLACK)
  33. draw.line((5, 170, 80, 245), fill = epd.BLUE)
  34. draw.line((80, 170, 5, 245), fill = epd.YELLOW)
  35. draw.rectangle((5, 170, 80, 245), outline = epd.BLACK)
  36. draw.rectangle((90, 170, 165, 245), fill = epd.GREEN)
  37. draw.arc((5, 250, 80, 325), 0, 360, fill = epd.RED)
  38. draw.chord((90, 250, 165, 325), 0, 360, fill = epd.YELLOW)
  39. epd.display(epd.getbuffer(Himage))
  40. time.sleep(3)
  41. # read bmp file
  42. logging.info("2.read bmp file")
  43. Himage = Image.open(os.path.join(picdir, '7in3e.bmp'))
  44. epd.display(epd.getbuffer(Himage))
  45. time.sleep(3)
  46. logging.info("Clear...")
  47. epd.Clear()
  48. logging.info("Goto Sleep...")
  49. epd.sleep()
  50. except IOError as e:
  51. logging.info(e)
  52. except KeyboardInterrupt:
  53. logging.info("ctrl + c:")
  54. epd7in3e.epdconfig.module_exit(cleanup=True)
  55. exit()