-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoorIO.py
More file actions
122 lines (103 loc) · 4.37 KB
/
DoorIO.py
File metadata and controls
122 lines (103 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import RPi.GPIO as GPIO
import time
from picamera import PiCamera
from time import sleep
class HardwareDoorIO():
def __init__(self, type):
# Variable to indicate hardware type
if type == "Front": self.HW = "GertBoard"
else: self.HW = "PiFace"
#===============================================================
# setLocked()
#---------------------------------------------------------------
# Set door to locked state.
# return: True(successful), False(unsuccessful)
#---------------------------------------------------------------
def setLocked(self):
# Only run if actual state is different than passed state
if self.isLocked() is False:
if(self.HW == "GertBoard"):
pin_number=7
time_Complete = 10 # to be changed
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin_number, GPIO.OUT)
GPIO.output(pin_number, 1)
time.sleep(time_Complete)
GPIO.output(pin_number, 0)
GPIO.cleanup()
# Check if operation was successful
if self.isLocked() is True:
return True
return False
#===============================================================
# setUnocked()
#---------------------------------------------------------------
# Set door to unlocked state.
# return: True(successful), False(unsuccessful)
#---------------------------------------------------------------
def setUnlocked(self):
# Only run if actual state is different than passed state
if self.isLocked() is True:
if(self.HW == "GertBoard"):
pin_number=7
time_Complete = 10 # to be changed
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin_number, GPIO.OUT)
GPIO.output(pin_number, 1)
time.sleep(time_Complete)
GPIO.output(pin_number, 0)
GPIO.cleanup()
# Check if operation was successful
if self.isLocked() is False: return True
return False
#===============================================================
# isLocked()
#---------------------------------------------------------------
# Get the current state of the lock
# return: True(Locked), False(Unlocked)
#---------------------------------------------------------------
def isLocked(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, GPIO.PUD_UP)
if not GPIO.input(12):
return True # Door Locked
else:
return False # Door Unlocked
#===============================================================
# isOpen()
#---------------------------------------------------------------
# Get the current state of the door
# return: True(Open), False(Closed)
#---------------------------------------------------------------
def isOpen(self):
return False
#===============================================================
# displayLCD()
#---------------------------------------------------------------
# Display message on LCD
#---------------------------------------------------------------
def displayLCD(self, message):
return
#===============================================================
# playSound()
#---------------------------------------------------------------
# Play sound on keypad panel speaker
#---------------------------------------------------------------
def playSound(self, sound):
return
#===============================================================
# takePicture()
#---------------------------------------------------------------
# Take picture with camera
# return: byte[](Picture taken), False(Error Occurred)
#---------------------------------------------------------------
def takePicture(self):
try:
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
except IOError:
pass
#===============================================================