epd5in79.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. # *****************************************************************************
  2. # * | File : epd5in79.py
  3. # * | Author : Waveshare team
  4. # * | Function : Electronic paper driver
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.0
  8. # * | Date : 2024-03-05
  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 = 792
  33. EPD_HEIGHT = 272
  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. self.LUT_DATA_4Gray = [
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x01, 0x4A, 0x00, 0x00, 0x00, 0x01, 0x00,
  59. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  60. 0x01, 0x8A, 0x00, 0x00, 0x00, 0x01, 0x00,
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  62. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x01, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00,
  65. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  66. 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00,
  71. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  72. 0x01, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00,
  73. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  76. 0x01, 0x8A, 0x00, 0x00, 0x00, 0x01, 0x00,
  77. 0x01, 0x82, 0x42, 0x00, 0x00, 0x10, 0x00,
  78. 0x01, 0x4A, 0x00, 0x00, 0x00, 0x01, 0x00,
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  82. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84. 0x02, 0x00, 0x00,
  85. 0x22, 0x17, 0x41, 0xA8, 0x32, 0x40, ]
  86. # Hardware reset
  87. def reset(self):
  88. epdconfig.digital_write(self.reset_pin, 1)
  89. epdconfig.delay_ms(200)
  90. epdconfig.digital_write(self.reset_pin, 0)
  91. epdconfig.delay_ms(1)
  92. epdconfig.digital_write(self.reset_pin, 1)
  93. epdconfig.delay_ms(200)
  94. def send_command(self, command):
  95. epdconfig.digital_write(self.dc_pin, 0)
  96. epdconfig.digital_write(self.cs_pin, 0)
  97. epdconfig.spi_writebyte([command])
  98. epdconfig.digital_write(self.cs_pin, 1)
  99. def send_data(self, data):
  100. epdconfig.digital_write(self.dc_pin, 1)
  101. epdconfig.digital_write(self.cs_pin, 0)
  102. epdconfig.spi_writebyte([data])
  103. epdconfig.digital_write(self.cs_pin, 1)
  104. # send a lot of data
  105. def send_data2(self, data):
  106. epdconfig.digital_write(self.dc_pin, 1)
  107. epdconfig.digital_write(self.cs_pin, 0)
  108. epdconfig.spi_writebyte2(data)
  109. epdconfig.digital_write(self.cs_pin, 1)
  110. def ReadBusy(self):
  111. logger.debug("e-Paper busy")
  112. while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
  113. epdconfig.delay_ms(200)
  114. logger.debug("e-Paper busy release")
  115. def TurnOnDisplay(self):
  116. self.send_command(0x22)
  117. self.send_data(0xF7)
  118. self.send_command(0x20) # DISPLAY REFRESH
  119. epdconfig.delay_ms(100) # The delay here is necessary, 200uS at least!!!
  120. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  121. def TurnOnDisplay_Fast(self):
  122. self.send_command(0x22)
  123. self.send_data(0xC7)
  124. self.send_command(0x20) # DISPLAY REFRESH
  125. epdconfig.delay_ms(100) # The delay here is necessary, 200uS at least!!!
  126. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  127. def TurnOnDisplay_Partial(self):
  128. self.send_command(0x22)
  129. self.send_data(0xFF)
  130. self.send_command(0x20) # DISPLAY REFRESH
  131. epdconfig.delay_ms(100) # The delay here is necessary, 200uS at least!!!
  132. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  133. def TurnOnDisplay_4GRAY(self):
  134. self.send_command(0x22)
  135. self.send_data(0xCF)
  136. self.send_command(0x20) # DISPLAY REFRESH
  137. epdconfig.delay_ms(100) # The delay here is necessary, 200uS at least!!!
  138. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  139. def EPD_5in79_Lut(self):
  140. self.send_command(0x32)
  141. self.send_data2(self.LUT_DATA_4Gray[:227])
  142. self.send_command(0x3f)
  143. self.send_data(self.LUT_DATA_4Gray[227])
  144. self.send_command(0x03)
  145. self.send_data(self.LUT_DATA_4Gray[228])
  146. self.send_command(0x04)
  147. self.send_data(self.LUT_DATA_4Gray[229])
  148. self.send_data(self.LUT_DATA_4Gray[230])
  149. self.send_data(self.LUT_DATA_4Gray[231])
  150. self.send_command(0x2C)
  151. self.send_data(self.LUT_DATA_4Gray[232])
  152. def init(self):
  153. if (epdconfig.module_init() != 0):
  154. return -1
  155. self.reset()
  156. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  157. self.send_command(0x12) # POWER ON
  158. self.ReadBusy() # waiting for the electronic paper IC to release the idle signal
  159. self.send_command(0x11)
  160. self.send_data(0x01)
  161. self.send_command(0x44) # Set Ram X- address Start / End position
  162. self.send_data(0x00) # XStart, POR = 00h
  163. self.send_data(0x31) # 400/8-1
  164. self.send_command(0x45) # Set Ram Y- address Start / End position
  165. self.send_data(0x0f)
  166. self.send_data(0x01) # 300-1
  167. self.send_data(0x00) # YEnd L
  168. self.send_data(0x00) # YEnd H
  169. self.send_command(0x4e)
  170. self.send_data(0x00)
  171. self.send_command(0x4f)
  172. self.send_data(0x0f)
  173. self.send_data(0x01)
  174. self.ReadBusy()
  175. self.send_command(0x91)
  176. self.send_data(0x00)
  177. self.send_command(0xC4) # Set Ram X- address Start / End position
  178. self.send_data(0x31) # XStart, POR = 00h
  179. self.send_data(0x00) # 400/8-1
  180. self.send_command(0xC5) # Set Ram Y- address Start / End position
  181. self.send_data(0x0f)
  182. self.send_data(0x01) # 300-1
  183. self.send_data(0x00) # YEnd L
  184. self.send_data(0x00) # YEnd H
  185. self.send_command(0xCE)
  186. self.send_data(0x31)
  187. self.send_command(0xCF)
  188. self.send_data(0x0f)
  189. self.send_data(0x01)
  190. self.ReadBusy()
  191. return 0
  192. def init_Fast(self):
  193. if (epdconfig.module_init() != 0):
  194. return -1
  195. self.reset()
  196. self.ReadBusy()
  197. self.send_command(0x12)
  198. self.ReadBusy()
  199. self.send_command(0x18)
  200. self.send_data(0x80)
  201. self.send_command(0x22)
  202. self.send_data(0xB1)
  203. self.send_command(0x20)
  204. self.ReadBusy()
  205. self.send_command(0x1A)
  206. self.send_data(0x64)
  207. self.send_data(0x00)
  208. self.send_command(0x22)
  209. self.send_data(0x91)
  210. self.send_command(0x20)
  211. self.ReadBusy()
  212. self.send_command(0x11)
  213. self.send_data(0x01)
  214. self.send_command(0x44)
  215. self.send_data(0x00)
  216. self.send_data(0x31)
  217. self.send_command(0x45)
  218. self.send_data(0x0f)
  219. self.send_data(0x01)
  220. self.send_data(0x00)
  221. self.send_data(0x00)
  222. self.send_command(0x4e)
  223. self.send_data(0x00)
  224. self.send_command(0x4f)
  225. self.send_data(0x0f)
  226. self.send_data(0x01)
  227. self.ReadBusy()
  228. self.send_command(0x91)
  229. self.send_data(0x00)
  230. self.send_command(0xC4)
  231. self.send_data(0x31)
  232. self.send_data(0x00)
  233. self.send_command(0xC5)
  234. self.send_data(0x0f)
  235. self.send_data(0x01)
  236. self.send_data(0x00)
  237. self.send_data(0x00)
  238. self.send_command(0xCe)
  239. self.send_data(0x31)
  240. self.send_command(0xCf)
  241. self.send_data(0x0f)
  242. self.send_data(0x01)
  243. self.ReadBusy()
  244. return 0
  245. def init_Partial(self):
  246. if (epdconfig.module_init() != 0):
  247. return -1
  248. self.reset()
  249. self.ReadBusy()
  250. self.send_command(0x12)
  251. self.ReadBusy()
  252. self.send_command(0x3C)
  253. self.send_data(0x80)
  254. return 0
  255. def init_4Gray(self):
  256. if (epdconfig.module_init() != 0):
  257. return -1
  258. self.reset()
  259. self.ReadBusy()
  260. self.send_command(0x12)
  261. self.ReadBusy()
  262. self.send_command(0x0C)
  263. self.send_data(0x8B)
  264. self.send_data(0x9C)
  265. self.send_data(0xA6)
  266. self.send_data(0x0F)
  267. self.send_command(0x3C)
  268. self.send_data(0x81)
  269. self.ReadBusy()
  270. self.send_command(0x11)
  271. self.send_data(0x01)
  272. self.send_command(0x44)
  273. self.send_data(0x00)
  274. self.send_data(0x31)
  275. self.send_command(0x45)
  276. self.send_data(0x0f)
  277. self.send_data(0x01)
  278. self.send_data(0x00)
  279. self.send_data(0x00)
  280. self.send_command(0x4e)
  281. self.send_data(0x00)
  282. self.send_command(0x4f)
  283. self.send_data(0x0f)
  284. self.send_data(0x01)
  285. self.ReadBusy()
  286. self.send_command(0x91)
  287. self.send_data(0x00)
  288. self.send_command(0xC4)
  289. self.send_data(0x31)
  290. self.send_data(0x00)
  291. self.send_command(0xC5)
  292. self.send_data(0x0f)
  293. self.send_data(0x01)
  294. self.send_data(0x00)
  295. self.send_data(0x00)
  296. self.send_command(0xCe)
  297. self.send_data(0x31)
  298. self.send_command(0xCf)
  299. self.send_data(0x0f)
  300. self.send_data(0x01)
  301. self.EPD_5in79_Lut()
  302. return 0
  303. def getbuffer(self, image):
  304. # logger.debug("bufsiz = ",int(self.width/8) * self.height)
  305. buf = [0xFF] * (int(self.width / 8) * self.height)
  306. image_monocolor = image.convert('1')
  307. imwidth, imheight = image_monocolor.size
  308. pixels = image_monocolor.load()
  309. # logger.debug("imwidth = %d, imheight = %d",imwidth,imheight)
  310. if imwidth == self.width and imheight == self.height:
  311. logger.debug("Horizontal")
  312. for y in range(imheight):
  313. for x in range(imwidth):
  314. # Set the bits for the column of pixels at the current position.
  315. if pixels[x, y] == 0:
  316. buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8))
  317. elif imwidth == self.height and imheight == self.width:
  318. logger.debug("Vertical")
  319. for y in range(imheight):
  320. for x in range(imwidth):
  321. newx = y
  322. newy = self.height - x - 1
  323. if pixels[x, y] == 0:
  324. buf[int((newx + newy * self.width) / 8)] &= ~(0x80 >> (y % 8))
  325. return buf
  326. def getbuffer_4Gray(self, image):
  327. # logger.debug("bufsiz = ",int(self.width/8) * self.height)
  328. buf = [0xFF] * (int(self.width / 4) * self.height)
  329. image_monocolor = image.convert('L')
  330. imwidth, imheight = image_monocolor.size
  331. pixels = image_monocolor.load()
  332. i=0
  333. # logger.debug("imwidth = %d, imheight = %d",imwidth,imheight)
  334. if(imwidth == self.width and imheight == self.height):
  335. logger.debug("Vertical")
  336. for y in range(imheight):
  337. for x in range(imwidth):
  338. # Set the bits for the column of pixels at the current position.
  339. if(pixels[x, y] == 0xC0):
  340. pixels[x, y] = 0x80
  341. elif (pixels[x, y] == 0x80):
  342. pixels[x, y] = 0x40
  343. i= i+1
  344. if(i%4 == 0):
  345. 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)
  346. elif(imwidth == self.height and imheight == self.width):
  347. logger.debug("Horizontal")
  348. for x in range(imwidth):
  349. for y in range(imheight):
  350. newx = y
  351. newy = self.height - x - 1
  352. if(pixels[x, y] == 0xC0):
  353. pixels[x, y] = 0x80
  354. elif (pixels[x, y] == 0x80):
  355. pixels[x, y] = 0x40
  356. i= i+1
  357. if(i%4 == 0):
  358. 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)
  359. return buf
  360. def display(self, imageblack):
  361. Width =int(self.width / 16)+1
  362. Width1 =int(self.width / 8)
  363. self.send_command(0x24)
  364. for i in range(self.height):
  365. self.send_data2(imageblack[i * Width1 : i * Width1+Width])
  366. self.send_command(0X26)
  367. self.send_data2([0x00] * 13600)
  368. self.send_command(0xA4)
  369. for i in range(self.height):
  370. self.send_data2(imageblack[i * Width1 + Width - 1 : i * Width1 + Width * 2 - 1])
  371. self.send_command(0xA6)
  372. self.send_data2([0x00] * 13600)
  373. self.TurnOnDisplay()
  374. def display_Base(self, imageblack):
  375. Width =int(self.width / 16)+1
  376. Width1 =int(self.width / 8)
  377. self.send_command(0x24)
  378. for i in range(self.height):
  379. self.send_data2(imageblack[i * Width1 : i * Width1+Width])
  380. self.send_command(0X26)
  381. self.send_data2([0x00] * 13600)
  382. self.send_command(0xA4)
  383. for i in range(self.height):
  384. self.send_data2(imageblack[i * Width1 + Width - 1 : i * Width1 + Width * 2 - 1])
  385. self.send_command(0xA6)
  386. self.send_data2([0x00] * 13600)
  387. self.TurnOnDisplay()
  388. self.send_command(0x26)
  389. for i in range(self.height):
  390. self.send_data2(imageblack[i * Width1 : i * Width1+Width])
  391. self.send_command(0xA6)
  392. for i in range(self.height):
  393. self.send_data2(imageblack[i * Width1 + Width - 1 : i * Width1 + Width * 2 - 1])
  394. def display_Base_color(self, color):
  395. Width =int(self.width / 16)+1
  396. Width1 =int(self.width / 8)
  397. self.send_command(0x24)
  398. self.send_data2([color] * 13600)
  399. self.send_command(0X26)
  400. self.send_data2([0x00] * 13600)
  401. self.send_command(0xA4)
  402. self.send_data2([color] * 13600)
  403. self.send_command(0xA6)
  404. self.send_data2([0x00] * 13600)
  405. self.TurnOnDisplay()
  406. self.send_command(0x26)
  407. self.send_data2([color] * 13600)
  408. self.send_command(0xA6)
  409. self.send_data2([color] * 13600)
  410. def display_Fast(self, imageblack):
  411. Width =int(self.width / 16)+1
  412. Width1 =int(self.width / 8)
  413. self.send_command(0x24)
  414. for i in range(self.height):
  415. self.send_data2(imageblack[i * Width1 : i * Width1+Width])
  416. self.send_command(0X26)
  417. self.send_data2([0x00] * 13600)
  418. self.send_command(0xA4)
  419. for i in range(self.height):
  420. self.send_data2(imageblack[i * Width1 + Width - 1 : i * Width1 + Width * 2 - 1])
  421. self.send_command(0xA6)
  422. self.send_data2([0x00] * 13600)
  423. self.TurnOnDisplay_Fast()
  424. def display_Partial(self, Image):
  425. Width =int(self.width / 16)+1
  426. Width1 =int(self.width / 8)
  427. Height = self.height
  428. self.send_command(0x44)
  429. self.send_data(0x00)
  430. self.send_data(0x31)
  431. self.send_command(0x45)
  432. self.send_data(0x0f)
  433. self.send_data(0x01) # 300-1
  434. self.send_data(0x00) # YEnd L
  435. self.send_data(0x00) # YEnd H
  436. self.send_command(0x4e)
  437. self.send_data(0x00)
  438. self.send_command(0x4f)
  439. self.send_data(0x0f)
  440. self.send_data(0x01)
  441. self.send_command(0x24)
  442. for i in range(Height):
  443. self.send_data2(Image[i * Width1 : i * Width1+Width])
  444. self.send_command(0xC4) # Set Ram X- address Start / End position
  445. self.send_data(0x31) # XStart, POR = 00h
  446. self.send_data(0x00) # 400/8-1
  447. self.send_command(0xC5) # Set Ram Y- address Start / End position
  448. self.send_data(0x0f)
  449. self.send_data(0x01) # 300-1
  450. self.send_data(0x00) # YEnd L
  451. self.send_data(0x00) # YEnd H
  452. self.send_command(0xCe)
  453. self.send_data(0x31)
  454. self.send_command(0xCf)
  455. self.send_data(0x0f)
  456. self.send_data(0x01)
  457. self.send_command(0xA4)
  458. for i in range(Height):
  459. self.send_data2(Image[i * Width1 + Width - 1 : i * Width1 + Width * 2 - 1])
  460. self.TurnOnDisplay_Partial()
  461. def display_4Gray(self, image):
  462. Width =int(self.width / 16)+1
  463. Width1 =int(self.width / 8)
  464. self.send_command(0x24)
  465. for j in range(self.height):
  466. for i in range(Width):
  467. temp3=0
  468. for o in range(0, 2):
  469. temp1 = image[(j * Width1 + i)*2+o]
  470. for k in range(0, 4):
  471. temp2 = temp1&0xC0
  472. if(temp2 == 0xC0):
  473. temp3 |= 0x01
  474. elif(temp2 == 0x00):
  475. temp3 |= 0x00
  476. elif(temp2 == 0x80):
  477. temp3 |= 0x00
  478. else: #0x40
  479. temp3 |= 0x01
  480. if(o!=1 or k!=3):
  481. temp3 <<= 1
  482. temp1 <<= 2
  483. self.send_data(temp3)
  484. self.send_command(0x26)
  485. for j in range(self.height):
  486. for i in range(Width):
  487. temp3=0
  488. for o in range(0, 2):
  489. temp1 = image[(j * Width1 + i)*2+o]
  490. for k in range(0, 4):
  491. temp2 = temp1&0xC0
  492. if(temp2 == 0xC0):
  493. temp3 |= 0x01
  494. elif(temp2 == 0x00):
  495. temp3 |= 0x00
  496. elif(temp2 == 0x80):
  497. temp3 |= 0x01
  498. else: #0x40
  499. temp3 |= 0x00
  500. if(o!=1 or k!=3):
  501. temp3 <<= 1
  502. temp1 <<= 2
  503. self.send_data(temp3)
  504. self.send_command(0xA4)
  505. for j in range(self.height):
  506. for i in range(Width):
  507. temp3=0
  508. for o in range(0, 2):
  509. temp1 = image[(j * Width1 + i + Width - 1)*2+o]
  510. for k in range(0, 4):
  511. temp2 = temp1&0xC0
  512. if(temp2 == 0xC0):
  513. temp3 |= 0x01
  514. elif(temp2 == 0x00):
  515. temp3 |= 0x00
  516. elif(temp2 == 0x80):
  517. temp3 |= 0x00
  518. else: #0x40
  519. temp3 |= 0x01
  520. if(o!=1 or k!=3):
  521. temp3 <<= 1
  522. temp1 <<= 2
  523. self.send_data(temp3)
  524. self.send_command(0xA6)
  525. for j in range(self.height):
  526. for i in range(Width):
  527. temp3=0
  528. for o in range(0, 2):
  529. temp1 = image[(j * Width1 + i + Width - 1)*2+o]
  530. for k in range(0, 4):
  531. temp2 = temp1&0xC0
  532. if(temp2 == 0xC0):
  533. temp3 |= 0x01
  534. elif(temp2 == 0x00):
  535. temp3 |= 0x00
  536. elif(temp2 == 0x80):
  537. temp3 |= 0x01
  538. else: #0x40
  539. temp3 |= 0x00
  540. if(o!=1 or k!=3):
  541. temp3 <<= 1
  542. temp1 <<= 2
  543. self.send_data(temp3)
  544. self.TurnOnDisplay_4GRAY()
  545. def Clear(self):
  546. self.send_command(0x24)
  547. self.send_data2([0xFF] * 13600)
  548. self.send_command(0X26)
  549. self.send_data2([0x00] * 13600)
  550. self.send_command(0xA4)
  551. self.send_data2([0xFF] * 13600)
  552. self.send_command(0xA6)
  553. self.send_data2([0x00] * 13600)
  554. self.TurnOnDisplay()
  555. def sleep(self):
  556. self.send_command(0X10) # deep sleep
  557. self.send_data(0x03)
  558. epdconfig.delay_ms(2000)
  559. epdconfig.module_exit()
  560. ### END OF FILE ###