summaryrefslogtreecommitdiff
path: root/bin/script.py
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2024-11-07 17:00:19 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2024-11-07 17:00:19 +0100
commit32ec9336088799c42d8aa7ace6648802e1b267cf (patch)
treebc6d718631a2f2a210b4cde462a5f7f97bd6b613 /bin/script.py
parentfa7007d00c04fc73f668e2b7f339c3f60a64d055 (diff)
did alot of designing and testing out on a linux machine
Diffstat (limited to 'bin/script.py')
-rw-r--r--bin/script.py109
1 files changed, 0 insertions, 109 deletions
diff --git a/bin/script.py b/bin/script.py
deleted file mode 100644
index 5c33638..0000000
--- a/bin/script.py
+++ /dev/null
@@ -1,109 +0,0 @@
-from smbus2 import SMBus
-from time import sleep
-
-import speech_recognition as sr
-import sounddevice
-import os
-
-ALIGN_FUNC = {
- 'left': 'ljust',
- 'right': 'rjust',
- 'center': 'center'}
-CLEAR_DISPLAY = 0x01
-ENABLE_BIT = 0b00000100
-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'
-
-class LCD(object):
-
- def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
- self.address = address
- self.bus = SMBus(bus)
- self.delay = 0.0005
- self.rows = rows
- self.width = width
- self.backlight_status = backlight
-
- self.write(0x33)
- self.write(0x32)
- self.write(0x06)
- self.write(0x0C)
- self.write(0x28)
- self.write(CLEAR_DISPLAY)
- sleep(self.delay)
-
- def _write_byte(self, byte):
- 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))
- 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'):
- 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)
- for char in text:
- self.write(ord(char), mode=1)
- if other_lines and line <= self.rows - 1:
- self.text(other_lines, line + 1, align=align)
-
- def backlight(self, turn_on=True):
- self.backlight_status = turn_on
- self.write(0)
-
- def get_text_line(self, text):
- line_break = self.width
- if len(text) > self.width:
- 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)
-
-
-
-LCD = LCD()
-VOICE_REC = sr.Recognizer()
-MIC = sr.Microphone()
-PROCES_LOAD = os.getloadavg()
-TIME = current_time.time()
-UPTIME = time.CLOCK_UPTIME()
-
-
-
-def CPU_INFO():
- while (True):
- LCD.text(PROCES_LOAD(),1,left)
-
-def CURRENT_TIME():
- while True:
- backlight_mode = true
- LCD.text(UPTIME,1,left)
- LCD.text(TIME,2,center)
-
-
-
-
-OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU LOAD", "NOTES"]
-
-def USER_GUI():
- print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ")
- print(OPTIONS)