2
0

epd_2in66g_test.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 epd2in66g
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd2in9g Demo")
  17. epd = epd2in66g.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)
  27. draw = ImageDraw.Draw(Himage)
  28. draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
  29. draw.text((5, 20), '2.66inch G', font = font18, fill = epd.YELLOW)
  30. draw.text((5, 50), u'微雪电子', font = font40, fill = epd.BLACK)
  31. draw.text((5, 100), u'微雪电子', font = font40, fill = epd.YELLOW)
  32. draw.text((5, 150), u'微雪电子', font = font40, fill = epd.RED)
  33. draw.rectangle((5, 200, 75, 270), outline = epd.BLACK)
  34. draw.line((5, 200, 75, 270), fill = epd.RED)
  35. draw.line((75, 200, 5, 270), fill = epd.YELLOW)
  36. draw.rectangle((90, 200, 160, 270), fill = epd.BLACK)
  37. draw.arc((5, 300, 45, 340), 0, 360, fill = epd.BLACK)
  38. draw.chord((45, 300, 85, 340), 0, 360, fill = epd.BLACK)
  39. draw.chord((85, 300, 125, 340), 0, 360, fill = epd.YELLOW)
  40. draw.chord((125, 300, 165, 340), 0, 360, 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, '2in66g.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. epd2in66g.epdconfig.module_exit(cleanup=True)
  57. exit()