epd_7in5_V2_test.py 3.6 KB

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