-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglussconRASPI.py
More file actions
112 lines (103 loc) · 2.8 KB
/
glussconRASPI.py
File metadata and controls
112 lines (103 loc) · 2.8 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
import Adafruit_ADS1x15
import RPi.GPIO as GPIO
import time
import math
from time import sleep
from flask import Flask
import sys
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
adc = Adafruit_ADS1x15.ADS1115()
def actNameFromNumber(n):
m = n % 6
l = n / 6
return ''.join([chr(ord('A')+l),chr(ord('0')+m)])
def setmuxsel(num):
if num == 0:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
GPIO.output(23,GPIO.LOW)
GPIO.output(22,GPIO.LOW)
elif num == 1:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
GPIO.output(23,GPIO.LOW)
GPIO.output(22,GPIO.HIGH)
elif num == 2:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
GPIO.output(23,GPIO.HIGH)
GPIO.output(22,GPIO.LOW)
elif num == 3:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
GPIO.output(23,GPIO.HIGH)
GPIO.output(22,GPIO.HIGH)
elif num == 4:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
GPIO.output(23,GPIO.LOW)
GPIO.output(22,GPIO.LOW)
elif num == 5:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
GPIO.output(23,GPIO.LOW)
GPIO.output(22,GPIO.HIGH)
elif num == 6:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
GPIO.output(23,GPIO.HIGH)
GPIO.output(22,GPIO.LOW)
elif num == 7:
GPIO.output(25,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
GPIO.output(23,GPIO.HIGH)
GPIO.output(22,GPIO.HIGH)
elif num == 8:
GPIO.output(25,GPIO.HIGH)
GPIO.output(24,GPIO.LOW)
GPIO.output(23,GPIO.LOW)
GPIO.output(22,GPIO.LOW)
@app.route("/")
# '''
# def getpotval():
# result = "{"
# setmuxsel(8)
# result = result + "\"A8: " #%d\": " % (i)
# result = result + str(int(math.floor(adc.read_adc(0,gain=2/3)/17)))
# return result
# '''
@app.route("/")
def getpotval():
result = "{"
for i in range(0,9):
#print result
setmuxsel(i)
# setmuxsel(7)
# Because the current glusscon is physcially wired wrong,
# I attempt to correct it in software here by swapping #1 and #2.
if (i == 1):
result = result + "\""+actNameFromNumber(3) +"\": "
elif (i == 2):
result = result + "\""+actNameFromNumber(1) +"\": "
elif (i == 3):
result = result + "\""+actNameFromNumber(4) +"\": "
elif (i == 4):
result = result + "\""+actNameFromNumber(5) +"\": "
elif (i == 5):
result = result + "\""+actNameFromNumber(2) +"\": "
else:
result = result + "\""+actNameFromNumber(i) +"\": "
result = result + str(int(math.floor(adc.read_adc(0,gain=2/3)/17)))
if i == 8:
result = result + "\n"
else:
result = result + ",\n"
print >> sys.stderr, result
return result + "}"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)