diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 18:40:27 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2024-11-05 18:40:27 +0100 |
| commit | fa7007d00c04fc73f668e2b7f339c3f60a64d055 (patch) | |
| tree | 1c054d4f10759201134d496dbe170e2cfe49bfe5 | |
| parent | d7b8b6ae21c07fe52e691e9090c24de0d09a401f (diff) | |
did alot :)
| -rw-r--r-- | .idea/.gitignore | 3 | ||||
| -rw-r--r-- | .idea/inspectionProfiles/profiles_settings.xml | 6 | ||||
| -rw-r--r-- | .idea/misc.xml | 7 | ||||
| -rw-r--r-- | .idea/modules.xml | 8 | ||||
| -rw-r--r-- | .idea/security.iml | 8 | ||||
| -rw-r--r-- | .idea/vcs.xml | 6 | ||||
| -rw-r--r-- | .script.py.swp | bin | 12288 -> 0 bytes | |||
| -rw-r--r-- | bin/script.py | 109 | ||||
| -rw-r--r-- | documentation/lafvin_starterkit.pdf (renamed from recourses/ .pdf) | bin | 9311241 -> 9311241 bytes | |||
| -rw-r--r-- | documentation/rpi.pdf (renamed from recourses/rpi.pdf) | bin | 19405814 -> 19405814 bytes | |||
| -rw-r--r-- | recourses/.DS_Store | bin | 6148 -> 6148 bytes | |||
| -rw-r--r-- | recourses/.idea/.gitignore | 3 | ||||
| -rw-r--r-- | recourses/.idea/SecuritySystem.iml | 8 | ||||
| -rw-r--r-- | recourses/.idea/inspectionProfiles/profiles_settings.xml | 6 | ||||
| -rw-r--r-- | recourses/.idea/misc.xml | 7 | ||||
| -rw-r--r-- | recourses/.idea/modules.xml | 8 | ||||
| -rw-r--r-- | script.py | 27 | ||||
| -rw-r--r-- | sec.py | 83 |
18 files changed, 109 insertions, 180 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | # Default ignored files | ||
| 2 | /shelf/ | ||
| 3 | /workspace.xml | ||
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | <component name="InspectionProjectProfileManager"> | ||
| 2 | <settings> | ||
| 3 | <option name="USE_PROJECT_PROFILE" value="false" /> | ||
| 4 | <version value="1.0" /> | ||
| 5 | </settings> | ||
| 6 | </component> \ No newline at end of file | ||
diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1d3ce46..0000000 --- a/.idea/misc.xml +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project version="4"> | ||
| 3 | <component name="Black"> | ||
| 4 | <option name="sdkName" value="Python 3.13" /> | ||
| 5 | </component> | ||
| 6 | <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" /> | ||
| 7 | </project> \ No newline at end of file | ||
diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 20d6502..0000000 --- a/.idea/modules.xml +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project version="4"> | ||
| 3 | <component name="ProjectModuleManager"> | ||
| 4 | <modules> | ||
| 5 | <module fileurl="file://$PROJECT_DIR$/.idea/security.iml" filepath="$PROJECT_DIR$/.idea/security.iml" /> | ||
| 6 | </modules> | ||
| 7 | </component> | ||
| 8 | </project> \ No newline at end of file | ||
diff --git a/.idea/security.iml b/.idea/security.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/security.iml +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <module type="PYTHON_MODULE" version="4"> | ||
| 3 | <component name="NewModuleRootManager"> | ||
| 4 | <content url="file://$MODULE_DIR$" /> | ||
| 5 | <orderEntry type="inheritedJdk" /> | ||
| 6 | <orderEntry type="sourceFolder" forTests="false" /> | ||
| 7 | </component> | ||
| 8 | </module> \ No newline at end of file | ||
diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project version="4"> | ||
| 3 | <component name="VcsDirectoryMappings"> | ||
| 4 | <mapping directory="" vcs="Git" /> | ||
| 5 | </component> | ||
| 6 | </project> \ No newline at end of file | ||
diff --git a/.script.py.swp b/.script.py.swp deleted file mode 100644 index bf563bb..0000000 --- a/.script.py.swp +++ /dev/null | |||
| Binary files differ | |||
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 @@ | |||
| 1 | from smbus2 import SMBus | ||
| 2 | from time import sleep | ||
| 3 | |||
| 4 | import speech_recognition as sr | ||
| 5 | import sounddevice | ||
| 6 | import os | ||
| 7 | |||
| 8 | ALIGN_FUNC = { | ||
| 9 | 'left': 'ljust', | ||
| 10 | 'right': 'rjust', | ||
| 11 | 'center': 'center'} | ||
| 12 | CLEAR_DISPLAY = 0x01 | ||
| 13 | ENABLE_BIT = 0b00000100 | ||
| 14 | LINES = { | ||
| 15 | 1: 0x80, | ||
| 16 | 2: 0xC0, | ||
| 17 | 3: 0x94, | ||
| 18 | 4: 0xD4} | ||
| 19 | |||
| 20 | LCD_BACKLIGHT = 0x08 | ||
| 21 | LCD_NOBACKLIGHT = 0x00 | ||
| 22 | |||
| 23 | ERROR_BAD_REQUEST = '400' | ||
| 24 | ERROR_UNAUTHORIZED = '401' | ||
| 25 | ERROR_NOT_FOUND = '404' | ||
| 26 | ERROR_TIMEOUT = '408' | ||
| 27 | |||
| 28 | class 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 | |||
| 83 | LCD = LCD() | ||
| 84 | VOICE_REC = sr.Recognizer() | ||
| 85 | MIC = sr.Microphone() | ||
| 86 | PROCES_LOAD = os.getloadavg() | ||
| 87 | TIME = current_time.time() | ||
| 88 | UPTIME = time.CLOCK_UPTIME() | ||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | def CPU_INFO(): | ||
| 93 | while (True): | ||
| 94 | LCD.text(PROCES_LOAD(),1,left) | ||
| 95 | |||
| 96 | def 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 | |||
| 105 | OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU LOAD", "NOTES"] | ||
| 106 | |||
| 107 | def USER_GUI(): | ||
| 108 | print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ") | ||
| 109 | print(OPTIONS) | ||
diff --git a/recourses/ .pdf b/documentation/lafvin_starterkit.pdf index 9735753..9735753 100644 --- a/recourses/ .pdf +++ b/documentation/lafvin_starterkit.pdf | |||
| Binary files differ | |||
diff --git a/recourses/rpi.pdf b/documentation/rpi.pdf index a4a9d10..a4a9d10 100644 --- a/recourses/rpi.pdf +++ b/documentation/rpi.pdf | |||
| Binary files differ | |||
diff --git a/recourses/.DS_Store b/recourses/.DS_Store index 0815a5f..94a5988 100644 --- a/recourses/.DS_Store +++ b/recourses/.DS_Store | |||
| Binary files differ | |||
diff --git a/recourses/.idea/.gitignore b/recourses/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/recourses/.idea/.gitignore +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | # Default ignored files | ||
| 2 | /shelf/ | ||
| 3 | /workspace.xml | ||
diff --git a/recourses/.idea/SecuritySystem.iml b/recourses/.idea/SecuritySystem.iml deleted file mode 100644 index d0876a7..0000000 --- a/recourses/.idea/SecuritySystem.iml +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <module type="PYTHON_MODULE" version="4"> | ||
| 3 | <component name="NewModuleRootManager"> | ||
| 4 | <content url="file://$MODULE_DIR$" /> | ||
| 5 | <orderEntry type="inheritedJdk" /> | ||
| 6 | <orderEntry type="sourceFolder" forTests="false" /> | ||
| 7 | </component> | ||
| 8 | </module> \ No newline at end of file | ||
diff --git a/recourses/.idea/inspectionProfiles/profiles_settings.xml b/recourses/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/recourses/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | <component name="InspectionProjectProfileManager"> | ||
| 2 | <settings> | ||
| 3 | <option name="USE_PROJECT_PROFILE" value="false" /> | ||
| 4 | <version value="1.0" /> | ||
| 5 | </settings> | ||
| 6 | </component> \ No newline at end of file | ||
diff --git a/recourses/.idea/misc.xml b/recourses/.idea/misc.xml deleted file mode 100644 index 1d3ce46..0000000 --- a/recourses/.idea/misc.xml +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project version="4"> | ||
| 3 | <component name="Black"> | ||
| 4 | <option name="sdkName" value="Python 3.13" /> | ||
| 5 | </component> | ||
| 6 | <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" /> | ||
| 7 | </project> \ No newline at end of file | ||
diff --git a/recourses/.idea/modules.xml b/recourses/.idea/modules.xml deleted file mode 100644 index 080d960..0000000 --- a/recourses/.idea/modules.xml +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <project version="4"> | ||
| 3 | <component name="ProjectModuleManager"> | ||
| 4 | <modules> | ||
| 5 | <module fileurl="file://$PROJECT_DIR$/.idea/SecuritySystem.iml" filepath="$PROJECT_DIR$/.idea/SecuritySystem.iml" /> | ||
| 6 | </modules> | ||
| 7 | </component> | ||
| 8 | </project> \ No newline at end of file | ||
diff --git a/script.py b/script.py deleted file mode 100644 index 6f79a59..0000000 --- a/script.py +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | import random | ||
| 2 | import time | ||
| 3 | from rpi_LCD import LCD | ||
| 4 | import speech_recognition as sr | ||
| 5 | import sounddevice | ||
| 6 | import os | ||
| 7 | |||
| 8 | LCD = LCD() | ||
| 9 | VOICE_REC = sr.Recognizer() | ||
| 10 | MIC = sr.Microphone() | ||
| 11 | PROCES_LOAD = os.getloadavg() | ||
| 12 | TIME = current_time.time() | ||
| 13 | |||
| 14 | # ERROR CODES | ||
| 15 | ERROR_BAD_REQUEST = '400' | ||
| 16 | ERROR_UNAUTHORIZED = '401' | ||
| 17 | ERROR_NOT_FOUND = '404' | ||
| 18 | ERROR_TIMEOUT = '408' | ||
| 19 | |||
| 20 | def CPU_INFO(): | ||
| 21 | while (True): | ||
| 22 | LCD.tex(PROCES_LOAD(),1) | ||
| 23 | |||
| 24 | def CLOCK(): | ||
| 25 | LCD.text(TIME,1) | ||
| 26 | |||
| 27 | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | # A speach transcriber using the google speech recognizer and then dsplaying it on the lcd of a raspberry pi | ||
| 2 | |||
| 3 | from rpi_lcd import LCD | ||
| 4 | import RPi.GPIO as GPIO | ||
| 5 | import speech_recognition as sr | ||
| 6 | from time import sleep | ||
| 7 | import sounddevice | ||
| 8 | import os | ||
| 9 | |||
| 10 | r = sr.Recognizer() | ||
| 11 | lcd = LCD() | ||
| 12 | mic = sr.Microphone() | ||
| 13 | |||
| 14 | beepPin = 17 | ||
| 15 | allow = False | ||
| 16 | |||
| 17 | def stream(): | ||
| 18 | print("starting live steam") | ||
| 19 | # starting the motion live stream | ||
| 20 | os.system('motion') | ||
| 21 | |||
| 22 | # Listening to the user's voice and putting it into a variable | ||
| 23 | def listen_voice(): | ||
| 24 | global audio | ||
| 25 | with mic as source: | ||
| 26 | r.adjust_for_ambient_noise(source) | ||
| 27 | audio = r.listen(source) | ||
| 28 | return audio | ||
| 29 | |||
| 30 | # Transcribing the audio to text and printing it out | ||
| 31 | # Using the google speech recognizer | ||
| 32 | # Google speech recognizer does require a internet connection | ||
| 33 | def recognize_speech(audio): | ||
| 34 | error = "400" | ||
| 35 | r_error = "401" | ||
| 36 | |||
| 37 | try: | ||
| 38 | words = r.recognize_google(audio) | ||
| 39 | lcd.text(words, 1) | ||
| 40 | print(f"Printing on screen: {words}") | ||
| 41 | password = "linux" | ||
| 42 | while allow == False: | ||
| 43 | if words == password: | ||
| 44 | allow = True | ||
| 45 | print("That's the password!!!") | ||
| 46 | stream() | ||
| 47 | |||
| 48 | except sr.UnknownValueError: | ||
| 49 | lcd.text(error, 1) | ||
| 50 | print(error) | ||
| 51 | except sr.RequestError: | ||
| 52 | lcd.text(r_error, 1) | ||
| 53 | print(r_error) | ||
| 54 | |||
| 55 | def setup(): | ||
| 56 | print("clearing the lcd screen") | ||
| 57 | lcd.clear() | ||
| 58 | print("setting up the system") | ||
| 59 | GPIO.setmode(GPIO.BCM) | ||
| 60 | GPIO.setup(beepPin, GPIO.OUT, initial=GPIO.HIGH) | ||
| 61 | |||
| 62 | def main(): | ||
| 63 | while True: | ||
| 64 | audio = listen_voice() | ||
| 65 | recognize_speech(audio) | ||
| 66 | GPIO.output(beepPin,GPIO.HIGH) | ||
| 67 | sleep(0.5) | ||
| 68 | GPIO.output(beepPin,GPIO.LOW) | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | def destroy(): | ||
| 73 | lcd.clear() | ||
| 74 | |||
| 75 | if __name__ == '__main__': | ||
| 76 | # Clearing the lcd before starting the program | ||
| 77 | |||
| 78 | print("setting up the alarm") | ||
| 79 | setup() | ||
| 80 | try: | ||
| 81 | main() | ||
| 82 | except KeyboardInterrupt: | ||
| 83 | destroy() | ||
