Added the main execution code.

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-17 23:14:51 -05:00
parent 7449682016
commit 6296e949ad
10 changed files with 134 additions and 79 deletions

View file

@ -38,13 +38,13 @@ def login(username, password):
print("Invalid username or 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): def upload_data(user_id, firstname, lastname, email, phone, address):
data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone, "Address": address} data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone, "Address": address}
db.child("Users").child(user_id).set(data) 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): def remove_data(user_id):
db.child("Users").child(user_id).remove() db.child("Users").child(user_id).remove()
@ -143,3 +143,44 @@ def get_power():
def set_power(power): def set_power(power):
data = {"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()

View file

@ -188,7 +188,7 @@ def face_recognition_inference(rec_type):
cam = cv2.VideoCapture(0) cam = cv2.VideoCapture(0)
while True: while DBHelper.get_power() == "on":
# imagePath = testFiles[i] # imagePath = testFiles[i]
success, original = cam.read() success, original = cam.read()
im = cv2.resize(original, (640, 480)) im = cv2.resize(original, (640, 480))

View file

@ -2,9 +2,8 @@ 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 from time import sleep
class Motor: class Motor:
print("Starting of the program") print("Starting of the program")
def __init__(self): def __init__(self):
@ -46,8 +45,6 @@ class Motor:
self.motorStop = False self.motorStop = False
self.alarmStop = False self.alarmStop = False
# new update motor and alarm functions, are able to connect embedded system throught firebase # new update motor and alarm functions, are able to connect embedded system throught firebase
def start_motor(self): def start_motor(self):
@ -58,14 +55,12 @@ class Motor:
self.motorStop = self.stop_motor() self.motorStop = self.stop_motor()
def stop_motor(self): 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") signals = database.child("signal")
motorSignal = signals.child("1").child("motor").get().val() 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...") print("stopping motor...")
self.EN1.ChangeDutyCycle(0) self.EN1.ChangeDutyCycle(0)
@ -86,7 +81,6 @@ class Motor:
print("motor is turned on") print("motor is turned on")
return False return False
def start_alarm(self): def start_alarm(self):
self.alarmStop = self.stop_alarm() self.alarmStop = self.stop_alarm()
@ -96,6 +90,7 @@ class Motor:
self.alarmStop = self.stop_alarm() # infinitely check if alarmStop True self.alarmStop = self.stop_alarm() # infinitely check if alarmStop True
# break the loop if alarm is turned off # break the loop if alarm is turned off
def stop_alarm(self): 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
@ -114,11 +109,10 @@ class Motor:
return False return False
if _name__=="__main_": if __name__ == "__main__":
# print("Execute function...") # print("Execute function...")
motor1 = Motor() motor1 = Motor()
while True: # turn on the system forever while True: # turn on the system forever

20
Main.py Normal file
View 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.