diff --git a/DBHelper.py b/DBHelper.py index ba97a1faf..3efcc72a3 100644 --- a/DBHelper.py +++ b/DBHelper.py @@ -51,51 +51,31 @@ def remove_data(user_id): # Returns the first name or else an empty string. def get_firstname(user_id): - firstname = "" - users = db.child("Users").get() - for user in users.each(): - if user.key() == user_id: - firstname = user.val()["First Name"] + firstname = db.child("Users").child(str(user_id)).child("First Name").get().val() return firstname # Returns the last name or else an empty string. def get_lastname(user_id): - lastname = "" - users = db.child("Users").get() - for user in users.each(): - if user.key() == user_id: - lastname = user.val()["Last Name"] + lastname = db.child("Users").child(str(user_id)).child("Last Name").get().val() return lastname # Returns the e-mail or else an empty string. def get_email(user_id): - email = "" - users = db.child("Users").get() - for user in users.each(): - if user.key() == user_id: - email = user.val()["E-Mail"] + email = db.child("Users").child(str(user_id)).child("E-Mail").get().val() return email # Returns the phone or else an empty string. def get_phone(user_id): - phone = "" - users = db.child("Users").get() - for user in users.each(): - if user.key() == user_id: - phone = user.val()["Phone"] + phone = db.child("Users").child(str(user_id)).child("Phone").get().val() return phone # Returns the address or else an empty string. def get_address(user_id): - address = "" - users = db.child("Users").get() - for user in users.each(): - if user.key() == user_id: - address = user.val()["Address"] + address = db.child("Users").child(str(user_id)).child("Address").get().val() return address @@ -127,3 +107,39 @@ def delete_user_photo(user_photo): # Deletes photo of the specified thief. def delete_thief_photo(user_photo): storage.delete('Photos_of_Thieves/' + user_photo) + + +# Motor signal getter +def get_motor(): + motor = db.child("signal").child("1").child("motor").get().val() + return motor + + +# Motor signal setter +def set_motor(motor): + data = {"motor": motor} + db.child("signal").child("1").set(data) + + +# Alarm signal getter +def get_alarm(): + alarm = db.child("signal").child("1").child("alarm").get().val() + return alarm + + +# Alarm signal setter +def set_alarm(alarm): + data = {"alarm": alarm} + db.child("signal").child("1").set(data) + + +# Power signal getter +def get_power(): + alarm = db.child("signal").child("1").child("power").get().val() + return alarm + + +# Power signal setter +def set_power(power): + data = {"power": power} + db.child("signal").child("1").set(data) \ No newline at end of file diff --git a/Facial_Recognition_Registration.py b/Facial_Recognition_Registration.py index 418581b81..d73549514 100644 --- a/Facial_Recognition_Registration.py +++ b/Facial_Recognition_Registration.py @@ -28,3 +28,5 @@ def register_your_face(label): cap.release() cv2.destroyAllWindows() + + diff --git a/Facial_Recognition_Wrapper.py b/Facial_Recognition_Wrapper.py index 2b932e702..d4e5bb5d7 100644 --- a/Facial_Recognition_Wrapper.py +++ b/Facial_Recognition_Wrapper.py @@ -7,8 +7,8 @@ import numpy as np import Facial_Recognition_Render as fr import _pickle as cPickle import glob - -'import Hardware.Motor' # Line 225-228 +import DBHelper +import Hardware.Updated_HW_codes.NewMotorFunc # Line 225-228 faceWidth = 320 faceHeight = 320 @@ -223,10 +223,10 @@ def face_recognition_inference(rec_type): text = '{} {}%'.format(labelsMap[predictedLabel], round(score, 5)) cv2.rectangle(original, (x1, y1), (x2, y2), (0, 255, 0), 5) cv2.putText(original, text, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 3) - 'Hardware.Motor.Motor.stop_alarm()' - 'Hardware.Motor.Motor.start_motor()' - 'Hardware.Motor.Motor.stop_motor()' - 'Hardware.Motor.Motor.start_alarm()' + DBHelper.set_motor("on") + Hardware.Updated_HW_codes.NewMotorFunc.Motor.start_motor() + DBHelper.set_alarm("on") + Hardware.Updated_HW_codes.NewMotorFunc.Motor.start_alarm() cv2.imshow('Face Recognition Demo', original) diff --git a/Hardware/Updated HW codes/NewMotorFunc.py b/Hardware/Updated_HW_codes/NewMotorFunc.py similarity index 97% rename from Hardware/Updated HW codes/NewMotorFunc.py rename to Hardware/Updated_HW_codes/NewMotorFunc.py index 021a0d421..3fc146523 100644 --- a/Hardware/Updated HW codes/NewMotorFunc.py +++ b/Hardware/Updated_HW_codes/NewMotorFunc.py @@ -1,127 +1,127 @@ -import RPi.GPIO as GPIO -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" - } - - self.firebase = pyrebase.initialize_app(config) - - GPIO.setmode(GPIO.BCM) - GPIO.setwarnings(False) - - #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 - - 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) - - 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 - - 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() - - - def stop_motor(self): - - 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)): - print("stopping motor...") - self.EN1.ChangeDutyCycle(0) - self.EN2.ChangeDutyCycle(0) - print("motor stops") - return True - 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 - def stop_alarm(self): - - 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": - print("Alarm turning off...") - self.alarmStop=True - GPIO.output(26,False) - print("Alarm is off") - return 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 +import RPi.GPIO as GPIO +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" + } + + self.firebase = pyrebase.initialize_app(config) + + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + #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 + + 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) + + 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 + + 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() + + + def stop_motor(self): + + 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)): + print("stopping motor...") + self.EN1.ChangeDutyCycle(0) + self.EN2.ChangeDutyCycle(0) + print("motor stops") + return True + 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 + def stop_alarm(self): + + 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": + print("Alarm turning off...") + self.alarmStop=True + GPIO.output(26,False) + print("Alarm is off") + return 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 \ No newline at end of file diff --git a/Hardware/Updated HW codes/README.md b/Hardware/Updated_HW_codes/README.md similarity index 100% rename from Hardware/Updated HW codes/README.md rename to Hardware/Updated_HW_codes/README.md diff --git a/Hardware/__pycache__/Motor.cpython-36.pyc b/Hardware/__pycache__/Motor.cpython-36.pyc index 2beb98a5d..33ca6a5e8 100644 Binary files a/Hardware/__pycache__/Motor.cpython-36.pyc and b/Hardware/__pycache__/Motor.cpython-36.pyc differ diff --git a/UI/.idea/gradle.xml b/UI/.idea/gradle.xml index b9f8a5eb5..ac6b0aec6 100644 --- a/UI/.idea/gradle.xml +++ b/UI/.idea/gradle.xml @@ -1,5 +1,6 @@ +