summaryrefslogtreecommitdiff
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
parentfa7007d00c04fc73f668e2b7f339c3f60a64d055 (diff)
did alot of designing and testing out on a linux machine
-rw-r--r--.DS_Storebin6148 -> 6148 bytes
-rw-r--r--.idea/workspace.xml51
-rw-r--r--bin/icon.pngbin0 -> 3754 bytes
-rw-r--r--bin/kasper_gui.py10
-rw-r--r--bin/kasper_source.py (renamed from bin/script.py)70
-rw-r--r--documentation/lafvin_starterkit.pdfbin9311241 -> 0 bytes
-rw-r--r--documentation/rpi.pdfbin19405814 -> 0 bytes
-rw-r--r--recourses/.DS_Storebin6148 -> 0 bytes
-rw-r--r--recourses/Buzzer.py56
-rw-r--r--recourses/Keypad.py202
-rw-r--r--recourses/Membrane_Switch_Module.py27
11 files changed, 123 insertions, 293 deletions
diff --git a/.DS_Store b/.DS_Store
index 0f8dc76..8eba22d 100644
--- a/.DS_Store
+++ b/.DS_Store
Binary files differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..21b26aa
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,51 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<project version="4">
3 <component name="AutoImportSettings">
4 <option name="autoReloadType" value="SELECTIVE" />
5 </component>
6 <component name="ChangeListManager">
7 <list default="true" id="d549f8f9-3026-49a6-9adf-0d0fe6a5cb76" name="Changes" comment="">
8 <change beforePath="$PROJECT_DIR$/bin/script.py" beforeDir="false" />
9 </list>
10 <option name="SHOW_DIALOG" value="false" />
11 <option name="HIGHLIGHT_CONFLICTS" value="true" />
12 <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
13 <option name="LAST_RESOLUTION" value="IGNORE" />
14 </component>
15 <component name="Git.Settings">
16 <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
17 </component>
18 <component name="ProjectColorInfo"><![CDATA[{
19 "customColor": "",
20 "associatedIndex": 0
21}]]></component>
22 <component name="ProjectId" id="2oW3a2AGjKQ77ODouI0IMHmSxPP" />
23 <component name="ProjectViewState">
24 <option name="hideEmptyMiddlePackages" value="true" />
25 <option name="showLibraryContents" value="true" />
26 </component>
27 <component name="PropertiesComponent"><![CDATA[{
28 "keyToString": {
29 "RunOnceActivity.ShowReadmeOnStart": "true",
30 "git-widget-placeholder": "main"
31 }
32}]]></component>
33 <component name="SharedIndexes">
34 <attachedChunks>
35 <set>
36 <option value="bundled-python-sdk-d7ad00fb9fc3-c546a90a8094-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-242.23726.102" />
37 </set>
38 </attachedChunks>
39 </component>
40 <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
41 <component name="TaskManager">
42 <task active="true" id="Default" summary="Default task">
43 <changelist id="d549f8f9-3026-49a6-9adf-0d0fe6a5cb76" name="Changes" comment="" />
44 <created>1730971563473</created>
45 <option name="number" value="Default" />
46 <option name="presentableId" value="Default" />
47 <updated>1730971563473</updated>
48 </task>
49 <servers />
50 </component>
51</project> \ No newline at end of file
diff --git a/bin/icon.png b/bin/icon.png
new file mode 100644
index 0000000..c372c49
--- /dev/null
+++ b/bin/icon.png
Binary files differ
diff --git a/bin/kasper_gui.py b/bin/kasper_gui.py
new file mode 100644
index 0000000..2826638
--- /dev/null
+++ b/bin/kasper_gui.py
@@ -0,0 +1,10 @@
1import tkinter
2from tkinter import PhotoImage
3
4display = tkinter.Tk()
5display.title("Kasper")
6photo = PhotoImage(file = "icon.png")
7display.iconphoto(False, photo)
8
9
10display.mainloop() \ No newline at end of file
diff --git a/bin/script.py b/bin/kasper_source.py
index 5c33638..d8b0599 100644
--- a/bin/script.py
+++ b/bin/kasper_source.py
@@ -1,5 +1,7 @@
1from smbus2 import SMBus 1from smbus2 import SMBus
2from time import sleep 2from time import sleep
3from gpiozero import CPUTemperature
4from rpi_lcd import LCD
3 5
4import speech_recognition as sr 6import speech_recognition as sr
5import sounddevice 7import sounddevice
@@ -78,32 +80,84 @@ class LCD(object):
78 def clear(self): 80 def clear(self):
79 self.write(CLEAR_DISPLAY) 81 self.write(CLEAR_DISPLAY)
80 82
81 83LCD_DISPLAY = LCD()
82
83LCD = LCD()
84VOICE_REC = sr.Recognizer() 84VOICE_REC = sr.Recognizer()
85MIC = sr.Microphone() 85MIC = sr.Microphone()
86PROCES_LOAD = os.getloadavg() 86PROCES_LOAD = os.getloadavg()
87TIME = current_time.time() 87TIME = current_time.time()
88UPTIME = time.CLOCK_UPTIME() 88UPTIME = time.CLOCK_UPTIME()
89CPU_TEMP = CPUTemperature()
90
91# clearing the lcd from any text that was on it before the program started to ensure smooth operations
92lcd.clear()
89 93
94# Listening to the user's voice and putting it into a variable
95def listen_voice():
96 global audio
97 with mic as source:
98 r.adjust_for_ambient_noise(source)
99 audio = r.listen(source)
100 return audio
90 101
102# Transcribing the audio to text and printing it out
103# Using the Google Speech Recognizer
104def recognize_speech(audio):
105 try:
106 words = r.recognize_google(audio)
107 LCD_DISPLAY.text(words, 1)
108 print(f"Printing on screen: {words}")
109 except sr.UnknownValueError:
110 LCD_DISPLAY.text(ERROR_BAD_REQUEST, 1)
111 print(ERROR_BAD_REQUEST)
112 except sr.RequestError:
113 LCD_DISPLAY.text(ERROR_UNAUTHORIZED, 1)
114 print(ERROR_UNAUTHORIZED)
91 115
92def CPU_INFO(): 116def CPU_INFO():
117 print("you chose to display the cpou")
93 while (True): 118 while (True):
94 LCD.text(PROCES_LOAD(),1,left) 119 LCD.text(PROCES_LOAD(),1,left)
95 120
96def CURRENT_TIME(): 121def CURRENT_TIME():
97 while True: 122 while True:
98 backlight_mode = true 123 backlight_mode = True
99 LCD.text(UPTIME,1,left)
100 LCD.text(TIME,2,center) 124 LCD.text(TIME,2,center)
101
102 125
126def UPTIME():
127 while True:
128 LCD.text(UPTIME,1,left)
129
130def CPU_TEMP():
131 while True:
132 LCD.text(cpu.temperature)
133
134def CPU_LOAD():
135 backlight_mode = True
136 LCD.text(PROCES_LOAD,1,left)
103 137
138def NOTES():
139 count = 0
140 user_notes = input()
141 for i in user_notes:
142 while count < 20:
143 lcd.text(i,1,left)
144 count += 1
104 145
105OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU LOAD", "NOTES"] 146
147OPTIONS = ["CPU_CLOCK", "TIME", "UPTIME", "CPU_TEMP", "CPU_LOAD", "NOTES", "SPEECH_TRANSCRIBER"]
106 148
107def USER_GUI(): 149def PROGRAM(USER_INPUT):
108 print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ") 150 print("WELCOME TO THE I2C COMMAND LINE CENTER \n WHAT DO YOU WISH TO DO? ")
109 print(OPTIONS) 151 print(OPTIONS)
152
153 FOUND = False
154 while FOUND == False:
155
156 USER_INPUT = input().upper()
157 for i in OPTIONS:
158 if i == USER_INPUT:
159 FOUND = True
160 else:
161 print(ERROR_NOT_FOUND)
162
163PROGRAM() \ No newline at end of file
diff --git a/documentation/lafvin_starterkit.pdf b/documentation/lafvin_starterkit.pdf
deleted file mode 100644
index 9735753..0000000
--- a/documentation/lafvin_starterkit.pdf
+++ /dev/null
Binary files differ
diff --git a/documentation/rpi.pdf b/documentation/rpi.pdf
deleted file mode 100644
index a4a9d10..0000000
--- a/documentation/rpi.pdf
+++ /dev/null
Binary files differ
diff --git a/recourses/.DS_Store b/recourses/.DS_Store
deleted file mode 100644
index 94a5988..0000000
--- a/recourses/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/recourses/Buzzer.py b/recourses/Buzzer.py
deleted file mode 100644
index 8555184..0000000
--- a/recourses/Buzzer.py
+++ /dev/null
@@ -1,56 +0,0 @@
1#!/usr/bin/env python
2
3import RPi.GPIO as GPIO
4import time
5
6# Set #17 as buzzer pin
7BeepPin = 17
8
9def print_message():
10 print("========================================")
11 print ("| Beep |")
12 print ("| ------------------------------ |")
13 print ("| Buzzer connect to GPIO0 |")
14 print ("| |")
15 print ("| Make Buzzer beep |")
16 print ("| |")
17 print ("| |")
18 print ("========================================\n")
19 print 'Program is running...'
20 print 'Please press Ctrl+C to end the program...'
21 raw_input ("Press Enter to begin\n")
22
23def setup():
24 # Set the GPIO modes to BCM Numbering
25 GPIO.setmode(GPIO.BCM)
26 # Set LedPin's mode to output,
27 # and initial level to High(3.3v)
28 GPIO.setup(BeepPin, GPIO.OUT, initial=GPIO.HIGH)
29
30def main():
31 print_message()
32 while True:
33 # Buzzer on (Beep)
34 print 'Buzzer On'
35 GPIO.output(BeepPin, GPIO.LOW)
36 time.sleep(0.1)
37 # Buzzer off
38 print 'Buzzer Off'
39 GPIO.output(BeepPin, GPIO.HIGH)
40 time.sleep(0.1)
41
42def destroy():
43 # Turn off buzzer
44 GPIO.output(BeepPin, GPIO.HIGH)
45 # Release resource
46 GPIO.cleanup()
47
48# If run this script directly, do:
49if __name__ == '__main__':
50 setup()
51 try:
52 main()
53 # When 'Ctrl+C' is pressed, the child program
54 # destroy() will be executed.
55 except KeyboardInterrupt:
56 destroy() \ No newline at end of file
diff --git a/recourses/Keypad.py b/recourses/Keypad.py
deleted file mode 100644
index f762b4b..0000000
--- a/recourses/Keypad.py
+++ /dev/null
@@ -1,202 +0,0 @@
1#!/usr/bin/env python3
2
3import RPi.GPIO as GPIO
4import time
5#class Key:Define some of the properties of Key
6class Key(object):
7 NO_KEY = '\0'
8 #Defines the four states of Key
9 IDLE = 0
10 PRESSED = 1
11 HOLD = 2
12 RELEASED = 3
13 #define OPEN and CLOSED
14 OPEN = 0
15 CLOSED =1
16 #constructor
17 def __init__(self):
18 self.kchar = self.NO_KEY
19 self.kstate = self.IDLE
20 self.kcode = -1
21 self.stateChanged = False
22
23class Keypad(object):
24 NULL = '\0'
25 LIST_MAX = 10 #Max number of keys on the active list.
26 MAPSIZE = 10 #MAPSIZE is the number of rows (times 16 columns)
27 bitMap = [0]*MAPSIZE
28 key = [Key()]*LIST_MAX
29 holdTime = 500 #key hold time
30 holdTimer = 0
31 startTime = 0
32 #Allows custom keymap, pin configuration, and keypad sizes.
33 def __init__(self,usrKeyMap,row_Pins,col_Pins,num_Rows,num_Cols):
34 GPIO.setmode(GPIO.BOARD)
35 self.rowPins = row_Pins
36 self.colPins = col_Pins
37 self.numRows = num_Rows
38 self.numCols = num_Cols
39
40 self.keymap = usrKeyMap
41 self.setDebounceTime(10)
42 #Returns a single key only. Retained for backwards compatibility.
43 def getKey(self):
44 single_key = True
45 if(self.getKeys() and self.key[0].stateChanged and (self.key[0].kstate == self.key[0].PRESSED)):
46 return self.key[0].kchar
47 single_key = False
48 return self.key[0].NO_KEY
49 #Populate the key list.
50 def getKeys(self):
51 keyActivity = False
52 #Limit how often the keypad is scanned.
53 if((time.time() - self.startTime) > self.debounceTime*0.001):
54 self.scanKeys()
55 keyActivity = self.updateList()
56 self.startTime = time.time()
57 return keyActivity
58 #Hardware scan ,the result store in bitMap
59 def scanKeys(self):
60 #Re-intialize the row pins. Allows sharing these pins with other hardware.
61 for pin_r in self.rowPins:
62 GPIO.setup(pin_r,GPIO.IN,pull_up_down = GPIO.PUD_UP)
63 #bitMap stores ALL the keys that are being pressed.
64 for pin_c in self.colPins:
65 GPIO.setup(pin_c,GPIO.OUT)
66 GPIO.output(pin_c,GPIO.LOW)
67 for r in self.rowPins: #keypress is active low so invert to high.
68 self.bitMap[self.rowPins.index(r)] = self.bitWrite(self.bitMap[self.rowPins.index(r)],self.colPins.index(pin_c),not GPIO.input(r))
69 #Set pin to high impedance input. Effectively ends column pulse.
70 GPIO.output(pin_c,GPIO.HIGH)
71 GPIO.setup(pin_c,GPIO.IN)
72 #Manage the list without rearranging the keys. Returns true if any keys on the list changed state.
73 def updateList(self):
74 anyActivity = False
75 kk = Key()
76 #Delete any IDLE keys
77 for i in range(self.LIST_MAX):
78 if(self.key[i].kstate == kk.IDLE):
79 self.key[i].kchar = kk.NO_KEY
80 self.key[i].kcode = -1
81 self.key[i].stateChanged = False
82 # Add new keys to empty slots in the key list.
83 for r in range(self.numRows):
84 for c in range(self.numCols):
85 button = self.bitRead(self.bitMap[r],c)
86 keyChar = self.keymap[r * self.numCols +c]
87 keyCode = r * self.numCols +c
88 idx = self.findInList(keyCode)
89 #Key is already on the list so set its next state.
90 if(idx > -1):
91 self.nextKeyState(idx,button)
92 #Key is NOT on the list so add it.
93 if((idx == -1) and button):
94 for i in range(self.LIST_MAX):
95 if(self.key[i].kchar == kk.NO_KEY): #Find an empty slot or don't add key to list.
96 self.key[i].kchar = keyChar
97 self.key[i].kcode = keyCode
98 self.key[i].kstate = kk.IDLE #Keys NOT on the list have an initial state of IDLE.
99 self.nextKeyState(i,button)
100 break #Don't fill all the empty slots with the same key.
101 #Report if the user changed the state of any key.
102 for i in range(self.LIST_MAX):
103 if(self.key[i].stateChanged):
104 anyActivity = True
105 return anyActivity
106 #This function is a state machine but is also used for debouncing the keys.
107 def nextKeyState(self,idx, button):
108 self.key[idx].stateChanged = False
109 kk = Key()
110 if(self.key[idx].kstate == kk.IDLE):
111 if(button == kk.CLOSED):
112 self.transitionTo(idx,kk.PRESSED)
113 self.holdTimer = time.time() #Get ready for next HOLD state.
114 elif(self.key[idx].kstate == kk.PRESSED):
115 if((time.time() - self.holdTimer) > self.holdTime*0.001): #Waiting for a key HOLD...
116 self.transitionTo(idx,kk.HOLD)
117 elif(button == kk.OPEN): # or for a key to be RELEASED.
118 self.transitionTo(idx,kk.RELEASED)
119 elif(self.key[idx].kstate == kk.HOLD):
120 if(button == kk.OPEN):
121 self.transitionTo(idx,kk.RELEASED)
122 elif(self.key[idx].kstate == kk.RELEASED):
123 self.transitionTo(idx,kk.IDLE)
124
125 def transitionTo(self,idx,nextState):
126 self.key[idx].kstate = nextState
127 self.key[idx].stateChanged = True
128 #Search by code for a key in the list of active keys.
129 #Returns -1 if not found or the index into the list of active keys.
130 def findInList(self,keyCode):
131 for i in range(self.LIST_MAX):
132 if(self.key[i].kcode == keyCode):
133 return i
134 return -1
135 #set Debounce Time, The default is 50ms
136 def setDebounceTime(self,ms):
137 self.debounceTime = ms
138 #set HoldTime,The default is 500ms
139 def setHoldTime(self,ms):
140 self.holdTime = ms
141 #
142 def isPressed(keyChar):
143 for i in range(self.LIST_MAX):
144 if(self.key[i].kchar == keyChar):
145 if(self.key[i].kstate == self.self.key[i].PRESSED and self.key[i].stateChanged):
146 return True
147 return False
148 #
149 def waitForKey():
150 kk = Key()
151 waitKey = kk.NO_KEY
152 while(waitKey == kk.NO_KEY):
153 waitKey = getKey()
154 return waitKey
155
156 def getState():
157 return self.key[0].kstate
158 #
159 def keyStateChanged():
160 return self.key[0].stateChanged
161
162 def bitWrite(self,x,n,b):
163 if(b):
164 x |= (1<<n)
165 else:
166 x &=(~(1<<n))
167 return x
168 def bitRead(self,x,n):
169 if((x>>n)&1 == 1):
170 return True
171 else:
172 return False
173
174ROWS = 4
175COLS = 4
176keys = [ '1','2','3','A',
177 '4','5','6','B',
178 '7','8','9','C',
179 '*','0','#','D' ]
180rowsPins = [12,16,18,22]
181colsPins = [19,15,13,11]
182
183def loop():
184 keypad = Keypad(keys,rowsPins,colsPins,ROWS,COLS)
185 keypad.setDebounceTime(50)
186 while(True):
187 key = keypad.getKey()
188 if(key != keypad.NULL):
189 print ("You Pressed Key : %c "%(key) )
190
191if __name__ == '__main__': # Program start from here
192 print ("Program is starting ... ")
193 try:
194 loop()
195 except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
196 pass
197 GPIO.cleanup()
198
199
200
201
202
diff --git a/recourses/Membrane_Switch_Module.py b/recourses/Membrane_Switch_Module.py
deleted file mode 100644
index 168bcf9..0000000
--- a/recourses/Membrane_Switch_Module.py
+++ /dev/null
@@ -1,27 +0,0 @@
1#!/usr/bin/env python3
2
3import RPi.GPIO as GPIO
4import Keypad #import module Keypad
5ROWS = 4 # number of rows of the Keypad
6COLS = 4 #number of columns of the Keypad
7keys = [ '1','2','3','A', #key code
8 '4','5','6','B',
9 '7','8','9','C',
10 '*','0','#','D' ]
11rowsPins = [12,16,18,22] #connect to the row pinouts of the keypad
12colsPins = [19,15,13,11] #connect to the column pinouts of the keypad
13
14def loop():
15 keypad = Keypad.Keypad(keys,rowsPins,colsPins,ROWS,COLS) #creat Keypad object
16 keypad.setDebounceTime(50) #set the debounce time
17 while(True):
18 key = keypad.getKey() #obtain the state of keys
19 if(key != keypad.NULL): #if there is key pressed, print its key code.
20 print ("You Pressed Key : %c "%(key))
21
22if __name__ == '__main__': #Program start from here
23 print ("Program is starting ... ")
24 try:
25 loop()
26 except KeyboardInterrupt: #When 'Ctrl+C' is pressed, exit the program.
27 GPIO.cleanup()