本文整理汇总了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
示例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
示例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()
示例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()
示例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()
示例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
示例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)
示例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
示例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
示例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()
示例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
示例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
示例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)
示例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()
示例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)