GPIO is now enabled on demand
This commit is contained in:
@@ -10,7 +10,12 @@ from sys import exit
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
#import RPi.GPIO as GPIO
|
|
||||||
|
try:
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
gpio_enabled = True
|
||||||
|
except ImportError:
|
||||||
|
gpio_enabled = False
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
### Configuration ###
|
### Configuration ###
|
||||||
@@ -79,7 +84,6 @@ class GUI_PyGame:
|
|||||||
pygame.display.set_caption(name)
|
pygame.display.set_caption(name)
|
||||||
# Hide mouse cursor
|
# Hide mouse cursor
|
||||||
pygame.mouse.set_cursor(*pygame.cursors.load_xbm('transparent.xbm','transparent.msk'))
|
pygame.mouse.set_cursor(*pygame.cursors.load_xbm('transparent.xbm','transparent.msk'))
|
||||||
#pygame.mouse.set_visible(False)
|
|
||||||
# Store screen and size
|
# Store screen and size
|
||||||
self.size = size
|
self.size = size
|
||||||
self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN)
|
self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN)
|
||||||
@@ -187,6 +191,7 @@ class Camera:
|
|||||||
#################
|
#################
|
||||||
|
|
||||||
def take_picture():
|
def take_picture():
|
||||||
|
"""Implements the picture taking routine"""
|
||||||
display.clear()
|
display.clear()
|
||||||
# Show pose message
|
# Show pose message
|
||||||
display.show_picture(image_pose)
|
display.show_picture(image_pose)
|
||||||
@@ -243,23 +248,29 @@ def handle_exception(msg):
|
|||||||
sleep(3)
|
sleep(3)
|
||||||
|
|
||||||
def setup_gpio():
|
def setup_gpio():
|
||||||
# Display initial information
|
"""Enables GPIO in- and output and registers event handles"""
|
||||||
print "Your Raspberry Pi is board revision " + str(GPIO.RPI_INFO['P1_REVISION'])
|
if gpio_enabled:
|
||||||
print "RPi.GPIO version is " + str(GPIO.VERSION)
|
# Display initial information
|
||||||
# Choose BCM numbering system
|
print("Your Raspberry Pi is board revision " + str(GPIO.RPI_INFO['P1_REVISION']))
|
||||||
GPIO.setmode(GPIO.BCM)
|
print("RPi.GPIO version is " + str(GPIO.VERSION))
|
||||||
# Setup the trigger channel as input and listen for events
|
# Choose BCM numbering system
|
||||||
GPIO.setup(gpio_trigger_channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.add_event_detect(gpio_trigger_channel, GPIO.RISING,
|
# Setup the trigger channel as input and listen for events
|
||||||
callback=handle_gpio_event, bouncetime=200)
|
GPIO.setup(gpio_trigger_channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
GPIO.add_event_detect(gpio_trigger_channel, GPIO.RISING,
|
||||||
|
callback=handle_gpio_event, bouncetime=200)
|
||||||
|
else:
|
||||||
|
print("Warning: RPi.GPIO could not be loaded. GPIO disabled.")
|
||||||
|
|
||||||
|
|
||||||
def teardown(exit_code=0):
|
def teardown(exit_code=0):
|
||||||
display.teardown()
|
display.teardown()
|
||||||
#GPIO.cleanup()
|
if gpio_enabled:
|
||||||
|
GPIO.cleanup()
|
||||||
exit(exit_code)
|
exit(exit_code)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
#setup_gpio()
|
setup_gpio()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
display.mainloop(image_idle)
|
display.mainloop(image_idle)
|
||||||
|
|||||||
Reference in New Issue
Block a user