epd_2in13d_test.py 3.0 KB

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