import helpers # platform-specific imports if helpers.is_running_on_rpi():# running on Raspberry Pi import RPi.GPIO as GPIO print "freesprints.hardware using Rpi.GPIO" else: # running on computer import FakeRPiGPIO.GPIO as GPIO print "freesprints.hardware using FakeRpiGPIO.GPIO" roller_controller = None def get_roller_controller(): global roller_controller if roller_controller == None: roller_controller = RollerController() return roller_controller class Roller(object): pin = None # board number number = None spin_count = 0 spin_callback = None diameter = 300 def __init__(self, pin): self.pin = pin GPIO.setup(pin, GPIO.IN)
def start(self): # set up pygame pygame.init() pygame.font.init() if helpers.is_running_on_rpi(): disp_no = os.getenv("DISPLAY") if disp_no: print "I'm running under X display = {0}".format(disp_no) # Check which frame buffer drivers are available # Start with fbcon since directfb hangs with composite output drivers = ['fbcon', 'directfb', 'svgalib'] found = False for driver in drivers: # Make sure that SDL_VIDEODRIVER is set if not os.getenv('SDL_VIDEODRIVER'): os.putenv('SDL_VIDEODRIVER', driver) try: pygame.display.init() except pygame.error: print 'Driver: {0} failed.'.format(driver) continue found = True break if not found: raise Exception('No suitable video driver found!') size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print "Framebuffer size: %d x %d" % (size[0], size[1]) #self.window_surface = pygame.display.set_mode(size, pygame.FULLSCREEN) # set up the window pygame.display.set_caption('Freesprints') # set up the colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) # set up fonts #availableFonts = pygame.font.get_fonts() font_path = "./fonts/Cave-Story.ttf" #basicFont = pygame.font.SysFont(None, 30) basicFont = pygame.font.Font(font_path, 48) # set up the text #text = basicFont.render('asdasd', True, WHITE, BLUE) #textRect = text.get_rect() #textRect.centerx = self.window_surface.get_rect().centerx #textRect.centery = self.window_surface.get_rect().centery # draw the white background onto the surface self.window_surface.fill(BLACK) # draw a green polygon onto the surface #pygame.draw.polygon(self.window_surface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))) # draw some blue lines onto the surface #pygame.draw.line(self.window_surface, BLUE, (60, 60), (120, 60), 4) #pygame.draw.line(self.window_surface, BLUE, (120, 60), (60, 120)) #pygame.draw.line(self.window_surface, BLUE, (60, 120), (120, 120), 4) # draw a blue circle onto the surface #pygame.draw.circle(self.window_surface, BLUE, (300, 50), 20, 0) # draw a red ellipse onto the surface #pygame.draw.ellipse(self.window_surface, RED, (450, 160, 40, 80), 1) # menu background background = pygame.image.load('images/menu_background.png').convert() backgroundRect = background.get_rect() backgroundRect.x = 0 backgroundRect.y = 0 self.window_surface.blit(background, backgroundRect) # draw the window onto the screen pygame.display.update() self.menu.render() self.game_loop()