当前位置: 首页>>代码示例>>Python>>正文


Python Sensor.get_temperature方法代码示例

本文整理汇总了Python中sensor.Sensor.get_temperature方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.get_temperature方法的具体用法?Python Sensor.get_temperature怎么用?Python Sensor.get_temperature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor.Sensor的用法示例。


在下文中一共展示了Sensor.get_temperature方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import get_temperature [as 别名]
class Control:

    def __init__(self):
        logging.getLogger('pyro').info('Control is starting...')
        self.heat_start = 0
        self.heat_end = 0
        self.sensor = Sensor()
        self.turn_led_off(ready_led)

    def start(self):
        while not self.sensor.ready():
            self.sensor.initialize()
            self.flash_led(program_led, 1, 5)

        self.turn_led_on(ready_led)
        #GPIO.add_event_detect(program_button, GPIO.FALLING, callback=self.toggle_program, bouncetime=5000)
        scheduler.start()
        scheduler.add_job(self.track, 'interval', seconds=2)
        scheduler.add_job(self.control_power, 'interval', seconds=5)
        scheduler.print_jobs()

    def toggle_program(self, channel):
        db = get_db()
        enabled = db.get_enabled()
        logging.getLogger('pyro').info('Program was: %s' % enabled)
        if enabled == 'true':
            logging.getLogger('pyro').info('Program will be set to : false')
            db.set_enabled(False)
            self.turn_led_off(program_led)
        else:
            db.set_enabled(True)
            self.turn_led_on(program_led)
        enabled = db.get_enabled()
        logging.getLogger('pyro').info('Program is: %s' % enabled)
        db.shutdown()

    def turn_led_on(self, led):
        GPIO.output(led, 1)

    def turn_led_off(self, led):
        GPIO.output(led, 0)

    def flash_led(self, led, on_duration, num_times):
        count = 0
        while count < num_times:
            self.turn_led_on(led)
            time.sleep(on_duration)
            self.turn_led_off(led)
            time.sleep(.5)
            count += 1

    def set_heat_source(self, switch):
        GPIO.output(heat_source_pin, switch)

    def heat_is_on(self):
        return GPIO.input(heat_source_pin)

    def burst_heat(self, heat_duration, cool_duration):
        logging.getLogger('pyro').debug('starting burst..')
        now = current_time()
        if self.heat_is_on():
            logging.getLogger('pyro').debug('heat is already on %s %s %s' %
                                            (now, self.heat_start, heat_duration))
            if now > self.heat_start + heat_duration:
                logging.getLogger('pyro').debug('turning it off')
                self.heat_source_off()
            else:
                logging.getLogger('pyro').debug('leaving it on')
        else:
            logging.getLogger('pyro').debug('heat is off %s %s %s' %
                                            (now, self.heat_end, cool_duration))
            if now > self.heat_end + cool_duration:
                logging.getLogger('pyro').debug('cool done period ended, turing heat on')
                self.heat_source_on()
            else:
                logging.getLogger('pyro').debug('still cooling down')

    def heat_source_on(self):
        self.heat_start = current_time()
        self.set_heat_source(True)

    def heat_source_off(self):
        self.heat_end = current_time()
        self.set_heat_source(False)

    def track(self):
        current_temp = self.sensor.get_temperature()
        try:
            db = get_db()
            db.add_temperature(current_temp)
            db.shutdown()
        except Exception as e:
            print e
            print e.message

    def control_power(self):
        try:
            db = get_db()
            control_data = db.get_control_data()
            logging.getLogger('pyro').debug('using %s to control power' % control_data)
#.........这里部分代码省略.........
开发者ID:gurumitts,项目名称:pyrokinesis,代码行数:103,代码来源:control.py


注:本文中的sensor.Sensor.get_temperature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。