2
0

epd_2in36g_test.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 epd2in36g
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd2in36g Demo")
  17. epd = epd2in36g.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.36inch e-Paper', font = font18, fill = epd.YELLOW)
  30. draw.text((5, 40), u'微雪电子', font = font40, fill = epd.BLACK)
  31. draw.text((5, 85), u'微雪电子', font = font40, fill = epd.YELLOW)
  32. draw.text((5, 125), u'微雪电子', font = font40, fill = epd.RED)
  33. draw.line((5, 175, 45, 245), fill = epd.RED)
  34. draw.line((45, 175, 5, 245), fill = epd.YELLOW)
  35. draw.rectangle((5, 175, 45, 245), outline = epd.BLACK)
  36. draw.rectangle((55, 175, 95, 245), fill = epd.BLACK)
  37. draw.arc((115, 175, 150, 210), 0, 360, fill = epd.BLACK)
  38. draw.chord((115, 215, 150, 250), 0, 360, fill = epd.BLACK)
  39. draw.chord((10, 252, 50, 295), 0, 360, fill = epd.YELLOW)
  40. draw.chord((110, 252, 150, 295), 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, '2.36inch-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, '2.36inch-2.bmp'))
  50. epd.display(epd.getbuffer(Himage))
  51. time.sleep(3)
  52. logging.info("Clear...")
  53. epd.Clear()
  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. epd2in36g.epdconfig.module_exit(cleanup=True)
  61. exit()