-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgpio_connect.py
87 lines (77 loc) · 3.03 KB
/
gpio_connect.py
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
"""This program consist of the functions which are used in main.py file for operating the GPIO pins and ending the transaction when the operator presses the button on JuiceBox
"""
from __future__ import print_function
import RPi.GPIO as GPIO
from juicebox import *
# GPIO pins
pin_button = 40
pin_green = 7
pin_red = 8
pin_connect = 3
pin_led_ring = 33
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_connect, GPIO.OUT)
GPIO.output(pin_connect, False)
GPIO.setup(pin_led_ring, GPIO.OUT)
GPIO.output(pin_led_ring, False)
# subclass of Juicebox which contain the GPIO pins functions
class ConnectgpioPins(Juicebox):
"""This class is the subclass of Juicebox which contain the GPIO pins utility and ending transaction functionality
Attributes
----------
rid_1: str
RFID number of the operator
rid_2: str
RFID number of the staff member
temp_rid: str
temporary variable for storing the RFID number
role_1: int
assigned the default value of role_1 as 0
role_2: int
assigned the default value of role_2 as 0
trans_id: str
transaction id used for ending the transaction
go: bool
assigned the default value as False
"""
# function for ending the transaction after user hits the juicebox button
def end_trans(self):
"""This function is used to end the transaction when the operator hits the JuiceBox button. It ends the ticket that was initiated on the FabApp Dashboard
Returns:
str: It prints the success message with ticket number that has been closed
"""
GPIO.output(pin_connect, True)
GPIO.output(pin_led_ring, True)
time.sleep(0.5)
GPIO.wait_for_edge(pin_button, GPIO.FALLING)
payload = {"type": "end_transaction", "device": device_id}
try:
r = requests.request(
"POST", serverURL, json=payload, headers=headers)
response = r.json()
print(response)
except Exception as e:
response = "could not end transaction"
print(response, file=sys.stderr)
raise e
GPIO.output(pin_connect, False)
GPIO.output(pin_led_ring, False)
return response
def heart_beat(self):
"""This function is used to show output on the JuiceBox device by blinking the LED ligths. After the operator scans their tokens it is validated and if the information is correct it blinks once and solid red light is displayed. If the information is not correct it blinks multiple times and shuts down.
"""
global pin_led_ring
time.sleep(0.5)
GPIO.output(pin_led_ring, True)
time.sleep(0.25)
GPIO.output(pin_led_ring, False)
time.sleep(0.25)
GPIO.output(pin_led_ring, True)
time.sleep(0.25)
GPIO.output(pin_led_ring, False)
def refresh(self):
"""This function is used to refresh the JuiceBox for the next time use
"""
self.go = False
# end of subclass