Added the main execution code.
This commit is contained in:
		
							parent
							
								
									7449682016
								
							
						
					
					
						commit
						6296e949ad
					
				
					 10 changed files with 134 additions and 79 deletions
				
			
		
							
								
								
									
										47
									
								
								DBHelper.py
									
										
									
									
									
								
							
							
						
						
									
										47
									
								
								DBHelper.py
									
										
									
									
									
								
							|  | @ -38,13 +38,13 @@ def login(username, password): | |||
|         print("Invalid username or password.") | ||||
| 
 | ||||
| 
 | ||||
| # Uploads the data of specified user uploaded into firebase. | ||||
| # Uploads the data of specified user into firebase. | ||||
| def upload_data(user_id, firstname, lastname, email, phone, address): | ||||
|     data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone, "Address": address} | ||||
|     db.child("Users").child(user_id).set(data) | ||||
| 
 | ||||
| 
 | ||||
| # Removes the data of specified user uploaded into firebase. | ||||
| # Removes the data of specified user from firebase. | ||||
| def remove_data(user_id): | ||||
|     db.child("Users").child(user_id).remove() | ||||
| 
 | ||||
|  | @ -142,4 +142,45 @@ def get_power(): | |||
| # Power signal setter | ||||
| def set_power(power): | ||||
|     data = {"power": power} | ||||
|     db.child("signal").child("1").set(data) | ||||
|     db.child("signal").child("1").set(data) | ||||
| 
 | ||||
| 
 | ||||
| # Returns the first name or else an empty string. | ||||
| def get_signal_firstname(): | ||||
|     firstname = db.child("signal").child("2").child("First Name").get().val() | ||||
|     return firstname | ||||
| 
 | ||||
| 
 | ||||
| # Returns the last name or else an empty string. | ||||
| def get_signal_lastname(): | ||||
|     lastname = db.child("signal").child("2").child("Last Name").get().val() | ||||
|     return lastname | ||||
| 
 | ||||
| 
 | ||||
| # Returns the e-mail or else an empty string. | ||||
| def get_signal_email(): | ||||
|     email = db.child("signal").child("2").child("E-Mail").get().val() | ||||
|     return email | ||||
| 
 | ||||
| 
 | ||||
| # Returns the phone or else an empty string. | ||||
| def get_signal_phone(): | ||||
|     phone = db.child("signal").child("2").child("Phone").get().val() | ||||
|     return phone | ||||
| 
 | ||||
| 
 | ||||
| # Returns the address or else an empty string. | ||||
| def get_signal_address(): | ||||
|     address = db.child("signal").child("2").child("Address").get().val() | ||||
|     return address | ||||
| 
 | ||||
| 
 | ||||
| # Uploads the data of user input into firebase. | ||||
| def upload_signal_data(user_id, firstname, lastname, email, phone, address): | ||||
|     data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone, "Address": address} | ||||
|     db.child("signal").child("2").set(data) | ||||
| 
 | ||||
| 
 | ||||
| # Removes the inputs. | ||||
| def reset_data(): | ||||
|     db.child("signal").child("2").remove() | ||||
|  |  | |||
|  | @ -188,7 +188,7 @@ def face_recognition_inference(rec_type): | |||
| 
 | ||||
|     cam = cv2.VideoCapture(0) | ||||
| 
 | ||||
|     while True: | ||||
|     while DBHelper.get_power() == "on": | ||||
|         # imagePath = testFiles[i] | ||||
|         success, original = cam.read() | ||||
|         im = cv2.resize(original, (640, 480)) | ||||
|  |  | |||
|  | @ -1,127 +1,121 @@ | |||
| import RPi.GPIO as GPIO | ||||
| import pyrebase          # u need to install Pyrebase module firstly | ||||
| import pyrebase  # u need to install Pyrebase module firstly | ||||
| from time import sleep | ||||
| 
 | ||||
| 
 | ||||
| class Motor: | ||||
|      | ||||
|      | ||||
|     print("Starting of the program") | ||||
|      | ||||
| 
 | ||||
