From f65345ab0bcc3472f84ed99c13cb60b00f9bcbd8 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 4 Dec 2018 10:56:16 +0100 Subject: [PATCH] Quality Improvements - split a function into two for less complexity - removed wildcard import --- lib/controllib.py | 30 ++++++++++++++++-------------- lib/graphiclib.py | 3 +-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/controllib.py b/lib/controllib.py index a8eb98e..d47614d 100644 --- a/lib/controllib.py +++ b/lib/controllib.py @@ -21,20 +21,7 @@ class Joystick: self.pressed = [] self.splaying = False - def handle(self): - c = self.configuration - nav = self.navigator - axis_dict = {} - # axes - for i in range(self.joystick.get_numaxes()): - axis = self.joystick.get_axis(i) - axis_dict['Axis {}'.format(i)] = axis - - if i == c['GAS'] and axis > 0.1: - nav.forward() - elif i == c['GAS'] and axis < 0.1: - nav.stop() - # buttons + def _handle_buttons(self, axis_dict, c): for i in range(self.joystick.get_numbuttons()): button = self.joystick.get_button(i) axis_dict['Button {}'.format(i)] = button @@ -73,7 +60,22 @@ class Joystick: self.pressed.append(i) elif i == c['REC'] and button == 0 and i in self.pressed: self.pressed.remove(i) + return axis_dict + def handle(self): + c = self.configuration + nav = self.navigator + axis_dict = {} + # axes + for i in range(self.joystick.get_numaxes()): + axis = self.joystick.get_axis(i) + axis_dict['Axis {}'.format(i)] = axis + + if i == c['GAS'] and axis > 0.1: + nav.forward() + elif i == c['GAS'] and axis < 0.1: + nav.stop() + axis_dict = self._handle_buttons(axis_dict, c) # hats for i in range(self.joystick.get_numhats()): hat = self.joystick.get_hat(i) diff --git a/lib/graphiclib.py b/lib/graphiclib.py index 12d7af0..6b6238b 100644 --- a/lib/graphiclib.py +++ b/lib/graphiclib.py @@ -2,7 +2,6 @@ import picamera import picamera.array import pygame import pygame.camera -from pygame import * def render_text_line(rimage, rcolor, rfont, text, pos=(0, 0)): @@ -31,7 +30,7 @@ class Screen: else: displayinfo = pygame.display.Info() fullsize = (displayinfo.current_w, displayinfo.current_h) - pygame.display.set_mode(fullsize, FULLSCREEN | DOUBLEBUF) + pygame.display.set_mode(fullsize, pygame.FULLSCREEN | pygame.DOUBLEBUF) class List(pygame.sprite.Sprite):