From 5466f96bd75f602f5b5fd44a7ccee745f2abfca0 Mon Sep 17 00:00:00 2001 From: Abdellah El Morabit Date: Tue, 5 Nov 2024 09:24:48 +0100 Subject: no clue what i did here --- .DS_Store | Bin 0 -> 6148 bytes .idea/.gitignore | 3 + .idea/inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/security.iml | 8 + .idea/vcs.xml | 6 + recourses/ .pdf | Bin 0 -> 9311241 bytes recourses/.DS_Store | Bin 0 -> 6148 bytes recourses/.idea/.gitignore | 3 + recourses/.idea/SecuritySystem.iml | 8 + .../.idea/inspectionProfiles/profiles_settings.xml | 6 + recourses/.idea/misc.xml | 7 + recourses/.idea/modules.xml | 8 + recourses/Buzzer.py | 56 ++++++ recourses/Keypad.py | 202 +++++++++++++++++++++ recourses/Membrane_Switch_Module.py | 27 +++ recourses/rpi.pdf | Bin 0 -> 19405814 bytes sec.py | 2 - 19 files changed, 355 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/security.iml create mode 100644 .idea/vcs.xml create mode 100644 recourses/ .pdf create mode 100644 recourses/.DS_Store create mode 100644 recourses/.idea/.gitignore create mode 100644 recourses/.idea/SecuritySystem.iml create mode 100644 recourses/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 recourses/.idea/misc.xml create mode 100644 recourses/.idea/modules.xml create mode 100644 recourses/Buzzer.py create mode 100644 recourses/Keypad.py create mode 100644 recourses/Membrane_Switch_Module.py create mode 100644 recourses/rpi.pdf diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..0f8dc76 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1d3ce46 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..20d6502 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/security.iml b/.idea/security.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/security.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/recourses/ .pdf b/recourses/ .pdf new file mode 100644 index 0000000..9735753 Binary files /dev/null and b/recourses/ .pdf differ diff --git a/recourses/.DS_Store b/recourses/.DS_Store new file mode 100644 index 0000000..0815a5f Binary files /dev/null and b/recourses/.DS_Store differ diff --git a/recourses/.idea/.gitignore b/recourses/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/recourses/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/recourses/.idea/SecuritySystem.iml b/recourses/.idea/SecuritySystem.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/recourses/.idea/SecuritySystem.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/recourses/.idea/inspectionProfiles/profiles_settings.xml b/recourses/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/recourses/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/recourses/.idea/misc.xml b/recourses/.idea/misc.xml new file mode 100644 index 0000000..1d3ce46 --- /dev/null +++ b/recourses/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/recourses/.idea/modules.xml b/recourses/.idea/modules.xml new file mode 100644 index 0000000..080d960 --- /dev/null +++ b/recourses/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/recourses/Buzzer.py b/recourses/Buzzer.py new file mode 100644 index 0000000..8555184 --- /dev/null +++ b/recourses/Buzzer.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import RPi.GPIO as GPIO +import time + +# Set #17 as buzzer pin +BeepPin = 17 + +def print_message(): + print("========================================") + print ("| Beep |") + print ("| ------------------------------ |") + print ("| Buzzer connect to GPIO0 |") + print ("| |") + print ("| Make Buzzer beep |") + print ("| |") + print ("| |") + print ("========================================\n") + print 'Program is running...' + print 'Please press Ctrl+C to end the program...' + raw_input ("Press Enter to begin\n") + +def setup(): + # Set the GPIO modes to BCM Numbering + GPIO.setmode(GPIO.BCM) + # Set LedPin's mode to output, + # and initial level to High(3.3v) + GPIO.setup(BeepPin, GPIO.OUT, initial=GPIO.HIGH) + +def main(): + print_message() + while True: + # Buzzer on (Beep) + print 'Buzzer On' + GPIO.output(BeepPin, GPIO.LOW) + time.sleep(0.1) + # Buzzer off + print 'Buzzer Off' + GPIO.output(BeepPin, GPIO.HIGH) + time.sleep(0.1) + +def destroy(): + # Turn off buzzer + GPIO.output(BeepPin, GPIO.HIGH) + # Release resource + GPIO.cleanup() + +# If run this script directly, do: +if __name__ == '__main__': + setup() + try: + main() + # When 'Ctrl+C' is pressed, the child program + # destroy() will be executed. + except KeyboardInterrupt: + destroy() \ No newline at end of file diff --git a/recourses/Keypad.py b/recourses/Keypad.py new file mode 100644 index 0000000..f762b4b --- /dev/null +++ b/recourses/Keypad.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python3 + +import RPi.GPIO as GPIO +import time +#class Key:Define some of the properties of Key +class Key(object): + NO_KEY = '\0' + #Defines the four states of Key + IDLE = 0 + PRESSED = 1 + HOLD = 2 + RELEASED = 3 + #define OPEN and CLOSED + OPEN = 0 + CLOSED =1 + #constructor + def __init__(self): + self.kchar = self.NO_KEY + self.kstate = self.IDLE + self.kcode = -1 + self.stateChanged = False + +class Keypad(object): + NULL = '\0' + LIST_MAX = 10 #Max number of keys on the active list. + MAPSIZE = 10 #MAPSIZE is the number of rows (times 16 columns) + bitMap = [0]*MAPSIZE + key = [Key()]*LIST_MAX + holdTime = 500 #key hold time + holdTimer = 0 + startTime = 0 + #Allows custom keymap, pin configuration, and keypad sizes. + def __init__(self,usrKeyMap,row_Pins,col_Pins,num_Rows,num_Cols): + GPIO.setmode(GPIO.BOARD) + self.rowPins = row_Pins + self.colPins = col_Pins + self.numRows = num_Rows + self.numCols = num_Cols + + self.keymap = usrKeyMap + self.setDebounceTime(10) + #Returns a single key only. Retained for backwards compatibility. + def getKey(self): + single_key = True + if(self.getKeys() and self.key[0].stateChanged and (self.key[0].kstate == self.key[0].PRESSED)): + return self.key[0].kchar + single_key = False + return self.key[0].NO_KEY + #Populate the key list. + def getKeys(self): + keyActivity = False + #Limit how often the keypad is scanned. + if((time.time() - self.startTime) > self.debounceTime*0.001): + self.scanKeys() + keyActivity = self.updateList() + self.startTime = time.time() + return keyActivity + #Hardware scan ,the result store in bitMap + def scanKeys(self): + #Re-intialize the row pins. Allows sharing these pins with other hardware. + for pin_r in self.rowPins: + GPIO.setup(pin_r,GPIO.IN,pull_up_down = GPIO.PUD_UP) + #bitMap stores ALL the keys that are being pressed. + for pin_c in self.colPins: + GPIO.setup(pin_c,GPIO.OUT) + GPIO.output(pin_c,GPIO.LOW) + for r in self.rowPins: #keypress is active low so invert to high. + self.bitMap[self.rowPins.index(r)] = self.bitWrite(self.bitMap[self.rowPins.index(r)],self.colPins.index(pin_c),not GPIO.input(r)) + #Set pin to high impedance input. Effectively ends column pulse. + GPIO.output(pin_c,GPIO.HIGH) + GPIO.setup(pin_c,GPIO.IN) + #Manage the list without rearranging the keys. Returns true if any keys on the list changed state. + def updateList(self): + anyActivity = False + kk = Key() + #Delete any IDLE keys + for i in range(self.LIST_MAX): + if(self.key[i].kstate == kk.IDLE): + self.key[i].kchar = kk.NO_KEY + self.key[i].kcode = -1 + self.key[i].stateChanged = False + # Add new keys to empty slots in the key list. + for r in range(self.numRows): + for c in range(self.numCols): + button = self.bitRead(self.bitMap[r],c) + keyChar = self.keymap[r * self.numCols +c] + keyCode = r * self.numCols +c + idx = self.findInList(keyCode) + #Key is already on the list so set its next state. + if(idx > -1): + self.nextKeyState(idx,button) + #Key is NOT on the list so add it. + if((idx == -1) and button): + for i in range(self.LIST_MAX): + if(self.key[i].kchar == kk.NO_KEY): #Find an empty slot or don't add key to list. + self.key[i].kchar = keyChar + self.key[i].kcode = keyCode + self.key[i].kstate = kk.IDLE #Keys NOT on the list have an initial state of IDLE. + self.nextKeyState(i,button) + break #Don't fill all the empty slots with the same key. + #Report if the user changed the state of any key. + for i in range(self.LIST_MAX): + if(self.key[i].stateChanged): + anyActivity = True + return anyActivity + #This function is a state machine but is also used for debouncing the keys. + def nextKeyState(self,idx, button): + self.key[idx].stateChanged = False + kk = Key() + if(self.key[idx].kstate == kk.IDLE): + if(button == kk.CLOSED): + self.transitionTo(idx,kk.PRESSED) + self.holdTimer = time.time() #Get ready for next HOLD state. + elif(self.key[idx].kstate == kk.PRESSED): + if((time.time() - self.holdTimer) > self.holdTime*0.001): #Waiting for a key HOLD... + self.transitionTo(idx,kk.HOLD) + elif(button == kk.OPEN): # or for a key to be RELEASED. + self.transitionTo(idx,kk.RELEASED) + elif(self.key[idx].kstate == kk.HOLD): + if(button == kk.OPEN): + self.transitionTo(idx,kk.RELEASED) + elif(self.key[idx].kstate == kk.RELEASED): + self.transitionTo(idx,kk.IDLE) + + def transitionTo(self,idx,nextState): + self.key[idx].kstate = nextState + self.key[idx].stateChanged = True + #Search by code for a key in the list of active keys. + #Returns -1 if not found or the index into the list of active keys. + def findInList(self,keyCode): + for i in range(self.LIST_MAX): + if(self.key[i].kcode == keyCode): + return i + return -1 + #set Debounce Time, The default is 50ms + def setDebounceTime(self,ms): + self.debounceTime = ms + #set HoldTime,The default is 500ms + def setHoldTime(self,ms): + self.holdTime = ms + # + def isPressed(keyChar): + for i in range(self.LIST_MAX): + if(self.key[i].kchar == keyChar): + if(self.key[i].kstate == self.self.key[i].PRESSED and self.key[i].stateChanged): + return True + return False + # + def waitForKey(): + kk = Key() + waitKey = kk.NO_KEY + while(waitKey == kk.NO_KEY): + waitKey = getKey() + return waitKey + + def getState(): + return self.key[0].kstate + # + def keyStateChanged(): + return self.key[0].stateChanged + + def bitWrite(self,x,n,b): + if(b): + x |= (1<>n)&1 == 1): + return True + else: + return False + +ROWS = 4 +COLS = 4 +keys = [ '1','2','3','A', + '4','5','6','B', + '7','8','9','C', + '*','0','#','D' ] +rowsPins = [12,16,18,22] +colsPins = [19,15,13,11] + +def loop(): + keypad = Keypad(keys,rowsPins,colsPins,ROWS,COLS) + keypad.setDebounceTime(50) + while(True): + key = keypad.getKey() + if(key != keypad.NULL): + print ("You Pressed Key : %c "%(key) ) + +if __name__ == '__main__': # Program start from here + print ("Program is starting ... ") + try: + loop() + except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. + pass + GPIO.cleanup() + + + + + diff --git a/recourses/Membrane_Switch_Module.py b/recourses/Membrane_Switch_Module.py new file mode 100644 index 0000000..168bcf9 --- /dev/null +++ b/recourses/Membrane_Switch_Module.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import RPi.GPIO as GPIO +import Keypad #import module Keypad +ROWS = 4 # number of rows of the Keypad +COLS = 4 #number of columns of the Keypad +keys = [ '1','2','3','A', #key code + '4','5','6','B', + '7','8','9','C', + '*','0','#','D' ] +rowsPins = [12,16,18,22] #connect to the row pinouts of the keypad +colsPins = [19,15,13,11] #connect to the column pinouts of the keypad + +def loop(): + keypad = Keypad.Keypad(keys,rowsPins,colsPins,ROWS,COLS) #creat Keypad object + keypad.setDebounceTime(50) #set the debounce time + while(True): + key = keypad.getKey() #obtain the state of keys + if(key != keypad.NULL): #if there is key pressed, print its key code. + print ("You Pressed Key : %c "%(key)) + +if __name__ == '__main__': #Program start from here + print ("Program is starting ... ") + try: + loop() + except KeyboardInterrupt: #When 'Ctrl+C' is pressed, exit the program. + GPIO.cleanup() diff --git a/recourses/rpi.pdf b/recourses/rpi.pdf new file mode 100644 index 0000000..a4a9d10 Binary files /dev/null and b/recourses/rpi.pdf differ diff --git a/sec.py b/sec.py index a8685b7..0afd67f 100644 --- a/sec.py +++ b/sec.py @@ -19,7 +19,6 @@ def stream(): # starting the motion live stream os.system('motion') - # Listening to the user's voice and putting it into a variable def listen_voice(): global audio @@ -82,4 +81,3 @@ if __name__ == '__main__': main() except KeyboardInterrupt: destroy() - -- cgit v1.2.3-70-g09d2