2
0

epd_2in13_test.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 epd2in13
  11. import time
  12. from PIL import Image,ImageDraw,ImageFont
  13. import traceback
  14. logging.basicConfig(level=logging.DEBUG)
  15. try:
  16. logging.info("epd2in13 Demo")
  17. epd = epd2in13.EPD()
  18. logging.info("init and Clear")
  19. epd.init(epd.lut_full_update)
  20. epd.Clear(0xFF)
  21. # Drawing on the image
  22. font15 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15)
  23. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  24. logging.info("1.Drawing on the image...")
  25. image = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  26. draw = ImageDraw.Draw(image)
  27. draw.rectangle([(0,0),(50,50)],outline = 0)
  28. draw.rectangle([(55,0),(100,50)],fill = 0)
  29. draw.line([(0,0),(50,50)], fill = 0,width = 1)
  30. draw.line([(0,50),(50,0)], fill = 0,width = 1)
  31. draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
  32. draw.ellipse((55, 60, 95, 100), outline = 0)
  33. draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
  34. draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
  35. draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
  36. draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
  37. draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
  38. draw.text((110, 90), u'微雪电子', font = font24, fill = 0)
  39. epd.display(epd.getbuffer(image))
  40. time.sleep(2)
  41. # read bmp file
  42. logging.info("2.read bmp file...")
  43. image = Image.open(os.path.join(picdir, '2in13.bmp'))
  44. epd.display(epd.getbuffer(image))
  45. time.sleep(2)
  46. # read bmp file on window
  47. logging.info("3.read bmp file on window...")
  48. # epd.Clear(0xFF)
  49. image1 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  50. bmp = Image.open(os.path.join(picdir, '100x100.bmp'))
  51. image1.paste(bmp, (2,2))
  52. epd.display(epd.getbuffer(image1))
  53. time.sleep(2)
  54. # # partial update
  55. logging.info("4.show time...")
  56. epd.init(epd.lut_partial_update)
  57. epd.Clear(0xFF)
  58. time_image = Image.new('1', (epd.height, epd.width), 255)
  59. time_draw = ImageDraw.Draw(time_image)
  60. num = 0
  61. while (True):
  62. time_draw.rectangle((120, 80, 220, 105), fill = 255)
  63. time_draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  64. epd.display(epd.getbuffer(time_image))
  65. num = num + 1
  66. if(num == 10):
  67. break
  68. logging.info("Clear...")
  69. epd.init(epd.lut_full_update)
  70. epd.Clear(0xFF)
  71. logging.info("Goto Sleep...")
  72. epd.sleep()
  73. except IOError as e:
  74. logging.info(e)
  75. except KeyboardInterrupt:
  76. logging.info("ctrl + c:")
  77. epd2in13.epdconfig.module_exit(cleanup=True)
  78. exit()