-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathdiagnostic.py
105 lines (86 loc) · 2.67 KB
/
diagnostic.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from machine import ADC
from time import sleep
from europi import (
OLED_HEIGHT,
OLED_WIDTH,
ain,
b1,
b2,
cv1,
cv2,
cv3,
cv4,
cv5,
cv6,
din,
k1,
k2,
oled,
europi_config,
thermometer,
)
from europi_script import EuroPiScript
import configuration
"""
A diagnostic utility intended to help prove out a new EuroPi build and calibration. Each aspect of the EuroPi's hardware
is exercised.
- din: value displayed on screen
- ain: value displayed on screen
- b1: rotate output voltages backwards
- b2: rotate output voltages forwards
- k1: value 0-99 displayed on screen
- k2: value 0-99 displayed on screen
- cvX: output a constant voltage, one of [0, 0.5, 1, 2.5, 5, 10]
"""
TEMP_CONV_FACTOR = 3.3 / 65535
class Diagnostic(EuroPiScript):
def __init__(self):
super().__init__()
self.voltages = [
0, # min
0.5, # not 0 but still below DI's threshold
1,
2.5,
5,
10, # max
]
self.temp_units = self.config.TEMP_UNITS
self.use_fahrenheit = self.temp_units == "F"
@classmethod
def config_points(cls):
return [configuration.choice(name="TEMP_UNITS", choices=["C", "F"], default="C")]
def calc_temp(self):
# see the pico's datasheet for the details of this calculation
t = thermometer.read_temperature()
if self.use_fahrenheit:
t = (t * 1.8) + 32
return t
def rotate_r(self):
self.voltages = self.voltages[-1:] + self.voltages[:-1]
def rotate_l(self):
self.voltages = self.voltages[1:] + self.voltages[:1]
def main(self):
b1.handler(self.rotate_l)
b2.handler(self.rotate_r)
while True:
# Set the outputs to useful values
cv1.voltage(self.voltages[0])
cv2.voltage(self.voltages[1])
cv3.voltage(self.voltages[2])
cv4.voltage(self.voltages[3])
cv5.voltage(self.voltages[4])
cv6.voltage(self.voltages[5])
oled.fill(0)
# calc and format temp
t = self.calc_temp()
formatted_temp = f"{int(t)}{self.temp_units}"
# display the input values
oled.text(f"ain: {ain.read_voltage():5.2f}v {formatted_temp}", 2, 3, 1)
oled.text(f"k1: {k1.read_position():2} k2: {k2.read_position():2}", 2, 13, 1)
oled.text(f"din:{din.value()} b1:{b1.value()} b2:{b2.value()}", 2, 23, 1)
# show the screen boundaries
oled.rect(0, 0, OLED_WIDTH, OLED_HEIGHT, 1)
oled.show()
sleep(0.1)
if __name__ == "__main__":
Diagnostic().main()