epd_1in64g_test.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. BLACK = 0x00
  18. WHITE = 0x55
  19. YELLOW = 0xAA
  20. RED = 0xFF
  21. epd = epd1in64g.EPD()
  22. logging.info("init and Clear")
  23. epd.init()
  24. epd.Clear(WHITE)
  25. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  26. font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
  27. font30 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
  28. # Drawing on the image
  29. logging.info("1.Drawing on the image...")
  30. Himage = Image.new('RGB', (epd.width, epd.height), 0xffffff)
  31. draw = ImageDraw.Draw(Himage)
  32. draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
  33. draw.text((5, 20), '1.64inch e-Paper', font = font18, fill = epd.YELLOW)
  34. draw.text((5, 40), u'微雪电子', font = font30, fill = epd.BLACK)
  35. draw.line((5, 90, 45, 160), fill = epd.RED)
  36. draw.line((45, 90, 5, 160), fill = epd.YELLOW)
  37. draw.rectangle((5, 90, 45, 160), outline = epd.BLACK)
  38. draw.rectangle((55, 90, 95, 160), fill = epd.BLACK)
  39. draw.arc((115, 90, 150, 125), 0, 360, fill = epd.BLACK)
  40. draw.chord((115, 130, 150, 165), 0, 360, fill = epd.BLACK)
  41. epd.display(epd.getbuffer(Himage))
  42. time.sleep(3)
  43. # read bmp file
  44. logging.info("3.read bmp file")
  45. Himage = Image.open(os.path.join(picdir, '1.64inch-1.bmp'))
  46. epd.display(epd.getbuffer(Himage))
  47. time.sleep(3)
  48. logging.info("3.read bmp file")
  49. Himage = Image.open(os.path.join(picdir, '1.64inch-2.bmp'))
  50. epd.display(epd.getbuffer(Himage))
  51. time.sleep(3)
  52. logging.info("Clear...")
  53. epd.Clear(WHITE)
  54. logging.info("Goto Sleep...")
  55. epd.sleep()
  56. except IOError as e:
  57. logging.info(e)
  58. except KeyboardInterrupt:
  59. logging.info("ctrl + c:")
  60. epd1in64g.epdconfig.module_exit()
  61. exit()