diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 696ff08..c0c25ee 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,8 @@ + + @@ -321,14 +336,6 @@ - - - - - - - - @@ -496,10 +503,20 @@ + + + + + + + + + + - - + + @@ -508,7 +525,7 @@ - + @@ -518,8 +535,8 @@ - - + + diff --git a/lib/controllib.py b/lib/controllib.py index 169a406..7268a88 100644 --- a/lib/controllib.py +++ b/lib/controllib.py @@ -1,13 +1,13 @@ import pygame, os -class Joystick(): +class Joystick(): def __init__(self, navigator, light, configuration, camera): - #joystick + # joystick pygame.joystick.init() joystick = pygame.joystick.Joystick(0) joystick.init() - #sound + # sound pygame.mixer.init() sound = pygame.mixer.Sound('./sounds/gasgasgas.wav') sound.set_volume(0.3) @@ -24,27 +24,27 @@ class Joystick(): c = self.configuration nav = self.navigator dict = {} - #axes + # axes for i in range(self.joystick.get_numaxes()): axis = self.joystick.get_axis(i) - dict['Axis {}'.format(i)]=axis + dict['Axis {}'.format(i)] = axis - if i==c['GAS'] and axis>0.1: + if i == c['GAS'] and axis > 0.1: nav.forward() - elif i==c['GAS'] and axis<0.1: + elif i == c['GAS'] and axis < 0.1: nav.stop() - #buttons + # buttons for i in range(self.joystick.get_numbuttons()): button = self.joystick.get_button(i) dict['Button {}'.format(i)] = button - if i==c['LIGHT'] and button==1 and button not in self.pressed: + if i == c['LIGHT'] and button == 1 and button not in self.pressed: self.light.switch() self.pressed.append(i) - elif i==c['LIGHT'] and button==0 and button in self.pressed: + elif i == c['LIGHT'] and button == 0 and button in self.pressed: self.pressed.remove(i) - elif i==c['MUSIC'] and button==1 and button not in self.pressed: + elif i == c['MUSIC'] and button == 1 and button not in self.pressed: if self.splaying: self.sound.stop() self.splaying = False @@ -52,35 +52,35 @@ class Joystick(): self.sound.play() self.splaying = True self.pressed.append(i) - elif i==c['MUSIC'] and button==0 and button in self.pressed: + elif i == c['MUSIC'] and button == 0 and button in self.pressed: self.pressed.remove(i) - elif i==c['VOLIN'] and button==1 and button not in self.pressed: - self.sound.set_volume(self.sound.get_volume()+0.1) + elif i == c['VOLIN'] and button == 1 and button not in self.pressed: + self.sound.set_volume(self.sound.get_volume() + 0.1) self.pressed.append(i) - elif i==c['VOLIN'] and button==0 and button in self.pressed: + elif i == c['VOLIN'] and button == 0 and button in self.pressed: self.sound.set_volume(self.sound.get_volume() - 0.1) self.pressed.remove(i) - elif i==c['VOLDE'] and button==1 and button not in self.pressed: + elif i == c['VOLDE'] and button == 1 and button not in self.pressed: self.pressed.append(i) - elif i==c['VOLDE'] and button==0 and button in self.pressed: + elif i == c['VOLDE'] and button == 0 and button in self.pressed: self.pressed.remove(i) - elif i==c['REC'] and button==1 and button not in self.pressed: + elif i == c['REC'] and button == 1 and button not in self.pressed: self._save_camimg() self.pressed.append(i) - elif i==c['REC'] and button==0 and button in self.pressed: + elif i == c['REC'] and button == 0 and button in self.pressed: self.pressed.remove(i) - #hats + # hats for i in range(self.joystick.get_numhats()): hat = self.joystick.get_hat(i) dict['Hat {}'.format(i)] = hat - if hat==(-1,0): + if hat == (-1, 0): nav.left() - elif hat==(1,0): + elif hat == (1, 0): nav.right() else: nav.straight() @@ -88,13 +88,12 @@ class Joystick(): dict['Volume'] = self.sound.get_volume() return dict - def _save_camimg(self): self.camera.new_frame() img = self.camera.image if os.path.isfile('image.jpg'): - count=0 + count = 0 while os.path.isfile('./images/img{}.jpg'.format(count)): - count+=1 + count += 1 os.rename('image.jpg', 'images/img{}.jpg'.format(count)) - pygame.image.save(img, 'image.jpg') \ No newline at end of file + pygame.image.save(img, 'image.jpg') diff --git a/lib/hardwarelib.py b/lib/hardwarelib.py index 513b06f..51abee8 100644 --- a/lib/hardwarelib.py +++ b/lib/hardwarelib.py @@ -2,6 +2,7 @@ from subprocess import call, check_output from lib import ultrasonic import RPi.GPIO as GPIO + class Navigator(): """Forward Motor with relais, Steering with servo""" @@ -11,29 +12,24 @@ class Navigator(): GPIO.setup(self.mrelpin, GPIO.OUT) self.stop() - def left(self): if self.steer != 'left': call(['python', './lib/servolib.py', 'left']) self.steer = 'left' - def right(self): if self.steer != 'right': call(['python', './lib/servolib.py', 'right']) self.steer = 'right' - def straight(self): if self.steer: call(['python', './lib/servolib.py']) self.steer = None - def forward(self): GPIO.output(self.mrelpin, False) - def stop(self): GPIO.output(self.mrelpin, True) @@ -47,16 +43,14 @@ class Light: GPIO.output(self.pin, True) self.shine = False - def switch(self): + print('light switch {}'.format(self.shine)) GPIO.output(self.pin, not self.shine) self.shine = not self.shine - def switch_on(self): GPIO.output(self.pin, False) - def switch_of(self): GPIO.output(self.pin, True) @@ -65,15 +59,13 @@ class Ultrasonic: """A ultrasonic sensor""" def __init__(self, trigger, echo): - self.sensor =ultrasonic.Sensor() + self.sensor = ultrasonic.Sensor() self.sensor.init(trigger, echo) - def get_distance(self): distance = self.sensor.echo() return distance - def __del__(self): self.sensor.clean() @@ -82,12 +74,11 @@ class Temperature: """A temperature sensor""" def get_Temperature(self): - outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1') + outp = check_output(['python', '-u', './lib/thermolib.py']).decode('ISO-8859-1') temp, hum = outp.split('|') return temp - def get_Humidity(self): - outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1') + outp = check_output(['python', '-u', './lib/thermolib.py']).decode('ISO-8859-1') temp, hum = outp.split('|') - return hum \ No newline at end of file + return hum diff --git a/main.py b/main.py index 81d4c25..5a3196f 100644 --- a/main.py +++ b/main.py @@ -36,15 +36,10 @@ def main(): running = False dict = jstick.handle() - print('joystick handled') list.set_dict(dict) - print('list has dict') all_sprites.update() - print('updating sprites') update_rects = all_sprites.draw(screen.screen) - print('drawing sprites') screen.refresh(rectangles= update_rects) - print('refreshing screen') pygame.quit()