diff --git a/.idea/für Robotototo.iml b/.idea/für Robotototo.iml new file mode 100644 index 0000000..2be6dbc --- /dev/null +++ b/.idea/für Robotototo.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/install.sh b/install.sh index af6a0dd..531fe66 100644 --- a/install.sh +++ b/install.sh @@ -3,8 +3,8 @@ sudo apt update sudo apt upgrade sudo apt dist-upgrade sudo pip3 install pygame -sudo apt install python-smbus -sudo apt install i2c-tools +sudo apt-get install -y python-smbus +sudo apt-get install -y i2c-tools sudo pip install adafruit-pca9685 sudo apt install vsftpd sudo apt install vlc diff --git a/lib/controllib.py b/lib/controllib.py index 781b53b..cc88d4d 100644 --- a/lib/controllib.py +++ b/lib/controllib.py @@ -3,7 +3,6 @@ import pygame class Joystick(): - def __init__(self, navigator, light, configuration, camera): # joystick pygame.joystick.init() @@ -40,13 +39,13 @@ class Joystick(): 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 i 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 i 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 i not in self.pressed: if self.splaying: self.sound.stop() self.splaying = False @@ -54,25 +53,25 @@ 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 i in self.pressed: self.pressed.remove(i) - elif i == c['VOLIN'] and button == 1 and button not in self.pressed: + elif i == c['VOLIN'] and button == 1 and i 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 i 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 i 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 i 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 i 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 i in self.pressed: self.pressed.remove(i) # hats @@ -91,6 +90,7 @@ class Joystick(): return dict def _save_camimg(self): + self.camera.new_frame() img = self.camera.image if os.path.isfile('image.jpg'): count = 0 diff --git a/lib/graphiclib.py b/lib/graphiclib.py index 6c5ebb5..5a2bf80 100644 --- a/lib/graphiclib.py +++ b/lib/graphiclib.py @@ -1,5 +1,6 @@ -import pygame -import pygame.camera +import pygame, pygame.camera +import picamera +import picamera.array from pygame import * @@ -54,6 +55,7 @@ class List(pygame.sprite.Sprite): def update(self): if self.updated: height = 0 + self.image.fill((0, 0, 0)) for key in self.dict.keys(): line = '{}: {}'.format(key, self.dict[key]) @@ -69,14 +71,22 @@ class PiCamera(pygame.sprite.Sprite): def __init__(self, position, size): pygame.sprite.Sprite.__init__(self) pygame.camera.init() - cam_list = pygame.camera.list_cameras() - camera = pygame.camera.Camera(cam_list[0], size) + camera = picamera.PiCamera() + self.camsize = (size[0], int(size[0]/2)) + camera.resolution = self.camsize self.camera = camera + self.output = picamera.array.PiRGBArray(camera, size=self.camsize) self.size = size self.image = pygame.Surface(self.size) self.image.fill((0, 0, 0)) self.rect = self.image.get_rect() self.rect.topleft = position - def update(self): - self.camera.get_image(self.image) + def update(self, *args): + pass + + def new_frame(self): + self.output.truncate(0) + self.camera.capture(self.output, 'rgb', resize=self.camsize) + s = pygame.transform.rotate(pygame.surfarray.make_surface(self.output.array), 270) + self.image.blit(s, (0, 0)) \ No newline at end of file diff --git a/lib/hardwarelib.py b/lib/hardwarelib.py index 557ab56..f836b20 100644 --- a/lib/hardwarelib.py +++ b/lib/hardwarelib.py @@ -1,6 +1,7 @@ from subprocess import call, check_output from lib import ultrasonic import RPi.GPIO as GPIO +import time class Navigator(): @@ -44,6 +45,7 @@ class Light: self.shine = False def switch(self): + print('light switch {}'.format(self.shine)) GPIO.output(self.pin, not self.shine) self.shine = not self.shine @@ -60,10 +62,14 @@ class Ultrasonic: def __init__(self, trigger, echo): self.sensor = ultrasonic.Sensor() self.sensor.init(trigger, echo) + self.time = 0 + self.distance = 0 def get_distance(self): - distance = self.sensor.echo() - return distance + if (time.time()-self.time)>1: + self.distance = self.sensor.echo() + self.time = time.time() + return self.distance def __del__(self): self.sensor.clean() diff --git a/main.py b/main.py index fbce7bf..cba0e56 100644 --- a/main.py +++ b/main.py @@ -31,12 +31,15 @@ def main(): running = True while running: + clock.tick(25) for event in pygame.event.get(): if event.type == pygame.QUIT: + print('quit event') running = False dict = jstick.handle() + dict['Distance'] = ultrasonic.get_distance() list.set_dict(dict) all_sprites.update() update_rects = all_sprites.draw(screen.screen) diff --git a/sounds/gasgasgas.mp3 b/sounds/gasgasgas.mp3 new file mode 100644 index 0000000..b63cd47 Binary files /dev/null and b/sounds/gasgasgas.mp3 differ diff --git a/update.sh b/update.sh index fb4ab47..7b72112 100644 --- a/update.sh +++ b/update.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash cd .. if [ -d "spydian/" ];then - sudo git clone https://bitbucket.org/trivernis/spydian.git spydian_update + sudo git clone -b develop https://trivernis@bitbucket.org/trivernis/spydian.git spydian_update sudo rsync -a ./spydian_update/ ./spydian/ sudo rm -r ./spydian_update/ sudo chmod -R u+rw ./spydian/