From 16d54ef337f510e2dce2158d5cb95e26b29c9c57 Mon Sep 17 00:00:00 2001 From: nasrlol Date: Sun, 24 Nov 2024 16:13:37 +0100 Subject: fixed the bulk of the code so everyhting is running fine for now but i realised that the libraries i was using arent really all comatibnle with the rpi pico so features like speech transcription wont be working i think unless i can find a work around, because usb microphones arent an option i could maybe get some audio to get outputted using some DAC module or something still dont know, besied that there is still an issue with the pomodoro time display, still figuring out to setup a time count down that counts minutes and seconds --- bin/source/hardware_driver.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'bin/source/hardware_driver.py') diff --git a/bin/source/hardware_driver.py b/bin/source/hardware_driver.py index 1afb219..7d48e69 100644 --- a/bin/source/hardware_driver.py +++ b/bin/source/hardware_driver.py @@ -1,15 +1,21 @@ -from smbus2 import SMBus +from smbus import SMBus from time import sleep -ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"} +ALIGN_FUNC = { + 'left': 'ljust', + 'right': 'rjust', + 'center': 'center'} CLEAR_DISPLAY = 0x01 ENABLE_BIT = 0b00000100 -LINES = {1: 0x80, 2: 0xC0, 3: 0x94, 4: 0xD4} +LINES = { + 1: 0x80, + 2: 0xC0, + 3: 0x94, + 4: 0xD4} LCD_BACKLIGHT = 0x08 LCD_NOBACKLIGHT = 0x00 - class LCD(object): def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True): @@ -32,7 +38,7 @@ class LCD(object): self.bus.write_byte(self.address, byte) self.bus.write_byte(self.address, (byte | ENABLE_BIT)) sleep(self.delay) - self.bus.write_byte(self.address, (byte & ~ENABLE_BIT)) + self.bus.write_byte(self.address,(byte & ~ENABLE_BIT)) sleep(self.delay) def write(self, byte, mode=0): @@ -40,10 +46,10 @@ class LCD(object): self._write_byte(mode | (byte & 0xF0) | backlight_mode) self._write_byte(mode | ((byte << 4) & 0xF0) | backlight_mode) - def text(self, text, line, align="left"): + def text(self, text, line, align='left'): self.write(LINES.get(line, LINES[1])) text, other_lines = self.get_text_line(text) - text = getattr(text, ALIGN_FUNC.get(align, "ljust"))(self.width) + text = getattr(text, ALIGN_FUNC.get(align, 'ljust'))(self.width) for char in text: self.write(ord(char), mode=1) if other_lines and line <= self.rows - 1: @@ -56,13 +62,10 @@ class LCD(object): def get_text_line(self, text): line_break = self.width if len(text) > self.width: - line_break = text[: self.width + 1].rfind(" ") + line_break = text[:self.width + 1].rfind(' ') if line_break < 0: line_break = self.width return text[:line_break], text[line_break:].strip() def clear(self): self.write(CLEAR_DISPLAY) - - def read(self): - self._read_i2c_block_data -- cgit v1.2.3-70-g09d2