-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmodels.py
More file actions
114 lines (99 loc) · 3.16 KB
/
models.py
File metadata and controls
114 lines (99 loc) · 3.16 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
import itertools
import time
try:
import RPi.GPIO as GPIO
except ImportError:
import helpers.gpio_mock as GPIO
from helpers import barcode
from db import get_db, close_connection
class BrewSettings:
@staticmethod
def get(user):
cur = get_db().cursor()
cur.execute("SELECT * FROM brewSettings WHERE userID=?", (user,))
r = [
dict((cur.description[i][0], value) for i, value in enumerate(row))
for row in cur.fetchall()
]
return {"brewSettings": r}
class CoffeeInfo:
@staticmethod
def get(coffeeTypeId):
cur = get_db().cursor()
cur.execute("SELECT * FROM coffeeTypes WHERE coffeeTypeId=?", (coffeeTypeId,))
r = [
dict((cur.description[i][0], value) for i, value in enumerate(row))
for row in cur.fetchall()
]
cur.close()
close_connection()
return {"brewSettings": r}
class BarcodeScanner:
@staticmethod
def get():
count = 1
while count < 12:
contents = barcode.scan()
count = len(contents)
barcode.duringScan()
else:
for line in open("/var/mugsy/decaf/helpers/upc.txt"):
last = line
upc = [last.rstrip("\n")]
barcode.afterScan()
cur = get_db().cursor()
cur.execute("SELECT * FROM coffeeTypes WHERE upc=?", (upc,))
r = [
dict((cur.description[i][0], value) for i, value in enumerate(row))
for row in cur.fetchall()
]
cur.close()
close_connection()
return {"coffeeInfo": r}
class PinMappings:
@staticmethod
def get(hardwareType):
cur = get_db().cursor()
cur.execute(
"SELECT pinMappingId, relayChannel, j.hardwareTypeId, "
"pinNumber FROM (hardwareTypes INNER JOIN pinMappings ON "
"(hardwareTypes.hardwareTypeID = pinMappings.hardwareTypeId))"
" AS j WHERE hardwareType=?",
(hardwareType,),
)
r = [
dict((cur.description[i][0], value) for i, value in enumerate(row))
for row in cur.fetchall()
]
cur.close()
close_connection()
return {"pinInfo": r}
class RelayControl:
@staticmethod
def get(pin, channel, timeOn, repeat, repeatDelay, hardware):
pin = int(pin)
timeOn = float(timeOn)
repeat = int(repeat)
repeatDelay = float(repeatDelay)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
if repeat > 1:
for _ in itertools.repeat(None, repeat):
GPIO.output(pin, GPIO.LOW)
time.sleep(timeOn)
GPIO.output(pin, GPIO.HIGH)
time.sleep(repeatDelay)
else:
GPIO.output(pin, GPIO.LOW)
time.sleep(timeOn)
GPIO.output(pin, GPIO.HIGH)
GPIO.cleanup()
response = {
"pin": pin,
"channel": channel,
"timeOn": timeOn,
"repeat": repeat,
"repeatDelay": repeatDelay,
"hardware": hardware,
}
return {"relayController": response}