summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authornasrlol <nsrddyn@gmail.com>2024-11-13 00:30:41 +0100
committernasrlol <nsrddyn@gmail.com>2024-11-13 00:30:41 +0100
commitecd194028a652cc29f300e4a6ca24675b5b8d9ba (patch)
tree4732c5edc5d8f30f5bacc6823298e4365cebc1fb /bin
parent0a7689fbf896aa3629f9783c4316a4b453928b6f (diff)
fixed the speechtranscriber bug
Diffstat (limited to 'bin')
-rw-r--r--bin/kasper_source.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/bin/kasper_source.py b/bin/kasper_source.py
index bd61942..d878f6c 100644
--- a/bin/kasper_source.py
+++ b/bin/kasper_source.py
@@ -19,6 +19,7 @@ ERROR_TIMEOUT = "408 Request Timeout"
# LCD Control Class
class LCD:
+
def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
self.address = address
self.bus = SMBus(bus)
@@ -26,14 +27,17 @@ class LCD:
self.rows = rows
self.backlight_status = backlight
self.delay = 0.0005
+
# LCD Initialization
for cmd in (0x33, 0x32, 0x06, 0x0C, 0x28, 0x01):
self.write(cmd)
time.sleep(self.delay)
+
def write(self, byte, mode=0):
"""Send a command or character to the LCD."""
backlight = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT
self._write_byte(mode | ((byte << 4) & 0xF0) | backlight)
+
def _write_byte(self, byte):
"""Write a byte to the I2C bus."""
self.bus.write_byte(self.address, byte)
@@ -41,15 +45,18 @@ class LCD:
time.sleep(self.delay)
self.bus.write_byte(self.address, (byte & ~ENABLE_BIT))
time.sleep(self.delay)
+
def display_text(self, text, line=1, align="left"):
"""Display text on a specified line with alignment."""
self.write(LINES.get(line, LINES[1]))
aligned_text = getattr(text, ALIGN_FUNC.get(align, "ljust"))(self.width)
for char in aligned_text:
self.write(ord(char), mode=1)
+
def clear(self):
"""Clear the display."""
self.write(0x01)
+
def set_backlight(self, turn_on=True):
"""Toggle backlight on or off."""
self.backlight_status = turn_on
@@ -97,7 +104,7 @@ def recognize_speech():
except speech.UnknownValueError:
lcd.display_text(ERROR_BAD_REQUEST, line=1)
print(ERROR_BAD_REQUEST)
- except s.RequestError:
+ except speech.RequestError:
lcd.display_text(ERROR_UNAUTHORIZED, line=1)
print(ERROR_UNAUTHORIZED)