epd_5in79g_test.py 2.3 KB

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