|
1 | | -class SerialLogger: |
2 | | - |
3 | | - # def __init__(self): |
4 | | - # print("MIN_PRESSURE::", detector.min_pressure) |
5 | | - # print("HIGH_PRESSURE_THRESHOLD::", detector.high_pressure) |
6 | | - |
7 | | - @classmethod |
8 | | - def run(cls, detector, state_map, puff_stat): |
9 | | - polarity, peak_level, duration = puff_stat |
10 | | - state_str = state_map[detector.state][polarity][0] |
11 | | - state_str = state_str.replace(" ", "_").upper() |
12 | | - |
13 | | - input_type_str = state_map[detector.state][polarity][1][peak_level] |
14 | | - |
15 | | - if state_map[detector.state]["name"] == "WAITING": |
16 | | - print(state_str) |
17 | | - |
18 | | - if state_map[detector.state]["name"] == "STARTED": |
19 | | - print(state_str.replace(" ", "_").upper()) |
20 | | - |
21 | | - if state_map[detector.state]["name"] == "DETECTED": |
22 | | - type_detected = input_type_str[0].replace(" ", "_").upper() |
23 | | - log_str = "%s::%s::DURATION:%0.3f" % (state_str, type_detected, duration) |
24 | | - print(log_str) |
25 | | - |
26 | | - |
27 | | -################################# |
28 | | -# def log_state_change(self, puff_stat): |
29 | | -# state_changed = self.prev_state == self.state |
30 | | -# self.prev_state = self.state |
31 | | -# if state_changed: |
32 | | -# return |
33 | | -# polarity, peak_level, duration = puff_stat |
34 | | - |
35 | | -# state_str = STATE_MAP[self.state][polarity][0] |
36 | | -# input_type_str = STATE_MAP[self.state][polarity][1][peak_level] |
37 | | -# state_str = state_str.replace(" ", "_").upper() |
38 | | -# if self.state is WAITING: |
39 | | -# print(state_str) |
40 | | -# if self.state is STARTED: |
41 | | -# print(state_str.replace(" ", "_").upper()) |
42 | | -# if self.state is DETECTED: |
43 | | -# type_detected = input_type_str[0] |
44 | | -# log_str = "%s::%s::DURATION:%0.3f" % (state_str, type_detected, duration) |
45 | | -# print(log_str) |
| 1 | +import puff_detector |
| 2 | + |
| 3 | +detector = puff_detector.PuffDetector() |
| 4 | + |
| 5 | +@detector.on_sip |
| 6 | +def on_sip(strength, duration): |
| 7 | + if strength == puff_detector.STRONG: |
| 8 | + strength_str = "STRONG" |
| 9 | + if strength == puff_detector.SOFT: |
| 10 | + strength_str = "SOFT" |
| 11 | + log_str = "DETECTED::SIP:%s::DURATION:%0.3f" % (strength_str, duration) |
| 12 | + print(log_str) |
| 13 | + |
| 14 | +@detector.on_puff |
| 15 | +def on_puff(strength, duration): |
| 16 | + if strength == puff_detector.STRONG: |
| 17 | + strength_str = "STRONG" |
| 18 | + if strength == puff_detector.SOFT: |
| 19 | + strength_str = "SOFT" |
| 20 | + log_str = "DETECTED::PUFF:%s::DURATION:%0.3f" % (strength_str, duration) |
| 21 | + print(log_str) |
| 22 | + |
| 23 | +detector.run() |
0 commit comments