本文整理汇总了Python中sensor.Sensor.get_cpm方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.get_cpm方法的具体用法?Python Sensor.get_cpm怎么用?Python Sensor.get_cpm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor.Sensor
的用法示例。
在下文中一共展示了Sensor.get_cpm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Manager
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import get_cpm [as 别名]
#.........这里部分代码省略.........
now = time.time()
self.vprint(
2, 'sleep_until offset is {} seconds'.format(now - end_time))
# normally this offset is < 0.1 s
# although a reboot normally produces an offset of 9.5 s
# on the first cycle
if not catching_up_flag and (now - end_time > 10 or now < end_time):
# raspberry pi clock reset during this interval
# normally the first half of the condition triggers it.
raise SleepError
def get_interval(self, start_time):
"""
Return start and end time for interval, based on given start_time.
"""
end_time = start_time + self.interval
return start_time, end_time
def data_log(self, file, cpm, cpm_err):
"""
Writes cpm to data-log.
"""
time_string = time.strftime("%Y-%m-%d %H:%M:%S")
if self.datalogflag:
with open(file, 'a') as f:
f.write('{0}, {1}, {2}'.format(time_string, cpm, cpm_err))
f.write('\n')
self.vprint(2, 'Writing CPM to data log at {}'.format(file))
def handle_cpm(self, this_start, this_end):
"""
Get CPM from sensor, display text, send to server.
"""
cpm, cpm_err = self.sensor.get_cpm(this_start, this_end)
counts = int(round(cpm * self.interval / 60))
self.data_handler.main(
self.datalog, cpm, cpm_err, this_start, this_end, counts)
def takedown(self):
"""Delete self and child objects and clean up GPIO nicely."""
# sensor
self.sensor.cleanup()
del(self.sensor)
# power LED
try:
self.power_LED.off()
except AttributeError:
# no LED
pass
try:
GPIO.cleanup()
except NameError:
# not on a Raspberry Pi so no GPIO
pass
# send the rest of the queue object to DEFAULT_DATA_BACKLOG_FILE upon
# shutdown
self.data_handler.send_all_to_backlog()
# self. can I even do this?
del(self)
@classmethod
def from_argparse(cls):