epd_2in13d_test.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. sys.path.append(r'../lib')
  5. import epd2in13d
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd2in13d Demo")
  12. epd = epd2in13d.EPD()
  13. print("init and Clear")
  14. epd.init()
  15. epd.Clear(0xFF)
  16. font15 = ImageFont.truetype('../lib/Font.ttc', 15)
  17. # Drawing on the Horizontal image
  18. print("1.Drawing on the Horizontal image...")
  19. Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  20. draw = ImageDraw.Draw(Himage)
  21. draw.rectangle([(0,0),(50,50)],outline = 0)
  22. draw.rectangle([(55,0),(100,50)],fill = 0)
  23. draw.line([(0,0),(50,50)], fill = 0,width = 1)
  24. draw.line([(0,50),(50,0)], fill = 0,width = 1)
  25. draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
  26. draw.ellipse((55, 60, 95, 100), outline = 0)
  27. draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
  28. draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
  29. draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
  30. draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
  31. draw.text((110, 60), 'e-Paper demo', font = font15, fill = 0)
  32. draw.text((110, 80), u'微雪电子', font = font15, fill = 0)
  33. epd.display(epd.getbuffer(Himage))
  34. time.sleep(2)
  35. print("3.read bmp file")
  36. Himage = Image.open('../pic/2in13d.bmp')
  37. epd.display(epd.getbuffer(Himage))
  38. time.sleep(2)
  39. print("4.read bmp file on window")
  40. Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  41. bmp = Image.open('../pic/100x100.bmp')
  42. Himage2.paste(bmp, (20,20))
  43. epd.display(epd.getbuffer(Himage2))
  44. time.sleep(2)
  45. # # partial update
  46. print("5.show time...")
  47. epd.init()
  48. epd.Clear(0xFF)
  49. time_image = Image.new('1', (epd.width, epd.height), 255)
  50. time_draw = ImageDraw.Draw(time_image)
  51. num = 0
  52. while (True):
  53. time_draw.rectangle((10, 10, 120, 50), fill = 255)
  54. time_draw.text((10, 10), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  55. newimage = time_image.crop([10, 10, 120, 50])
  56. time_image.paste(newimage, (10,10))
  57. epd.DisplayPartial(epd.getbuffer(time_image))
  58. num = num + 1
  59. if(num == 10):
  60. break
  61. print("Clear...")
  62. epd.Clear(0xFF)
  63. print("Goto Sleep...")
  64. epd.sleep()
  65. except IOError as e:
  66. print(e)
  67. except KeyboardInterrupt:
  68. print("ctrl + c:")
  69. epdconfig.module_exit()
  70. exit()