2
0

epd_13in3b_test.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 epd13in3b
  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 = epd13in3b.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("2.read bmp file")
  25. HBlackimage = Image.open(os.path.join(picdir, '13in3b_r.bmp'))
  26. HRedimage = Image.open(os.path.join(picdir, '13in3b_b.bmp'))
  27. epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
  28. time.sleep(2)
  29. # Drawing on the Horizontal image
  30. logging.info("3.Drawing on the Horizontal image...")
  31. HBlackimage = Image.new('1', (epd.width, epd.height), 255)
  32. HRedimage = Image.new('1', (epd.width, epd.height), 255)
  33. drawblack = ImageDraw.Draw(HBlackimage)
  34. drawred = ImageDraw.Draw(HRedimage)
  35. drawblack.text((10, 0), 'hello world', font = font24, fill = 0)
  36. drawred.text((10, 20), '13.3inch e-Paper (B)', font = font24, fill = 0)
  37. drawblack.text((150, 0), u'微雪电子', font = font24, fill = 0)
  38. drawred.line((20, 50, 70, 100), fill = 0)
  39. drawblack.line((70, 50, 20, 100), fill = 0)
  40. drawred.rectangle((20, 50, 70, 100), outline = 0)
  41. drawblack.line((165, 50, 165, 100), fill = 0)
  42. drawred.line((140, 75, 190, 75), fill = 0)
  43. drawblack.arc((140, 50, 190, 100), 0, 360, fill = 0)
  44. drawred.rectangle((80, 50, 130, 100), fill = 0)
  45. drawblack.chord((200, 50, 250, 100), 0, 360, fill = 0)
  46. epd.display_Base(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
  47. time.sleep(2)
  48. # partial update
  49. logging.info("4.show time")
  50. '''
  51. # If you didn't use the epd.display_Base() function to refresh the image before,
  52. # use the epd.Clear_Base() function to refresh the background color,
  53. # otherwise the background color will be garbled
  54. '''
  55. # epd.Clear_Base()
  56. # Himage = Image.new('1', (epd.height ,epd.width), 0xff)
  57. # draw = ImageDraw.Draw(time_image)
  58. num = 0
  59. while (True):
  60. drawblack.rectangle((0, 110, 120, 150), fill = 255)
  61. drawblack.text((10, 120), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  62. epd.display_Partial(epd.getbuffer(HBlackimage),0, 110, 120, 160)
  63. num = num + 1
  64. if(num == 10):
  65. break
  66. logging.info("Clear...")
  67. epd.init()
  68. epd.Clear()
  69. logging.info("Goto Sleep...")
  70. epd.sleep()
  71. except IOError as e:
  72. logging.info(e)
  73. except KeyboardInterrupt:
  74. logging.info("ctrl + c:")
  75. epd13in3b.epdconfig.module_exit(cleanup=True)
  76. exit()