23 lines
No EOL
794 B
Python
23 lines
No EOL
794 B
Python
import asyncio
|
|
from LCD import LCD
|
|
|
|
class display:
|
|
def __init__(self, width=20, height=4, i2c_addr=0x27):
|
|
self.width = width
|
|
self.height = height
|
|
self.device = LCD(2, i2c_addr, True)
|
|
self.contents = [""] * self.height
|
|
|
|
async def redraw(self, row = None):
|
|
if row == None:
|
|
for row, line in enumerate(self.contents):
|
|
await self.device.async_message(line, row + 1)
|
|
else:
|
|
await self.device.async_message(self.contents[row - 1], row)
|
|
|
|
async def read(self, row):
|
|
return self.contents[row]
|
|
|
|
async def write(self, row, data, offset = 0):
|
|
self.contents[row - 1] = f'{self.contents[row][:offset]}{data}{self.contents[row][offset+len(data):]}'
|
|
await self.redraw(row) |