epd_2in13_V2_test.py 2.6 KB

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