test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. import os
  5. pydir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
  6. picdir = os.path.join(pydir, 'pic')
  7. libdir = os.path.join(pydir, 'lib')
  8. if os.path.exists(libdir):
  9. sys.path.append(libdir)
  10. import logging
  11. from waveshare_epd import epd2in13_V2
  12. import time
  13. from PIL import Image,ImageDraw,ImageFont
  14. from PIL.ImageOps import invert
  15. import traceback
  16. logging.basicConfig(level=logging.DEBUG)
  17. try:
  18. logging.info("epd2in13_V2 Demo")
  19. font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
  20. epd = epd2in13_V2.EPD()
  21. logging.info("init and Clear")
  22. epd.init(epd.FULL_UPDATE)
  23. epd.Clear(0xFF)
  24. # read bmp file
  25. logging.info("2.read bmp file...")
  26. image = Image.open(os.path.join(picdir, '2in13.bmp'))
  27. draw = ImageDraw.Draw(image)
  28. epd.displayPartBaseImage(epd.getbuffer(image))
  29. time.sleep(2)
  30. logging.info("4.show time...")
  31. image = Image.new('1', (epd.height, epd.width), 255)
  32. draw = ImageDraw.Draw(image)
  33. epd.init(epd.FULL_UPDATE)
  34. epd.displayPartBaseImage(epd.getbuffer(image))
  35. epd.init(epd.PART_UPDATE)
  36. draw.text((120, 60), " ".join(sys.argv[1:]), font = font24, fill = 0)
  37. num = 0
  38. while (True):
  39. draw.rectangle((120, 80, 220, 105), fill = 255)
  40. draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  41. epd.displayPartial(epd.getbuffer(image.rotate(180)))
  42. num = num + 1
  43. if(num == 10):
  44. break
  45. time.sleep(2)
  46. logging.info("Goto Sleep...")
  47. epd.sleep()
  48. epd.Dev_exit()
  49. except IOError as e:
  50. logging.info(e)
  51. except KeyboardInterrupt:
  52. logging.info("ctrl + c:")
  53. epd2in13_V2.epdconfig.module_exit()
  54. exit()