epd_7in5_V2_test.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 epd7in5_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("epd7in5_V2 Demo")
  17. epd = epd7in5_V2.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. font35 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 35)
  24. logging.info("read bmp file")
  25. Himage = Image.open(os.path.join(picdir, '7in5_V2.bmp'))
  26. epd.display(epd.getbuffer(Himage))
  27. time.sleep(2)
  28. logging.info("read bmp file on window")
  29. Himage2 = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  30. bmp = Image.open(os.path.join(picdir, '100x100.bmp'))
  31. Himage2.paste(bmp, (50,10))
  32. epd.display(epd.getbuffer(Himage2))
  33. time.sleep(2)
  34. # Drawing on the Horizontal image
  35. logging.info("Drawing on the Horizontal image...")
  36. epd.init_fast()
  37. Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  38. draw = ImageDraw.Draw(Himage)
  39. draw.text((10, 0), 'hello world', font = font24, fill = 0)
  40. draw.text((10, 20), '7.5inch e-Paper', font = font24, fill = 0)
  41. draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
  42. draw.line((20, 50, 70, 100), fill = 0)
  43. draw.line((70, 50, 20, 100), fill = 0)
  44. draw.rectangle((20, 50, 70, 100), outline = 0)
  45. draw.line((165, 50, 165, 100), fill = 0)
  46. draw.line((140, 75, 190, 75), fill = 0)
  47. draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
  48. draw.rectangle((80, 50, 130, 100), fill = 0)
  49. draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
  50. epd.display(epd.getbuffer(Himage))
  51. time.sleep(2)
  52. # partial update
  53. logging.info("5.show time")
  54. epd.init_part()
  55. # Himage = Image.new('1', (epd.width, epd.height), 0)
  56. # draw = ImageDraw.Draw(Himage)
  57. num = 0
  58. while (True):
  59. draw.rectangle((10, 120, 130, 170), fill = 255)
  60. draw.text((10, 120), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  61. epd.display_Partial(epd.getbuffer(Himage),0, 0, epd.width, epd.height)
  62. num = num + 1
  63. if(num == 10):
  64. break
  65. # # Drawing on the Vertical image
  66. # logging.info("2.Drawing on the Vertical image...")
  67. # epd.init()
  68. # Limage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  69. # draw = ImageDraw.Draw(Limage)
  70. # draw.text((2, 0), 'hello world', font = font18, fill = 0)
  71. # draw.text((2, 20), '7.5inch epd', font = font18, fill = 0)
  72. # draw.text((20, 50), u'微雪电子', font = font18, fill = 0)
  73. # draw.line((10, 90, 60, 140), fill = 0)
  74. # draw.line((60, 90, 10, 140), fill = 0)
  75. # draw.rectangle((10, 90, 60, 140), outline = 0)
  76. # draw.line((95, 90, 95, 140), fill = 0)
  77. # draw.line((70, 115, 120, 115), fill = 0)
  78. # draw.arc((70, 90, 120, 140), 0, 360, fill = 0)
  79. # draw.rectangle((10, 150, 60, 200), fill = 0)
  80. # draw.chord((70, 150, 120, 200), 0, 360, fill = 0)
  81. # epd.display(epd.getbuffer(Limage))
  82. # time.sleep(2)
  83. # '''4Gray display'''
  84. # # The feature will only be available on screens sold after 24/10/23
  85. # logging.info("4Gray display--------------------------------")
  86. # epd.init_4Gray()
  87. # Limage = Image.new('L', (epd.width, epd.height), 0) # 255: clear the frame
  88. # draw = ImageDraw.Draw(Limage)
  89. # draw.text((20, 0), u'微雪电子', font = font35, fill = epd.GRAY1)
  90. # draw.text((20, 35), u'微雪电子', font = font35, fill = epd.GRAY2)
  91. # draw.text((20, 70), u'微雪电子', font = font35, fill = epd.GRAY3)
  92. # draw.text((40, 110), 'hello world', font = font18, fill = epd.GRAY1)
  93. # draw.line((10, 140, 60, 190), fill = epd.GRAY1)
  94. # draw.line((60, 140, 10, 190), fill = epd.GRAY1)
  95. # draw.rectangle((10, 140, 60, 190), outline = epd.GRAY1)
  96. # draw.line((95, 140, 95, 190), fill = epd.GRAY1)
  97. # draw.line((70, 165, 120, 165), fill = epd.GRAY1)
  98. # draw.arc((70, 140, 120, 190), 0, 360, fill = epd.GRAY1)
  99. # draw.rectangle((10, 200, 60, 250), fill = epd.GRAY1)
  100. # draw.chord((70, 200, 120, 250), 0, 360, fill = epd.GRAY1)
  101. # epd.display_4Gray(epd.getbuffer_4Gray(Limage))
  102. # time.sleep(2)
  103. logging.info("Clear...")
  104. epd.init()
  105. epd.Clear()
  106. logging.info("Goto Sleep...")
  107. epd.sleep()
  108. except IOError as e:
  109. logging.info(e)
  110. except KeyboardInterrupt:
  111. logging.info("ctrl + c:")
  112. epd7in5_V2.epdconfig.module_exit(cleanup=True)
  113. exit()