epd_5in83b_V2_test.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 epd5in83b_V2
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd5in83b_V2 Demo")
  17. epd = epd5in83b_V2.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. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  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.width, epd.height), 255) # 648*480
  29. HRYimage = Image.new('1', (epd.width, epd.height), 255) # 648*480 HRYimage: red or yellow image
  30. drawblack = ImageDraw.Draw(HBlackimage)
  31. drawry = ImageDraw.Draw(HRYimage)
  32. drawblack.text((10, 0), 'hello world', font = font24, fill = 0)
  33. drawblack.text((10, 20), '5.83inch e-Paper b V2', font = font24, fill = 0)
  34. drawblack.text((150, 0), u'微雪电子', font = font24, 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((200, 50, 250, 100), 0, 360, fill = 0)
  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.height, epd.width), 255)
  48. LRYimage = Image.new('1', (epd.height, epd.width), 255)
  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), '5.83inch epd b V2', 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.line((95, 90, 95, 140), fill = 0)
  58. drawry.line((70, 115, 120, 115), fill = 0)
  59. drawry.arc((70, 90, 120, 140), 0, 360, fill = 0)
  60. drawry.rectangle((10, 150, 60, 200), fill = 0)
  61. drawry.chord((70, 150, 120, 200), 0, 360, fill = 0)
  62. epd.display(epd.getbuffer(LBlackimage), epd.getbuffer(LRYimage))
  63. time.sleep(2)
  64. logging.info("3.read bmp file")
  65. HBlackimage = Image.open(os.path.join(picdir, '5in83b_V2_b.bmp'))
  66. HRYimage = Image.open(os.path.join(picdir, '5in83b_V2_r.bmp'))
  67. epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage))
  68. time.sleep(2)
  69. logging.info("4.read bmp file on window")
  70. blackimage1 = Image.new('1', (epd.width, epd.height), 255)
  71. redimage1 = Image.new('1', (epd.width, epd.height), 255)
  72. newimage = Image.open(os.path.join(picdir, '100x100.bmp'))
  73. blackimage1.paste(newimage, (50,10))
  74. epd.display(epd.getbuffer(blackimage1), epd.getbuffer(redimage1))
  75. logging.info("Clear...")
  76. epd.init()
  77. epd.Clear()
  78. logging.info("Goto Sleep...")
  79. epd.sleep()
  80. except IOError as e:
  81. logging.info(e)
  82. except KeyboardInterrupt:
  83. logging.info("ctrl + c:")
  84. epd5in83b_V2.epdconfig.module_exit(cleanup=True)
  85. exit()