epd_7in3g_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 epd7in3g
  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 = epd7in3g.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) # 255: clear the frame
  31. draw = ImageDraw.Draw(Himage)
  32. draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
  33. draw.text((5, 20), '7.3inch e-Paper', font = font24, fill = epd.YELLOW)
  34. draw.text((5, 45), u'微雪电子', font = font30, fill = epd.BLACK)
  35. draw.text((5, 85), u'微雪电子', font = font30, fill = epd.YELLOW)
  36. draw.text((5, 125), u'微雪电子', font = font30, fill = epd.RED)
  37. draw.line((5, 170, 80, 245), fill = epd.RED)
  38. draw.line((80, 170, 5, 245), fill = epd.YELLOW)
  39. draw.rectangle((5, 170, 80, 245), outline = epd.BLACK)
  40. draw.rectangle((90, 170, 165, 245), fill = epd.YELLOW)
  41. draw.arc((5, 250, 80, 325), 0, 360, fill = epd.BLACK)
  42. draw.chord((90, 250, 165, 325), 0, 360, fill = epd.RED)
  43. epd.display(epd.getbuffer(Himage))
  44. time.sleep(3)
  45. # read bmp file
  46. logging.info("3.read bmp file")
  47. Himage = Image.open(os.path.join(picdir, '7.3inch-1.bmp'))
  48. epd.display(epd.getbuffer(Himage))
  49. time.sleep(3)
  50. logging.info("3.read bmp file")
  51. Himage = Image.open(os.path.join(picdir, '7.3inch-2.bmp'))
  52. epd.display(epd.getbuffer(Himage))
  53. time.sleep(3)
  54. logging.info("3.read bmp file")
  55. Himage = Image.open(os.path.join(picdir, '7.3inch-3.bmp'))
  56. epd.display(epd.getbuffer(Himage))
  57. time.sleep(3)
  58. logging.info("Clear...")
  59. epd.Clear(WHITE)
  60. logging.info("Goto Sleep...")
  61. epd.sleep()
  62. except IOError as e:
  63. logging.info(e)
  64. except KeyboardInterrupt:
  65. logging.info("ctrl + c:")
  66. epd7in3g.epdconfig.module_exit()
  67. exit()