Page 303 - 2020학년도 MDP과제발표회 자료집 (통신과) (3)
P. 303
def measureStart(self):
self.on_measure = True
self._start_tick = self._last_tick = self.pi.get_current_tick()
self._last_level = self.pi.read(self.gpio)
def measureStop(self):
self.on_measure = False
# lastly check the level time and add
level = self.pi.read(self.gpio)
tick = self.pi.get_current_tick()
ticks = pigpio.tickDiff(self._last_tick, tick)
if level == 0: # last level to timeout is low
self._low_ticks += ticks
elif level == 1: # last level to timeout is high
self._high_ticks += ticks
else: # timeout level, not used
pass
# Method for calculating Ratio and Concentration
def read(self):
interval = self._low_ticks + self._high_ticks
if interval > 0:
ratio = float(self._low_ticks)/float(interval)*100.0
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62
else:
ratio = 0
concentration = 0.0
tcnt = self.total_interrupt_count
wcnt = self.wrong_level_count
self.total_interrupt_count = 0
self.wrong_level_count = 0
self._start_tick = None
self._last_tick = None
self._low_ticks = 0
self._high_ticks = 0
self._last_level = 0
return (self.gpio, interval, ratio, concentration, tcnt, wcnt)
- 315 -