2
0

epd_5in83_test.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 epd5in83
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd5in83 Demo")
  17. epd = epd5in83.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. # Drawing on the Horizontal image
  24. logging.info("1.Drawing on the Horizontal image...")
  25. Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  26. draw = ImageDraw.Draw(Himage)
  27. draw.text((10, 0), 'hello world', font = font24, fill = 0)
  28. draw.text((10, 20), '5.83inch e-Paper', font = font24, fill = 0)
  29. draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
  30. draw.line((20, 50, 70, 100), fill = 0)
  31. draw.line((70, 50, 20, 100), fill = 0)
  32. draw.rectangle((20, 50, 70, 100), outline = 0)
  33. draw.line((165, 50, 165, 100), fill = 0)
  34. draw.line((140, 75, 190, 75), fill = 0)
  35. draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
  36. draw.rectangle((80, 50, 130, 100), fill = 0)
  37. draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
  38. epd.display(epd.getbuffer(Himage))
  39. time.sleep(2)
  40. # Drawing on the Vertical image
  41. logging.info("2.Drawing on the Vertical image...")
  42. Limage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  43. draw = ImageDraw.Draw(Limage)
  44. draw.text((2, 0), 'hello world', font = font18, fill = 0)
  45. draw.text((2, 20), '5.83inch epd', font = font18, fill = 0)
  46. draw.text((20, 50), u'微雪电子', font = font18, fill = 0)
  47. draw.line((10, 90, 60, 140), fill = 0)
  48. draw.line((60, 90, 10, 140), fill = 0)
  49. draw.rectangle((10, 90, 60, 140), outline = 0)
  50. draw.line((95, 90, 95, 140), fill = 0)
  51. draw.line((70, 115, 120, 115), fill = 0)
  52. draw.arc((70, 90, 120, 140), 0, 360, fill = 0)
  53. draw.rectangle((10, 150, 60, 200), fill = 0)
  54. draw.chord((70, 150, 120, 200), 0, 360, fill = 0)
  55. epd.display(epd.getbuffer(Limage))
  56. time.sleep(2)
  57. logging.info("3.read bmp file")
  58. Himage = Image.open(os.path.join(picdir, '5in83.bmp'))
  59. epd.display(epd.getbuffer(Himage))
  60. time.sleep(2)
  61. logging.info("4.read bmp file on window")
  62. Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  63. bmp = Image.open(os.path.join(picdir, '100x100.bmp'))
  64. Himage2.paste(bmp, (50,10))
  65. epd.display(epd.getbuffer(Himage2))
  66. time.sleep(2)
  67. logging.info("Clear...")
  68. epd.init()
  69. epd.Clear()
  70. logging.info("Goto Sleep...")
  71. epd.sleep()
  72. except IOError as e:
  73. logging.info(e)
  74. except KeyboardInterrupt:
  75. logging.info("ctrl + c:")
  76. epd5in83.epdconfig.module_exit(cleanup=True)
  77. exit()