summaryrefslogtreecommitdiff
path: root/bin/kasper_source.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/kasper_source.py')
-rw-r--r--bin/kasper_source.py98
1 files changed, 52 insertions, 46 deletions
diff --git a/bin/kasper_source.py b/bin/kasper_source.py
index 4ff5e70..50fb48c 100644
--- a/bin/kasper_source.py
+++ b/bin/kasper_source.py
@@ -1,30 +1,23 @@
from smbus2 import SMBus
from time import sleep
from gpiozero import CPUTemperature
-
import speech_recognition as sr
-import sounddevice
+import time
import os
-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
-ERROR_BAD_REQUEST = '400'
-ERROR_UNAUTHORIZED = '401'
-ERROR_NOT_FOUND = '404'
-ERROR_TIMEOUT = '408'
+ERROR_BAD_REQUEST = "400"
+ERROR_UNAUTHORIZED = "401"
+ERROR_NOT_FOUND = "404"
+ERROR_TIMEOUT = "408"
+
class LCD(object):
@@ -48,17 +41,17 @@ 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):
backlight_mode = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT
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:
@@ -71,7 +64,7 @@ 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()
@@ -79,30 +72,34 @@ class LCD(object):
def clear(self):
self.write(CLEAR_DISPLAY)
+
LCD_DISPLAY = LCD()
VOICE_REC = sr.Recognizer()
MIC = sr.Microphone()
PROCES_LOAD = os.getloadavg()
-TIME = current_time.time()
+TIME = time.localtime()
+CURRENT_TIME = time.strftime("%H:%M:%S", TIME)
UPTIME = time.CLOCK_UPTIME()
CPU_TEMP = CPUTemperature()
# clearing the lcd from any text that was on it before the program started to ensure smooth operations
-lcd.clear()
+LCD_DISPLAY.clear()
+
# Listening to the user's voice and putting it into a variable
def listen_voice():
global audio
- with mic as source:
- r.adjust_for_ambient_noise(source)
- audio = r.listen(source)
+ with MIC as source:
+ VOICE_REC.adjust_for_ambient_noise(source)
+ audio = VOICE_REC.listen(source)
return audio
+
# Transcribing the audio to text and printing it out
-# Using the Google Speech Recognizer
+# Using the Google Speech Recognizer
def recognize_speech(audio):
try:
- words = r.recognize_google(audio)
+ words = VOICE_REC.recognize_google(audio)
LCD_DISPLAY.text(words, 1)
print(f"Printing on screen: {words}")
except sr.UnknownValueError:
@@ -110,40 +107,48 @@ def recognize_speech(audio):
print(ERROR_BAD_REQUEST)
except sr.RequestError:
LCD_DISPLAY.text(ERROR_UNAUTHORIZED, 1)
- print(ERROR_UNAUTHORIZED)
+ print(ERROR_UNAUTHORIZED)
+
def CPU_INFO():
print("you chose to display the cpou")
- while (True):
- LCD.text(PROCES_LOAD(),1,left)
-
-def CURRENT_TIME():
while True:
- backlight_mode = True
- LCD.text(TIME,2,center)
+ LCD.text(
+ PROCES_LOAD(),
+ 1,
+ )
-def UPTIME():
- while True:
- LCD.text(UPTIME,1,left)
-
-def CPU_TEMP():
- while True:
- LCD.text(cpu.temperature)
def CPU_LOAD():
- backlight_mode = True
- LCD.text(PROCES_LOAD,1,left)
+ LCD.backlight_mode = True
+ LCD.text(
+ PROCES_LOAD,
+ 1,
+ )
+
def NOTES():
count = 0
user_notes = input()
for i in user_notes:
while count < 20:
- lcd.text(i,1,left)
+ LCD_DISPLAY.text(
+ i,
+ 1,
+ )
count += 1
-
-OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU_LOAD", "NOTES", "SPEECH_TRANSCRIBER"]
+
+OPTIONS = [
+ "CPU_CLOCK",
+ "TIME",
+ "UPTIME",
+ "CPU_TEMP",
+ "CPU_LOAD",
+ "NOTES",
+ "SPEECH_TRANSCRIBER",
+]
+
def PROGRAM(USER_INPUT):
print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ")
@@ -159,4 +164,5 @@ def PROGRAM(USER_INPUT):
else:
print(ERROR_NOT_FOUND)
-PROGRAM() \ No newline at end of file
+
+PROGRAM()