summaryrefslogtreecommitdiff
path: root/bin/script.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/script.py')
-rw-r--r--bin/script.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/bin/script.py b/bin/script.py
new file mode 100644
index 0000000..5c33638
--- /dev/null
+++ b/bin/script.py
@@ -0,0 +1,109 @@
1from smbus2 import SMBus
2from time import sleep
3
4import speech_recognition as sr
5import sounddevice
6import os
7
8ALIGN_FUNC = {
9 'left': 'ljust',
10 'right': 'rjust',
11 'center': 'center'}
12CLEAR_DISPLAY = 0x01
13ENABLE_BIT = 0b00000100
14LINES = {
15 1: 0x80,
16 2: 0xC0,
17 3: 0x94,
18 4: 0xD4}
19
20LCD_BACKLIGHT = 0x08
21LCD_NOBACKLIGHT = 0x00
22
23ERROR_BAD_REQUEST = '400'
24ERROR_UNAUTHORIZED = '401'
25ERROR_NOT_FOUND = '404'
26ERROR_TIMEOUT = '408'
27
28class LCD(object):
29
30 def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
31 self.address = address
32 self.bus = SMBus(bus)
33 self.delay = 0.0005
34 self.rows = rows
35 self.width = width
36 self.backlight_status = backlight
37
38 self.write(0x33)
39 self.write(0x32)
40 self.write(0x06)
41 self.write(0x0C)
42 self.write(0x28)
43 self.write(CLEAR_DISPLAY)
44 sleep(self.delay)
45
46 def _write_byte(self, byte):
47 self.bus.write_byte(self.address, byte)
48 self.bus.write_byte(self.address, (byte | ENABLE_BIT))
49 sleep(self.delay)
50 self.bus.write_byte(self.address,(byte & ~ENABLE_BIT))
51 sleep(self.delay)
52
53 def write(self, byte, mode=0):
54 backlight_mode = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT
55 self._write_byte(mode | ((byte << 4) & 0xF0) | backlight_mode)
56
57 def text(self, text, line, align='left'):
58 self.write(LINES.get(line, LINES[1]))
59 text, other_lines = self.get_text_line(text)
60 text = getattr(text, ALIGN_FUNC.get(align, 'ljust'))(self.width)
61 for char in text:
62 self.write(ord(char), mode=1)
63 if other_lines and line <= self.rows - 1:
64 self.text(other_lines, line + 1, align=align)
65
66 def backlight(self, turn_on=True):
67 self.backlight_status = turn_on
68 self.write(0)
69
70 def get_text_line(self, text):
71 line_break = self.width
72 if len(text) > self.width:
73 line_break = text[:self.width + 1].rfind(' ')
74 if line_break < 0:
75 line_break = self.width
76 return text[:line_break], text[line_break:].strip()
77
78 def clear(self):
79 self.write(CLEAR_DISPLAY)
80
81
82
83LCD = LCD()
84VOICE_REC = sr.Recognizer()
85MIC = sr.Microphone()
86PROCES_LOAD = os.getloadavg()
87TIME = current_time.time()
88UPTIME = time.CLOCK_UPTIME()
89
90
91
92def CPU_INFO():
93 while (True):
94 LCD.text(PROCES_LOAD(),1,left)
95
96def CURRENT_TIME():
97 while True:
98 backlight_mode = true
99 LCD.text(UPTIME,1,left)
100 LCD.text(TIME,2,center)
101
102
103
104
105OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU LOAD", "NOTES"]
106
107def USER_GUI():
108 print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ")
109 print(OPTIONS)