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