epd_7in3f_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 epd7in3f
  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 = epd7in3f.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 (F)', 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.ORANGE)
  33. draw.line((5, 170, 80, 245), fill = epd.BLUE)
  34. draw.line((80, 170, 5, 245), fill = epd.ORANGE)
  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, '7in3f1.bmp'))
  44. epd.display(epd.getbuffer(Himage))
  45. time.sleep(3)
  46. logging.info("3.read bmp file")
  47. Himage = Image.open(os.path.join(picdir, '7in3f3.bmp'))
  48. epd.display(epd.getbuffer(Himage))
  49. time.sleep(3)
  50. logging.info("Clear...")
  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. epd7in3f.epdconfig.module_exit(cleanup=True)
  59. exit()