當前位置: 首頁>>代碼示例>>Python>>正文


Python gpio_pins.GPIO類代碼示例

本文整理匯總了Python中gpio_pins.GPIO的典型用法代碼示例。如果您正苦於以下問題:Python GPIO類的具體用法?Python GPIO怎麽用?Python GPIO使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GPIO類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_rain

def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense) == gv.sd['rs']: #  Rain sensor changed, reading and gv.sd['rs'] are inverse.
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs'] #  toggle
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense) != gv.sd['rs']:  # Rain sensor changed
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs'] #  toggle
    except NameError:
        pass
開發者ID:sbruggeman,項目名稱:SIP,代碼行數:33,代碼來源:helpers.py

示例2: check_rain

def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if not GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
    except NameError:
        pass
開發者ID:aocana,項目名稱:SIP,代碼行數:35,代碼來源:helpers.py

示例3: reboot

def reboot(wait=1, block=False):
    """
    Reboots the Raspberry Pi from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Rebooting...')
        except Exception:
            pass
        subprocess.Popen(['reboot'])
    else:
        t = Thread(target=reboot, args=(wait, True))
        t.start()
開發者ID:aocana,項目名稱:SIP,代碼行數:27,代碼來源:helpers.py

示例4: poweroff

def poweroff(wait=1, block=False):
    """
    Powers off the Raspberry Pi from a new thread.
    
    @type wait: int or float
    @param wait: number of seconds to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
開發者ID:aocana,項目名稱:SIP,代碼行數:27,代碼來源:helpers.py

示例5: restart

def restart(wait=1, block=False):
    """
    Restarts the software from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        report_restart()
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            gv.logger.info(_('Restarting...'))
        except Exception:
            pass
        subprocess.Popen('service sip restart'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
開發者ID:bkoblenz,項目名稱:SIP,代碼行數:28,代碼來源:helpers.py

示例6: GET

 def GET(self):
     try:
         GPIO.output(pin_relay, GPIO.HIGH)  # turn relay on
         time.sleep(3)
         GPIO.output(pin_relay, GPIO.LOW)  # Turn relay off
     except Exception:
         pass
     raise web.seeother('/')  # return to home page
開發者ID:alustig,項目名稱:OSPi,代碼行數:8,代碼來源:relay.py

示例7: notify_zone_change

def notify_zone_change(name, **kw):
    relayGPIO = 10 
    targetZone = 8

    if len(gv.srvals) >= targetZone:
        if gv.srvals[targetZone] == 1:
            GPIO.output(relayGPIO, GPIO.HIGH)
        else:
            GPIO.output(relayGPIO, GPIO.LOW)
開發者ID:greglarious,項目名稱:sip_plugins,代碼行數:9,代碼來源:zone8_relay.py

示例8: check_rain

def check_rain():
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if not GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
    except NameError:
        pass
開發者ID:ntc490,項目名稱:OSPi,代碼行數:14,代碼來源:helpers.py

示例9: check_rain

def check_rain():
    try:
        if gv.sd['rst'] == 0:
            if GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
        elif gv.sd['rst'] == 1:
            if not GPIO.input(pin_rain_sense):
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
    except NameError:
        pass
開發者ID:alustig,項目名稱:OSPi,代碼行數:14,代碼來源:helpers.py

示例10: poweroff

def poweroff(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
開發者ID:ntc490,項目名稱:OSPi,代碼行數:15,代碼來源:helpers.py

示例11: GET

    def GET(self):
        global pi
        try:
            if gv.use_pigpio:
                pi.write(pin_relay, 1)  
            else:
                GPIO.output(pin_relay, GPIO.HIGH)  # turn relay on
            time.sleep(3)
            if gv.use_pigpio:
                pi.write(pin_relay, 0)
            else:
                GPIO.output(pin_relay, GPIO.LOW)  # Turn relay off
        except Exception, e:
#            print "Relay plugin error: ", e
            pass
開發者ID:Dan-in-CA,項目名稱:sip_plugins,代碼行數:15,代碼來源:relay.py

示例12: get_check_pressure

def get_check_pressure():
    datapressure = get_pressure_options()
    try:
        if datapressure['normally'] != 'off':
            if GPIO.input(pin_pressure):  # pressure detected
                press = 1
            else:
                press = 0
        elif datapressure['normally'] != 'on':
            if not GPIO.input(pin_pressure):
                press = 1
            else:
                press = 0
        return press
    except NameError:
        pass
開發者ID:teodoryantcheff,項目名稱:OSPy,代碼行數:16,代碼來源:pressure_adj.py

示例13: get_pressure_sensor

def get_pressure_sensor():
    if GPIO.input(pin_pressure) != 1:
        press = ('Pressure sensor is not active.')  # sensor pin is connected to ground
    else:
        press = ('Pressure sensor is active - pressure in pipeline is OK.')  # sensor pin is unconnected

    return str(press)
開發者ID:Dan-in-CA,項目名稱:sip_plugins,代碼行數:7,代碼來源:pressure_adj.py

示例14: restart

def restart(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        try:
            GPIO.cleanup()
        except Exception:
            pass
        time.sleep(wait)
        try:
            print _('Restarting...')
        except Exception:
            pass
        subprocess.Popen('service ospi restart'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
開發者ID:ntc490,項目名稱:OSPi,代碼行數:18,代碼來源:helpers.py

示例15: run

    def run(self):
        time.sleep(randint(3, 10))  # Sleep some time to prevent printing before startup information
        print "Pressure plugin is active"
        send = False
        SUBJ = "Reporting from ospi"  # Subject in email
        self.add_status('Waiting...')

        while True:
            try:
                datapressure = get_pressure_options()                             # load data from file
                if datapressure['press'] != 'off':                                # if pressure plugin is enabled
                    if (gv.sd['mas'] != 0) and not (gv.sd['mm']):                   # if is use master station and not manual control
                        if gv.srvals[gv.sd['mas']] != 0:                              # if master station is ON
                            if GPIO.input(pin_pressure) == 0:                           # if sensor is open
                                self._sleep(int(datapressure['time']))                   # wait to activated pressure sensor
                                if GPIO.input(pin_pressure) == 0:                        # if sensor is current open
                                    stop_stations()
                                    self.add_status('Pressure sensor is not activated in time -> stops all stations and sends email.')
                                    if datapressure['sendeml'] != 'off':  # if enabled send email
                                        send = True

                    else:  # if not used master station
                        self.status = ''
                        self.add_status('Not used master station.')

                if send:
                    TEXT = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(
                        time.time())) + ' System detected error: pressure sensor.')
                    try:
                        from plugins.email_adj import email
                        email(SUBJ, TEXT)     # send email without attachments
                        self.add_status('Email was sent: ' + TEXT)
                        send = False
                    except Exception as err:
                        self.add_status('Email was not sent! ' + str(err))

                self._sleep(1)

            except Exception:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
                self.add_status('Pressure plugin encountered error: ' + err_string)
                self._sleep(60)
開發者ID:Dan-in-CA,項目名稱:sip_plugins,代碼行數:43,代碼來源:pressure_adj.py


注:本文中的gpio_pins.GPIO類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。