-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.py
75 lines (54 loc) · 2.16 KB
/
pi.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
import qwiic_oled_display
from time import sleep
import threading as th
from constants import DELAY_SECONDS, PORT
from devices import Magnetometer, Temperature
from Flask import Flask
app = Flask(__name__)
def lcd_updater():
myOLED = qwiic_oled_display.QwiicOledDisplay()
if not myOLED.connected:
raise RuntimeError("The Qwiic Micro OLED device isn't connected to the system. Please check connection")
myOLED.begin()
# clear(ALL) will clear out the OLED's graphic memory.
# clear(PAGE) will clear the Arduino's display buffer.
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
myOLED.clear(myOLED.PAGE) # Clear the display's memory (gets rid of artifacts)
myOLED.display()
while True:
myOLED.clear(myOLED.PAGE) # Clear the display's memory (gets rid of artifacts)
myOLED.line(x0=66, y0=0, x1=66, y1=32)
myOLED.set_cursor(74, 0) # Set cursor to top-middle-left
myOLED.set_font_type(0) # Repeat
myOLED.print('Celsius')
myOLED.set_cursor(74, 16) # Set cursor to top-middle-left
myOLED.set_font_type(1) # Repeat
myOLED.print(f'{temperature():2.1f}')
myOLED.set_cursor(0, 0) # Set cursor to top-middle-left
myOLED.set_font_type(0) # Repeat
myOLED.print('Gauss')
myOLED.set_cursor(0, 16) # Set cursor to top-middle-left
myOLED.set_font_type(1) # Repeat
myOLED.print(f'{magnetometer.magnitude:1.2f}')
myOLED.display()
sleep(DELAY_SECONDS)
@app.route('/temperature')
def measurements():
return str(temperature())
@app.route('/magnetic')
def measurements():
return '{:g} {:g} {:g}'.format(*magnetometer())
@app.route('/magnitude')
def measurements():
return str(magnetometer.magnitude)
if __name__ == '__main__':
magnetometer = Magnetometer()
temperature = Temperature()
# init thread for LCD printing
th_lcd = th.Thread(target=lcd_updater, daemon=True, name='lcd_updater')
th_lcd.start()
# init server
PORT = 8080
IP = "0.0.0.0"
print('Initiating server', flush=True)
app.run_server(debug=False, host=IP, port=PORT, threaded=True)