epd2in9_V2.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. # *****************************************************************************
  2. # * | File : epd2in9_V2.py
  3. # * | Author : Waveshare team
  4. # * | Function : Electronic paper driver
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.1
  8. # * | Date : 2022-08-9
  9. # # | Info : python demo
  10. # -----------------------------------------------------------------------------
  11. # Permission is hereby granted, free of charge, to any person obtaining a copy
  12. # of this software and associated documnetation files (the "Software"), to deal
  13. # in the Software without restriction, including without limitation the rights
  14. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. # copies of the Software, and to permit persons to whom the Software is
  16. # furished to do so, subject to the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included in
  19. # all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. # THE SOFTWARE.
  28. #
  29. import logging
  30. from . import epdconfig
  31. # Display resolution
  32. EPD_WIDTH = 128
  33. EPD_HEIGHT = 296
  34. GRAY1 = 0xff #white
  35. GRAY2 = 0xC0
  36. GRAY3 = 0x80 #gray
  37. GRAY4 = 0x00 #Blackest
  38. logger = logging.getLogger(__name__)
  39. class EPD:
  40. def __init__(self):
  41. self.reset_pin = epdconfig.RST_PIN
  42. self.dc_pin = epdconfig.DC_PIN
  43. self.busy_pin = epdconfig.BUSY_PIN
  44. self.cs_pin = epdconfig.CS_PIN
  45. self.width = EPD_WIDTH
  46. self.height = EPD_HEIGHT
  47. self.GRAY1 = GRAY1 #white
  48. self.GRAY2 = GRAY2
  49. self.GRAY3 = GRAY3 #gray
  50. self.GRAY4 = GRAY4 #Blackest
  51. WF_PARTIAL_2IN9 = [
  52. 0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  53. 0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  54. 0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  55. 0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  56. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  57. 0x0A,0x0,0x0,0x0,0x0,0x0,0x1,
  58. 0x1,0x0,0x0,0x0,0x0,0x0,0x0,
  59. 0x1,0x0,0x0,0x0,0x0,0x0,0x0,
  60. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  61. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  62. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  63. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  64. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  65. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  66. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  67. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  68. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  69. 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0,
  70. 0x22,0x17,0x41,0xB0,0x32,0x36,
  71. ]
  72. WS_20_30 = [
  73. 0x80, 0x66, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0,
  74. 0x10, 0x66, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0,
  75. 0x80, 0x66, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0,
  76. 0x10, 0x66, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0,
  77. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  78. 0x14, 0x8, 0x0, 0x0, 0x0, 0x0, 0x2,
  79. 0xA, 0xA, 0x0, 0xA, 0xA, 0x0, 0x1,
  80. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  81. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  82. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  83. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  84. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  85. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  86. 0x14, 0x8, 0x0, 0x1, 0x0, 0x0, 0x1,
  87. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1,
  88. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  89. 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  90. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x0, 0x0, 0x0,
  91. 0x22, 0x17, 0x41, 0x0, 0x32, 0x36
  92. ]
  93. Gray4 = [
  94. 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  95. 0x20, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  96. 0x28, 0x60, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  97. 0x2A, 0x60, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00,
  100. 0x1E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01,
  101. 0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00,
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  111. 0x24, 0x22, 0x22, 0x22, 0x23, 0x32, 0x00, 0x00, 0x00,
  112. 0x22, 0x17, 0x41, 0xAE, 0x32, 0x28,
  113. ]
  114. WF_FULL = [
  115. 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  116. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  117. 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  118. 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  120. 0x19, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  122. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  123. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  124. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  126. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  127. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  130. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  131. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  132. 0x24, 0x42, 0x22, 0x22, 0x23, 0x32, 0x00, 0x00, 0x00,
  133. 0x22, 0x17, 0x41, 0xAE, 0x32, 0x38]
  134. # Hardware reset
  135. def reset(self):
  136. epdconfig.digital_write(self.reset_pin, 1)
  137. epdconfig.delay_ms(50)
  138. epdconfig.digital_write(self.reset_pin, 0)
  139. epdconfig.delay_ms(2)
  140. epdconfig.digital_write(self.reset_pin, 1)
  141. epdconfig.delay_ms(50)
  142. def send_command(self, command):
  143. epdconfig.digital_write(self.dc_pin, 0)
  144. epdconfig.digital_write(self.cs_pin, 0)
  145. epdconfig.spi_writebyte([command])
  146. epdconfig.digital_write(self.cs_pin, 1)
  147. def send_data(self, data):
  148. epdconfig.digital_write(self.dc_pin, 1)
  149. epdconfig.digital_write(self.cs_pin, 0)
  150. epdconfig.spi_writebyte([data])
  151. epdconfig.digital_write(self.cs_pin, 1)
  152. # send a lot of data
  153. def send_data2(self, data):
  154. epdconfig.digital_write(self.dc_pin, 1)
  155. epdconfig.digital_write(self.cs_pin, 0)
  156. epdconfig.spi_writebyte2(data)
  157. epdconfig.digital_write(self.cs_pin, 1)
  158. def ReadBusy(self):
  159. logger.debug("e-Paper busy")
  160. while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
  161. epdconfig.delay_ms(10)
  162. logger.debug("e-Paper busy release")
  163. def TurnOnDisplay(self):
  164. self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
  165. self.send_data(0xc7)
  166. self.send_command(0x20) # MASTER_ACTIVATION
  167. self.ReadBusy()
  168. def TurnOnDisplay_Partial(self):
  169. self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
  170. self.send_data(0x0F)
  171. self.send_command(0x20) # MASTER_ACTIVATION
  172. self.ReadBusy()
  173. def lut(self, lut):
  174. self.send_command(0x32)
  175. for i in range(0, 153):
  176. self.send_data(lut[i])
  177. self.ReadBusy()
  178. def SetLut(self, lut):
  179. self.lut(lut)
  180. self.send_command(0x3f)
  181. self.send_data(lut[153])
  182. self.send_command(0x03); # gate voltage
  183. self.send_data(lut[154])
  184. self.send_command(0x04); # source voltage
  185. self.send_data(lut[155]) # VSH
  186. self.send_data(lut[156]) # VSH2
  187. self.send_data(lut[157]) # VSL
  188. self.send_command(0x2c); # VCOM
  189. self.send_data(lut[158])
  190. def SetWindow(self, x_start, y_start, x_end, y_end):
  191. self.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
  192. # x point must be the multiple of 8 or the last 3 bits will be ignored
  193. self.send_data((x_start>>3) & 0xFF)
  194. self.send_data((x_end>>3) & 0xFF)
  195. self.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
  196. self.send_data(y_start & 0xFF)
  197. self.send_data((y_start >> 8) & 0xFF)
  198. self.send_data(y_end & 0xFF)
  199. self.send_data((y_end >> 8) & 0xFF)
  200. def SetCursor(self, x, y):
  201. self.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
  202. # x point must be the multiple of 8 or the last 3 bits will be ignored
  203. self.send_data(x & 0xFF)
  204. self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
  205. self.send_data(y & 0xFF)
  206. self.send_data((y >> 8) & 0xFF)
  207. def init(self):
  208. if (epdconfig.module_init() != 0):
  209. return -1
  210. # EPD hardware init start
  211. self.reset()
  212. self.ReadBusy()
  213. self.send_command(0x12) #SWRESET
  214. self.ReadBusy()
  215. self.send_command(0x01) #Driver output control
  216. self.send_data(0x27)
  217. self.send_data(0x01)
  218. self.send_data(0x00)
  219. self.send_command(0x11) #data entry mode
  220. self.send_data(0x03)
  221. self.SetWindow(0, 0, self.width-1, self.height-1)
  222. self.send_command(0x21) # Display update control
  223. self.send_data(0x00)
  224. self.send_data(0x80)
  225. self.SetCursor(0, 0)
  226. self.ReadBusy()
  227. self.SetLut(self.WS_20_30)
  228. # EPD hardware init end
  229. return 0
  230. def init_Fast(self):
  231. if (epdconfig.module_init() != 0):
  232. return -1
  233. # EPD hardware init start
  234. self.reset()
  235. self.ReadBusy()
  236. self.send_command(0x12) #SWRESET
  237. self.ReadBusy()
  238. self.send_command(0x01) #Driver output control
  239. self.send_data(0x27)
  240. self.send_data(0x01)
  241. self.send_data(0x00)
  242. self.send_command(0x11) #data entry mode
  243. self.send_data(0x03)
  244. self.SetWindow(0, 0, self.width-1, self.height-1)
  245. self.send_command(0x3C)
  246. self.send_data(0x05)
  247. self.send_command(0x21) # Display update control
  248. self.send_data(0x00)
  249. self.send_data(0x80)
  250. self.SetCursor(0, 0)
  251. self.ReadBusy()
  252. self.SetLut(self.WF_FULL)
  253. # EPD hardware init end
  254. return 0
  255. def Init_4Gray(self):
  256. if (epdconfig.module_init() != 0):
  257. return -1
  258. self.reset()
  259. epdconfig.delay_ms(100)
  260. self.ReadBusy()
  261. self.send_command(0x12) #SWRESET
  262. self.ReadBusy()
  263. self.send_command(0x01) #Driver output control
  264. self.send_data(0x27)
  265. self.send_data(0x01)
  266. self.send_data(0x00)
  267. self.send_command(0x11) #data entry mode
  268. self.send_data(0x03)
  269. self.SetWindow(8, 0, self.width, self.height-1)
  270. self.send_command(0x3C)
  271. self.send_data(0x04)
  272. self.SetCursor(1, 0)
  273. self.ReadBusy()
  274. self.SetLut(self.Gray4)
  275. # EPD hardware init end
  276. return 0
  277. def getbuffer(self, image):
  278. # logger.debug("bufsiz = ",int(self.width/8) * self.height)
  279. buf = [0xFF] * (int(self.width/8) * self.height)
  280. image_monocolor = image.convert('1')
  281. imwidth, imheight = image_monocolor.size
  282. pixels = image_monocolor.load()
  283. # logger.debug("imwidth = %d, imheight = %d",imwidth,imheight)
  284. if(imwidth == self.width and imheight == self.height):
  285. logger.debug("Vertical")
  286. for y in range(imheight):
  287. for x in range(imwidth):
  288. # Set the bits for the column of pixels at the current position.
  289. if pixels[x, y] == 0:
  290. buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8))
  291. elif(imwidth == self.height and imheight == self.width):
  292. logger.debug("Horizontal")
  293. for y in range(imheight):
  294. for x in range(imwidth):
  295. newx = y
  296. newy = self.height - x - 1
  297. if pixels[x, y] == 0:
  298. buf[int((newx + newy*self.width) / 8)] &= ~(0x80 >> (y % 8))
  299. return buf
  300. def getbuffer_4Gray(self, image):
  301. # logger.debug("bufsiz = ",int(self.width/8) * self.height)
  302. buf = [0xFF] * (int(self.width / 4) * self.height)
  303. image_monocolor = image.convert('L')
  304. imwidth, imheight = image_monocolor.size
  305. pixels = image_monocolor.load()
  306. i=0
  307. # logger.debug("imwidth = %d, imheight = %d",imwidth,imheight)
  308. if(imwidth == self.width and imheight == self.height):
  309. logger.debug("Vertical")
  310. for y in range(imheight):
  311. for x in range(imwidth):
  312. # Set the bits for the column of pixels at the current position.
  313. if(pixels[x, y] == 0xC0):
  314. pixels[x, y] = 0x80
  315. elif (pixels[x, y] == 0x80):
  316. pixels[x, y] = 0x40
  317. i= i+1
  318. if(i%4 == 0):
  319. buf[int((x + (y * self.width))/4)] = ((pixels[x-3, y]&0xc0) | (pixels[x-2, y]&0xc0)>>2 | (pixels[x-1, y]&0xc0)>>4 | (pixels[x, y]&0xc0)>>6)
  320. elif(imwidth == self.height and imheight == self.width):
  321. logger.debug("Horizontal")
  322. for x in range(imwidth):
  323. for y in range(imheight):
  324. newx = y
  325. newy = self.height - x - 1
  326. if(pixels[x, y] == 0xC0):
  327. pixels[x, y] = 0x80
  328. elif (pixels[x, y] == 0x80):
  329. pixels[x, y] = 0x40
  330. i= i+1
  331. if(i%4 == 0):
  332. buf[int((newx + (newy * self.width))/4)] = ((pixels[x, y-3]&0xc0) | (pixels[x, y-2]&0xc0)>>2 | (pixels[x, y-1]&0xc0)>>4 | (pixels[x, y]&0xc0)>>6)
  333. return buf
  334. def display(self, image):
  335. if (image == None):
  336. return
  337. self.send_command(0x24) # WRITE_RAM
  338. self.send_data2(image)
  339. self.TurnOnDisplay()
  340. def display_Base(self, image):
  341. if (image == None):
  342. return
  343. self.send_command(0x24) # WRITE_RAM
  344. self.send_data2(image)
  345. self.send_command(0x26) # WRITE_RAM
  346. self.send_data2(image)
  347. self.TurnOnDisplay()
  348. def display_4Gray(self, image):
  349. self.send_command(0x24)
  350. for i in range(0, 4736):
  351. temp3=0
  352. for j in range(0, 2):
  353. temp1 = image[i*2+j]
  354. for k in range(0, 2):
  355. temp2 = temp1&0xC0
  356. if(temp2 == 0xC0):
  357. temp3 |= 0x00
  358. elif(temp2 == 0x00):
  359. temp3 |= 0x01
  360. elif(temp2 == 0x80):
  361. temp3 |= 0x01
  362. else: #0x40
  363. temp3 |= 0x00
  364. temp3 <<= 1
  365. temp1 <<= 2
  366. temp2 = temp1&0xC0
  367. if(temp2 == 0xC0):
  368. temp3 |= 0x00
  369. elif(temp2 == 0x00):
  370. temp3 |= 0x01
  371. elif(temp2 == 0x80):
  372. temp3 |= 0x01
  373. else : #0x40
  374. temp3 |= 0x00
  375. if(j!=1 or k!=1):
  376. temp3 <<= 1
  377. temp1 <<= 2
  378. self.send_data(temp3)
  379. self.send_command(0x26)
  380. for i in range(0, 4736):
  381. temp3=0
  382. for j in range(0, 2):
  383. temp1 = image[i*2+j]
  384. for k in range(0, 2):
  385. temp2 = temp1&0xC0
  386. if(temp2 == 0xC0):
  387. temp3 |= 0x00
  388. elif(temp2 == 0x00):
  389. temp3 |= 0x01
  390. elif(temp2 == 0x80):
  391. temp3 |= 0x00
  392. else: #0x40
  393. temp3 |= 0x01
  394. temp3 <<= 1
  395. temp1 <<= 2
  396. temp2 = temp1&0xC0
  397. if(temp2 == 0xC0):
  398. temp3 |= 0x00
  399. elif(temp2 == 0x00):
  400. temp3 |= 0x01
  401. elif(temp2 == 0x80):
  402. temp3 |= 0x00
  403. else: #0x40
  404. temp3 |= 0x01
  405. if(j!=1 or k!=1):
  406. temp3 <<= 1
  407. temp1 <<= 2
  408. self.send_data(temp3)
  409. self.TurnOnDisplay()
  410. def display_Partial(self, image):
  411. if (image == None):
  412. return
  413. epdconfig.digital_write(self.reset_pin, 0)
  414. epdconfig.delay_ms(2)
  415. epdconfig.digital_write(self.reset_pin, 1)
  416. epdconfig.delay_ms(2)
  417. self.SetLut(self.WF_PARTIAL_2IN9)
  418. self.send_command(0x37)
  419. self.send_data(0x00)
  420. self.send_data(0x00)
  421. self.send_data(0x00)
  422. self.send_data(0x00)
  423. self.send_data(0x00)
  424. self.send_data(0x40)
  425. self.send_data(0x00)
  426. self.send_data(0x00)
  427. self.send_data(0x00)
  428. self.send_data(0x00)
  429. self.send_command(0x3C) #BorderWavefrom
  430. self.send_data(0x80)
  431. self.send_command(0x22)
  432. self.send_data(0xC0)
  433. self.send_command(0x20)
  434. self.ReadBusy()
  435. self.SetWindow(0, 0, self.width - 1, self.height - 1)
  436. self.SetCursor(0, 0)
  437. self.send_command(0x24) # WRITE_RAM
  438. self.send_data2(image)
  439. self.TurnOnDisplay_Partial()
  440. def Clear(self, color=0xFF):
  441. if self.width%8 == 0:
  442. linewidth = int(self.width/8)
  443. else:
  444. linewidth = int(self.width/8) + 1
  445. self.send_command(0x24) # WRITE_RAM
  446. self.send_data2([color] * int(self.height * linewidth))
  447. self.TurnOnDisplay()
  448. self.send_command(0x26) # WRITE_RAM
  449. self.send_data2([color] * int(self.height * linewidth))
  450. self.TurnOnDisplay()
  451. def sleep(self):
  452. self.send_command(0x10) # DEEP_SLEEP_MODE
  453. self.send_data(0x01)
  454. epdconfig.delay_ms(2000)
  455. epdconfig.module_exit()
  456. ### END OF FILE ###