|     def __init__(self): | ||||
|          | ||||
|         config = {      | ||||
|           "apiKey": "AIzaSyAdL0W5HscjEDFPK4BDi6Cnc7FLa30GPYY", | ||||
|           "authDomain": "vehicleantitheftrecognition.firebaseapp.com", | ||||
|           "databaseURL": "https://vehicleantitheftrecognition.firebaseio.com/", | ||||
|           "storageBucket": "vehicleantitheftrecognition.firebaseapp.com" | ||||
| 
 | ||||
|         config = { | ||||
|             "apiKey": "AIzaSyAdL0W5HscjEDFPK4BDi6Cnc7FLa30GPYY", | ||||
|             "authDomain": "vehicleantitheftrecognition.firebaseapp.com", | ||||
|             "databaseURL": "https://vehicleantitheftrecognition.firebaseio.com/", | ||||
|             "storageBucket": "vehicleantitheftrecognition.firebaseapp.com" | ||||
|         } | ||||
| 
 | ||||
|         self.firebase = pyrebase.initialize_app(config) | ||||
|          | ||||
| 
 | ||||
|         GPIO.setmode(GPIO.BCM) | ||||
|         GPIO.setwarnings(False) | ||||
|      | ||||
|         #preset GPIO ports for 2 motors | ||||
| 
 | ||||
|         # preset GPIO ports for 2 motors | ||||
|         self.Motor1 = {'EN': 25, 'input1': 24, 'input2': 23} | ||||
|         self.Motor2 = {'EN': 17, 'input1': 27, 'input2': 22} | ||||
|          | ||||
| 
 | ||||
|         # preset the port for buttons and alarm | ||||
|         GPIO.setup(5,GPIO.IN)     # start motor button, initially True | ||||
|         GPIO.setup(13,GPIO.IN)    # stop motor button, initially True | ||||
|         GPIO.setup(16,GPIO.IN)    # start alarm button, initially True | ||||
|         GPIO.setup(26,GPIO.OUT)   # alarm output | ||||
|          | ||||
|         GPIO.setup(5, GPIO.IN)  # start motor button, initially True | ||||
|         GPIO.setup(13, GPIO.IN)  # stop motor button, initially True | ||||
|         GPIO.setup(16, GPIO.IN)  # start alarm button, initially True | ||||
|         GPIO.setup(26, GPIO.OUT)  # alarm output | ||||
| 
 | ||||
|         for x in self.Motor1: | ||||
|             GPIO.setup(self.Motor1[x], GPIO.OUT) | ||||
|             GPIO.setup(self.Motor2[x], GPIO.OUT) | ||||
| 
 | ||||
|         #utilize PWM function, enable motors and frequency is 100Hz | ||||
|         self.EN1 = GPIO.PWM(self.Motor1['EN'], 100)     | ||||
|         self.EN2 = GPIO.PWM(self.Motor2['EN'], 100)     | ||||
|         # utilize PWM function, enable motors and frequency is 100Hz | ||||
|         self.EN1 = GPIO.PWM(self.Motor1['EN'], 100) | ||||
|         self.EN2 = GPIO.PWM(self.Motor2['EN'], 100) | ||||
| 
 | ||||
|         self.EN1.start(0)                     | ||||
|         self.EN1.start(0) | ||||
|         self.EN2.start(0) | ||||
|          | ||||
|         #stop signals for motors and alarm | ||||
|         self.motorStop=False | ||||
|         self.alarmStop=False | ||||
|          | ||||
|       | ||||
|      | ||||
| # new update motor and alarm functions, are able to connect embedded system throught firebase | ||||
| 
 | ||||
|         # stop signals for motors and alarm | ||||
|         self.motorStop = False | ||||
|         self.alarmStop = False | ||||
| 
 | ||||
|     # new update motor and alarm functions, are able to connect embedded system throught firebase | ||||
| 
 | ||||
|     def start_motor(self): | ||||
|          | ||||
|         self.motorStop=self.stop_motor() | ||||
|          | ||||
|         while (not self.motorStop) or (not GPIO.input(5)): #break the loop when motor stop signal is detected | ||||
|              | ||||
|             self.motorStop=self.stop_motor() | ||||
| 
 | ||||
|      | ||||
|         self.motorStop = self.stop_motor() | ||||
| 
 | ||||
|         while (not self.motorStop) or (not GPIO.input(5)):  # break the loop when motor stop signal is detected | ||||
| 
 | ||||
|             self.motorStop = self.stop_motor() | ||||
| 
 | ||||
|     def stop_motor(self): | ||||
|          | ||||
|         database = self.firebase.database() # get alarm on/off signal from firebase | ||||
| 
 | ||||
|         database = self.firebase.database()  # get alarm on/off signal from firebase | ||||
|         signals = database.child("signal") | ||||
|         motorSignal = signals.child("1").child("motor").get().val() | ||||
|          | ||||
|          | ||||
|         if (motorSignal=="off") or (not GPIO.input(13)): | ||||
| 
 | ||||
|         if (motorSignal == "off") or (not GPIO.input(13)): | ||||
|             print("stopping motor...") | ||||
|             self.EN1.ChangeDutyCycle(0) | ||||
|             self.EN2.ChangeDutyCycle(0) | ||||
|             print("motor stops") | ||||
|             return True | ||||
|         elif motorSignal=="on": | ||||
|              | ||||
|         elif motorSignal == "on": | ||||
| 
 | ||||
|             self.EN1.ChangeDutyCycle(50) | ||||
|             self.EN2.ChangeDutyCycle(50) | ||||
| 
 | ||||
|             GPIO.output(self.Motor1['input1'], GPIO.HIGH) | ||||
|             GPIO.output(self.Motor1['input2'], GPIO.LOW) | ||||
|                  | ||||
| 
 | ||||
|             GPIO.output(self.Motor2['input1'], GPIO.HIGH) | ||||
|             GPIO.output(self.Motor2['input2'], GPIO.LOW) | ||||
|              | ||||
| 
 | ||||
|             print("motor is turned on") | ||||
|             return False | ||||
| 
 | ||||
|      | ||||
|     def start_alarm(self): | ||||
|          | ||||
|         self.alarmStop=self.stop_alarm() | ||||
|          | ||||
|         while (not self.alarmStop) or (not GPIO.input(16)): # if alarmStop is False or button is pressed | ||||
| #                                                           # enter the loop | ||||
|             self.alarmStop=self.stop_alarm()                # infinitely check if alarmStop True | ||||
|              | ||||
|                                                             # break the loop if alarm is turned off | ||||
| 
 | ||||
|         self.alarmStop = self.stop_alarm() | ||||
| 
 | ||||
|         while (not self.alarmStop) or (not GPIO.input(16)):  # if alarmStop is False or button is pressed | ||||
|             #                                                           # enter the loop | ||||
|             self.alarmStop = self.stop_alarm()  # infinitely check if alarmStop True | ||||
| 
 | ||||
|             # break the loop if alarm is turned off | ||||
| 
 | ||||
|     def stop_alarm(self): | ||||
|          | ||||
|         database = self.firebase.database() # get alarm on/off signal from firebase | ||||
| 
 | ||||
|         database = self.firebase.database()  # get alarm on/off signal from firebase | ||||
|         signals = database.child("signal") | ||||
|         alarmSignal = signals.child("1").child("alarm").get().val() | ||||
| 
 | ||||
|         if alarmSignal=="off": | ||||
|         if alarmSignal == "off": | ||||
|             print("Alarm turning off...") | ||||
|             self.alarmStop=True | ||||
|             GPIO.output(26,False) | ||||
|             self.alarmStop = True | ||||
|             GPIO.output(26, False) | ||||
|             print("Alarm is off") | ||||
|             return True | ||||
|         elif alarmSignal=="on": | ||||
|             GPIO.output(26,True) | ||||
|         elif alarmSignal == "on": | ||||
|             GPIO.output(26, True) | ||||
|             print("Alarm is turned on") | ||||
|             return False | ||||
| 
 | ||||
|          | ||||
| if _name__=="__main_": | ||||
|          | ||||
|     #print("Execute function...") | ||||
|          | ||||
|      | ||||
|     motor1=Motor() | ||||
|      | ||||
|     while True: # turn on the system forever | ||||
|          | ||||
|         motor1.start_alarm() # alarm on/off test | ||||
|         motor1.start_motor() # motor on/off test | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
| 
 | ||||
|     # print("Execute function...") | ||||
| 
 | ||||
|     motor1 = Motor() | ||||
| 
 | ||||
|     while True:  # turn on the system forever | ||||
| 
 | ||||
|         motor1.start_alarm()  # alarm on/off test | ||||
|         motor1.start_motor()  # motor on/off test | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										20
									
								
								Main.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Main.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | |||
| import DBHelper | ||||
| import Start_Engine | ||||
| import Upload_Face | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     print("Starting the Program.") | ||||
|     while True: | ||||
|         if DBHelper.get_power() == "on": | ||||
|             Start_Engine.start() | ||||
| 
 | ||||
|         if None not in (DBHelper.get_signal_firstname(), | ||||
|             DBHelper.get_signal_lastname(), | ||||
|             DBHelper.get_signal_email(), | ||||
|             DBHelper.get_signal_phone(), | ||||
|             DBHelper.get_signal_address()): | ||||
|                 Upload_Face.upload_your_face(DBHelper.get_signal_firstname(), DBHelper.get_signal_lastname(), | ||||
|                                              DBHelper.get_signal_email(), DBHelper.get_signal_phone(), | ||||
|                                              DBHelper.get_signal_address()) | ||||
|                 DBHelper.reset_data() | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								__pycache__/Start_Engine.cpython-36.pyc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								__pycache__/Start_Engine.cpython-36.pyc
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								__pycache__/Upload_Face.cpython-36.pyc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								__pycache__/Upload_Face.cpython-36.pyc
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue