2
0

epd_13in3k_test.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 epd13in3k
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd13in3k Demo")
  17. epd = epd13in3k.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. # Drawing on the Vertical image
  25. logging.info("1.Drawing on the Vertical image...")
  26. Limage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  27. draw = ImageDraw.Draw(Limage)
  28. draw.text((2, 0), 'hello world', font = font18, fill = 0)
  29. draw.text((2, 20), '13.3inch e-Paper (K)', font = font18, fill = 0)
  30. draw.text((20, 50), u'微雪电子', font = font18, fill = 0)
  31. draw.line((10, 90, 60, 140), fill = 0)
  32. draw.line((60, 90, 10, 140), fill = 0)
  33. draw.rectangle((10, 90, 60, 140), outline = 0)
  34. draw.line((95, 90, 95, 140), fill = 0)
  35. draw.line((70, 115, 120, 115), fill = 0)
  36. draw.arc((70, 90, 120, 140), 0, 360, fill = 0)
  37. draw.rectangle((10, 150, 60, 200), fill = 0)
  38. draw.chord((70, 150, 120, 200), 0, 360, fill = 0)
  39. epd.display(epd.getbuffer(Limage))
  40. time.sleep(2)
  41. logging.info("2.read bmp file")
  42. Himage = Image.open(os.path.join(picdir, '13in3.bmp'))
  43. epd.display(epd.getbuffer(Himage))
  44. time.sleep(2)
  45. # Drawing on the Horizontal image
  46. logging.info("3.Drawing on the Horizontal image...")
  47. Himage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  48. draw = ImageDraw.Draw(Himage)
  49. draw.text((10, 0), 'hello world', font = font24, fill = 0)
  50. draw.text((10, 20), '13.3inch e-Paper (K)', font = font24, fill = 0)
  51. draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
  52. draw.line((20, 50, 70, 100), fill = 0)
  53. draw.line((70, 50, 20, 100), fill = 0)
  54. draw.rectangle((20, 50, 70, 100), outline = 0)
  55. draw.line((165, 50, 165, 100), fill = 0)
  56. draw.line((140, 75, 190, 75), fill = 0)
  57. draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
  58. draw.rectangle((80, 50, 130, 100), fill = 0)
  59. draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
  60. epd.display_Base(epd.getbuffer(Himage))
  61. time.sleep(2)
  62. # partial update
  63. logging.info("4.show time")
  64. epd.init_Part()
  65. '''
  66. # If you didn't use the epd.display_Base() function to refresh the image before,
  67. # use the epd.display_Base_color() function to refresh the background color,
  68. # otherwise the background color will be garbled
  69. '''
  70. # epd.display_Base_color(0xff)
  71. # Himage = Image.new('1', (epd.height ,epd.width), 0xff)
  72. # draw = ImageDraw.Draw(time_image)
  73. num = 0
  74. while (True):
  75. draw.rectangle((0, 110, 120, 150), fill = 255)
  76. draw.text((10, 120), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  77. epd.display_Partial(epd.getbuffer(Himage),0, 110, 120, 160)
  78. num = num + 1
  79. if(num == 10):
  80. break
  81. '''4Gray display'''
  82. logging.info("4Gray display--------------------------------")
  83. epd.init_4GRAY()
  84. Limage = Image.new('L', (epd.width, epd.height), 255) # 255: clear the frame
  85. draw = ImageDraw.Draw(Limage)
  86. draw.text((20, 0), u'微雪电子', font = font35, fill = epd.GRAY2)
  87. draw.text((20, 35), u'微雪电子', font = font35, fill = epd.GRAY3)
  88. draw.text((20, 70), u'微雪电子', font = font35, fill = epd.GRAY4)
  89. draw.text((40, 110), 'hello world', font = font18, fill = epd.GRAY4)
  90. draw.line((10, 140, 60, 190), fill = epd.GRAY4)
  91. draw.line((60, 140, 10, 190), fill = epd.GRAY4)
  92. draw.rectangle((10, 140, 60, 190), outline = epd.GRAY4)
  93. draw.line((95, 140, 95, 190), fill = epd.GRAY4)
  94. draw.line((70, 165, 120, 165), fill = epd.GRAY4)
  95. draw.arc((70, 140, 120, 190), 0, 360, fill = epd.GRAY4)
  96. draw.rectangle((10, 200, 60, 250), fill = epd.GRAY4)
  97. draw.chord((70, 200, 120, 250), 0, 360, fill = epd.GRAY4)
  98. epd.display_4Gray(epd.getbuffer_4Gray(Limage))
  99. time.sleep(2)
  100. #display 4Gra bmp
  101. Himage = Image.open(os.path.join(picdir, '13in3k_Scale.bmp'))
  102. epd.display_4Gray(epd.getbuffer_4Gray(Himage))
  103. time.sleep(2)
  104. logging.info("Clear...")
  105. epd.init()
  106. epd.Clear()
  107. logging.info("Goto Sleep...")
  108. epd.sleep()
  109. except IOError as e:
  110. logging.info(e)
  111. except KeyboardInterrupt:
  112. logging.info("ctrl + c:")
  113. epd13in3k.epdconfig.module_exit(cleanup=True)
  114. exit()