Merge remote-tracking branch 'origin/develop' into develop

pull/1/head
Trivernis 6 years ago
commit 66379ea24d

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6 (spydian)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -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

@ -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

@ -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))

@ -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()

@ -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)

Binary file not shown.

@ -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/

Loading…
Cancel
Save