epd_2in13b_V4_test.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 epd2in13b_V4
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd2in13b_V4 Demo")
  17. epd = epd2in13b_V4.EPD()
  18. logging.info("init and Clear")
  19. epd.init()
  20. epd.Clear()
  21. time.sleep(1)
  22. # Drawing on the image
  23. logging.info("Drawing")
  24. font20 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20)
  25. font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
  26. # Drawing on the Horizontal image
  27. logging.info("1.Drawing on the Horizontal image...")
  28. HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 250*122
  29. HRYimage = Image.new('1', (epd.height, epd.width), 255) # 250*122
  30. drawblack = ImageDraw.Draw(HBlackimage)
  31. drawry = ImageDraw.Draw(HRYimage)
  32. drawblack.text((10, 0), 'hello world', font = font20, fill = 0)
  33. drawblack.text((10, 20), '2.13inch e-Paper b V4', font = font20, fill = 0)
  34. drawblack.text((120, 0), u'微雪电子', font = font20, fill = 0)
  35. drawblack.line((20, 50, 70, 100), fill = 0)
  36. drawblack.line((70, 50, 20, 100), fill = 0)
  37. drawblack.rectangle((20, 50, 70, 100), outline = 0)
  38. drawry.line((165, 50, 165, 100), fill = 0)
  39. drawry.line((140, 75, 190, 75), fill = 0)
  40. drawry.arc((140, 50, 190, 100), 0, 360, fill = 0)
  41. drawry.rectangle((80, 50, 130, 100), fill = 0)
  42. drawry.chord((85, 55, 125, 95), 0, 360, fill =1)
  43. epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage))
  44. time.sleep(2)
  45. # Drawing on the Vertical image
  46. logging.info("2.Drawing on the Vertical image...")
  47. LBlackimage = Image.new('1', (epd.width, epd.height), 255) # 122*250
  48. LRYimage = Image.new('1', (epd.width, epd.height), 255) # 122*250
  49. drawblack = ImageDraw.Draw(LBlackimage)
  50. drawry = ImageDraw.Draw(LRYimage)
  51. drawblack.text((2, 0), 'hello world', font = font18, fill = 0)
  52. drawblack.text((2, 20), '2.13 epd b V4', font = font18, fill = 0)
  53. drawblack.text((20, 50), u'微雪电子', font = font18, fill = 0)
  54. drawblack.line((10, 90, 60, 140), fill = 0)
  55. drawblack.line((60, 90, 10, 140), fill = 0)
  56. drawblack.rectangle((10, 90, 60, 140), outline = 0)
  57. drawry.rectangle((10, 150, 60, 200), fill = 0)
  58. drawry.arc((15, 95, 55, 135), 0, 360, fill = 0)
  59. drawry.chord((15, 155, 55, 195), 0, 360, fill =1)
  60. epd.display(epd.getbuffer(LBlackimage), epd.getbuffer(LRYimage))
  61. time.sleep(2)
  62. logging.info("3.read bmp file")
  63. Blackimage = Image.open(os.path.join(picdir, '2in13b_V4b.bmp'))
  64. RYimage = Image.open(os.path.join(picdir, '2in13b_V4b.bmp'))
  65. epd.display(epd.getbuffer(Blackimage), epd.getbuffer(RYimage))
  66. time.sleep(2)
  67. logging.info("4.read bmp file on window")
  68. blackimage1 = Image.new('1', (epd.height, epd.width), 255) # 250*122
  69. redimage1 = Image.new('1', (epd.height, epd.width), 255) # 250*122
  70. newimage = Image.open(os.path.join(picdir, '100x100.bmp'))
  71. blackimage1.paste(newimage, (0,0))
  72. epd.display(epd.getbuffer(blackimage1), epd.getbuffer(redimage1))
  73. logging.info("Clear...")
  74. epd.init()
  75. epd.clear()
  76. logging.info("Goto Sleep...")
  77. epd.sleep()
  78. except IOError as e:
  79. logging.info(e)
  80. except KeyboardInterrupt:
  81. logging.info("ctrl + c:")
  82. epd2in13b_V4.epdconfig.module_exit(cleanup=True)
  83. exit()