main.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import epd2in13
  4. import time
  5. from PIL import Image,ImageDraw,ImageFont
  6. import traceback
  7. try:
  8. epd = epd2in13.EPD()
  9. epd.init(epd.lut_full_update)
  10. epd.Clear(0xFF)
  11. # read bmp file on window
  12. print("read bmp file on window")
  13. epd.Clear(0xFF)
  14. image1 = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255) # 255: clear the frame
  15. bmp = Image.open('100x100.bmp')
  16. image1.paste(bmp, (10,10))
  17. epd.display(epd.getbuffer(image1))
  18. time.sleep(2)
  19. # Drawing on the image
  20. image2 = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
  21. # read bmp file
  22. print("read bmp file")
  23. epd.Clear(0xFF)
  24. image2 = Image.open('2in13.bmp')
  25. epd.display(epd.getbuffer(image2.rotate(180)))
  26. print("Drawing")
  27. epd.Clear(0xFF)
  28. image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
  29. draw = ImageDraw.Draw(image)
  30. draw.rectangle([(0,0),(50,50)],outline = 0)
  31. draw.rectangle([(55,0),(100,50)],fill = 0)
  32. draw.line([(0,0),(50,50)], fill = 0,width = 1)
  33. draw.line([(0,50),(50,0)], fill = 0,width = 1)
  34. draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
  35. draw.ellipse((55, 60, 95, 100), outline = 0)
  36. draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
  37. draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
  38. draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
  39. draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
  40. font15 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 15)
  41. draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
  42. # draw.text((110, 80), 'Hello world', font = font15, fill = 0)
  43. epd.display(epd.getbuffer(image.rotate(180)))
  44. time.sleep(2)
  45. # partial update
  46. print("Show time")
  47. epd.init(epd.lut_partial_update)
  48. font24 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
  49. # time_image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255)
  50. draw = ImageDraw.Draw(image)
  51. while (True):
  52. draw.rectangle((120, 80, 220, 105), fill = 255)
  53. draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  54. # newimage = time_image.crop([10, 10, 120, 50])
  55. # time_image.paste(newimage, (10,10))
  56. epd.display(epd.getbuffer(image.rotate(180)))
  57. epd.sleep()
  58. except Exception, e:
  59. print 'traceback.format_exc():\n%s' % traceback.format_exc()
  60. exit()