-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.py
70 lines (54 loc) · 1.27 KB
/
sensor.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
import pinesp32
class Sensor():
"""Sensor class, for one phototransistor"""
def __init__(self, channel_number: int):
self.channel = channel_number
self.min = 0
self.max = 4096
self.val = 0
def map_raw_value(self) -> int:
""" map raw value to range 0-100"""
return ((self.val - self.min) * 100) // (self.max - self.min)
# return int(((self.val - self.min) // (self.max - self.min)))
# Sensor instances
white: list[Sensor] = [
Sensor(pinesp32.ADC_PT_L_1),
Sensor(pinesp32.ADC_PT_L_0),
Sensor(pinesp32.ADC_PT_M),
Sensor(pinesp32.ADC_PT_R_0),
Sensor(pinesp32.ADC_PT_R_1),
]
green: list[Sensor] = [
Sensor(pinesp32.ADC_PT_L_0),
Sensor(pinesp32.ADC_PT_R_0),
]
red: list[Sensor] = [
Sensor(pinesp32.ADC_PT_L_0),
Sensor(pinesp32.ADC_PT_R_0),
]
silver: list[Sensor] = [
Sensor(pinesp32.ADC_PT_REF_L),
Sensor(pinesp32.ADC_PT_REF_R),
]
front_green: list[Sensor] = [
Sensor(pinesp32.ADC_PT_RGB),
]
front_red: list[Sensor] = [
Sensor(pinesp32.ADC_PT_RGB),
]
all: list[list[Sensor]] = [
white,
green,
red,
silver,
front_green,
front_red,
]
all_names: list[str] = [
"white",
"green",
"red",
"silver",
"front_green",
"front_red",
]