epd_1in64g_test.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 epd1in64g
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd1in64g Demo")
  17. epd = epd1in64g.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. # # The Sunrise X3 PI is a bit problematic to use
  25. # # Drawing on the image
  26. # logging.info("1.Drawing on the image...")
  27. # Himage = Image.new('RGB', (epd.width, epd.height), epd.WHITE)
  28. # draw = ImageDraw.Draw(Himage)
  29. # draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
  30. # draw.text((5, 20), '1.64inch e-Paper', font = font18, fill = epd.YELLOW)
  31. # draw.text((5, 40), u'微雪电子', font = font40, fill = epd.BLACK)
  32. # draw.line((5, 90, 45, 160), fill = epd.RED)
  33. # draw.line((45, 90, 5, 160), fill = epd.YELLOW)
  34. # draw.rectangle((5, 90, 45, 160), outline = epd.BLACK)
  35. # draw.rectangle((55, 90, 95, 160), fill = epd.BLACK)
  36. # draw.arc((115, 90, 150, 125), 0, 360, fill = epd.BLACK)
  37. # draw.chord((115, 130, 150, 165), 0, 360, fill = epd.BLACK)
  38. # epd.display(epd.getbuffer(Himage))
  39. # time.sleep(3)
  40. # # read bmp file
  41. # logging.info("2.read bmp file")
  42. # Himage = Image.open(os.path.join(picdir, '1.64inch-1.bmp'))
  43. # epd.display(epd.getbuffer(Himage))
  44. # time.sleep(3)
  45. logging.info("3.read bmp file")
  46. Himage = Image.open(os.path.join(picdir, '1.64inch-2.bmp'))
  47. epd.display(epd.getbuffer(Himage))
  48. time.sleep(3)
  49. logging.info("Clear...")
  50. epd.Clear()
  51. logging.info("Goto Sleep...")
  52. epd.sleep()
  53. except IOError as e:
  54. logging.info(e)
  55. except KeyboardInterrupt:
  56. logging.info("ctrl + c:")
  57. epd1in64g.epdconfig.module_exit()
  58. exit()